test: generate dispatch.eterm in dashboard test
This commit is contained in:
parent
a6e3a09118
commit
f713f13b2c
|
@ -33,6 +33,7 @@
|
||||||
-include_lib("emqx/include/logger.hrl").
|
-include_lib("emqx/include/logger.hrl").
|
||||||
-include_lib("emqx/include/http_api.hrl").
|
-include_lib("emqx/include/http_api.hrl").
|
||||||
-include_lib("emqx/include/emqx_release.hrl").
|
-include_lib("emqx/include/emqx_release.hrl").
|
||||||
|
-dialyzer({[no_opaque, no_match, no_return], [init_cache_dispatch/2, start_listeners/1]}).
|
||||||
|
|
||||||
-define(EMQX_MIDDLE, emqx_dashboard_middleware).
|
-define(EMQX_MIDDLE, emqx_dashboard_middleware).
|
||||||
-define(DISPATCH_FILE, "dispatch.eterm").
|
-define(DISPATCH_FILE, "dispatch.eterm").
|
||||||
|
@ -54,7 +55,7 @@ start_listeners(Listeners) ->
|
||||||
{OkListeners, ErrListeners} =
|
{OkListeners, ErrListeners} =
|
||||||
lists:foldl(
|
lists:foldl(
|
||||||
fun({Name, Protocol, Bind, RanchOptions, ProtoOpts}, {OkAcc, ErrAcc}) ->
|
fun({Name, Protocol, Bind, RanchOptions, ProtoOpts}, {OkAcc, ErrAcc}) ->
|
||||||
init_cache_dispatch(Name, InitDispatch),
|
ok = init_cache_dispatch(Name, InitDispatch),
|
||||||
Options = #{
|
Options = #{
|
||||||
dispatch => InitDispatch,
|
dispatch => InitDispatch,
|
||||||
swagger_support => SwaggerSupport,
|
swagger_support => SwaggerSupport,
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
-include("emqx_dashboard.hrl").
|
-include("emqx_dashboard.hrl").
|
||||||
|
|
||||||
|
-dialyzer({nowarn_function, [start/2]}).
|
||||||
|
|
||||||
start(_StartType, _StartArgs) ->
|
start(_StartType, _StartArgs) ->
|
||||||
Tables = lists:append([
|
Tables = lists:append([
|
||||||
emqx_dashboard_admin:create_tables(),
|
emqx_dashboard_admin:create_tables(),
|
||||||
|
|
|
@ -61,7 +61,6 @@ init_per_suite(Config) ->
|
||||||
Apps = emqx_machine_boot:reboot_apps(),
|
Apps = emqx_machine_boot:reboot_apps(),
|
||||||
ct:pal("load apps:~p~n", [Apps]),
|
ct:pal("load apps:~p~n", [Apps]),
|
||||||
lists:foreach(fun(App) -> application:load(App) end, Apps),
|
lists:foreach(fun(App) -> application:load(App) end, Apps),
|
||||||
emqx_dashboard:save_dispatch_eterm(emqx_conf:schema_module()),
|
|
||||||
SuiteApps = emqx_cth_suite:start(
|
SuiteApps = emqx_cth_suite:start(
|
||||||
[
|
[
|
||||||
emqx_conf,
|
emqx_conf,
|
||||||
|
@ -70,6 +69,9 @@ init_per_suite(Config) ->
|
||||||
],
|
],
|
||||||
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
),
|
),
|
||||||
|
_ = emqx_conf_schema:roots(),
|
||||||
|
ok = emqx_dashboard_desc_cache:init(),
|
||||||
|
emqx_dashboard:save_dispatch_eterm(emqx_conf:schema_module()),
|
||||||
emqx_common_test_http:create_default_app(),
|
emqx_common_test_http:create_default_app(),
|
||||||
[{suite_apps, SuiteApps} | Config].
|
[{suite_apps, SuiteApps} | Config].
|
||||||
|
|
||||||
|
@ -89,6 +91,26 @@ t_overview(_) ->
|
||||||
].
|
].
|
||||||
|
|
||||||
t_dashboard_restart(Config) ->
|
t_dashboard_restart(Config) ->
|
||||||
|
emqx_config:put([dashboard], #{
|
||||||
|
i18n_lang => en,
|
||||||
|
swagger_support => true,
|
||||||
|
listeners =>
|
||||||
|
#{
|
||||||
|
http =>
|
||||||
|
#{
|
||||||
|
inet6 => false,
|
||||||
|
bind => 18083,
|
||||||
|
ipv6_v6only => false,
|
||||||
|
send_timeout => 10000,
|
||||||
|
num_acceptors => 8,
|
||||||
|
max_connections => 512,
|
||||||
|
backlog => 1024,
|
||||||
|
proxy_header => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
application:stop(emqx_dashboard),
|
||||||
|
application:start(emqx_dashboard),
|
||||||
Name = 'http:dashboard',
|
Name = 'http:dashboard',
|
||||||
t_overview(Config),
|
t_overview(Config),
|
||||||
[{'_', [], Rules}] = Dispatch = persistent_term:get(Name),
|
[{'_', [], Rules}] = Dispatch = persistent_term:get(Name),
|
||||||
|
@ -96,10 +118,9 @@ t_dashboard_restart(Config) ->
|
||||||
?assertNotMatch([{[], [], cowboy_static, _} | _], Rules),
|
?assertNotMatch([{[], [], cowboy_static, _} | _], Rules),
|
||||||
?assert(erlang:length(Rules) > 150),
|
?assert(erlang:length(Rules) > 150),
|
||||||
CheckRules = fun(Tag) ->
|
CheckRules = fun(Tag) ->
|
||||||
io:format("zhongwen:~p~n", [Tag]),
|
[{'_', [], NewRules}] = persistent_term:get(Name, Tag),
|
||||||
[{'_', [], NewRules}] = persistent_term:get(Name),
|
?assertEqual(length(Rules), length(NewRules), Tag),
|
||||||
?assertEqual(length(NewRules), length(Rules), Tag),
|
?assertEqual(lists:sort(Rules), lists:sort(NewRules), Tag)
|
||||||
?assertEqual(lists:sort(NewRules), lists:sort(Rules), Tag)
|
|
||||||
end,
|
end,
|
||||||
?check_trace(
|
?check_trace(
|
||||||
?wait_async_action(
|
?wait_async_action(
|
||||||
|
@ -123,9 +144,9 @@ t_dashboard_restart(Config) ->
|
||||||
?check_trace(
|
?check_trace(
|
||||||
?wait_async_action(
|
?wait_async_action(
|
||||||
begin
|
begin
|
||||||
ok = application:stop(emqx_dashboard),
|
|
||||||
%% erase to mock the initial dashboard startup.
|
%% erase to mock the initial dashboard startup.
|
||||||
persistent_term:erase(Name),
|
persistent_term:erase(Name),
|
||||||
|
ok = application:stop(emqx_dashboard),
|
||||||
ok = application:start(emqx_dashboard),
|
ok = application:start(emqx_dashboard),
|
||||||
ct:sleep(800),
|
ct:sleep(800),
|
||||||
%% regenerate the dispatch rules again
|
%% regenerate the dispatch rules again
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
-export([
|
-export([
|
||||||
api_spec/0,
|
api_spec/0,
|
||||||
validate_xml_content_type/2,
|
|
||||||
paths/0,
|
paths/0,
|
||||||
schema/1,
|
schema/1,
|
||||||
namespace/0
|
namespace/0
|
||||||
|
@ -41,9 +40,6 @@ namespace() -> "dashboard_sso".
|
||||||
api_spec() ->
|
api_spec() ->
|
||||||
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => false, translate_body => false}).
|
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => false, translate_body => false}).
|
||||||
|
|
||||||
validate_xml_content_type(Params, Meta) ->
|
|
||||||
emqx_dashboard_swagger:validate_content_type(Params, Meta, <<"application/xml">>).
|
|
||||||
|
|
||||||
paths() ->
|
paths() ->
|
||||||
[
|
[
|
||||||
"/sso/saml/acs",
|
"/sso/saml/acs",
|
||||||
|
|
Loading…
Reference in New Issue