fix(plugins): fix relative positioning
This commit is contained in:
parent
48ad0adbaa
commit
b1ec8c1aba
|
@ -139,7 +139,7 @@ ensure_state(NameVsn, Position, State) ->
|
||||||
Item = #{ name_vsn => NameVsn
|
Item = #{ name_vsn => NameVsn
|
||||||
, enable => State
|
, enable => State
|
||||||
},
|
},
|
||||||
ensure_configured(Item, Position);
|
tryit("ensure_state", fun() -> ensure_configured(Item, Position) end);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
@ -150,13 +150,18 @@ ensure_configured(#{name_vsn := NameVsn} = Item, Position) ->
|
||||||
{Front, Rear} = lists:splitwith(SplitFun, Configured),
|
{Front, Rear} = lists:splitwith(SplitFun, Configured),
|
||||||
NewConfigured =
|
NewConfigured =
|
||||||
case Rear of
|
case Rear of
|
||||||
[_ | More] -> Front ++ [Item | More];
|
[_ | More] when Position =:= no_move ->
|
||||||
[] -> add_new_configured(Configured, Position, Item)
|
Front ++ [Item | More];
|
||||||
|
[_ | More] ->
|
||||||
|
add_new_configured(Front ++ More, Position, Item);
|
||||||
|
[] ->
|
||||||
|
add_new_configured(Configured, Position, Item)
|
||||||
end,
|
end,
|
||||||
ok = put_configured(NewConfigured).
|
ok = put_configured(NewConfigured).
|
||||||
|
|
||||||
add_new_configured(Configured, no_move, Item) ->
|
add_new_configured(Configured, no_move, Item) ->
|
||||||
Configured ++ [Item];
|
%% default to rear
|
||||||
|
add_new_configured(Configured, rear, Item);
|
||||||
add_new_configured(Configured, front, Item) ->
|
add_new_configured(Configured, front, Item) ->
|
||||||
[Item | Configured];
|
[Item | Configured];
|
||||||
add_new_configured(Configured, rear, Item) ->
|
add_new_configured(Configured, rear, Item) ->
|
||||||
|
@ -164,6 +169,11 @@ add_new_configured(Configured, rear, Item) ->
|
||||||
add_new_configured(Configured, {before, NameVsn}, Item) ->
|
add_new_configured(Configured, {before, NameVsn}, Item) ->
|
||||||
SplitFun = fun(#{name_vsn := Nv}) -> bin(Nv) =/= bin(NameVsn) end,
|
SplitFun = fun(#{name_vsn := Nv}) -> bin(Nv) =/= bin(NameVsn) end,
|
||||||
{Front, Rear} = lists:splitwith(SplitFun, Configured),
|
{Front, Rear} = lists:splitwith(SplitFun, Configured),
|
||||||
|
Rear =:= [] andalso
|
||||||
|
throw(#{error => "position_anchor_plugin_not_configured",
|
||||||
|
hint => "maybe_install_and_configure",
|
||||||
|
name_vsn => NameVsn
|
||||||
|
}),
|
||||||
Front ++ [Item | Rear].
|
Front ++ [Item | Rear].
|
||||||
|
|
||||||
%% @doc Delete the package file.
|
%% @doc Delete the package file.
|
||||||
|
|
|
@ -149,7 +149,7 @@ t_start_restart_and_stop(Config) ->
|
||||||
assert_app_running(emqx_plugin_template, true),
|
assert_app_running(emqx_plugin_template, true),
|
||||||
|
|
||||||
%% fake enable bar-2
|
%% fake enable bar-2
|
||||||
ok = emqx_plugins:ensure_state(Bar2, reat, true),
|
ok = emqx_plugins:ensure_state(Bar2, rear, true),
|
||||||
%% should cause an error
|
%% should cause an error
|
||||||
?assertError(#{function := _, errors := [_ | _]},
|
?assertError(#{function := _, errors := [_ | _]},
|
||||||
emqx_plugins:ensure_started()),
|
emqx_plugins:ensure_started()),
|
||||||
|
|
|
@ -31,7 +31,9 @@ test_ensure_configured() ->
|
||||||
emqx_plugins:ensure_configured(P1, front),
|
emqx_plugins:ensure_configured(P1, front),
|
||||||
emqx_plugins:ensure_configured(P2, {before, <<"p-1">>}),
|
emqx_plugins:ensure_configured(P2, {before, <<"p-1">>}),
|
||||||
emqx_plugins:ensure_configured(P3, {before, <<"p-1">>}),
|
emqx_plugins:ensure_configured(P3, {before, <<"p-1">>}),
|
||||||
?assertEqual([P2, P3, P1], emqx_plugins:configured()).
|
?assertEqual([P2, P3, P1], emqx_plugins:configured()),
|
||||||
|
?assertThrow(#{error := "position_anchor_plugin_not_configured"},
|
||||||
|
emqx_plugins:ensure_configured(P3, {before, <<"unknown-x">>})).
|
||||||
|
|
||||||
read_plugin_test() ->
|
read_plugin_test() ->
|
||||||
with_rand_install_dir(
|
with_rand_install_dir(
|
||||||
|
|
Loading…
Reference in New Issue