Merge pull request #12435 from zhongwencool/dont-add-disable-resource-to-connector
fix: don't add disable bridge to connector's channel
This commit is contained in:
commit
42a4bc3382
|
@ -221,6 +221,32 @@ t_create_remove(_) ->
|
|||
ok = emqx_bridge_v2:remove(bridge_type(), my_test_bridge),
|
||||
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(_) ->
|
||||
[] = emqx_bridge_v2:list(),
|
||||
{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:expect(?CONNECTOR, callback_mode, 0, async_if_possible),
|
||||
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_stop, 2, ok),
|
||||
meck:expect(?CONNECTOR, on_get_status, 2, connected),
|
||||
|
|
|
@ -622,13 +622,16 @@ start_resource(Data, From) ->
|
|||
|
||||
add_channels(Data) ->
|
||||
%% 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.
|
||||
ChannelIDConfigTuples = emqx_resource:call_get_channels(Data#data.id, Data#data.mod),
|
||||
Channels = Data#data.added_channels,
|
||||
NewChannels = lists:foldl(
|
||||
fun({ChannelID, _Conf}, Acc) ->
|
||||
maps:put(ChannelID, channel_status(), Acc)
|
||||
fun
|
||||
({ChannelID, #{enable := true}}, Acc) ->
|
||||
maps:put(ChannelID, channel_status(), Acc);
|
||||
({_, #{enable := false}}, Acc) ->
|
||||
Acc
|
||||
end,
|
||||
Channels,
|
||||
ChannelIDConfigTuples
|
||||
|
|
Loading…
Reference in New Issue