-
Notifications
You must be signed in to change notification settings - Fork 36
/
test-cli.js
61 lines (53 loc) · 1.94 KB
/
test-cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* globals describe it */
var assert = require('assert')
var childProcess = require('child_process')
var conString1 = 'postgres://postgres:postgres@localhost/db1'
var conSettings2 = {
dialect: 'postgres',
username: 'postgres',
password: 'postgres',
database: 'db2',
host: 'localhost',
dialectOptions: {
ssl: false
}
}
var utils = require('./utils')('postgres', conString1, conSettings2)
const exec = (cmd) => {
return new Promise((resolve, reject) => {
childProcess.exec(cmd, (err, stdout, stderr) => {
err && !stderr ? reject(err) : resolve({ stdout, stderr })
})
})
}
describe('CLI interface', () => {
it('should run as a cli application', () => {
var conString1 = 'postgres://postgres:postgres@localhost/db1'
var conString2 = 'postgres://postgres:postgres@localhost/db2'
return utils.runCommands(['CREATE SEQUENCE seq_name'], [])
.then(() => exec(`node index.js ${conString1} ${conString2}`))
.then((result) => {
var { stdout } = result
assert.equal(stdout, 'DROP SEQUENCE "public"."seq_name";\n')
})
})
it('should run as a cli application with level argument', () => {
var conString1 = 'postgres://postgres:postgres@localhost/db1'
var conString2 = 'postgres://postgres:postgres@localhost/db2'
return utils.runCommands(['CREATE TABLE users (email VARCHAR(255))'], [])
.then(() => exec(`node index.js -l safe ${conString1} ${conString2}`))
.then((result) => {
var { stdout } = result
assert.equal(stdout, '-- DROP TABLE "public"."users";\n')
})
})
it('should fail with an erorr', () => {
var conString1 = 'postgres://postgres:postgres@localhost/db1'
var conString2 = 'postgres://postgres:postgres@localhost/none'
return exec(`node index.js ${conString1} ${conString2}`)
.then((result) => {
var { stderr } = result
assert.ok(stderr.indexOf('error: database "none" does not exist') >= 0)
})
})
})