Просмотр исходного кода

test(gw): use emqx_config:init_load/2

JianBo He 4 лет назад
Родитель
Сommit
c986f89319

+ 1 - 1
apps/emqx_gateway/test/emqx_exproto_SUITE.erl

@@ -66,7 +66,7 @@ end_per_group(_, Cfg) ->
 set_special_cfg(emqx_gateway) ->
 set_special_cfg(emqx_gateway) ->
     LisType = get(grpname),
     LisType = get(grpname),
     emqx_config:put(
     emqx_config:put(
-      [emqx_gateway, exproto],
+      [gateway, exproto],
       #{'1' =>
       #{'1' =>
         #{authenticator => allow_anonymous,
         #{authenticator => allow_anonymous,
           server => #{bind => 9100},
           server => #{bind => 9100},

+ 8 - 26
apps/emqx_gateway/test/emqx_gateway_registry_SUITE.erl

@@ -21,6 +21,12 @@
 -compile(export_all).
 -compile(export_all).
 -compile(nowarn_export_all).
 -compile(nowarn_export_all).
 
 
+-define(CONF_DEFAULT, <<"""
+gateway: {
+    stomp.1 {}
+}
+""">>).
+
 all() -> emqx_ct:all(?MODULE).
 all() -> emqx_ct:all(?MODULE).
 
 
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
@@ -28,37 +34,14 @@ all() -> emqx_ct:all(?MODULE).
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 
 
 init_per_suite(Cfg) ->
 init_per_suite(Cfg) ->
-    emqx_ct_helpers:start_apps([emqx_gateway], fun set_special_configs/1),
+    ok = emqx_config:init_load(emqx_gateway_schema, ?CONF_DEFAULT),
+    emqx_ct_helpers:start_apps([emqx_gateway]),
     Cfg.
     Cfg.
 
 
 end_per_suite(_Cfg) ->
 end_per_suite(_Cfg) ->
     emqx_ct_helpers:stop_apps([emqx_gateway]),
     emqx_ct_helpers:stop_apps([emqx_gateway]),
     ok.
     ok.
 
 
-set_special_configs(emqx_gateway) ->
-    emqx_config:put(
-      [emqx_gateway],
-      #{stomp =>
-        #{'1' =>
-          #{authenticator => allow_anonymous,
-            clientinfo_override =>
-                #{password => "${Packet.headers.passcode}",
-                  username => "${Packet.headers.login}"},
-            frame =>
-                #{max_body_length => 8192,
-                  max_headers => 10,
-                  max_headers_length => 1024},
-            listener =>
-                #{tcp =>
-                  #{'1' =>
-                    #{acceptors => 16,active_n => 100,backlog => 1024,
-                      bind => 61613,high_watermark => 1048576,
-                      max_conn_rate => 1000,max_connections => 1024000,
-                      send_timeout => 15000,send_timeout_close => true}}}}}}),
-    ok;
-set_special_configs(_) ->
-    ok.
-
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 %% Test cases
 %% Test cases
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
@@ -84,4 +67,3 @@ t_load_unload(_) ->
 
 
 init([paramsin]) ->
 init([paramsin]) ->
     {ok, _GwState = #{gwstate => 1}}.
     {ok, _GwState = #{gwstate => 1}}.
-

+ 28 - 3
apps/emqx_gateway/test/emqx_sn_protocol_SUITE.erl

@@ -50,6 +50,31 @@
 %% erlang:system_time should be unique and random enough
 %% erlang:system_time should be unique and random enough
 -define(CLIENTID, iolist_to_binary([atom_to_list(?FUNCTION_NAME), "-",
 -define(CLIENTID, iolist_to_binary([atom_to_list(?FUNCTION_NAME), "-",
                                     integer_to_list(erlang:system_time())])).
                                     integer_to_list(erlang:system_time())])).
+
+-define(CONF_DEFAULT, <<"""
+gateway: {
+    mqttsn.1: {
+        gateway_id: 1
+        broadcast: true
+        enable_stats: true
+        enable_qos3: true
+        predefined: [
+            {id: 1, topic: \"/predefined/topic/name/hello\"},
+            {id: 2, topic: \"/predefined/topic/name/nice\"}
+        ]
+        clientinfo_override: {
+            username: \"user1\"
+            password: \"pw123\"
+        }
+        listener.udp.1: {
+            bind: 1884
+            max_connections: 10240000
+            max_conn_rate: 1000
+        }
+    }
+}
+""">>).
+
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 %% Setups
 %% Setups
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
@@ -58,8 +83,8 @@ all() ->
     emqx_ct:all(?MODULE).
     emqx_ct:all(?MODULE).
 
 
 init_per_suite(Config) ->
 init_per_suite(Config) ->
-    logger:set_module_level(emqx_sn_gateway, debug),
-    emqx_ct_helpers:start_apps([emqx_gateway], fun set_special_confs/1),
+    ok = emqx_config:init_load(emqx_gateway_schema, ?CONF_DEFAULT),
+    emqx_ct_helpers:start_apps([emqx_gateway]),
     Config.
     Config.
 
 
 end_per_suite(_) ->
 end_per_suite(_) ->
@@ -67,7 +92,7 @@ end_per_suite(_) ->
 
 
 set_special_confs(emqx_gateway) ->
 set_special_confs(emqx_gateway) ->
     emqx_config:put(
     emqx_config:put(
-      [emqx_gateway],
+      [gateway],
       #{ mqttsn =>
       #{ mqttsn =>
          #{'1' =>
          #{'1' =>
             #{broadcast => true,
             #{broadcast => true,

+ 17 - 25
apps/emqx_gateway/test/emqx_stomp_SUITE.erl

@@ -23,6 +23,21 @@
 
 
 -define(HEARTBEAT, <<$\n>>).
 -define(HEARTBEAT, <<$\n>>).
 
 
+-define(CONF_DEFAULT, <<"""
+gateway: {
+    stomp.1: {
+        authenticator: allow_anonymous
+        clientinfo_override: {
+            username: \"${Packet.headers.login}\"
+            password: \"${Packet.headers.passcode}\"
+        }
+        listener.tcp.1: {
+            bind: 61613
+        }
+    }
+}
+""">>).
+
 all() -> emqx_ct:all(?MODULE).
 all() -> emqx_ct:all(?MODULE).
 
 
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
@@ -30,37 +45,14 @@ all() -> emqx_ct:all(?MODULE).
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 
 
 init_per_suite(Cfg) ->
 init_per_suite(Cfg) ->
-    emqx_ct_helpers:start_apps([emqx_gateway], fun set_special_configs/1),
+    ok = emqx_config:init_load(emqx_gateway_schema, ?CONF_DEFAULT),
+    emqx_ct_helpers:start_apps([emqx_gateway]),
     Cfg.
     Cfg.
 
 
 end_per_suite(_Cfg) ->
 end_per_suite(_Cfg) ->
     emqx_ct_helpers:stop_apps([emqx_gateway]),
     emqx_ct_helpers:stop_apps([emqx_gateway]),
     ok.
     ok.
 
 
-set_special_configs(emqx_gateway) ->
-    emqx_config:put(
-      [emqx_gateway],
-      #{stomp =>
-        #{'1' =>
-          #{authenticator => allow_anonymous,
-            clientinfo_override =>
-                #{password => "${Packet.headers.passcode}",
-                  username => "${Packet.headers.login}"},
-            frame =>
-                #{max_body_length => 8192,
-                  max_headers => 10,
-                  max_headers_length => 1024},
-            listener =>
-                #{tcp =>
-                  #{'1' =>
-                    #{acceptors => 16,active_n => 100,backlog => 1024,
-                      bind => 61613,high_watermark => 1048576,
-                      max_conn_rate => 1000,max_connections => 1024000,
-                      send_timeout => 15000,send_timeout_close => true}}}}}}),
-    ok;
-set_special_configs(_) ->
-    ok.
-
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 %% Test Cases
 %% Test Cases
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------