fix: don't add disable bridge to connector's channel
This commit is contained in:
parent
06f9d762cd
commit
f9d16340e0
|
@ -221,6 +221,32 @@ t_create_remove(_) ->
|
||||||
ok = emqx_bridge_v2:remove(bridge_type(), my_test_bridge),
|
ok = emqx_bridge_v2:remove(bridge_type(), my_test_bridge),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
t_create_disabled_bridge(_) ->
|
||||||
|
Config = #{<<"connector">> := Connector} = bridge_config(),
|
||||||
|
Disable = Config#{<<"enable">> => false},
|
||||||
|
BridgeType = bridge_type(),
|
||||||
|
{ok, _} = emqx_bridge_v2:create(BridgeType, my_enable_bridge, Config),
|
||||||
|
{ok, _} = emqx_bridge_v2:create(BridgeType, my_disable_bridge, Disable),
|
||||||
|
ConnectorId = emqx_connector_resource:resource_id(con_type(), Connector),
|
||||||
|
?assertMatch(
|
||||||
|
[
|
||||||
|
{_, #{
|
||||||
|
enable := true,
|
||||||
|
connector := Connector,
|
||||||
|
bridge_type := _
|
||||||
|
}},
|
||||||
|
{_, #{
|
||||||
|
enable := false,
|
||||||
|
connector := Connector,
|
||||||
|
bridge_type := _
|
||||||
|
}}
|
||||||
|
],
|
||||||
|
emqx_bridge_v2:get_channels_for_connector(ConnectorId)
|
||||||
|
),
|
||||||
|
ok = emqx_bridge_v2:remove(bridge_type(), my_enable_bridge),
|
||||||
|
ok = emqx_bridge_v2:remove(bridge_type(), my_disable_bridge),
|
||||||
|
ok.
|
||||||
|
|
||||||
t_list(_) ->
|
t_list(_) ->
|
||||||
[] = emqx_bridge_v2:list(),
|
[] = emqx_bridge_v2:list(),
|
||||||
{ok, _} = emqx_bridge_v2:create(bridge_type(), my_test_bridge, bridge_config()),
|
{ok, _} = emqx_bridge_v2:create(bridge_type(), my_test_bridge, bridge_config()),
|
||||||
|
|
|
@ -159,7 +159,7 @@ t_remove_fail({'init', Config}) ->
|
||||||
meck:new(?CONNECTOR, [non_strict]),
|
meck:new(?CONNECTOR, [non_strict]),
|
||||||
meck:expect(?CONNECTOR, callback_mode, 0, async_if_possible),
|
meck:expect(?CONNECTOR, callback_mode, 0, async_if_possible),
|
||||||
meck:expect(?CONNECTOR, on_start, 2, {ok, connector_state}),
|
meck:expect(?CONNECTOR, on_start, 2, {ok, connector_state}),
|
||||||
meck:expect(?CONNECTOR, on_get_channels, 1, [{<<"my_channel">>, #{}}]),
|
meck:expect(?CONNECTOR, on_get_channels, 1, [{<<"my_channel">>, #{enable => true}}]),
|
||||||
meck:expect(?CONNECTOR, on_add_channel, 4, {ok, connector_state}),
|
meck:expect(?CONNECTOR, on_add_channel, 4, {ok, connector_state}),
|
||||||
meck:expect(?CONNECTOR, on_stop, 2, ok),
|
meck:expect(?CONNECTOR, on_stop, 2, ok),
|
||||||
meck:expect(?CONNECTOR, on_get_status, 2, connected),
|
meck:expect(?CONNECTOR, on_get_status, 2, connected),
|
||||||
|
|
|
@ -622,13 +622,16 @@ start_resource(Data, From) ->
|
||||||
|
|
||||||
add_channels(Data) ->
|
add_channels(Data) ->
|
||||||
%% Add channels to the Channels map but not to the resource state
|
%% Add channels to the Channels map but not to the resource state
|
||||||
%% Channels will be added to the resouce state after the initial health_check
|
%% Channels will be added to the resource state after the initial health_check
|
||||||
%% if that succeeds.
|
%% if that succeeds.
|
||||||
ChannelIDConfigTuples = emqx_resource:call_get_channels(Data#data.id, Data#data.mod),
|
ChannelIDConfigTuples = emqx_resource:call_get_channels(Data#data.id, Data#data.mod),
|
||||||
Channels = Data#data.added_channels,
|
Channels = Data#data.added_channels,
|
||||||
NewChannels = lists:foldl(
|
NewChannels = lists:foldl(
|
||||||
fun({ChannelID, _Conf}, Acc) ->
|
fun
|
||||||
maps:put(ChannelID, channel_status(), Acc)
|
({ChannelID, #{enable := true}}, Acc) ->
|
||||||
|
maps:put(ChannelID, channel_status(), Acc);
|
||||||
|
({_, #{enable := false}}, Acc) ->
|
||||||
|
Acc
|
||||||
end,
|
end,
|
||||||
Channels,
|
Channels,
|
||||||
ChannelIDConfigTuples
|
ChannelIDConfigTuples
|
||||||
|
|
Loading…
Reference in New Issue