test: handle bad payload
This commit is contained in:
parent
860d7b169a
commit
938d62a666
|
@ -116,6 +116,7 @@ create_bridge(Config, Overrides) ->
|
||||||
Name = ?config(bridge_name, Config),
|
Name = ?config(bridge_name, Config),
|
||||||
BridgeConfig0 = ?config(bridge_config, Config),
|
BridgeConfig0 = ?config(bridge_config, Config),
|
||||||
BridgeConfig = emqx_utils_maps:deep_merge(BridgeConfig0, Overrides),
|
BridgeConfig = emqx_utils_maps:deep_merge(BridgeConfig0, Overrides),
|
||||||
|
ct:pal("creating bridge with config: ~p", [BridgeConfig]),
|
||||||
emqx_bridge:create(BridgeType, Name, BridgeConfig).
|
emqx_bridge:create(BridgeType, Name, BridgeConfig).
|
||||||
|
|
||||||
create_bridge_api(Config) ->
|
create_bridge_api(Config) ->
|
||||||
|
|
|
@ -403,8 +403,6 @@ device_id(Message, State) ->
|
||||||
case maps:get(payload, Message) of
|
case maps:get(payload, Message) of
|
||||||
#{<<"device_id">> := DeviceId} ->
|
#{<<"device_id">> := DeviceId} ->
|
||||||
DeviceId;
|
DeviceId;
|
||||||
#{device_id := DeviceId} ->
|
|
||||||
DeviceId;
|
|
||||||
_NotFound ->
|
_NotFound ->
|
||||||
Topic = maps:get(topic, Message),
|
Topic = maps:get(topic, Message),
|
||||||
case re:replace(Topic, "/", ".", [global, {return, binary}]) of
|
case re:replace(Topic, "/", ".", [global, {return, binary}]) of
|
||||||
|
|
|
@ -326,6 +326,36 @@ t_sync_query_fail(Config) ->
|
||||||
end,
|
end,
|
||||||
emqx_bridge_testlib:t_sync_query(Config, MakeMessageFun, IsSuccessCheck, iotdb_bridge_on_query).
|
emqx_bridge_testlib:t_sync_query(Config, MakeMessageFun, IsSuccessCheck, iotdb_bridge_on_query).
|
||||||
|
|
||||||
|
t_sync_query_badpayload(Config) ->
|
||||||
|
DeviceId = iotdb_device(Config),
|
||||||
|
BadPayload = #{foo => bar},
|
||||||
|
IsSuccessCheck =
|
||||||
|
fun(Result) ->
|
||||||
|
?assertEqual({error, invalid_data}, Result)
|
||||||
|
end,
|
||||||
|
emqx_bridge_testlib:t_sync_query(
|
||||||
|
Config,
|
||||||
|
make_message_fun(DeviceId, BadPayload),
|
||||||
|
IsSuccessCheck,
|
||||||
|
iotdb_bridge_on_query
|
||||||
|
),
|
||||||
|
ok.
|
||||||
|
|
||||||
|
t_async_query_badpayload(Config) ->
|
||||||
|
DeviceId = iotdb_device(Config),
|
||||||
|
BadPayload = #{foo => bar},
|
||||||
|
IsSuccessCheck =
|
||||||
|
fun(Result) ->
|
||||||
|
?assertEqual({error, invalid_data}, Result)
|
||||||
|
end,
|
||||||
|
emqx_bridge_testlib:t_async_query(
|
||||||
|
Config,
|
||||||
|
make_message_fun(DeviceId, BadPayload),
|
||||||
|
IsSuccessCheck,
|
||||||
|
iotdb_bridge_on_query_async
|
||||||
|
),
|
||||||
|
ok.
|
||||||
|
|
||||||
t_create_via_http(Config) ->
|
t_create_via_http(Config) ->
|
||||||
emqx_bridge_testlib:t_create_via_http(Config).
|
emqx_bridge_testlib:t_create_via_http(Config).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue