Skip to content

Commit ce4501a

Browse files
committed
Properly bootstrap test setup
1 parent 66f46b9 commit ce4501a

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

tests/bootstrap.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const cp = require('child_process')
2+
3+
exec('psql -c "create user postgres_js_test"')
4+
exec('psql -c "alter system set password_encryption=md5"')
5+
exec('psql -c "select pg_reload_conf()"')
6+
exec('psql -c "create user postgres_js_test_md5 with password \'postgres_js_test_md5\'"')
7+
exec('psql -c "alter system set password_encryption=\'scram-sha-256\'"')
8+
exec('psql -c "select pg_reload_conf()"')
9+
exec('psql -c "create user postgres_js_test_scram with password \'postgres_js_test_scram\'"')
10+
11+
cp.execSync('dropdb postgres_js_test;createdb postgres_js_test')
12+
;['postgres_js_test', 'postgres_js_test', 'postgres_js_test', 'postgres_js_test'].forEach(x =>
13+
cp.execSync('psql -c "grant all on database postgres_js_test to ' + x + '"')
14+
)
15+
16+
function exec(cmd) {
17+
try {
18+
cp.execSync(cmd, { stdio: 'pipe', encoding: 'utf8' })
19+
} catch (err) {
20+
if (err.stderr.indexOf('already exists') === -1)
21+
throw err
22+
}
23+
}

tests/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint no-console: 0 */
22

3+
require('./bootstrap.js')
4+
35
const { t, not, ot } = require('./test.js') // eslint-disable-line
4-
const cp = require('child_process')
56
const path = require('path')
67
const net = require('net')
78

@@ -32,11 +33,6 @@ const options = {
3233
max: 1
3334
}
3435

35-
cp.execSync('dropdb ' + options.db + ';createdb ' + options.db)
36-
;[login, login_clear, login_md5, login_scram].forEach(x =>
37-
cp.execSync('psql -c "grant all on database ' + options.db + ' to ' + x.user + '"')
38-
)
39-
4036
const sql = postgres(options)
4137

4238
t('Connects with no options', async() => {

0 commit comments

Comments
 (0)