Modify test_helper to work with Semaphore CI
This commit is contained in:
parent
e012413a35
commit
e38b0b6b79
|
|
@ -4,9 +4,8 @@ defmodule IsnTest do
|
||||||
alias Postgrex.Connection, as: P
|
alias Postgrex.Connection, as: P
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
{:ok, pid} = P.start_link(
|
options = Keyword.merge(conn_options, [extensions: [{Isn, {}}]])
|
||||||
database: "isn_test",
|
{:ok, pid} = P.start_link(options)
|
||||||
extensions: [{Isn, {}}])
|
|
||||||
{:ok, [pid: pid]}
|
{:ok, [pid: pid]}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,38 @@
|
||||||
ExUnit.start()
|
ExUnit.start()
|
||||||
|
|
||||||
{:ok, pid} = Postgrex.Connection.start_link(
|
# db_options = [
|
||||||
hostname: "localhost",
|
# hostname: "localhost",
|
||||||
database: "postgres"
|
# database: "postgres"]
|
||||||
)
|
#
|
||||||
|
# db_user = System.get_env("DATABASE_POSTGRESQL_USERNAME")
|
||||||
Postgrex.Connection.query!(pid, "DROP DATABASE IF EXISTS isn_test;", [])
|
# db_pass = System.get_env("DATABASE_POSTGRESQL_PASSWORD")
|
||||||
Postgrex.Connection.query!(pid, "CREATE DATABASE isn_test;", [])
|
#
|
||||||
{:ok, pid} = Postgrex.Connection.start_link(
|
# if db_user, do: db_options = Dict.put(db_options, :username, db_user)
|
||||||
hostname: "localhost",
|
# if db_pass, do: db_options = Dict.put(db_options, :password, db_pass)
|
||||||
database: "isn_test"
|
#
|
||||||
)
|
# {:ok, pid} = Postgrex.Connection.start_link(db_options)
|
||||||
Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", [])
|
#
|
||||||
|
# Postgrex.Connection.query!(pid, "DROP DATABASE IF EXISTS isn_test;", [])
|
||||||
|
# Postgrex.Connection.query!(pid, "CREATE DATABASE isn_test;", [])
|
||||||
|
# conn_options = Keyword.merge(db_options, [database: "isn_test"])
|
||||||
|
# {:ok, pid} = Postgrex.Connection.start_link(conn_options)
|
||||||
|
# Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", [])
|
||||||
|
|
||||||
defmodule Isn.TestHelper do
|
defmodule Isn.TestHelper do
|
||||||
|
def conn_options do
|
||||||
|
db_options = [
|
||||||
|
hostname: "localhost",
|
||||||
|
database: "isn_test"]
|
||||||
|
|
||||||
|
db_user = System.get_env("DATABASE_POSTGRESQL_USERNAME")
|
||||||
|
db_pass = System.get_env("DATABASE_POSTGRESQL_PASSWORD")
|
||||||
|
|
||||||
|
if db_user, do: db_options = Dict.put(db_options, :username, db_user)
|
||||||
|
if db_pass, do: db_options = Dict.put(db_options, :password, db_pass)
|
||||||
|
|
||||||
|
db_options
|
||||||
|
end
|
||||||
|
|
||||||
defmacro query(pid, statement, params) do
|
defmacro query(pid, statement, params) do
|
||||||
quote bind_quoted: [pid: pid, statement: statement, params: params] do
|
quote bind_quoted: [pid: pid, statement: statement, params: params] do
|
||||||
case Postgrex.Connection.query(pid, statement, params, []) do
|
case Postgrex.Connection.query(pid, statement, params, []) do
|
||||||
|
|
@ -24,3 +43,11 @@ defmodule Isn.TestHelper do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
db_options = Keyword.merge(Isn.TestHelper.conn_options, [database: "postgres"])
|
||||||
|
{:ok, pid} = Postgrex.Connection.start_link(db_options)
|
||||||
|
|
||||||
|
Postgrex.Connection.query!(pid, "DROP DATABASE IF EXISTS isn_test;", [])
|
||||||
|
Postgrex.Connection.query!(pid, "CREATE DATABASE isn_test;", [])
|
||||||
|
{:ok, pid} = Postgrex.Connection.start_link(Isn.TestHelper.conn_options)
|
||||||
|
Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", [])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue