fix(ft-api): update FT API tests to use emqx_cth_suite

This commit is contained in:
Ilya Averyanov 2023-07-04 18:41:25 +03:00
parent fde506838a
commit e0353ab750
3 changed files with 29 additions and 66 deletions

View File

@ -305,7 +305,7 @@ default_appspec(emqx_conf, SuiteOpts) ->
#{ #{
config => SharedConfig, config => SharedConfig,
% NOTE % NOTE
% We inform `emqx` of our config loader before starting `emqx_conf` sothat it won't % We inform `emqx` of our config loader before starting `emqx_conf` so that it won't
% overwrite everything with a default configuration. % overwrite everything with a default configuration.
before_start => fun() -> before_start => fun() ->
emqx_app:set_config_loader(?MODULE) emqx_app:set_config_loader(?MODULE)

View File

@ -114,10 +114,7 @@ schema("/file_transfer") ->
summary => <<"Get current File Transfer configuration">>, summary => <<"Get current File Transfer configuration">>,
description => ?DESC("file_transfer_get_config"), description => ?DESC("file_transfer_get_config"),
responses => #{ responses => #{
200 => ?SCHEMA_CONFIG, 200 => ?SCHEMA_CONFIG
503 => emqx_dashboard_swagger:error_codes(
['SERVICE_UNAVAILABLE'], error_desc('SERVICE_UNAVAILABLE')
)
} }
}, },
put => #{ put => #{
@ -129,9 +126,6 @@ schema("/file_transfer") ->
200 => ?SCHEMA_CONFIG, 200 => ?SCHEMA_CONFIG,
400 => emqx_dashboard_swagger:error_codes( 400 => emqx_dashboard_swagger:error_codes(
['INVALID_CONFIG'], error_desc('INVALID_CONFIG') ['INVALID_CONFIG'], error_desc('INVALID_CONFIG')
),
503 => emqx_dashboard_swagger:error_codes(
['SERVICE_UNAVAILABLE'], error_desc('SERVICE_UNAVAILABLE')
) )
} }
} }

View File

@ -24,58 +24,24 @@
-import(emqx_dashboard_api_test_helpers, [host/0, uri/1]). -import(emqx_dashboard_api_test_helpers, [host/0, uri/1]).
all() -> all() -> emqx_common_test_helpers:all(?MODULE).
[
{group, single},
{group, cluster}
].
groups() ->
[
{single, [], emqx_common_test_helpers:all(?MODULE)},
{cluster, [], emqx_common_test_helpers:all(?MODULE) -- [t_ft_disabled]}
].
suite() -> suite() ->
[{timetrap, {seconds, 90}}]. [{timetrap, {seconds, 90}}].
init_per_suite(Config) -> init_per_suite(Config) ->
Config.
end_per_suite(_Config) ->
ok.
init_per_group(Group = single, Config) ->
WorkDir = ?config(priv_dir, Config),
Apps = emqx_cth_suite:start(
[
{emqx, #{}},
{emqx_ft, "file_transfer { enable = true }"},
{emqx_management, #{}},
{emqx_dashboard, "dashboard.listeners.http { enable = true, bind = 18083 }"}
],
#{work_dir => WorkDir}
),
{ok, App} = emqx_common_test_http:create_default_app(),
[{group, Group}, {group_apps, Apps}, {api, App} | Config];
init_per_group(Group = cluster, Config) ->
WorkDir = ?config(priv_dir, Config), WorkDir = ?config(priv_dir, Config),
Cluster = mk_cluster_specs(Config), Cluster = mk_cluster_specs(Config),
Nodes = [Node1 | _] = emqx_cth_cluster:start(Cluster, #{work_dir => WorkDir}), Nodes = [Node1 | _] = emqx_cth_cluster:start(Cluster, #{work_dir => WorkDir}),
{ok, App} = erpc:call(Node1, emqx_common_test_http, create_default_app, []), {ok, App} = erpc:call(Node1, emqx_common_test_http, create_default_app, []),
[{group, Group}, {cluster_nodes, Nodes}, {api, App} | Config]. [{cluster_nodes, Nodes}, {api, App} | Config].
end_per_group(single, Config) -> end_per_suite(Config) ->
{ok, _} = emqx_common_test_http:delete_default_app(), ok = emqx_cth_cluster:stop(?config(cluster_nodes, Config)).
ok = emqx_cth_suite:stop(?config(group_apps, Config));
end_per_group(cluster, Config) ->
ok = emqx_cth_cluster:stop(?config(cluster_nodes, Config));
end_per_group(_Group, _Config) ->
ok.
mk_cluster_specs(_Config) -> mk_cluster_specs(_Config) ->
Apps = [ Apps = [
{emqx_conf, #{start => false}}, emqx_conf,
{emqx, #{override_env => [{boot_modules, [broker, listeners]}]}}, {emqx, #{override_env => [{boot_modules, [broker, listeners]}]}},
{emqx_ft, "file_transfer { enable = true }"}, {emqx_ft, "file_transfer { enable = true }"},
{emqx_management, #{}} {emqx_management, #{}}
@ -106,14 +72,8 @@ mk_cluster_specs(_Config) ->
init_per_testcase(Case, Config) -> init_per_testcase(Case, Config) ->
[{tc, Case} | Config]. [{tc, Case} | Config].
end_per_testcase(t_ft_disabled, _Config) -> end_per_testcase(_Case, Config) ->
emqx_config:put([file_transfer, enable], true); ok = reset_ft_config(Config, true),
end_per_testcase(t_configure, Config) ->
{ok, 200, _} = request(put, uri(["file_transfer"]), #{
<<"enable">> => true,
<<"storage">> => emqx_ft_test_helpers:local_storage(Config)
});
end_per_testcase(_Case, _Config) ->
ok. ok.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -299,7 +259,7 @@ t_ft_disabled(Config) ->
) )
), ),
ok = emqx_config:put([file_transfer, enable], false), ok = reset_ft_config(Config, false),
?assertMatch( ?assertMatch(
{ok, 503, _}, {ok, 503, _},
@ -469,12 +429,7 @@ t_configure(Config) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
test_nodes(Config) -> test_nodes(Config) ->
case proplists:get_value(cluster_nodes, Config, []) of ?config(cluster_nodes, Config).
[] ->
[node()];
Nodes ->
Nodes
end.
client_id(Config) -> client_id(Config) ->
iolist_to_binary(io_lib:format("~s.~s", [?config(group, Config), ?config(tc, Config)])). iolist_to_binary(io_lib:format("~s.~s", [?config(group, Config), ?config(tc, Config)])).
@ -493,12 +448,12 @@ request(Method, Url, Body, Config) ->
request(Method, Url, Body, Opts, Config). request(Method, Url, Body, Opts, Config).
request(Method, Url, Body, Opts, Config) -> request(Method, Url, Body, Opts, Config) ->
emqx_mgmt_api_test_util:request_api(Method, Url, Body, auth_header(Config), [], Opts). emqx_mgmt_api_test_util:request_api(Method, Url, [], auth_header(Config), Body, Opts).
request_json(Method, Url, Body, Config) -> request_json(Method, Url, Body, Config) ->
case request(Method, Url, Body, [], Config) of case request(Method, Url, Body, Config) of
{ok, Code, Body} -> {ok, Code, RespBody} ->
{ok, Code, json(Body)}; {ok, Code, json(RespBody)};
Otherwise -> Otherwise ->
Otherwise Otherwise
end. end.
@ -531,3 +486,17 @@ to_list(L) when is_list(L) ->
pick(N, List) -> pick(N, List) ->
lists:nth(1 + (N rem length(List)), List). lists:nth(1 + (N rem length(List)), List).
reset_ft_config(Config, Enable) ->
[Node | _] = test_nodes(Config),
LocalConfig =
#{
<<"enable">> => Enable,
<<"storage">> => #{
<<"local">> => #{
<<"enable">> => true
}
}
},
{ok, _} = rpc:call(Node, emqx_ft_conf, update, [LocalConfig]),
ok.