|
1 | 1 | %%--------------------------------------------------------------------
|
2 |
| -%% Copyright (c) 2019-2022 EMQ Technologies Co., Ltd. All Rights Reserved. |
| 2 | +%% Copyright (c) 2019-2022, 2025 EMQ Technologies Co., Ltd. All Rights Reserved. |
3 | 3 | %%
|
4 | 4 | %% Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | %% you may not use this file except in compliance with the License.
|
@@ -39,53 +39,55 @@ init_per_testcase(t_restart_process, Config) ->
|
39 | 39 | {skip, no_etcd}
|
40 | 40 | end;
|
41 | 41 | init_per_testcase(_TestCase, Config) ->
|
42 |
| - ok = meck:new(httpc, [non_strict, passthrough, no_history]), |
| 42 | + ok = meck:new(ekka_httpc, [non_strict, no_history]), |
43 | 43 | Config.
|
44 | 44 |
|
45 | 45 | end_per_testcase(t_restart_process, _Config) ->
|
46 | 46 | application:stop(eetcd);
|
47 | 47 | end_per_testcase(TestCase, _Config) ->
|
48 |
| - ok = meck:unload(httpc), |
| 48 | + ok = meck:unload(ekka_httpc), |
49 | 49 | ekka_ct:cleanup(TestCase).
|
50 | 50 |
|
51 | 51 | t_discover(_Config) ->
|
52 | 52 | Json = << "{\"node\": {\"nodes\": [{\"key\": \"ekkacl/[email protected]\"}]}}">>,
|
53 |
| - ok = meck:expect(httpc, request, fun(get, _Req, _Opts, _) -> {ok, 200, Json} end), |
| 53 | + ok = meck:expect(ekka_httpc, get, fun(_Server, _Path, _Params, _Opts) -> |
| 54 | + {ok, jsone:decode(Json)} |
| 55 | + end), |
54 | 56 | { ok, [ '[email protected]']} = ekka_cluster_strategy: discover( ekka_cluster_etcd, ?OPTIONS).
|
55 | 57 |
|
56 | 58 | t_lock(_Config) ->
|
57 |
| - ok = meck:expect(httpc, request, fun(put, _Req, _Opts, _) -> |
58 |
| - {ok, 200, <<"{\"errorCode\": 0}">>} |
59 |
| - end), |
| 59 | + ok = meck:expect(ekka_httpc, put, fun(_Server, _Path, _Params, _Opts) -> |
| 60 | + {ok, jsone:decode(<<"{\"errorCode\": 0}">>)} |
| 61 | + end), |
60 | 62 | ok = ekka_cluster_strategy:lock(ekka_cluster_etcd, ?OPTIONS).
|
61 | 63 |
|
62 | 64 | t_unlock(_) ->
|
63 |
| - ok = meck:expect(httpc, request, fun(delete, _Req, _Opts, _) -> |
64 |
| - {ok, 200, <<"{\"errorCode\": 0}">>} |
65 |
| - end), |
| 65 | + ok = meck:expect(ekka_httpc, delete, fun(_Server, _Path, _Params, _Opts) -> |
| 66 | + {ok, jsone:decode(<<"{\"errorCode\": 0}">>)} |
| 67 | + end), |
66 | 68 | ok = ekka_cluster_strategy:unlock(ekka_cluster_etcd, ?OPTIONS).
|
67 | 69 |
|
68 | 70 | t_register(_) ->
|
69 | 71 | ok = meck:new(ekka_cluster_sup, [non_strict, passthrough, no_history]),
|
70 | 72 | ok = meck:expect(ekka_cluster_sup, start_child, fun(_, _) -> {ok, self()} end),
|
71 |
| - ok = meck:expect(httpc, request, fun(put, _Req, _Opts, _) -> |
72 |
| - {ok, 200, <<"{\"errorCode\": 0}">>} |
73 |
| - end), |
| 73 | + ok = meck:expect(ekka_httpc, put, fun(_Server, _Path, _Params, _Opts) -> |
| 74 | + {ok, jsone:decode(<<"{\"errorCode\": 0}">>)} |
| 75 | + end), |
74 | 76 | ok = ekka_cluster_strategy:register(ekka_cluster_etcd, ?OPTIONS),
|
75 | 77 | ok = meck:unload(ekka_cluster_sup).
|
76 | 78 |
|
77 | 79 | t_unregister(_) ->
|
78 |
| - ok = meck:expect(httpc, request, fun(delete, _Req, _Opts, _) -> |
79 |
| - {ok, 200, <<"{\"errorCode\": 0}">>} |
80 |
| - end), |
| 80 | + ok = meck:expect(ekka_httpc, delete, fun(_Server, _Path, _Params, _Opts) -> |
| 81 | + {ok, jsone:decode(<<"{\"errorCode\": 0}">>)} |
| 82 | + end), |
81 | 83 | ok = meck:expect(ekka_cluster_sup, stop_child, fun(_) -> ok end),
|
82 | 84 | ok = ekka_cluster_strategy:unregister(ekka_cluster_etcd, ?OPTIONS),
|
83 | 85 | ok = meck:unload(ekka_cluster_sup).
|
84 | 86 |
|
85 | 87 | t_etcd_set_node_key(_) ->
|
86 |
| - ok = meck:expect(httpc, request, fun(put, _Req, _Opts, _) -> |
87 |
| - {ok, 200, <<"{\"errorCode\": 0}">>} |
88 |
| - end), |
| 88 | + ok = meck:expect(ekka_httpc, put, fun(_Server, _Path, _Params, _Opts) -> |
| 89 | + {ok, jsone:decode(<<"{\"errorCode\": 0}">>)} |
| 90 | + end), |
89 | 91 | {ok, #{<<"errorCode">> := 0}} = ekka_cluster_etcd:etcd_set_node_key(?OPTIONS).
|
90 | 92 |
|
91 | 93 | t_restart_process(_) ->
|
|
0 commit comments