Skip to content

Commit b44ecd5

Browse files
akirakcodex
andcommitted
add more comprehensive test cases for ministack
Co-Authored-By: Codex <noreply@openai.com>
1 parent 6706100 commit b44ecd5

1 file changed

Lines changed: 93 additions & 11 deletions

File tree

test/container/ministack_container_test.exs

Lines changed: 93 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,107 @@ defmodule Testcontainers.Container.MinistackContainerTest do
33
use ExUnit.Case, async: true
44

55
import Testcontainers.ExUnit
6+
67
alias Testcontainers.ContainerBuilder
7-
alias Testcontainers.LogWaitStrategy
88
alias Testcontainers.MinistackContainer
99

1010
@ministack_container MinistackContainer.new()
1111

12-
container(:ministack, @ministack_container)
12+
describe "new/0 and builder options" do
13+
test "returns default ministack configuration" do
14+
config = MinistackContainer.new()
15+
16+
assert config.image == "ministackorg/ministack:1.3.42"
17+
assert config.username == "111111111111"
18+
assert config.password == "anything"
19+
assert config.wait_timeout == 60_000
20+
assert config.reuse == false
21+
end
22+
23+
test "exposes default S3 and UI ports and sets AWS credentials" do
24+
container =
25+
MinistackContainer.new()
26+
|> MinistackContainer.with_reuse(true)
27+
|> ContainerBuilder.build()
28+
29+
assert {MinistackContainer.default_s3_port(), nil} in container.exposed_ports
30+
assert {MinistackContainer.default_ui_port(), nil} in container.exposed_ports
31+
assert container.environment[:AWS_ACCESS_KEY_ID] == MinistackContainer.get_username()
32+
assert container.environment[:AWS_SECRET_ACCESS_KEY] == MinistackContainer.get_password()
33+
assert container.reuse == true
34+
end
35+
end
36+
37+
describe "runtime behavior" do
38+
container(:ministack, @ministack_container)
39+
40+
test "provides connection helpers", %{
41+
ministack: ministack
42+
} do
43+
host = Testcontainers.get_host(ministack)
44+
port = MinistackContainer.port(ministack)
45+
conn_opts = MinistackContainer.connection_opts(ministack)
46+
47+
assert is_integer(port)
48+
assert MinistackContainer.connection_url(ministack) == "http://#{host}:#{port}"
49+
50+
assert conn_opts == [
51+
port: port,
52+
scheme: "http://",
53+
host: host,
54+
access_key_id: MinistackContainer.get_username(),
55+
secret_access_key: MinistackContainer.get_password()
56+
]
57+
end
58+
59+
test "responds from health-check endpoint", %{
60+
ministack: ministack
61+
} do
62+
health_url = "#{MinistackContainer.connection_url(ministack)}/_ministack/health"
1363

14-
test "creates and starts ministack container", %{ministack: ministack} do
15-
conn_opts = MinistackContainer.connection_opts(ministack)
64+
{:ok, %{status: 200, body: body}} = Tesla.get(health_url)
65+
{:ok, health} = Jason.decode(body)
1666

17-
{:ok, _result} =
18-
ExAws.S3.put_bucket("my-bucket", "")
19-
|> ExAws.request(conn_opts)
67+
assert is_map(health)
68+
assert map_size(health) > 0
69+
end
2070

21-
{:ok, %{body: %{buckets: [first_bucket | _rest]}}} =
22-
ExAws.S3.list_buckets()
23-
|> ExAws.request(conn_opts)
71+
test "supports bucket and file object operations", %{
72+
ministack: ministack
73+
} do
74+
conn_opts = MinistackContainer.connection_opts(ministack)
75+
76+
bucket = bucket_name("files")
77+
object_key = "fixtures/hello.txt"
78+
file_contents = "Hello from a Ministack-backed S3 object"
79+
80+
{:ok, _result} =
81+
ExAws.S3.put_bucket(bucket, "")
82+
|> ExAws.request(conn_opts)
83+
84+
{:ok, %{body: %{buckets: buckets}}} =
85+
ExAws.S3.list_buckets()
86+
|> ExAws.request(conn_opts)
87+
88+
assert Enum.any?(buckets, &(&1.name == bucket))
89+
90+
{:ok, _result} =
91+
ExAws.S3.put_object(bucket, object_key, file_contents)
92+
|> ExAws.request(conn_opts)
93+
94+
{:ok, %{body: %{contents: objects}}} =
95+
ExAws.S3.list_objects(bucket, prefix: "fixtures/")
96+
|> ExAws.request(conn_opts)
97+
98+
assert Enum.any?(objects, &(&1.key == object_key))
99+
100+
{:ok, %{body: ^file_contents}} =
101+
ExAws.S3.get_object(bucket, object_key)
102+
|> ExAws.request(conn_opts)
103+
end
104+
end
24105

25-
assert first_bucket.name == "my-bucket"
106+
defp bucket_name(prefix) do
107+
"ministack-#{prefix}-#{System.unique_integer([:positive])}"
26108
end
27109
end

0 commit comments

Comments
 (0)