Merge pull request #7578 from EMQ-YangM/improve_code_cover

test: improve emqx_mgmt_api_stats test coverage to 100%
This commit is contained in:
Yang Miao 2022-04-12 10:37:09 +08:00 committed by GitHub
commit 7af9919823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -31,6 +31,15 @@ end_per_suite(_) ->
emqx_mgmt_api_test_util:end_suite(). emqx_mgmt_api_test_util:end_suite().
t_stats_api(_) -> t_stats_api(_) ->
S = emqx_mgmt_api_test_util:api_path(["stats?aggregate=false"]),
{ok, S1} = emqx_mgmt_api_test_util:request_api(get, S),
[Stats1] = emqx_json:decode(S1, [return_maps]),
SystemStats1 = emqx_mgmt:get_stats(),
Fun1 =
fun(Key) ->
?assertEqual(maps:get(Key, SystemStats1), maps:get(atom_to_binary(Key, utf8), Stats1))
end,
lists:foreach(Fun1, maps:keys(SystemStats1)),
StatsPath = emqx_mgmt_api_test_util:api_path(["stats?aggregate=true"]), StatsPath = emqx_mgmt_api_test_util:api_path(["stats?aggregate=true"]),
SystemStats = emqx_mgmt:get_stats(), SystemStats = emqx_mgmt:get_stats(),
{ok, StatsResponse} = emqx_mgmt_api_test_util:request_api(get, StatsPath), {ok, StatsResponse} = emqx_mgmt_api_test_util:request_api(get, StatsPath),