|
|
@@ -78,6 +78,85 @@ t_proto_ver(_) ->
|
|
|
?assertEqual(Ver, emqx_packet:proto_ver(ConnPkt))
|
|
|
end, [?MQTT_PROTO_V3, ?MQTT_PROTO_V4, ?MQTT_PROTO_V5]).
|
|
|
|
|
|
+t_connect_info(_) ->
|
|
|
+ ConnPkt = #mqtt_packet_connect{will_flag = true,
|
|
|
+ clientid = <<"clientid">>,
|
|
|
+ username = <<"username">>,
|
|
|
+ will_retain = true,
|
|
|
+ will_qos = ?QOS_2,
|
|
|
+ will_topic = <<"topic">>,
|
|
|
+ will_props = undefined,
|
|
|
+ will_payload = <<"payload">>
|
|
|
+ },
|
|
|
+ ?assertEqual(<<"MQTT">>, emqx_packet:info(proto_name, ConnPkt)),
|
|
|
+ ?assertEqual(4, emqx_packet:info(proto_ver, ConnPkt)),
|
|
|
+ ?assertEqual(false, emqx_packet:info(is_bridge, ConnPkt)),
|
|
|
+ ?assertEqual(true, emqx_packet:info(clean_start, ConnPkt)),
|
|
|
+ ?assertEqual(true, emqx_packet:info(will_flag, ConnPkt)),
|
|
|
+ ?assertEqual(?QOS_2, emqx_packet:info(will_qos, ConnPkt)),
|
|
|
+ ?assertEqual(true, emqx_packet:info(will_retain, ConnPkt)),
|
|
|
+ ?assertEqual(0, emqx_packet:info(keepalive, ConnPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(properties, ConnPkt)),
|
|
|
+ ?assertEqual(<<"clientid">>, emqx_packet:info(clientid, ConnPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(will_props, ConnPkt)),
|
|
|
+ ?assertEqual(<<"topic">>, emqx_packet:info(will_topic, ConnPkt)),
|
|
|
+ ?assertEqual(<<"payload">>, emqx_packet:info(will_payload, ConnPkt)),
|
|
|
+ ?assertEqual(<<"username">>, emqx_packet:info(username, ConnPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(password, ConnPkt)).
|
|
|
+
|
|
|
+t_connack_info(_) ->
|
|
|
+ AckPkt = #mqtt_packet_connack{ack_flags = 0, reason_code = 0},
|
|
|
+ ?assertEqual(0, emqx_packet:info(ack_flags, AckPkt)),
|
|
|
+ ?assertEqual(0, emqx_packet:info(reason_code, AckPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(properties, AckPkt)).
|
|
|
+
|
|
|
+t_publish_info(_) ->
|
|
|
+ PubPkt = #mqtt_packet_publish{topic_name = <<"t">>, packet_id = 1},
|
|
|
+ ?assertEqual(1, emqx_packet:info(packet_id, PubPkt)),
|
|
|
+ ?assertEqual(<<"t">>, emqx_packet:info(topic_name, PubPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(properties, PubPkt)).
|
|
|
+
|
|
|
+t_puback_info(_) ->
|
|
|
+ AckPkt = #mqtt_packet_puback{packet_id = 1, reason_code = 0},
|
|
|
+ ?assertEqual(1, emqx_packet:info(packet_id, AckPkt)),
|
|
|
+ ?assertEqual(0, emqx_packet:info(reason_code, AckPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(properties, AckPkt)).
|
|
|
+
|
|
|
+t_subscribe_info(_) ->
|
|
|
+ TopicFilters = [{<<"t/#">>, #{}}],
|
|
|
+ SubPkt = #mqtt_packet_subscribe{packet_id = 1, topic_filters = TopicFilters},
|
|
|
+ ?assertEqual(1, emqx_packet:info(packet_id, SubPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(properties, SubPkt)),
|
|
|
+ ?assertEqual(TopicFilters, emqx_packet:info(topic_filters, SubPkt)).
|
|
|
+
|
|
|
+t_suback_info(_) ->
|
|
|
+ SubackPkt = #mqtt_packet_suback{packet_id = 1, reason_codes = [0]},
|
|
|
+ ?assertEqual(1, emqx_packet:info(packet_id, SubackPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(properties, SubackPkt)),
|
|
|
+ ?assertEqual([0], emqx_packet:info(reason_codes, SubackPkt)).
|
|
|
+
|
|
|
+t_unsubscribe_info(_) ->
|
|
|
+ UnsubPkt = #mqtt_packet_unsubscribe{packet_id = 1, topic_filters = [<<"t/#">>]},
|
|
|
+ ?assertEqual(1, emqx_packet:info(packet_id, UnsubPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(properties, UnsubPkt)),
|
|
|
+ ?assertEqual([<<"t/#">>], emqx_packet:info(topic_filters, UnsubPkt)).
|
|
|
+
|
|
|
+t_unsuback_info(_) ->
|
|
|
+ AckPkt = #mqtt_packet_unsuback{packet_id = 1, reason_codes = [0]},
|
|
|
+ ?assertEqual(1, emqx_packet:info(packet_id, AckPkt)),
|
|
|
+ ?assertEqual([0], emqx_packet:info(reason_codes, AckPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(properties, AckPkt)).
|
|
|
+
|
|
|
+t_disconnect_info(_) ->
|
|
|
+ DisconnPkt = #mqtt_packet_disconnect{reason_code = 0},
|
|
|
+ ?assertEqual(0, emqx_packet:info(reason_code, DisconnPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(properties, DisconnPkt)).
|
|
|
+
|
|
|
+t_auth_info(_) ->
|
|
|
+ AuthPkt = #mqtt_packet_auth{reason_code = 0},
|
|
|
+ ?assertEqual(0, emqx_packet:info(reason_code, AuthPkt)),
|
|
|
+ ?assertEqual(undefined, emqx_packet:info(properties, AuthPkt)).
|
|
|
+
|
|
|
t_check_publish(_) ->
|
|
|
Props = #{'Response-Topic' => <<"responsetopic">>, 'Topic-Alias' => 1},
|
|
|
ok = emqx_packet:check(?PUBLISH_PACKET(?QOS_1, <<"topic">>, 1, Props, <<"payload">>)),
|