-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix reuse issue and remove ecto tests (#127)
- Loading branch information
Showing
9 changed files
with
91 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule Testcontainers.ContainerBuilderHelper do | ||
import Testcontainers.Constants | ||
alias Testcontainers.Util.Hash | ||
alias Testcontainers.Container | ||
alias Testcontainers.ContainerBuilder | ||
|
||
def build(builder, state) when is_map(state) and is_struct(builder) do | ||
config = | ||
ContainerBuilder.build(builder) | ||
|> Container.with_label(container_version_label(), library_version()) | ||
|> Container.with_label(container_lang_label(), container_lang_value()) | ||
|> Container.with_label(container_label(), "#{true}") | ||
|
||
reuse = config.reuse && true == Map.get(state.properties, "testcontainers.reuse.enable", false) | ||
|
||
if reuse do | ||
hash = Hash.struct_to_hash(config) | ||
config | ||
|> Container.with_label(container_reuse(), "true") | ||
|> Container.with_label(container_reuse_hash_label(), hash) | ||
|> Container.with_label(container_sessionId_label(), state.session_id) | ||
|> Kernel.then(&{:reuse, &1, hash}) | ||
else | ||
config | ||
|> Container.with_label(container_reuse(), "false") | ||
|> Container.with_label(container_sessionId_label(), state.session_id) | ||
|> Kernel.then(&{:noreuse, &1, nil}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule Testcontainers.ContainerBuilderHelperTest do | ||
use ExUnit.Case, async: false | ||
|
||
alias Testcontainers.ContainerBuilderHelper | ||
import Testcontainers.Constants | ||
|
||
test "build/2 returns a tuple with false, built config with correct labels and nil for hash" do | ||
builder = Testcontainers.PostgresContainer.new() |> Testcontainers.PostgresContainer.with_reuse(true) | ||
state = %{ properties: %{}, session_id: "123" } | ||
{:noreuse, built, nil} = ContainerBuilderHelper.build(builder, state) | ||
assert Map.get(built.labels, container_reuse()) == "false" | ||
assert Map.get(built.labels, container_reuse_hash_label()) == nil | ||
assert Map.get(built.labels, container_sessionId_label()) == "123" | ||
assert Map.get(built.labels, container_version_label()) == library_version() | ||
assert Map.get(built.labels, container_lang_label()) == container_lang_value() | ||
assert Map.get(built.labels, container_label()) == "true" | ||
end | ||
|
||
test "build/2 returns a tuple with true, built config with correct labels and a non nil hash" do | ||
builder = Testcontainers.PostgresContainer.new() |> Testcontainers.PostgresContainer.with_reuse(true) | ||
state = %{ properties: %{ "testcontainers.reuse.enable" => true }, session_id: "123" } | ||
{:reuse, built, hash} = ContainerBuilderHelper.build(builder, state) | ||
assert hash != nil | ||
assert Map.get(built.labels, container_reuse()) == "true" | ||
assert Map.get(built.labels, container_reuse_hash_label()) != nil | ||
assert Map.get(built.labels, container_sessionId_label()) == "123" | ||
assert Map.get(built.labels, container_version_label()) == library_version() | ||
assert Map.get(built.labels, container_lang_label()) == container_lang_value() | ||
assert Map.get(built.labels, container_label()) == "true" | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.