test: generate dispatch.eterm in dashboard test

This commit is contained in:
zhongwencool 2024-06-14 21:52:58 +08:00
parent a6e3a09118
commit f713f13b2c
4 changed files with 31 additions and 11 deletions

View File

@ -33,6 +33,7 @@
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx/include/http_api.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(DISPATCH_FILE, "dispatch.eterm").
@ -54,7 +55,7 @@ start_listeners(Listeners) ->
{OkListeners, ErrListeners} =
lists:foldl(
fun({Name, Protocol, Bind, RanchOptions, ProtoOpts}, {OkAcc, ErrAcc}) ->
init_cache_dispatch(Name, InitDispatch),
ok = init_cache_dispatch(Name, InitDispatch),
Options = #{
dispatch => InitDispatch,
swagger_support => SwaggerSupport,

View File

@ -25,6 +25,8 @@
-include("emqx_dashboard.hrl").
-dialyzer({nowarn_function, [start/2]}).
start(_StartType, _StartArgs) ->
Tables = lists:append([
emqx_dashboard_admin:create_tables(),

View File

@ -61,7 +61,6 @@ init_per_suite(Config) ->
Apps = emqx_machine_boot:reboot_apps(),
ct:pal("load apps:~p~n", [Apps]),
lists:foreach(fun(App) -> application:load(App) end, Apps),
emqx_dashboard:save_dispatch_eterm(emqx_conf:schema_module()),
SuiteApps = emqx_cth_suite:start(
[
emqx_conf,
@ -70,6 +69,9 @@ init_per_suite(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(),
[{suite_apps, SuiteApps} | Config].
@ -89,6 +91,26 @@ t_overview(_) ->
].
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',
t_overview(Config),
[{'_', [], Rules}] = Dispatch = persistent_term:get(Name),
@ -96,10 +118,9 @@ t_dashboard_restart(Config) ->
?assertNotMatch([{[], [], cowboy_static, _} | _], Rules),
?assert(erlang:length(Rules) > 150),
CheckRules = fun(Tag) ->
io:format("zhongwen:~p~n", [Tag]),
[{'_', [], NewRules}] = persistent_term:get(Name),
?assertEqual(length(NewRules), length(Rules), Tag),
?assertEqual(lists:sort(NewRules), lists:sort(Rules), Tag)
[{'_', [], NewRules}] = persistent_term:get(Name, Tag),
?assertEqual(length(Rules), length(NewRules), Tag),
?assertEqual(lists:sort(Rules), lists:sort(NewRules), Tag)
end,
?check_trace(
?wait_async_action(
@ -123,9 +144,9 @@ t_dashboard_restart(Config) ->
?check_trace(
?wait_async_action(
begin
ok = application:stop(emqx_dashboard),
%% erase to mock the initial dashboard startup.
persistent_term:erase(Name),
ok = application:stop(emqx_dashboard),
ok = application:start(emqx_dashboard),
ct:sleep(800),
%% regenerate the dispatch rules again

View File

@ -20,7 +20,6 @@
-export([
api_spec/0,
validate_xml_content_type/2,
paths/0,
schema/1,
namespace/0
@ -41,9 +40,6 @@ namespace() -> "dashboard_sso".
api_spec() ->
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() ->
[
"/sso/saml/acs",