|
@@ -21,6 +21,8 @@
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
-include_lib("common_test/include/ct.hrl").
|
|
-include_lib("common_test/include/ct.hrl").
|
|
|
|
|
|
|
|
|
|
+-import(emqx_common_test_helpers, [on_exit/1]).
|
|
|
|
|
+
|
|
|
%%------------------------------------------------------------------------------
|
|
%%------------------------------------------------------------------------------
|
|
|
%% CT boilerplate
|
|
%% CT boilerplate
|
|
|
%%------------------------------------------------------------------------------
|
|
%%------------------------------------------------------------------------------
|
|
@@ -48,6 +50,13 @@ app_specs() ->
|
|
|
emqx_mgmt_api_test_util:emqx_dashboard()
|
|
emqx_mgmt_api_test_util:emqx_dashboard()
|
|
|
].
|
|
].
|
|
|
|
|
|
|
|
|
|
+init_per_testcase(_TestCase, Config) ->
|
|
|
|
|
+ Config.
|
|
|
|
|
+
|
|
|
|
|
+end_per_testcase(_TestCase, _Config) ->
|
|
|
|
|
+ emqx_common_test_helpers:call_janitor(),
|
|
|
|
|
+ ok.
|
|
|
|
|
+
|
|
|
%%------------------------------------------------------------------------------
|
|
%%------------------------------------------------------------------------------
|
|
|
%% Helper fns
|
|
%% Helper fns
|
|
|
%%------------------------------------------------------------------------------
|
|
%%------------------------------------------------------------------------------
|
|
@@ -124,7 +133,13 @@ create_rule(Overrides) ->
|
|
|
Method = post,
|
|
Method = post,
|
|
|
Path = emqx_mgmt_api_test_util:api_path(["rules"]),
|
|
Path = emqx_mgmt_api_test_util:api_path(["rules"]),
|
|
|
Res = request(Method, Path, Params),
|
|
Res = request(Method, Path, Params),
|
|
|
- emqx_mgmt_api_test_util:simplify_result(Res).
|
|
|
|
|
|
|
+ case emqx_mgmt_api_test_util:simplify_result(Res) of
|
|
|
|
|
+ {201, #{<<"id">> := RuleId}} = SRes ->
|
|
|
|
|
+ on_exit(fun() -> ok = emqx_rule_engine:delete_rule(RuleId) end),
|
|
|
|
|
+ SRes;
|
|
|
|
|
+ SRes ->
|
|
|
|
|
+ SRes
|
|
|
|
|
+ end.
|
|
|
|
|
|
|
|
sources_sql(Sources) ->
|
|
sources_sql(Sources) ->
|
|
|
Froms = iolist_to_binary(lists:join(<<", ">>, lists:map(fun source_from/1, Sources))),
|
|
Froms = iolist_to_binary(lists:join(<<", ">>, lists:map(fun source_from/1, Sources))),
|
|
@@ -586,3 +601,21 @@ t_filter_by_source_and_action(_Config) ->
|
|
|
),
|
|
),
|
|
|
|
|
|
|
|
ok.
|
|
ok.
|
|
|
|
|
+
|
|
|
|
|
+%% Checks that creating a rule with a `null' JSON value id is forbidden.
|
|
|
|
|
+t_create_rule_with_null_id(_Config) ->
|
|
|
|
|
+ ?assertMatch(
|
|
|
|
|
+ {400, #{<<"message">> := <<"rule id must be a string">>}},
|
|
|
|
|
+ create_rule(#{<<"id">> => null})
|
|
|
|
|
+ ),
|
|
|
|
|
+ %% The string `"null"' should be fine.
|
|
|
|
|
+ ?assertMatch(
|
|
|
|
|
+ {201, _},
|
|
|
|
|
+ create_rule(#{<<"id">> => <<"null">>})
|
|
|
|
|
+ ),
|
|
|
|
|
+ ?assertMatch({201, _}, create_rule(#{})),
|
|
|
|
|
+ ?assertMatch(
|
|
|
|
|
+ {200, #{<<"data">> := [_, _]}},
|
|
|
|
|
+ list_rules([])
|
|
|
|
|
+ ),
|
|
|
|
|
+ ok.
|