-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtest.js
49 lines (45 loc) · 1.2 KB
/
test.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
const assert = require("assert");
const { createdb, dropdb, PgtoolsError } = require("../");
const config = process.env.PG_CONNECTION_STRING || {
host: process.env.DB_HOST || "127.0.0.1",
user: process.env.DB_USER || process.env.USER || "postgres",
};
/**
* @param {string} name
*/
function validateError(name) {
/**
* @param {PgtoolsError} err
*/
return (err) => {
assert.ok(err instanceof PgtoolsError);
assert.equal(err.name, name);
return true;
};
}
async function test() {
console.log("dropdb");
await dropdb(config, "pgtools-test").catch(() => {
// might throw an error if first time test is run
// we can ignore
});
console.log("createdb");
await createdb(config, "pgtools-test");
console.log("createdb (db already exists error)");
await assert.rejects(
createdb(config, "pgtools-test"),
validateError("duplicate_database")
);
console.log("dropdb");
await dropdb(config, "pgtools-test");
console.log("dropdb (db does not exist error)");
await assert.rejects(
dropdb(config, "pgtools-test"),
validateError("invalid_catalog_name")
);
console.log("All tests pass");
}
test().catch((err) => {
console.error(err);
process.exit(1);
});