fix test cases
This commit is contained in:
parent
711a875e23
commit
30875c0706
|
@ -53,8 +53,8 @@ compile_test() ->
|
||||||
?assertEqual({deny, all}, compile({deny, all})).
|
?assertEqual({deny, all}, compile({deny, all})).
|
||||||
|
|
||||||
match_test() ->
|
match_test() ->
|
||||||
User = #mqtt_client{ipaddress = {127,0,0,1}, client_id = <<"testClient">>, username = <<"TestUser">>},
|
User = #mqtt_client{peername = {{127,0,0,1}, 2948}, client_id = <<"testClient">>, username = <<"TestUser">>},
|
||||||
User2 = #mqtt_client{ipaddress = {192,168,0,10}, client_id = <<"testClient">>, username = <<"TestUser">>},
|
User2 = #mqtt_client{peername = {{192,168,0,10}, 3028}, client_id = <<"testClient">>, username = <<"TestUser">>},
|
||||||
|
|
||||||
?assertEqual({matched, allow}, match(User, <<"Test/Topic">>, {allow, all})),
|
?assertEqual({matched, allow}, match(User, <<"Test/Topic">>, {allow, all})),
|
||||||
?assertEqual({matched, deny}, match(User, <<"Test/Topic">>, {deny, all})),
|
?assertEqual({matched, deny}, match(User, <<"Test/Topic">>, {deny, all})),
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
parse_connect_test() ->
|
parse_connect_test() ->
|
||||||
State = emqttd_parser:init([]),
|
Parser = emqttd_parser:new([]),
|
||||||
%% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQIsdp, ProtoVsn=3, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined)
|
%% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQIsdp, ProtoVsn=3, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined)
|
||||||
V31ConnBin = <<16,37,0,6,77,81,73,115,100,112,3,2,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,49,45,105,77,97,99,46,108,111,99,97>>,
|
V31ConnBin = <<16,37,0,6,77,81,73,115,100,112,3,2,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,49,45,105,77,97,99,46,108,111,99,97>>,
|
||||||
?assertMatch({ok, #mqtt_packet{
|
?assertMatch({ok, #mqtt_packet{
|
||||||
|
@ -45,7 +45,7 @@ parse_connect_test() ->
|
||||||
proto_name = <<"MQIsdp">>,
|
proto_name = <<"MQIsdp">>,
|
||||||
client_id = <<"mosqpub/10451-iMac.loca">>,
|
client_id = <<"mosqpub/10451-iMac.loca">>,
|
||||||
clean_sess = true,
|
clean_sess = true,
|
||||||
keep_alive = 60}}, <<>>}, emqttd_parser:parse(V31ConnBin, State)),
|
keep_alive = 60}}, <<>>}, Parser(V31ConnBin)),
|
||||||
%% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined)
|
%% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined)
|
||||||
V311ConnBin = <<16,35,0,4,77,81,84,84,4,2,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,49,45,105,77,97,99,46,108,111,99,97>>,
|
V311ConnBin = <<16,35,0,4,77,81,84,84,4,2,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,49,45,105,77,97,99,46,108,111,99,97>>,
|
||||||
?assertMatch({ok, #mqtt_packet{
|
?assertMatch({ok, #mqtt_packet{
|
||||||
|
@ -57,7 +57,7 @@ parse_connect_test() ->
|
||||||
proto_name = <<"MQTT">>,
|
proto_name = <<"MQTT">>,
|
||||||
client_id = <<"mosqpub/10451-iMac.loca">>,
|
client_id = <<"mosqpub/10451-iMac.loca">>,
|
||||||
clean_sess = true,
|
clean_sess = true,
|
||||||
keep_alive = 60 } }, <<>>}, emqttd_parser:parse(V311ConnBin, State)),
|
keep_alive = 60 } }, <<>>}, Parser(V311ConnBin)),
|
||||||
|
|
||||||
%% CONNECT(Qos=0, Retain=false, Dup=false, ClientId="", ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60)
|
%% CONNECT(Qos=0, Retain=false, Dup=false, ClientId="", ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60)
|
||||||
V311ConnWithoutClientId = <<16,12,0,4,77,81,84,84,4,2,0,60,0,0>>,
|
V311ConnWithoutClientId = <<16,12,0,4,77,81,84,84,4,2,0,60,0,0>>,
|
||||||
|
@ -70,7 +70,7 @@ parse_connect_test() ->
|
||||||
proto_name = <<"MQTT">>,
|
proto_name = <<"MQTT">>,
|
||||||
client_id = <<>>,
|
client_id = <<>>,
|
||||||
clean_sess = true,
|
clean_sess = true,
|
||||||
keep_alive = 60 } }, <<>>}, emqttd_parser:parse(V311ConnWithoutClientId, State)),
|
keep_alive = 60 } }, <<>>}, Parser(V311ConnWithoutClientId)),
|
||||||
%%CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10452-iMac.loca, ProtoName=MQIsdp, ProtoVsn=3, CleanSess=true, KeepAlive=60, Username=test, Password=******, Will(Qos=1, Retain=false, Topic=/will, Msg=willmsg))
|
%%CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10452-iMac.loca, ProtoName=MQIsdp, ProtoVsn=3, CleanSess=true, KeepAlive=60, Username=test, Password=******, Will(Qos=1, Retain=false, Topic=/will, Msg=willmsg))
|
||||||
ConnBinWithWill = <<16,67,0,6,77,81,73,115,100,112,3,206,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,50,45,105,77,97,99,46,108,111,99,97,0,5,47,119,105,108,108,0,7,119,105,108,108,109,115,103,0,4,116,101,115,116,0,6,112,117,98,108,105,99>>,
|
ConnBinWithWill = <<16,67,0,6,77,81,73,115,100,112,3,206,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,50,45,105,77,97,99,46,108,111,99,97,0,5,47,119,105,108,108,0,7,119,105,108,108,109,115,103,0,4,116,101,115,116,0,6,112,117,98,108,105,99>>,
|
||||||
?assertMatch({ok, #mqtt_packet{
|
?assertMatch({ok, #mqtt_packet{
|
||||||
|
@ -90,11 +90,11 @@ parse_connect_test() ->
|
||||||
will_msg = <<"willmsg">> ,
|
will_msg = <<"willmsg">> ,
|
||||||
username = <<"test">>,
|
username = <<"test">>,
|
||||||
password = <<"public">>}},
|
password = <<"public">>}},
|
||||||
<<>> }, emqttd_parser:parse(ConnBinWithWill, State)),
|
<<>> }, Parser(ConnBinWithWill)),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
parse_publish_test() ->
|
parse_publish_test() ->
|
||||||
State = emqttd_parser:init([]),
|
Parser = emqttd_parser:new([]),
|
||||||
%%PUBLISH(Qos=1, Retain=false, Dup=false, TopicName=a/b/c, PacketId=1, Payload=<<"hahah">>)
|
%%PUBLISH(Qos=1, Retain=false, Dup=false, TopicName=a/b/c, PacketId=1, Payload=<<"hahah">>)
|
||||||
PubBin = <<50,14,0,5,97,47,98,47,99,0,1,104,97,104,97,104>>,
|
PubBin = <<50,14,0,5,97,47,98,47,99,0,1,104,97,104,97,104>>,
|
||||||
?assertMatch({ok, #mqtt_packet{
|
?assertMatch({ok, #mqtt_packet{
|
||||||
|
@ -104,7 +104,7 @@ parse_publish_test() ->
|
||||||
retain = false},
|
retain = false},
|
||||||
variable = #mqtt_packet_publish{topic_name = <<"a/b/c">>,
|
variable = #mqtt_packet_publish{topic_name = <<"a/b/c">>,
|
||||||
packet_id = 1},
|
packet_id = 1},
|
||||||
payload = <<"hahah">> }, <<>>}, emqttd_parser:parse(PubBin, State)),
|
payload = <<"hahah">> }, <<>>}, Parser(PubBin)),
|
||||||
|
|
||||||
%PUBLISH(Qos=0, Retain=false, Dup=false, TopicName=xxx/yyy, PacketId=undefined, Payload=<<"hello">>)
|
%PUBLISH(Qos=0, Retain=false, Dup=false, TopicName=xxx/yyy, PacketId=undefined, Payload=<<"hello">>)
|
||||||
%DISCONNECT(Qos=0, Retain=false, Dup=false)
|
%DISCONNECT(Qos=0, Retain=false, Dup=false)
|
||||||
|
@ -116,15 +116,16 @@ parse_publish_test() ->
|
||||||
retain = false},
|
retain = false},
|
||||||
variable = #mqtt_packet_publish{topic_name = <<"xxx/yyy">>,
|
variable = #mqtt_packet_publish{topic_name = <<"xxx/yyy">>,
|
||||||
packet_id = undefined},
|
packet_id = undefined},
|
||||||
payload = <<"hello">> }, <<224,0>>}, emqttd_parser:parse(PubBin1, State)),
|
payload = <<"hello">> }, <<224,0>>}, Parser(PubBin1)),
|
||||||
?assertMatch({ok, #mqtt_packet{
|
?assertMatch({ok, #mqtt_packet{
|
||||||
header = #mqtt_packet_header{type = ?DISCONNECT,
|
header = #mqtt_packet_header{type = ?DISCONNECT,
|
||||||
dup = false,
|
dup = false,
|
||||||
qos = 0,
|
qos = 0,
|
||||||
retain = false}
|
retain = false}
|
||||||
}, <<>>}, emqttd_parser:parse(<<224, 0>>, State)).
|
}, <<>>}, Parser(<<224, 0>>)).
|
||||||
|
|
||||||
parse_puback_test() ->
|
parse_puback_test() ->
|
||||||
|
Parser = emqttd_parser:new([]),
|
||||||
%%PUBACK(Qos=0, Retain=false, Dup=false, PacketId=1)
|
%%PUBACK(Qos=0, Retain=false, Dup=false, PacketId=1)
|
||||||
PubAckBin = <<64,2,0,1>>,
|
PubAckBin = <<64,2,0,1>>,
|
||||||
?assertMatch({ok, #mqtt_packet {
|
?assertMatch({ok, #mqtt_packet {
|
||||||
|
@ -132,7 +133,7 @@ parse_puback_test() ->
|
||||||
dup = false,
|
dup = false,
|
||||||
qos = 0,
|
qos = 0,
|
||||||
retain = false }
|
retain = false }
|
||||||
}, <<>>}, emqttd_parser:parse(PubAckBin, emqttd_parser:init([]))),
|
}, <<>>}, Parser(PubAckBin)),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
parse_subscribe_test() ->
|
parse_subscribe_test() ->
|
||||||
|
@ -142,6 +143,7 @@ parse_pingreq_test() ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
parse_disconnect_test() ->
|
parse_disconnect_test() ->
|
||||||
|
Parser = emqttd_parser:new([]),
|
||||||
%DISCONNECT(Qos=0, Retain=false, Dup=false)
|
%DISCONNECT(Qos=0, Retain=false, Dup=false)
|
||||||
Bin = <<224, 0>>,
|
Bin = <<224, 0>>,
|
||||||
?assertMatch({ok, #mqtt_packet{
|
?assertMatch({ok, #mqtt_packet{
|
||||||
|
@ -149,7 +151,7 @@ parse_disconnect_test() ->
|
||||||
dup = false,
|
dup = false,
|
||||||
qos = 0,
|
qos = 0,
|
||||||
retain = false}
|
retain = false}
|
||||||
}, <<>>}, emqttd_parser:parse(Bin, emqttd_parser:init([]))).
|
}, <<>>}, Parser(Bin)).
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue