Skip to content

Commit

Permalink
ft: add Postgres.js integration tests to the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleth committed Nov 12, 2024
1 parent 8ffc3aa commit 84bcd29
Show file tree
Hide file tree
Showing 12 changed files with 3,026 additions and 49 deletions.
308 changes: 261 additions & 47 deletions flake.lock

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@
{
pre-commit.hooks = {
alejandra.enable = true;
typos.enable = true;
typos = {
enable = true;
excludes = [
"test/integration/"
];
};
};
}
{
Expand All @@ -78,6 +83,7 @@

services.postgres = {
enable = true;
package = pkgs.postgresql_15;
initialScript = ''
${builtins.readFile ./dev/postgres/00-setup.sql}
Expand All @@ -87,11 +93,18 @@
port = 6432;
};

process.implementation = "honcho";
process.manager.implementation = "honcho";

# Force connection through TCP instead of Unix socket
env.PGHOST = lib.mkForce "";
}
{
languages.javascript = {
enable = true;
bun.enable = true;
yarn.enable = true;
};
}
({
pkgs,
lib,
Expand Down
1 change: 1 addition & 0 deletions test/integration/js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
13 changes: 13 additions & 0 deletions test/integration/js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "supavisor-integration",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"license": "MIT",
"scripts": {
"test:postgres": "node ./postgres/index.js"
},
"dependencies": {
"postgres": "^3.4.5"
}
}
36 changes: 36 additions & 0 deletions test/integration/js/postgres/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { spawnSync } from 'child_process'

//exec('dropdb', ['postgres_js_test'])

//exec('psql', ['-c', 'alter system set ssl=on'])
//exec('psql', ['-c', 'drop user postgres_js_test'])
//exec('psql', ['-c', 'create user postgres_js_test'])
//exec('psql', ['-c', 'alter system set password_encryption=md5'])
//exec('psql', ['-c', 'select pg_reload_conf()'])
//exec('psql', ['-c', 'drop user if exists postgres_js_test_md5'])
//exec('psql', ['-c', 'create user postgres_js_test_md5 with password \'postgres_js_test_md5\''])
//exec('psql', ['-c', 'alter system set password_encryption=\'scram-sha-256\''])
//exec('psql', ['-c', 'select pg_reload_conf()'])
//exec('psql', ['-c', 'drop user if exists postgres_js_test_scram'])
//exec('psql', ['-c', 'create user postgres_js_test_scram with password \'postgres_js_test_scram\''])
//
//exec('createdb', ['postgres_js_test'])
//exec('psql', ['-c', 'grant all on database postgres_js_test to postgres_js_test'])
//exec('psql', ['-c', 'alter database postgres_js_test owner to postgres_js_test'])

exec('psql', ['-c', 'drop table test'])

export function exec(cmd, args) {
const { stderr } = spawnSync(cmd, args, { stdio: 'pipe', encoding: 'utf8' })
if (stderr && !stderr.includes('already exists') && !stderr.includes('does not exist'))
throw stderr
}

async function execAsync(cmd, args) { // eslint-disable-line
let stderr = ''
const cp = await spawn(cmd, args, { stdio: 'pipe', encoding: 'utf8' }) // eslint-disable-line
cp.stderr.on('data', x => stderr += x)
await new Promise(x => cp.on('exit', x))
if (stderr && !stderr.includes('already exists') && !stderr.includes('does not exist'))
throw new Error(stderr)
}
2 changes: 2 additions & 0 deletions test/integration/js/postgres/copy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 2 3
4 5 6
Loading

0 comments on commit 84bcd29

Please sign in to comment.