diff --git a/lib/container/cassandra_container.ex b/lib/container/cassandra_container.ex index 60d0e34..79ec7d4 100644 --- a/lib/container/cassandra_container.ex +++ b/lib/container/cassandra_container.ex @@ -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 diff --git a/lib/container/ceph_container.ex b/lib/container/ceph_container.ex index 6457d66..f4a3ebf 100644 --- a/lib/container/ceph_container.ex +++ b/lib/container/ceph_container.ex @@ -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 diff --git a/lib/container/kafka_container.ex b/lib/container/kafka_container.ex index ee22f59..9f4d757 100644 --- a/lib/container/kafka_container.ex +++ b/lib/container/kafka_container.ex @@ -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------------------ diff --git a/lib/container/minio_container.ex b/lib/container/minio_container.ex index fc3e2c4..8b09b24 100644 --- a/lib/container/minio_container.ex +++ b/lib/container/minio_container.ex @@ -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 diff --git a/lib/container/mysql_container.ex b/lib/container/mysql_container.ex index 621d110..ba11c4a 100644 --- a/lib/container/mysql_container.ex +++ b/lib/container/mysql_container.ex @@ -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 diff --git a/lib/container/postgres_container.ex b/lib/container/postgres_container.ex index b12272c..2a37480 100644 --- a/lib/container/postgres_container.ex +++ b/lib/container/postgres_container.ex @@ -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 diff --git a/lib/container/protocols/container_builder.ex b/lib/container/protocols/container_builder.ex index f53c795..26ace0e 100644 --- a/lib/container/protocols/container_builder.ex +++ b/lib/container/protocols/container_builder.ex @@ -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 diff --git a/lib/container/rabbitmq_container.ex b/lib/container/rabbitmq_container.ex index 66de5ff..02185bd 100644 --- a/lib/container/rabbitmq_container.ex +++ b/lib/container/rabbitmq_container.ex @@ -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 diff --git a/lib/container/redis_container.ex b/lib/container/redis_container.ex index 641e94c..ff22a61 100644 --- a/lib/container/redis_container.ex +++ b/lib/container/redis_container.ex @@ -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 diff --git a/lib/container/selenium_container.ex b/lib/container/selenium_container.ex index 4899784..dae0f99 100644 --- a/lib/container/selenium_container.ex +++ b/lib/container/selenium_container.ex @@ -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 diff --git a/lib/docker/api.ex b/lib/docker/api.ex index 86c689d..955ef3d 100644 --- a/lib/docker/api.ex +++ b/lib/docker/api.ex @@ -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") @@ -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), diff --git a/test/support/nginx_container.ex b/test/support/nginx_container.ex index 7abf966..d2df0f7 100644 --- a/test/support/nginx_container.ex +++ b/test/support/nginx_container.ex @@ -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