Skip to content

Commit

Permalink
remove a couple of dialyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Nov 5, 2024
1 parent c6bdefc commit 294ea94
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 26 deletions.
1 change: 0 additions & 1 deletion lib/container/cassandra_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ defmodule Testcontainers.CassandraContainer do
end

@impl true
@spec after_start(%CassandraContainer{}, %Container{}, %Tesla.Env{}) :: :ok
def after_start(_config, _container, _conn), do: :ok
end
end
1 change: 0 additions & 1 deletion lib/container/ceph_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ defmodule Testcontainers.CephContainer do
end

@impl true
@spec after_start(%CephContainer{}, %Container{}, %Tesla.Env{}) :: :ok
def after_start(_config, _container, _conn), do: :ok
end
end
9 changes: 2 additions & 7 deletions lib/container/kafka_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,9 @@ defmodule Testcontainers.KafkaContainer do
assign them to the config.
"""
@impl true
@spec after_start(%KafkaContainer{}, %Testcontainers.Container{}, %Tesla.Env{}) :: :ok
@dialyzer {:no_return, after_start: 3}
def after_start(config = %{start_file_path: start_file_path}, container, conn) do
with script <- build_startup_script(container, config),
{:ok, _} <-
Docker.Api.put_file(container.container_id, conn, "/", start_file_path, script) do
:ok
end
script = build_startup_script(container, config)
Docker.Api.put_file(container.container_id, conn, "/", start_file_path, script)
end

# ------------------Listeners------------------
Expand Down
1 change: 0 additions & 1 deletion lib/container/minio_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ defmodule Testcontainers.MinioContainer do
end

@impl true
@spec after_start(%MinioContainer{}, %Container{}, %Tesla.Env{}) :: :ok
def after_start(_config, _container, _conn), do: :ok
end
end
1 change: 0 additions & 1 deletion lib/container/mysql_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ defmodule Testcontainers.MySqlContainer do
end

@impl true
@spec after_start(%MySqlContainer{}, %Container{}, %Tesla.Env{}) :: :ok
def after_start(_config, _container, _conn), do: :ok
end

Expand Down
1 change: 0 additions & 1 deletion lib/container/postgres_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ defmodule Testcontainers.PostgresContainer do
end

@impl true
@spec after_start(%PostgresContainer{}, %Container{}, %Tesla.Env{}) :: :ok
def after_start(_config, _container, _conn), do: :ok
end

Expand Down
2 changes: 1 addition & 1 deletion lib/container/protocols/container_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ defprotocol Testcontainers.ContainerBuilder do
@doc """
Do stuff after container has started.
"""
@spec after_start(t(), %Testcontainers.Container{}, %Tesla.Env{}) :: :ok
@spec after_start(t(), %Testcontainers.Container{}, %Tesla.Env{}) :: :ok | {:error, term()}
def after_start(builder, container, connection)
end
1 change: 0 additions & 1 deletion lib/container/rabbitmq_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ defmodule Testcontainers.RabbitMQContainer do
end

@impl true
@spec after_start(%RabbitMQContainer{}, %Container{}, %Tesla.Env{}) :: :ok
def after_start(_config, _container, _conn), do: :ok
end
end
1 change: 0 additions & 1 deletion lib/container/redis_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ defmodule Testcontainers.RedisContainer do
end

@impl true
@spec after_start(%RedisContainer{}, %Container{}, %Tesla.Env{}) :: :ok
def after_start(_config, _container, _conn), do: :ok
end
end
1 change: 0 additions & 1 deletion lib/container/selenium_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ defmodule Testcontainers.SeleniumContainer do
end

@impl true
@spec after_start(%SeleniumContainer{}, %Container{}, %Tesla.Env{}) :: :ok
def after_start(_config, _container, _conn), do: :ok
end
end
9 changes: 4 additions & 5 deletions lib/docker/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,14 @@ defmodule Testcontainers.Docker.Api do
end
end

@dialyzer {:no_return, put_file: 5}
def put_file(container_id, connection, path, file_name, file_contents) do
with {:ok, tar_file_contents} <- create_tar_stream(file_name, file_contents) do
Api.Container.put_container_archive(connection, container_id, path, tar_file_contents)
with {:ok, tar_file_contents} <- create_tar_stream(file_name, file_contents),
{:ok, %Tesla.Env{}} <- Api.Container.put_container_archive(connection, container_id, path, tar_file_contents) do
:ok
end
end

# Helper function to create a tar stream from a file
@dialyzer {:no_return, create_tar_stream: 2}
defp create_tar_stream(file_name, file_contents) do
tar_file = System.tmp_dir!() |> Path.join("#{UUID.uuid4()})-#{file_name}.tar")

Expand All @@ -115,7 +114,7 @@ defmodule Testcontainers.Docker.Api do
tar_file,
# file_name must be charlist ref https://til.kaiwern.com/tags/88
[{file_name |> String.to_charlist(), file_contents}],
[:write, :compressed]
[:compressed]
)

with {:ok, tar_file_contents} <- File.read(tar_file),
Expand Down
6 changes: 1 addition & 5 deletions test/support/nginx_container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ defmodule Test.NginxContainer do
end

@impl true
@spec after_start(%Test.NginxContainer{}, %Testcontainers.Container{}, %Tesla.Env{}) :: :ok
def after_start(_config, container, conn) do
with {:ok, _} <-
Docker.Api.put_file(container.container_id, conn, "/tmp", "foo.txt", "Hello foo bar") do
:ok
end
Docker.Api.put_file(container.container_id, conn, "/tmp", "foo.txt", "Hello foo bar")
end
end
end

0 comments on commit 294ea94

Please sign in to comment.