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
|
@$(SCRIPTS)/get-dashboard.sh
|
||||||
|
|
||||||
.PHONY: eunit
|
.PHONY: eunit
|
||||||
eunit: $(REBAR)
|
eunit: $(REBAR) conf-segs
|
||||||
@ENABLE_COVER_COMPILE=1 $(REBAR) eunit -v -c
|
@ENABLE_COVER_COMPILE=1 $(REBAR) eunit -v -c
|
||||||
|
|
||||||
.PHONY: proper
|
.PHONY: proper
|
||||||
|
|
|
@ -31,9 +31,11 @@
|
||||||
|
|
||||||
-define(TOPICS, [?TOPIC_C, ?TOPIC_U, ?TOPIC_H, ?TOPIC_P, ?TOPIC_A, ?TOPIC_S]).
|
-define(TOPICS, [?TOPIC_C, ?TOPIC_U, ?TOPIC_H, ?TOPIC_P, ?TOPIC_A, ?TOPIC_S]).
|
||||||
|
|
||||||
-define(ENSURE_TOPICS , [<<"/c/auto_sub_c">>
|
-define(ENSURE_TOPICS, [
|
||||||
, <<"/u/auto_sub_u">>
|
<<"/c/auto_sub_c">>,
|
||||||
, ?TOPIC_S]).
|
<<"/u/auto_sub_u">>,
|
||||||
|
?TOPIC_S
|
||||||
|
]).
|
||||||
|
|
||||||
-define(CLIENT_ID, <<"auto_sub_c">>).
|
-define(CLIENT_ID, <<"auto_sub_c">>).
|
||||||
-define(CLIENT_USERNAME, <<"auto_sub_u">>).
|
-define(CLIENT_USERNAME, <<"auto_sub_u">>).
|
||||||
|
@ -45,60 +47,58 @@ init_per_suite(Config) ->
|
||||||
mria:start(),
|
mria:start(),
|
||||||
application:stop(?APP),
|
application:stop(?APP),
|
||||||
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_schema, fields, fun("auto_subscribe") ->
|
meck:expect(emqx_schema, fields, fun
|
||||||
|
("auto_subscribe") ->
|
||||||
meck:passthrough(["auto_subscribe"]) ++
|
meck:passthrough(["auto_subscribe"]) ++
|
||||||
emqx_auto_subscribe_schema:fields("auto_subscribe");
|
emqx_auto_subscribe_schema:fields("auto_subscribe");
|
||||||
(F) -> meck:passthrough([F])
|
(F) ->
|
||||||
|
meck:passthrough([F])
|
||||||
end),
|
end),
|
||||||
|
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
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, create, fun(_, _, _) -> {ok, meck_data} end),
|
||||||
meck:expect(emqx_resource, update, 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(emqx_dashboard),
|
||||||
application:load(?APP),
|
application:load(?APP),
|
||||||
ok = emqx_common_test_helpers:load_config(emqx_auto_subscribe_schema,
|
ok = emqx_common_test_helpers:load_config(
|
||||||
<<"auto_subscribe {
|
emqx_auto_subscribe_schema,
|
||||||
topics = [
|
<<"auto_subscribe {\n"
|
||||||
{
|
" topics = [\n"
|
||||||
topic = \"/c/${clientid}\"
|
" {\n"
|
||||||
},
|
" topic = \"/c/${clientid}\"\n"
|
||||||
{
|
" },\n"
|
||||||
topic = \"/u/${username}\"
|
" {\n"
|
||||||
},
|
" topic = \"/u/${username}\"\n"
|
||||||
{
|
" },\n"
|
||||||
topic = \"/h/${host}\"
|
" {\n"
|
||||||
},
|
" topic = \"/h/${host}\"\n"
|
||||||
{
|
" },\n"
|
||||||
topic = \"/p/${port}\"
|
" {\n"
|
||||||
},
|
" topic = \"/p/${port}\"\n"
|
||||||
{
|
" },\n"
|
||||||
topic = \"/client/${clientid}/username/${username}/host/${host}/port/${port}\"
|
" {\n"
|
||||||
},
|
" topic = \"/client/${clientid}/username/${username}/host/${host}/port/${port}\"\n"
|
||||||
{
|
" },\n"
|
||||||
topic = \"/topic/simple\"
|
" {\n"
|
||||||
qos = 1
|
" topic = \"/topic/simple\"\n"
|
||||||
rh = 0
|
" qos = 1\n"
|
||||||
rap = 0
|
" rh = 0\n"
|
||||||
nl = 0
|
" rap = 0\n"
|
||||||
}
|
" nl = 0\n"
|
||||||
]
|
" }\n"
|
||||||
}">>),
|
" ]\n"
|
||||||
emqx_common_test_helpers:start_apps([emqx_conf, emqx_dashboard, ?APP],
|
" }">>
|
||||||
fun set_special_configs/1),
|
),
|
||||||
|
emqx_common_test_helpers:start_apps(
|
||||||
|
[emqx_conf, emqx_dashboard, ?APP],
|
||||||
|
fun set_special_configs/1
|
||||||
|
),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
set_special_configs(emqx_dashboard) ->
|
set_special_configs(emqx_dashboard) ->
|
||||||
Config = #{
|
emqx_dashboard_api_test_helpers:set_default_config(),
|
||||||
default_username => <<"admin">>,
|
|
||||||
default_password => <<"public">>,
|
|
||||||
listeners => [#{
|
|
||||||
protocol => http,
|
|
||||||
port => 18083
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
emqx_config:put([emqx_dashboard], Config),
|
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(_) ->
|
set_special_configs(_) ->
|
||||||
ok.
|
ok.
|
||||||
|
@ -148,7 +148,6 @@ t_update(_) ->
|
||||||
?assertEqual(1, erlang:length(GETResponseMap)),
|
?assertEqual(1, erlang:length(GETResponseMap)),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
||||||
check_subs(Count) ->
|
check_subs(Count) ->
|
||||||
Subs = ets:tab2list(emqx_suboption),
|
Subs = ets:tab2list(emqx_suboption),
|
||||||
ct:pal("---> ~p ~p ~n", [Subs, Count]),
|
ct:pal("---> ~p ~p ~n", [Subs, Count]),
|
||||||
|
|
|
@ -9,5 +9,6 @@
|
||||||
doc_gen_test() ->
|
doc_gen_test() ->
|
||||||
Dir = "tmp",
|
Dir = "tmp",
|
||||||
ok = filelib:ensure_dir(filename:join("tmp", foo)),
|
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.
|
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}}.
|
ip_port({{IP, Port}, Opts}, _) -> {Opts#{port => Port, ip => IP}, {IP, Port}}.
|
||||||
|
|
||||||
init_i18n() ->
|
init_i18n() ->
|
||||||
File = emqx:etc_file("i18n.conf"),
|
File = i18n_file(),
|
||||||
Lang = emqx_conf:get([dashboard, i18n_lang]),
|
Lang = emqx_conf:get([dashboard, i18n_lang], en),
|
||||||
init_i18n(File, Lang).
|
init_i18n(File, Lang).
|
||||||
|
|
||||||
ranch_opts(RanchOptions) ->
|
ranch_opts(RanchOptions) ->
|
||||||
|
@ -267,3 +267,9 @@ return_unauthorized(Code, Message) ->
|
||||||
<<"Basic Realm=\"minirest-server\"">>
|
<<"Basic Realm=\"minirest-server\"">>
|
||||||
},
|
},
|
||||||
#{code => Code, message => Message}}.
|
#{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),
|
emqx_config:put([emqx_management], Config),
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(emqx_dashboard) ->
|
set_special_configs(emqx_dashboard) ->
|
||||||
Listeners = [#{protocol => http, port => 18083}],
|
emqx_dashboard_api_test_helpers:set_default_config(),
|
||||||
Config = #{listeners => Listeners,
|
|
||||||
default_username => <<"admin">>,
|
|
||||||
default_password => <<"public">>
|
|
||||||
},
|
|
||||||
emqx_config:put([dashboard], Config),
|
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(_) ->
|
set_special_configs(_) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -35,9 +35,16 @@ set_default_config(DefaultUsername) ->
|
||||||
Config = #{listeners => [#{protocol => http,
|
Config = #{listeners => [#{protocol => http,
|
||||||
port => 18083}],
|
port => 18083}],
|
||||||
default_username => DefaultUsername,
|
default_username => DefaultUsername,
|
||||||
default_password => <<"public">>
|
default_password => <<"public">>,
|
||||||
|
i18n_lang => en
|
||||||
},
|
},
|
||||||
emqx_config:put([dashboard], Config),
|
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.
|
ok.
|
||||||
|
|
||||||
request(Method, Url) ->
|
request(Method, Url) ->
|
||||||
|
|
|
@ -35,15 +35,7 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
set_special_configs(emqx_dashboard) ->
|
set_special_configs(emqx_dashboard) ->
|
||||||
Config = #{
|
emqx_dashboard_api_test_helpers:set_default_config(),
|
||||||
default_username => <<"admin">>,
|
|
||||||
default_password => <<"public">>,
|
|
||||||
listeners => [#{
|
|
||||||
protocol => http,
|
|
||||||
port => 18083
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
emqx_config:put([emqx_dashboard], Config),
|
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(_) ->
|
set_special_configs(_) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -35,15 +35,7 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
set_special_configs(emqx_dashboard) ->
|
set_special_configs(emqx_dashboard) ->
|
||||||
Config = #{
|
emqx_dashboard_api_test_helpers:set_default_config(),
|
||||||
default_username => <<"admin">>,
|
|
||||||
default_password => <<"public">>,
|
|
||||||
listeners => [#{
|
|
||||||
protocol => http,
|
|
||||||
port => 18083
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
emqx_config:put([emqx_dashboard], Config),
|
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(_) ->
|
set_special_configs(_) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -40,15 +40,7 @@ end_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
set_special_configs(emqx_dashboard) ->
|
set_special_configs(emqx_dashboard) ->
|
||||||
Config = #{
|
emqx_dashboard_api_test_helpers:set_default_config(),
|
||||||
default_username => <<"admin">>,
|
|
||||||
default_password => <<"public">>,
|
|
||||||
listeners => [#{
|
|
||||||
protocol => http,
|
|
||||||
port => 18083
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
emqx_config:put([dashboard], Config),
|
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(_) ->
|
set_special_configs(_) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -39,15 +39,7 @@ end_suite(Apps) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
set_special_configs(emqx_dashboard) ->
|
set_special_configs(emqx_dashboard) ->
|
||||||
Config = #{
|
emqx_dashboard_api_test_helpers:set_default_config(),
|
||||||
default_username => <<"admin">>,
|
|
||||||
default_password => <<"public">>,
|
|
||||||
listeners => [#{
|
|
||||||
protocol => http,
|
|
||||||
port => 18083
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
emqx_config:put([dashboard], Config),
|
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(_App) ->
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -9,5 +9,6 @@
|
||||||
doc_gen_test() ->
|
doc_gen_test() ->
|
||||||
Dir = "tmp",
|
Dir = "tmp",
|
||||||
ok = filelib:ensure_dir(filename:join("tmp", foo)),
|
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.
|
ok.
|
||||||
|
|
Loading…
Reference in New Issue