Skip to content

Commit

Permalink
test: dashboard ct failed with lack i18n_lang
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwencool committed Apr 15, 2022
1 parent 700c2cf commit 164754b
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 100 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ get-dashboard:
@$(SCRIPTS)/get-dashboard.sh

.PHONY: eunit
eunit: $(REBAR)
eunit: $(REBAR) conf-segs
@ENABLE_COVER_COMPILE=1 $(REBAR) eunit -v -c

.PHONY: proper
Expand Down
103 changes: 51 additions & 52 deletions apps/emqx_auto_subscribe/test/emqx_auto_subscribe_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@

-define(TOPICS, [?TOPIC_C, ?TOPIC_U, ?TOPIC_H, ?TOPIC_P, ?TOPIC_A, ?TOPIC_S]).

-define(ENSURE_TOPICS , [<<"/c/auto_sub_c">>
, <<"/u/auto_sub_u">>
, ?TOPIC_S]).
-define(ENSURE_TOPICS, [
<<"/c/auto_sub_c">>,
<<"/u/auto_sub_u">>,
?TOPIC_S
]).

-define(CLIENT_ID, <<"auto_sub_c">>).
-define(CLIENT_USERNAME, <<"auto_sub_u">>).
Expand All @@ -45,71 +47,69 @@ init_per_suite(Config) ->
mria:start(),
application:stop(?APP),
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, fields, fun("auto_subscribe") ->
meck:passthrough(["auto_subscribe"]) ++
emqx_auto_subscribe_schema:fields("auto_subscribe");
(F) -> meck:passthrough([F])
end),
meck:expect(emqx_schema, fields, fun
("auto_subscribe") ->
meck:passthrough(["auto_subscribe"]) ++
emqx_auto_subscribe_schema:fields("auto_subscribe");
(F) ->
meck:passthrough([F])
end),

meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
meck:expect(emqx_resource, update, fun(_, _, _, _) -> {ok, meck_data} end),
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
meck:expect(emqx_resource, remove, fun(_) -> ok end),

application:load(emqx_dashboard),
application:load(?APP),
ok = emqx_common_test_helpers:load_config(emqx_auto_subscribe_schema,
<<"auto_subscribe {
topics = [
{
topic = \"/c/${clientid}\"
},
{
topic = \"/u/${username}\"
},
{
topic = \"/h/${host}\"
},
{
topic = \"/p/${port}\"
},
{
topic = \"/client/${clientid}/username/${username}/host/${host}/port/${port}\"
},
{
topic = \"/topic/simple\"
qos = 1
rh = 0
rap = 0
nl = 0
}
]
}">>),
emqx_common_test_helpers:start_apps([emqx_conf, emqx_dashboard, ?APP],
fun set_special_configs/1),
ok = emqx_common_test_helpers:load_config(
emqx_auto_subscribe_schema,
<<"auto_subscribe {\n"
" topics = [\n"
" {\n"
" topic = \"/c/${clientid}\"\n"
" },\n"
" {\n"
" topic = \"/u/${username}\"\n"
" },\n"
" {\n"
" topic = \"/h/${host}\"\n"
" },\n"
" {\n"
" topic = \"/p/${port}\"\n"
" },\n"
" {\n"
" topic = \"/client/${clientid}/username/${username}/host/${host}/port/${port}\"\n"
" },\n"
" {\n"
" topic = \"/topic/simple\"\n"
" qos = 1\n"
" rh = 0\n"
" rap = 0\n"
" nl = 0\n"
" }\n"
" ]\n"
" }">>
),
emqx_common_test_helpers:start_apps(
[emqx_conf, emqx_dashboard, ?APP],
fun set_special_configs/1
),
Config.

set_special_configs(emqx_dashboard) ->
Config = #{
default_username => <<"admin">>,
default_password => <<"public">>,
listeners => [#{
protocol => http,
port => 18083
}]
},
emqx_config:put([emqx_dashboard], Config),
emqx_dashboard_api_test_helpers:set_default_config(),
ok;
set_special_configs(_) ->
ok.

topic_config(T) ->
#{
topic => T,
qos => 0,
rh => 0,
rap => 0,
nl => 0
qos => 0,
rh => 0,
rap => 0,
nl => 0
}.

end_per_suite(_) ->
Expand Down Expand Up @@ -148,7 +148,6 @@ t_update(_) ->
?assertEqual(1, erlang:length(GETResponseMap)),
ok.


check_subs(Count) ->
Subs = ets:tab2list(emqx_suboption),
ct:pal("---> ~p ~p ~n", [Subs, Count]),
Expand Down
3 changes: 2 additions & 1 deletion apps/emqx_conf/test/emqx_conf_schema_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
doc_gen_test() ->
Dir = "tmp",
ok = filelib:ensure_dir(filename:join("tmp", foo)),
_ = emqx_conf:dump_schema(Dir),
I18nFile = filename:join(["_build", "test", "lib", "emqx_dashboard", "etc", "i18n.conf.all"]),
_ = emqx_conf:dump_schema(Dir, emqx_conf_schema, I18nFile),
ok.
10 changes: 8 additions & 2 deletions apps/emqx_dashboard/src/emqx_dashboard.erl
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ ip_port({Port, Opts}, _) when is_integer(Port) -> {Opts#{port => Port}, Port};
ip_port({{IP, Port}, Opts}, _) -> {Opts#{port => Port, ip => IP}, {IP, Port}}.

init_i18n() ->
File = emqx:etc_file("i18n.conf"),
Lang = emqx_conf:get([dashboard, i18n_lang]),
File = i18n_file(),
Lang = emqx_conf:get([dashboard, i18n_lang], en),
init_i18n(File, Lang).

ranch_opts(RanchOptions) ->
Expand Down Expand Up @@ -267,3 +267,9 @@ return_unauthorized(Code, Message) ->
<<"Basic Realm=\"minirest-server\"">>
},
#{code => Code, message => Message}}.

i18n_file() ->
case application:get_env(emqx_dashboard, i18n_file) of
undefined -> emqx:etc_file("i18n.conf");
{ok, File} -> File
end.
7 changes: 1 addition & 6 deletions apps/emqx_dashboard/test/emqx_dashboard_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ set_special_configs(emqx_management) ->
emqx_config:put([emqx_management], Config),
ok;
set_special_configs(emqx_dashboard) ->
Listeners = [#{protocol => http, port => 18083}],
Config = #{listeners => Listeners,
default_username => <<"admin">>,
default_password => <<"public">>
},
emqx_config:put([dashboard], Config),
emqx_dashboard_api_test_helpers:set_default_config(),
ok;
set_special_configs(_) ->
ok.
Expand Down
9 changes: 8 additions & 1 deletion apps/emqx_dashboard/test/emqx_dashboard_api_test_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ set_default_config(DefaultUsername) ->
Config = #{listeners => [#{protocol => http,
port => 18083}],
default_username => DefaultUsername,
default_password => <<"public">>
default_password => <<"public">>,
i18n_lang => en
},
emqx_config:put([dashboard], Config),
I18nFile = filename:join([
filename:dirname(code:priv_dir(emqx_dashboard)),
"etc",
"i18n.conf.all"
]),
application:set_env(emqx_dashboard, i18n_file, I18nFile),
ok.

request(Method, Url) ->
Expand Down
10 changes: 1 addition & 9 deletions apps/emqx_dashboard/test/emqx_dashboard_bad_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@ init_per_suite(Config) ->
Config.

set_special_configs(emqx_dashboard) ->
Config = #{
default_username => <<"admin">>,
default_password => <<"public">>,
listeners => [#{
protocol => http,
port => 18083
}]
},
emqx_config:put([emqx_dashboard], Config),
emqx_dashboard_api_test_helpers:set_default_config(),
ok;
set_special_configs(_) ->
ok.
Expand Down
10 changes: 1 addition & 9 deletions apps/emqx_dashboard/test/emqx_dashboard_error_code_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@ init_per_suite(Config) ->
Config.

set_special_configs(emqx_dashboard) ->
Config = #{
default_username => <<"admin">>,
default_password => <<"public">>,
listeners => [#{
protocol => http,
port => 18083
}]
},
emqx_config:put([emqx_dashboard], Config),
emqx_dashboard_api_test_helpers:set_default_config(),
ok;
set_special_configs(_) ->
ok.
Expand Down
10 changes: 1 addition & 9 deletions apps/emqx_dashboard/test/emqx_dashboard_monitor_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,7 @@ end_per_suite(Config) ->
Config.

set_special_configs(emqx_dashboard) ->
Config = #{
default_username => <<"admin">>,
default_password => <<"public">>,
listeners => [#{
protocol => http,
port => 18083
}]
},
emqx_config:put([dashboard], Config),
emqx_dashboard_api_test_helpers:set_default_config(),
ok;
set_special_configs(_) ->
ok.
Expand Down
10 changes: 1 addition & 9 deletions apps/emqx_management/test/emqx_mgmt_api_test_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@ end_suite(Apps) ->
ok.

set_special_configs(emqx_dashboard) ->
Config = #{
default_username => <<"admin">>,
default_password => <<"public">>,
listeners => [#{
protocol => http,
port => 18083
}]
},
emqx_config:put([dashboard], Config),
emqx_dashboard_api_test_helpers:set_default_config(),
ok;
set_special_configs(_App) ->
ok.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
doc_gen_test() ->
Dir = "tmp",
ok = filelib:ensure_dir(filename:join("tmp", foo)),
_ = emqx_conf:dump_schema(Dir, emqx_enterprise_conf_schema),
I18nFile = filename:join(["_build", "test", "lib", "emqx_dashboard", "etc", "i18n.conf.all"]),
_ = emqx_conf:dump_schema(Dir, emqx_enterprise_conf_schema, I18nFile),
ok.

0 comments on commit 164754b

Please sign in to comment.