Feng пре 10 година
родитељ
комит
c0d283aaa7

+ 2 - 2
test/emqttd_access_control_tests.erl

@@ -71,8 +71,8 @@ unregister_mod_test() ->
 check_acl_test() ->
     with_acl(
         fun() ->
-            User1 = #mqtt_client{clientid = <<"client1">>, username = <<"testuser">>},
-            User2 = #mqtt_client{clientid = <<"client2">>, username = <<"xyz">>},
+            User1 = #mqtt_client{client_id = <<"client1">>, username = <<"testuser">>},
+            User2 = #mqtt_client{client_id = <<"client2">>, username = <<"xyz">>},
             ?assertEqual(allow, emqttd_access_control:check_acl(User1, subscribe, <<"users/testuser/1">>)),
 	    ?assertEqual(allow, emqttd_access_control:check_acl(User1, subscribe, <<"clients/client1">>)),
 	    ?assertEqual(deny, emqttd_access_control:check_acl(User1, subscribe, <<"clients/client1/x/y">>)),

+ 2 - 2
test/emqttd_access_rule_tests.erl

@@ -53,8 +53,8 @@ compile_test() ->
     ?assertEqual({deny, all},  compile({deny, all})).
 
 match_test() ->
-    User = #mqtt_client{ipaddress = {127,0,0,1}, clientid = <<"testClient">>, username = <<"TestUser">>},
-    User2 = #mqtt_client{ipaddress = {192,168,0,10}, clientid = <<"testClient">>, username = <<"TestUser">>},
+    User = #mqtt_client{ipaddress = {127,0,0,1}, client_id = <<"testClient">>, username = <<"TestUser">>},
+    User2 = #mqtt_client{ipaddress = {192,168,0,10}, client_id = <<"testClient">>, username = <<"TestUser">>},
     
     ?assertEqual({matched, allow}, match(User, <<"Test/Topic">>, {allow, all})),
     ?assertEqual({matched, deny},  match(User, <<"Test/Topic">>, {deny, all})),

+ 38 - 0
test/emqttd_guid_tests.erl

@@ -0,0 +1,38 @@
+%%%-----------------------------------------------------------------------------
+%%% @Copyright (C) 2012-2015, Feng Lee <feng@emqtt.io>
+%%%
+%%% Permission is hereby granted, free of charge, to any person obtaining a copy
+%%% of this software and associated documentation files (the "Software"), to deal
+%%% in the Software without restriction, including without limitation the rights
+%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+%%% copies of the Software, and to permit persons to whom the Software is
+%%% furnished to do so, subject to the following conditions:
+%%%
+%%% The above copyright notice and this permission notice shall be included in all
+%%% copies or substantial portions of the Software.
+%%%
+%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+%%% SOFTWARE.
+%%%-----------------------------------------------------------------------------
+
+-module(emqttd_guid_tests).
+
+-ifdef(TEST).
+
+-include_lib("eunit/include/eunit.hrl").
+
+gen_test() ->
+    Guid1 = emqttd_guid:gen(),
+    Guid2 = emqttd_guid:gen(),
+    ?assertMatch(<<_:128>>, Guid1),
+    ?assertEqual(true, Guid2 >= Guid1).
+
+-endif.
+
+
+

+ 6 - 6
test/emqttd_parser_tests.erl

@@ -26,10 +26,10 @@
 %%%-----------------------------------------------------------------------------
 -module(emqttd_parser_tests).
 
--include("emqttd_protocol.hrl").
-
 -ifdef(TEST).
 
+-include("emqttd_protocol.hrl").
+
 -include_lib("eunit/include/eunit.hrl").
 
 parse_connect_test() ->
@@ -43,7 +43,7 @@ parse_connect_test() ->
                                                       retain = false},
                          variable = #mqtt_packet_connect{proto_ver  = 3,
                                                          proto_name = <<"MQIsdp">>,
-                                                         clientid   = <<"mosqpub/10451-iMac.loca">>,
+                                                         client_id  = <<"mosqpub/10451-iMac.loca">>,
                                                          clean_sess = true,
                                                          keep_alive = 60}}, <<>>}, emqttd_parser:parse(V31ConnBin, State)),
     %% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined)
@@ -55,7 +55,7 @@ parse_connect_test() ->
                                                       retain = false}, 
                          variable = #mqtt_packet_connect{proto_ver  = 4, 
                                                          proto_name = <<"MQTT">>, 
-                                                         clientid   = <<"mosqpub/10451-iMac.loca">>,
+                                                         client_id  = <<"mosqpub/10451-iMac.loca">>,
                                                          clean_sess = true, 
                                                          keep_alive = 60 } }, <<>>}, emqttd_parser:parse(V311ConnBin, State)),
 
@@ -68,7 +68,7 @@ parse_connect_test() ->
                                                       retain = false}, 
                          variable = #mqtt_packet_connect{proto_ver = 4, 
                                                          proto_name = <<"MQTT">>, 
-                                                         clientid = <<>>,
+                                                         client_id  = <<>>,
                                                          clean_sess = true, 
                                                          keep_alive = 60 } }, <<>>}, emqttd_parser:parse(V311ConnWithoutClientId, State)),
     %%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))
@@ -80,7 +80,7 @@ parse_connect_test() ->
                                                       retain = false},
                          variable = #mqtt_packet_connect{proto_ver = 3,
                                                          proto_name = <<"MQIsdp">>, 
-                                                         clientid = <<"mosqpub/10452-iMac.loca">>,
+                                                         client_id  = <<"mosqpub/10452-iMac.loca">>,
                                                          clean_sess = true, 
                                                          keep_alive = 60,
                                                          will_retain = false,