Skip to content

Commit

Permalink
no need for existing repo config
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Nov 7, 2023
1 parent 3482e81 commit c739c68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
16 changes: 1 addition & 15 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,4 @@ import Config

config :logger, level: :warning

config :testcontainers,
log_level: :warning

test_db_opts = [
username: "test",
password: "test",
hostname: "localhost",
database: "testcontainers_test",
queue_target: 30_000,
queue_interval: 30_000
]

config :testcontainers, Testcontainers.MysqlRepo, test_db_opts

config :testcontainers, Testcontainers.PostgresRepo, test_db_opts
config :testcontainers, log_level: :warning
28 changes: 11 additions & 17 deletions lib/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,17 @@ defmodule Testcontainers.Ecto do
System.at_exit(fn _ -> Testcontainers.stop_container(container.container_id) end)

:ok =
case Application.get_env(app, repo) do
nil ->
raise ArgumentError, "Cant get repo config: repo=#{inspect(repo)}"

repo_config ->
Application.put_env(
app,
repo,
repo_config
|> Keyword.merge(
username: user,
password: password,
database: database,
port: container_module.port(container)
)
)
end
Application.put_env(
app,
repo,
Application.get_env(app, repo, [])
|> Keyword.merge(
username: user,
password: password,
database: database,
port: container_module.port(container)
)
)

{:ok, pid} = repo.start_link()

Expand Down
2 changes: 1 addition & 1 deletion test/ecto_errors_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Testcontainers.EctoErrorsTest do
import Testcontainers.Ecto

test "repo cannot be nil" do
assert_raise ArgumentError, "Cant get repo config: repo=Testcontainers.Repo", fn ->
assert_raise UndefinedFunctionError, "function Testcontainers.Repo.start_link/0 is undefined (module Testcontainers.Repo is not available)", fn ->
mysql_container(
app: :testcontainers,
repo: nil
Expand Down

0 comments on commit c739c68

Please sign in to comment.