fix docker tests

This commit is contained in:
anlicheng 2026-04-23 18:17:38 +08:00
parent 3aae06577a
commit b7d12aa9d7
3 changed files with 18 additions and 34 deletions

View File

@ -36,13 +36,11 @@ check_image_exist(Image) when is_binary(Image) ->
-spec create_container(ContainerDir :: string(), Params :: message_pb:'ContainerDeployParams'()) ->
{ok, ContainerId :: binary()} | {error, Reason :: any()}.
create_container(ContainerDir, #'ContainerDeployParams'{
container_name = ContainerName,
create = Create0
}) when is_binary(ContainerName), is_list(ContainerDir) ->
create_container(ContainerDir, #'ContainerDeployParams'{container_name = ContainerName, create = CreateOpts })
when is_binary(ContainerName), is_list(ContainerDir) ->
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),
Body = iolist_to_binary(jiffy:encode(Options, [force_utf8])),
@ -51,6 +49,7 @@ create_container(ContainerDir, #'ContainerDeployParams'{
Headers = [
{<<"Content-Type">>, <<"application/json">>}
],
case docker_client:request("POST", Url, Body, Headers) of
{ok, 201, _Headers, Resp} ->
case catch jiffy:decode(Resp, [return_maps]) of

View File

@ -32,21 +32,12 @@
test_get_containers/0
]).
-export([test/0]).
-define(TEST_IMAGE, <<"docker.1ms.run/library/nginx:latest">>).
-define(TEST_CMD, [<<"nginx">>, <<"-g">>, <<"daemon off;">>]).
test() ->
try
test_all()
catch _:_:Stack ->
logger:debug("statck is: ~p", [Stack])
end.
-spec test_all() -> ok.
test_all() ->
%ok = test_pull(),
ok = test_pull(),
ok = test_check_image_exist(),
ok = test_check_image_not_exist(),
ok = test_create_container(),
@ -55,14 +46,14 @@ test_all() ->
ok = test_check_container_exist(),
ok = test_check_container_not_exist(),
ok = test_is_container_running(),
%ok = test_start_container(),
%ok = test_stop_container(),
%ok = test_stop_container_with_timeout(),
%ok = test_kill_container(),
%ok = test_kill_container_with_signal(),
%ok = test_remove_container(),
%ok = test_remove_container_with_options(),
%ok = test_get_containers(),
ok = test_start_container(),
ok = test_stop_container(),
ok = test_stop_container_with_timeout(),
ok = test_kill_container(),
ok = test_kill_container_with_signal(),
ok = test_remove_container(),
ok = test_remove_container_with_options(),
ok = test_get_containers(),
ok.
-spec test_pull() -> ok.
@ -90,7 +81,6 @@ await_pull(Ref, Pid, MRef) ->
-spec test_check_image_exist() -> ok.
test_check_image_exist() ->
ok = test_pull(),
true = docker_commands:check_image_exist(?TEST_IMAGE),
ok.
@ -103,14 +93,9 @@ test_check_image_not_exist() ->
test_create_container() ->
Name = test_container_name(<<"create">>),
ContainerDir = prepare_container_dir(Name),
try
ok = test_pull(),
{ok, ContainerId} = docker_commands:create_container(ContainerDir, minimal_params(Name)),
true = is_binary(ContainerId),
ok
after
cleanup_container(Name)
end.
ok.
-spec test_create_container_without_create_options() -> ok.
test_create_container_without_create_options() ->
@ -295,7 +280,7 @@ minimal_params(Name) when is_binary(Name) ->
-spec prepare_container_dir(binary()) -> string().
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 = file:write_file(Dir ++ "service.conf", <<>>, [write]),
Dir.

View File

@ -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},
[{state_timeout, 5000, auth_timeout}]};
{error, Reason} ->
logger:debug("[efka_client] connect failed, error: ~p", [Reason]),
%logger:debug("[efka_client] connect failed, error: ~p", [Reason]),
schedule_reconnect(),
{keep_state, State#state{socket = undefined}}
end;