test(emqx_modules): do not expect badmatch in test cases!!!

This commit is contained in:
Zaiming (Stone) Shi 2022-12-29 16:06:28 +01:00
parent 0ce1ca89b7
commit 981f75dc73
4 changed files with 24 additions and 15 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_modules, [
{description, "EMQX Modules"},
{vsn, "5.0.8"},
{vsn, "5.0.9"},
{modules, []},
{applications, [kernel, stdlib, emqx]},
{mod, {emqx_modules_app, []}},

View File

@ -88,8 +88,13 @@ regular_expression(_) -> undefined.
is_re(Bin) ->
case re:compile(Bin) of
{ok, _} -> ok;
{error, Reason} -> {error, {Bin, Reason}}
{ok, _} ->
ok;
{error, Reason} ->
{error, #{
regexp => Bin,
compile_error => Reason
}}
end.
array(Name, Meta) -> {Name, ?HOCON(?ARRAY(?R_REF(Name)), Meta)}.

View File

@ -67,8 +67,12 @@ list() ->
emqx_conf:get_raw([<<"rewrite">>], []).
update(Rules0) ->
{ok, _} = emqx_conf:update([rewrite], Rules0, #{override_to => cluster}),
ok.
case emqx_conf:update([rewrite], Rules0, #{override_to => cluster}) of
{ok, _} ->
ok;
{error, Reason} ->
throw(Reason)
end.
post_config_update(_KeyPath, _Config, Rules, _OldConf, _AppEnvs) ->
register_hook(Rules).

View File

@ -215,16 +215,16 @@ t_update_re_failed(_Config) ->
<<"action">> => <<"publish">>
}
],
?assertError(
{badmatch,
{error,
{_, [
?assertThrow(
#{
kind := validation_error,
reason := {Re, {"nothing to repeat", 0}},
value := Re
}
]}}},
path := "rewrite.1.re",
reason := #{
regexp := <<"*^test/*">>,
compile_error := {"nothing to repeat", 0}
},
value := <<"*^test/*">>
},
emqx_rewrite:update(Rules)
),
ok.