Skip to content

Commit

Permalink
test: add integration tests against Postgres.js to ExUnit test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleth committed Nov 13, 2024
1 parent 8a22fa4 commit 7346a44
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 126 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,54 @@ jobs:
- name: Run tests
run: mix test

integration:
name: Run integration tests
runs-on: u22-arm-runner
needs: [deps]

steps:
- uses: actions/checkout@v4
- name: Setup Elixir
id: beam
uses: erlef/setup-beam@v1
with:
otp-version: '25.3.2.7'
elixir-version: '1.14.5'
- uses: actions/setup-node@v4
with:
node-version: 'latest'
- name: Set up Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
- name: Cache Mix
uses: actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
- name: Cache native
uses: actions/cache@v4
with:
path: |
_build/${{ env.MIX_ENV }}/lib/supavisor/native
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-build-native-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/Cargo.lock')) }}
restore-keys: |
${{ runner.os }}-build-native-
- name: Compile deps
run: mix deps.compile
- name: Compile
run: mix compile
- name: Set up Postgres
run: docker-compose -f ./docker-compose.db.yml up -d
- name: Start epmd
run: epmd -daemon
- name: Run tests
run: mix test --only integration --trace

dialyzer:
name: Dialyze
runs-on: u22-arm-runner
Expand Down
2 changes: 2 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ config :supavisor, Supavisor.Vault,
}
]

config :logger, level: :error

# Print only warnings and errors during test
config :logger, :console,
level: :error,
Expand Down
86 changes: 86 additions & 0 deletions test/integration/external_test.exs
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

Check failure on line 43 in test/integration/external_test.exs

View workflow job for this annotation

GitHub Actions / Run integration tests

test Node Postgres.js session (Integration.ExternalTest)
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

Check failure on line 64 in test/integration/external_test.exs

View workflow job for this annotation

GitHub Actions / Run integration tests

test Node Postgres.js transaction (Integration.ExternalTest)
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
36 changes: 0 additions & 36 deletions test/integration/js/postgres/bootstrap.js

This file was deleted.

Loading

0 comments on commit 7346a44

Please sign in to comment.