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

Add more test cases for emqx_sys

zhanghongtong 6 лет назад
Родитель
Сommit
f1ae430d43
2 измененных файлов с 11 добавлено и 3 удалено
  1. 6 1
      src/emqx_sys.erl
  2. 5 2
      test/emqx_sys_SUITE.erl

+ 6 - 1
src/emqx_sys.erl

@@ -45,6 +45,11 @@
         , terminate/2
         ]).
 
+-ifdef(TEST).
+-compile(export_all).
+-compile(nowarn_export_all).
+-endif.
+
 -import(emqx_topic, [systop/1]).
 -import(emqx_misc, [start_timer/2]).
 
@@ -192,7 +197,7 @@ uptime(hours, H) when H < 24 ->
 uptime(hours, H) ->
     [uptime(days, H div 24), integer_to_list(H rem 24), " hours, "];
 uptime(days, D) ->
-    [integer_to_list(D), " days,"].
+    [integer_to_list(D), " days, "].
 
 publish(uptime, Uptime) ->
     safe_publish(systop(uptime), Uptime);

+ 5 - 2
test/emqx_sys_SUITE.erl

@@ -49,8 +49,11 @@ end_per_suite(_Config) ->
 % t_sysdescr(_) ->
 %     error('TODO').
 
-% t_uptime(_) ->
-%     error('TODO').
+t_uptime(_) ->
+    ?assertEqual(<<"1 seconds">>, iolist_to_binary(emqx_sys:uptime(seconds, 1))),
+    ?assertEqual(<<"1 minutes, 0 seconds">>, iolist_to_binary(emqx_sys:uptime(seconds, 60))),
+    ?assertEqual(<<"1 hours, 0 minutes, 0 seconds">>, iolist_to_binary(emqx_sys:uptime(seconds, 3600))),
+    ?assertEqual(<<"1 days, 0 hours, 0 minutes, 0 seconds">>, iolist_to_binary(emqx_sys:uptime(seconds, 86400))).
 
 % t_datetime(_) ->
 %     error('TODO').