test: dashboard ct failed with lack i18n_lang
This commit is contained in:
parent
700c2cfb39
commit
164754b182
2
Makefile
2
Makefile
|
@ -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
|
||||
|
|
|
@ -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">>).
|
||||
|
@ -45,60 +47,58 @@ 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.
|
||||
|
@ -106,10 +106,10 @@ set_special_configs(_) ->
|
|||
topic_config(T) ->
|
||||
#{
|
||||
topic => T,
|
||||
qos => 0,
|
||||
rh => 0,
|
||||
rap => 0,
|
||||
nl => 0
|
||||
qos => 0,
|
||||
rh => 0,
|
||||
rap => 0,
|
||||
nl => 0
|
||||
}.
|
||||
|
||||
end_per_suite(_) ->
|
||||
|
@ -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]),
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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) ->
|
||||
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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) ->
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue