-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add integration tests against Postgres.js to ExUnit test suite
- Loading branch information
Showing
6 changed files
with
235 additions
and
126 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
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,86 @@ | ||
defmodule Integration.ExternalTest do | ||
use ExUnit.Case, async: false | ||
|
||
@moduletag integration: true | ||
|
||
describe "Node" do | ||
@describetag runtime: "node" | ||
|
||
setup ctx do | ||
tool = get_tool("yarn") || raise "No Yarn" | ||
|
||
external_id = Enum.join([ctx.runtime, ctx.library, ctx.mode], "_") | ||
|
||
# Ensure that there are no leftovers | ||
_ = Supavisor.Tenants.delete_tenant_by_external_id(external_id) | ||
|
||
_ = Supavisor.Repo.query("DROP DATABASE IF EXISTS #{external_id}") | ||
assert {:ok, _} = Supavisor.Repo.query("CREATE DATABASE #{external_id}") | ||
|
||
assert {:ok, tenant} = | ||
Supavisor.Tenants.create_tenant(%{ | ||
default_parameter_status: %{}, | ||
db_host: "localhost", | ||
db_port: 6432, | ||
db_database: external_id, | ||
auth_query: "SELECT rolname, rolpassword FROM pg_authid WHERE rolname=$1;", | ||
external_id: external_id, | ||
users: [ | ||
%{ | ||
"pool_size" => 3, | ||
"db_user" => "postgres", | ||
"db_password" => "postgres", | ||
"is_manager" => true, | ||
"mode_type" => "session" | ||
} | ||
] | ||
}) | ||
|
||
{:ok, tool: tool, user: "postgres.#{external_id}", db: tenant.db_database} | ||
end | ||
|
||
@tag library: "postgresjs", mode: "session" | ||
test "Postgres.js session", ctx do | ||
env = [ | ||
{"NODE_OPTIONS", "--trace-uncaught"}, | ||
{"PGMODE", ctx.mode}, | ||
{"PGDATABASE", ctx.db}, | ||
{"PGHOST", "localhost"}, | ||
{"PGPORT", to_string(Application.fetch_env!(:supavisor, :proxy_port_session))}, | ||
{"PGUSER", ctx.user}, | ||
{"PGPASS", "postgres"} | ||
] | ||
|
||
# require IEx; IEx.pry | ||
|
||
assert {_, 0} = | ||
System.cmd(ctx.tool, ~w[run test:postgres], | ||
env: env, | ||
cd: Path.join(__DIR__, "js") | ||
) | ||
end | ||
|
||
@tag library: "postgresjs", mode: "transaction" | ||
test "Postgres.js transaction", ctx do | ||
env = [ | ||
{"NODE_OPTIONS", "--trace-uncaught"}, | ||
{"PGMODE", ctx.mode}, | ||
{"PGDATABASE", ctx.db}, | ||
{"PGHOST", "localhost"}, | ||
{"PGPORT", to_string(Application.fetch_env!(:supavisor, :proxy_port_transaction))}, | ||
{"PGUSER", ctx.user}, | ||
{"PGPASS", "postgres"} | ||
] | ||
|
||
# require IEx; IEx.pry | ||
|
||
assert {_, 0} = | ||
System.cmd(ctx.tool, ~w[run test:postgres], | ||
env: env, | ||
cd: Path.join(__DIR__, "js") | ||
) | ||
end | ||
end | ||
|
||
defp get_tool(name), do: System.find_executable(name) | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.