fix(bridges): update testcases for bridge APIs
This commit is contained in:
parent
e1794fbce6
commit
9b4fe87ed0
|
@ -21,7 +21,9 @@
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
-define(CONF_DEFAULT, <<"bridges: {}">>).
|
-define(CONF_DEFAULT, <<"bridges: {}">>).
|
||||||
-define(TEST_ID, <<"http:test_bridge">>).
|
-define(BRIDGE_TYPE, <<"http">>).
|
||||||
|
-define(BRIDGE_NAME, <<"test_bridge">>).
|
||||||
|
-define(BRIDGE_ID, <<"http:test_bridge">>).
|
||||||
-define(URL(PORT, PATH), list_to_binary(
|
-define(URL(PORT, PATH), list_to_binary(
|
||||||
io_lib:format("http://localhost:~s/~s",
|
io_lib:format("http://localhost:~s/~s",
|
||||||
[integer_to_list(PORT), PATH]))).
|
[integer_to_list(PORT), PATH]))).
|
||||||
|
@ -134,11 +136,15 @@ t_http_crud_apis(_) ->
|
||||||
%% POST /bridges/ will create a bridge
|
%% POST /bridges/ will create a bridge
|
||||||
URL1 = ?URL(Port, "path1"),
|
URL1 = ?URL(Port, "path1"),
|
||||||
{ok, 201, Bridge} = request(post, uri(["bridges"]),
|
{ok, 201, Bridge} = request(post, uri(["bridges"]),
|
||||||
?HTTP_BRIDGE(URL1)#{<<"id">> => ?TEST_ID}),
|
?HTTP_BRIDGE(URL1)#{
|
||||||
|
<<"type">> => ?BRIDGE_TYPE,
|
||||||
|
<<"name">> => ?BRIDGE_NAME
|
||||||
|
}),
|
||||||
|
|
||||||
%ct:pal("---bridge: ~p", [Bridge]),
|
%ct:pal("---bridge: ~p", [Bridge]),
|
||||||
?assertMatch(#{ <<"id">> := ?TEST_ID
|
?assertMatch(#{ <<"id">> := ?BRIDGE_ID
|
||||||
, <<"bridge_type">> := <<"http">>
|
, <<"type">> := ?BRIDGE_TYPE
|
||||||
|
, <<"name">> := ?BRIDGE_NAME
|
||||||
, <<"status">> := _
|
, <<"status">> := _
|
||||||
, <<"node_status">> := [_|_]
|
, <<"node_status">> := [_|_]
|
||||||
, <<"metrics">> := _
|
, <<"metrics">> := _
|
||||||
|
@ -148,7 +154,10 @@ t_http_crud_apis(_) ->
|
||||||
|
|
||||||
%% create a again returns an error
|
%% create a again returns an error
|
||||||
{ok, 400, RetMsg} = request(post, uri(["bridges"]),
|
{ok, 400, RetMsg} = request(post, uri(["bridges"]),
|
||||||
?HTTP_BRIDGE(URL1)#{<<"id">> => ?TEST_ID}),
|
?HTTP_BRIDGE(URL1)#{
|
||||||
|
<<"type">> => ?BRIDGE_TYPE,
|
||||||
|
<<"name">> => ?BRIDGE_NAME
|
||||||
|
}),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
#{ <<"code">> := _
|
#{ <<"code">> := _
|
||||||
, <<"message">> := <<"bridge already exists">>
|
, <<"message">> := <<"bridge already exists">>
|
||||||
|
@ -156,10 +165,11 @@ t_http_crud_apis(_) ->
|
||||||
|
|
||||||
%% update the request-path of the bridge
|
%% update the request-path of the bridge
|
||||||
URL2 = ?URL(Port, "path2"),
|
URL2 = ?URL(Port, "path2"),
|
||||||
{ok, 200, Bridge2} = request(put, uri(["bridges", ?TEST_ID]),
|
{ok, 200, Bridge2} = request(put, uri(["bridges", ?BRIDGE_ID]),
|
||||||
?HTTP_BRIDGE(URL2)),
|
?HTTP_BRIDGE(URL2)),
|
||||||
?assertMatch(#{ <<"id">> := ?TEST_ID
|
?assertMatch(#{ <<"id">> := ?BRIDGE_ID
|
||||||
, <<"bridge_type">> := <<"http">>
|
, <<"type">> := ?BRIDGE_TYPE
|
||||||
|
, <<"name">> := ?BRIDGE_NAME
|
||||||
, <<"status">> := _
|
, <<"status">> := _
|
||||||
, <<"node_status">> := [_|_]
|
, <<"node_status">> := [_|_]
|
||||||
, <<"metrics">> := _
|
, <<"metrics">> := _
|
||||||
|
@ -169,8 +179,9 @@ t_http_crud_apis(_) ->
|
||||||
|
|
||||||
%% list all bridges again, assert Bridge2 is in it
|
%% list all bridges again, assert Bridge2 is in it
|
||||||
{ok, 200, Bridge2Str} = request(get, uri(["bridges"]), []),
|
{ok, 200, Bridge2Str} = request(get, uri(["bridges"]), []),
|
||||||
?assertMatch([#{ <<"id">> := ?TEST_ID
|
?assertMatch([#{ <<"id">> := ?BRIDGE_ID
|
||||||
, <<"bridge_type">> := <<"http">>
|
, <<"type">> := ?BRIDGE_TYPE
|
||||||
|
, <<"name">> := ?BRIDGE_NAME
|
||||||
, <<"status">> := _
|
, <<"status">> := _
|
||||||
, <<"node_status">> := [_|_]
|
, <<"node_status">> := [_|_]
|
||||||
, <<"metrics">> := _
|
, <<"metrics">> := _
|
||||||
|
@ -179,9 +190,10 @@ t_http_crud_apis(_) ->
|
||||||
}], jsx:decode(Bridge2Str)),
|
}], jsx:decode(Bridge2Str)),
|
||||||
|
|
||||||
%% get the bridge by id
|
%% get the bridge by id
|
||||||
{ok, 200, Bridge3Str} = request(get, uri(["bridges", ?TEST_ID]), []),
|
{ok, 200, Bridge3Str} = request(get, uri(["bridges", ?BRIDGE_ID]), []),
|
||||||
?assertMatch(#{ <<"id">> := ?TEST_ID
|
?assertMatch(#{ <<"id">> := ?BRIDGE_ID
|
||||||
, <<"bridge_type">> := <<"http">>
|
, <<"type">> := ?BRIDGE_TYPE
|
||||||
|
, <<"name">> := ?BRIDGE_NAME
|
||||||
, <<"status">> := _
|
, <<"status">> := _
|
||||||
, <<"node_status">> := [_|_]
|
, <<"node_status">> := [_|_]
|
||||||
, <<"metrics">> := _
|
, <<"metrics">> := _
|
||||||
|
@ -190,11 +202,11 @@ t_http_crud_apis(_) ->
|
||||||
}, jsx:decode(Bridge3Str)),
|
}, jsx:decode(Bridge3Str)),
|
||||||
|
|
||||||
%% delete the bridge
|
%% delete the bridge
|
||||||
{ok, 204, <<>>} = request(delete, uri(["bridges", ?TEST_ID]), []),
|
{ok, 204, <<>>} = request(delete, uri(["bridges", ?BRIDGE_ID]), []),
|
||||||
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []),
|
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []),
|
||||||
|
|
||||||
%% update a deleted bridge returns an error
|
%% update a deleted bridge returns an error
|
||||||
{ok, 404, ErrMsg2} = request(put, uri(["bridges", ?TEST_ID]),
|
{ok, 404, ErrMsg2} = request(put, uri(["bridges", ?BRIDGE_ID]),
|
||||||
?HTTP_BRIDGE(URL2)),
|
?HTTP_BRIDGE(URL2)),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
#{ <<"code">> := _
|
#{ <<"code">> := _
|
||||||
|
@ -206,11 +218,15 @@ t_start_stop_bridges(_) ->
|
||||||
Port = start_http_server(fun handle_fun_200_ok/1),
|
Port = start_http_server(fun handle_fun_200_ok/1),
|
||||||
URL1 = ?URL(Port, "abc"),
|
URL1 = ?URL(Port, "abc"),
|
||||||
{ok, 201, Bridge} = request(post, uri(["bridges"]),
|
{ok, 201, Bridge} = request(post, uri(["bridges"]),
|
||||||
?HTTP_BRIDGE(URL1)#{<<"id">> => ?TEST_ID}),
|
?HTTP_BRIDGE(URL1)#{
|
||||||
|
<<"type">> => ?BRIDGE_TYPE,
|
||||||
|
<<"name">> => ?BRIDGE_NAME
|
||||||
|
}),
|
||||||
%ct:pal("the bridge ==== ~p", [Bridge]),
|
%ct:pal("the bridge ==== ~p", [Bridge]),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
#{ <<"id">> := ?TEST_ID
|
#{ <<"id">> := ?BRIDGE_ID
|
||||||
, <<"bridge_type">> := <<"http">>
|
, <<"type">> := ?BRIDGE_TYPE
|
||||||
|
, <<"name">> := ?BRIDGE_NAME
|
||||||
, <<"status">> := _
|
, <<"status">> := _
|
||||||
, <<"node_status">> := [_|_]
|
, <<"node_status">> := [_|_]
|
||||||
, <<"metrics">> := _
|
, <<"metrics">> := _
|
||||||
|
@ -219,42 +235,42 @@ t_start_stop_bridges(_) ->
|
||||||
}, jsx:decode(Bridge)),
|
}, jsx:decode(Bridge)),
|
||||||
%% stop it
|
%% stop it
|
||||||
{ok, 200, <<>>} = request(post,
|
{ok, 200, <<>>} = request(post,
|
||||||
uri(["nodes", node(), "bridges", ?TEST_ID, "operation", "stop"]),
|
uri(["nodes", node(), "bridges", ?BRIDGE_ID, "operation", "stop"]),
|
||||||
<<"">>),
|
<<"">>),
|
||||||
{ok, 200, Bridge2} = request(get, uri(["bridges", ?TEST_ID]), []),
|
{ok, 200, Bridge2} = request(get, uri(["bridges", ?BRIDGE_ID]), []),
|
||||||
?assertMatch(#{ <<"id">> := ?TEST_ID
|
?assertMatch(#{ <<"id">> := ?BRIDGE_ID
|
||||||
, <<"status">> := <<"disconnected">>
|
, <<"status">> := <<"disconnected">>
|
||||||
}, jsx:decode(Bridge2)),
|
}, jsx:decode(Bridge2)),
|
||||||
%% start again
|
%% start again
|
||||||
{ok, 200, <<>>} = request(post,
|
{ok, 200, <<>>} = request(post,
|
||||||
uri(["nodes", node(), "bridges", ?TEST_ID, "operation", "start"]),
|
uri(["nodes", node(), "bridges", ?BRIDGE_ID, "operation", "start"]),
|
||||||
<<"">>),
|
<<"">>),
|
||||||
{ok, 200, Bridge3} = request(get, uri(["bridges", ?TEST_ID]), []),
|
{ok, 200, Bridge3} = request(get, uri(["bridges", ?BRIDGE_ID]), []),
|
||||||
?assertMatch(#{ <<"id">> := ?TEST_ID
|
?assertMatch(#{ <<"id">> := ?BRIDGE_ID
|
||||||
, <<"status">> := <<"connected">>
|
, <<"status">> := <<"connected">>
|
||||||
}, jsx:decode(Bridge3)),
|
}, jsx:decode(Bridge3)),
|
||||||
%% restart an already started bridge
|
%% restart an already started bridge
|
||||||
{ok, 200, <<>>} = request(post,
|
{ok, 200, <<>>} = request(post,
|
||||||
uri(["nodes", node(), "bridges", ?TEST_ID, "operation", "restart"]),
|
uri(["nodes", node(), "bridges", ?BRIDGE_ID, "operation", "restart"]),
|
||||||
<<"">>),
|
<<"">>),
|
||||||
{ok, 200, Bridge3} = request(get, uri(["bridges", ?TEST_ID]), []),
|
{ok, 200, Bridge3} = request(get, uri(["bridges", ?BRIDGE_ID]), []),
|
||||||
?assertMatch(#{ <<"id">> := ?TEST_ID
|
?assertMatch(#{ <<"id">> := ?BRIDGE_ID
|
||||||
, <<"status">> := <<"connected">>
|
, <<"status">> := <<"connected">>
|
||||||
}, jsx:decode(Bridge3)),
|
}, jsx:decode(Bridge3)),
|
||||||
%% stop it again
|
%% stop it again
|
||||||
{ok, 200, <<>>} = request(post,
|
{ok, 200, <<>>} = request(post,
|
||||||
uri(["nodes", node(), "bridges", ?TEST_ID, "operation", "stop"]),
|
uri(["nodes", node(), "bridges", ?BRIDGE_ID, "operation", "stop"]),
|
||||||
<<"">>),
|
<<"">>),
|
||||||
%% restart a stopped bridge
|
%% restart a stopped bridge
|
||||||
{ok, 200, <<>>} = request(post,
|
{ok, 200, <<>>} = request(post,
|
||||||
uri(["nodes", node(), "bridges", ?TEST_ID, "operation", "restart"]),
|
uri(["nodes", node(), "bridges", ?BRIDGE_ID, "operation", "restart"]),
|
||||||
<<"">>),
|
<<"">>),
|
||||||
{ok, 200, Bridge4} = request(get, uri(["bridges", ?TEST_ID]), []),
|
{ok, 200, Bridge4} = request(get, uri(["bridges", ?BRIDGE_ID]), []),
|
||||||
?assertMatch(#{ <<"id">> := ?TEST_ID
|
?assertMatch(#{ <<"id">> := ?BRIDGE_ID
|
||||||
, <<"status">> := <<"connected">>
|
, <<"status">> := <<"connected">>
|
||||||
}, jsx:decode(Bridge4)),
|
}, jsx:decode(Bridge4)),
|
||||||
%% delete the bridge
|
%% delete the bridge
|
||||||
{ok, 204, <<>>} = request(delete, uri(["bridges", ?TEST_ID]), []),
|
{ok, 204, <<>>} = request(delete, uri(["bridges", ?BRIDGE_ID]), []),
|
||||||
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []).
|
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue