Skip to content

Commit 4de33c1

Browse files
committed
add unit test
1 parent 852a1db commit 4de33c1

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

test/docker_test.exs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
11
defmodule DockerTest do
2-
use ExUnit.Case
2+
use ExUnit.Case, async: false
33

4-
test "the truth" do
5-
assert 1 + 1 == 2
4+
setup do
5+
server = %{
6+
baseUrl: "https://docker-06.lan.zhaowei.jimubox.com:2376",
7+
ssl_options: [
8+
{:certfile, 'docker.crt'},
9+
{:keyfile, 'docker.key'},
10+
]
11+
}
12+
{:ok,conn} = Docker.start_link server
13+
{:ok,[conn: conn]}
14+
end
15+
16+
test "docker info", ctx do
17+
assert {:ok, %{"ID"=>_}} = Docker.info ctx.conn
18+
end
19+
20+
test "docker ps", ctx do
21+
assert {:ok, list} = Docker.Container.list ctx.conn
22+
assert is_list list
23+
end
24+
25+
test "docker images", ctx do
26+
assert {:ok, list} = Docker.Image.list ctx.conn
27+
assert is_list list
28+
end
29+
30+
test "docker create, attach, wait and delete", ctx do
31+
{:ok, %{"Id" => id}} = Docker.Container.create ctx.conn, "test", %{
32+
"Cmd": ["bash","-c","sleep 1; echo hello world; exit 100"],
33+
"Image": "ubuntu",
34+
}
35+
assert :ok = Docker.Container.start(ctx.conn, id)
36+
assert {:ok, ref} = Docker.Container.follow ctx.conn, id
37+
assert_receive %Docker.AsyncReply{id: ^ref, reply: {:chunk,[{:stdout, "hello world\n"}]}}, 2000
38+
assert_receive %Docker.AsyncReply{id: ^ref, reply: :done}, 1000
39+
assert {:ok, %{"StatusCode"=> 100}} = Docker.Container.wait(ctx.conn, id, :infinity)
40+
assert :ok = Docker.Container.delete(ctx.conn, id)
641
end
742
end
43+
44+

0 commit comments

Comments
 (0)