fix docker tests
This commit is contained in:
parent
3aae06577a
commit
b7d12aa9d7
@ -36,13 +36,11 @@ check_image_exist(Image) when is_binary(Image) ->
|
|||||||
|
|
||||||
-spec create_container(ContainerDir :: string(), Params :: message_pb:'ContainerDeployParams'()) ->
|
-spec create_container(ContainerDir :: string(), Params :: message_pb:'ContainerDeployParams'()) ->
|
||||||
{ok, ContainerId :: binary()} | {error, Reason :: any()}.
|
{ok, ContainerId :: binary()} | {error, Reason :: any()}.
|
||||||
create_container(ContainerDir, #'ContainerDeployParams'{
|
create_container(ContainerDir, #'ContainerDeployParams'{container_name = ContainerName, create = CreateOpts })
|
||||||
container_name = ContainerName,
|
when is_binary(ContainerName), is_list(ContainerDir) ->
|
||||||
create = Create0
|
|
||||||
}) when is_binary(ContainerName), is_list(ContainerDir) ->
|
|
||||||
|
|
||||||
Url = lists:flatten(io_lib:format("/containers/create?name=~s", [binary_to_list(ContainerName)])),
|
Url = lists:flatten(io_lib:format("/containers/create?name=~s", [binary_to_list(ContainerName)])),
|
||||||
Options = docker_container_builder:build_options(ContainerName, ContainerDir, Create0),
|
Options = docker_container_builder:build_options(ContainerName, ContainerDir, CreateOpts),
|
||||||
display_options(Options),
|
display_options(Options),
|
||||||
|
|
||||||
Body = iolist_to_binary(jiffy:encode(Options, [force_utf8])),
|
Body = iolist_to_binary(jiffy:encode(Options, [force_utf8])),
|
||||||
@ -51,6 +49,7 @@ create_container(ContainerDir, #'ContainerDeployParams'{
|
|||||||
Headers = [
|
Headers = [
|
||||||
{<<"Content-Type">>, <<"application/json">>}
|
{<<"Content-Type">>, <<"application/json">>}
|
||||||
],
|
],
|
||||||
|
|
||||||
case docker_client:request("POST", Url, Body, Headers) of
|
case docker_client:request("POST", Url, Body, Headers) of
|
||||||
{ok, 201, _Headers, Resp} ->
|
{ok, 201, _Headers, Resp} ->
|
||||||
case catch jiffy:decode(Resp, [return_maps]) of
|
case catch jiffy:decode(Resp, [return_maps]) of
|
||||||
|
|||||||
@ -32,21 +32,12 @@
|
|||||||
test_get_containers/0
|
test_get_containers/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([test/0]).
|
|
||||||
|
|
||||||
-define(TEST_IMAGE, <<"docker.1ms.run/library/nginx:latest">>).
|
-define(TEST_IMAGE, <<"docker.1ms.run/library/nginx:latest">>).
|
||||||
-define(TEST_CMD, [<<"nginx">>, <<"-g">>, <<"daemon off;">>]).
|
-define(TEST_CMD, [<<"nginx">>, <<"-g">>, <<"daemon off;">>]).
|
||||||
|
|
||||||
test() ->
|
|
||||||
try
|
|
||||||
test_all()
|
|
||||||
catch _:_:Stack ->
|
|
||||||
logger:debug("statck is: ~p", [Stack])
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec test_all() -> ok.
|
-spec test_all() -> ok.
|
||||||
test_all() ->
|
test_all() ->
|
||||||
%ok = test_pull(),
|
ok = test_pull(),
|
||||||
ok = test_check_image_exist(),
|
ok = test_check_image_exist(),
|
||||||
ok = test_check_image_not_exist(),
|
ok = test_check_image_not_exist(),
|
||||||
ok = test_create_container(),
|
ok = test_create_container(),
|
||||||
@ -55,14 +46,14 @@ test_all() ->
|
|||||||
ok = test_check_container_exist(),
|
ok = test_check_container_exist(),
|
||||||
ok = test_check_container_not_exist(),
|
ok = test_check_container_not_exist(),
|
||||||
ok = test_is_container_running(),
|
ok = test_is_container_running(),
|
||||||
%ok = test_start_container(),
|
ok = test_start_container(),
|
||||||
%ok = test_stop_container(),
|
ok = test_stop_container(),
|
||||||
%ok = test_stop_container_with_timeout(),
|
ok = test_stop_container_with_timeout(),
|
||||||
%ok = test_kill_container(),
|
ok = test_kill_container(),
|
||||||
%ok = test_kill_container_with_signal(),
|
ok = test_kill_container_with_signal(),
|
||||||
%ok = test_remove_container(),
|
ok = test_remove_container(),
|
||||||
%ok = test_remove_container_with_options(),
|
ok = test_remove_container_with_options(),
|
||||||
%ok = test_get_containers(),
|
ok = test_get_containers(),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-spec test_pull() -> ok.
|
-spec test_pull() -> ok.
|
||||||
@ -90,7 +81,6 @@ await_pull(Ref, Pid, MRef) ->
|
|||||||
|
|
||||||
-spec test_check_image_exist() -> ok.
|
-spec test_check_image_exist() -> ok.
|
||||||
test_check_image_exist() ->
|
test_check_image_exist() ->
|
||||||
ok = test_pull(),
|
|
||||||
true = docker_commands:check_image_exist(?TEST_IMAGE),
|
true = docker_commands:check_image_exist(?TEST_IMAGE),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
@ -103,14 +93,9 @@ test_check_image_not_exist() ->
|
|||||||
test_create_container() ->
|
test_create_container() ->
|
||||||
Name = test_container_name(<<"create">>),
|
Name = test_container_name(<<"create">>),
|
||||||
ContainerDir = prepare_container_dir(Name),
|
ContainerDir = prepare_container_dir(Name),
|
||||||
try
|
{ok, ContainerId} = docker_commands:create_container(ContainerDir, minimal_params(Name)),
|
||||||
ok = test_pull(),
|
true = is_binary(ContainerId),
|
||||||
{ok, ContainerId} = docker_commands:create_container(ContainerDir, minimal_params(Name)),
|
ok.
|
||||||
true = is_binary(ContainerId),
|
|
||||||
ok
|
|
||||||
after
|
|
||||||
cleanup_container(Name)
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec test_create_container_without_create_options() -> ok.
|
-spec test_create_container_without_create_options() -> ok.
|
||||||
test_create_container_without_create_options() ->
|
test_create_container_without_create_options() ->
|
||||||
@ -295,7 +280,7 @@ minimal_params(Name) when is_binary(Name) ->
|
|||||||
|
|
||||||
-spec prepare_container_dir(binary()) -> string().
|
-spec prepare_container_dir(binary()) -> string().
|
||||||
prepare_container_dir(Name) when is_binary(Name) ->
|
prepare_container_dir(Name) when is_binary(Name) ->
|
||||||
Dir = lists:flatten(io_lib:format("/tmp/efka_docker_tests/~ts/", [Name])),
|
Dir = lists:flatten(io_lib:format("/usr/local/code/efka/~ts/", [Name])),
|
||||||
ok = filelib:ensure_dir(Dir ++ "placeholder"),
|
ok = filelib:ensure_dir(Dir ++ "placeholder"),
|
||||||
ok = file:write_file(Dir ++ "service.conf", <<>>, [write]),
|
ok = file:write_file(Dir ++ "service.conf", <<>>, [write]),
|
||||||
Dir.
|
Dir.
|
||||||
|
|||||||
@ -131,7 +131,7 @@ handle_event(info, {timeout, _, create_transport}, ?STATE_DISCONNECTED, State =
|
|||||||
{next_state, ?STATE_AUTH, State#state{socket = Socket, auth_packet_id = PacketId, next_packet_id = PacketId + 1},
|
{next_state, ?STATE_AUTH, State#state{socket = Socket, auth_packet_id = PacketId, next_packet_id = PacketId + 1},
|
||||||
[{state_timeout, 5000, auth_timeout}]};
|
[{state_timeout, 5000, auth_timeout}]};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
logger:debug("[efka_client] connect failed, error: ~p", [Reason]),
|
%logger:debug("[efka_client] connect failed, error: ~p", [Reason]),
|
||||||
schedule_reconnect(),
|
schedule_reconnect(),
|
||||||
{keep_state, State#state{socket = undefined}}
|
{keep_state, State#state{socket = undefined}}
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user