-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
49 lines (42 loc) · 1.67 KB
/
test.js
File metadata and controls
49 lines (42 loc) · 1.67 KB
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
var pgconfig = require('pg-connection-string').parse;
var assert = require('assert');
var MapPg = require('./');
var https = require('https');
var pg = require('pg');
var req = https.get('https://ci-postgresql.herokuapp.com', (res) => {
var data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => {
var url = data;
var pool = new pg.Pool(pgconfig(url+'?ssl=true'));
pool.connect(ready);
})
});
var type = {
"key": "TEXT",
"value": "TEXT"
};
var ready = function(err, db, done) {
var mapa = new MapPg(db);
var mapb = new MapPg(db, 'map', type, 'key', ['value']);
var mapc = new MapPg(db, 'map', type, 'key', ['key', 'value']);
var mapd = new MapPg(db, 'map', type, ['key'], ['key', 'value']);
mapa.setup().then((err, ans) => console.log('Table created'));
mapa.set('n', 'Noble');
mapb.set('p', {'value': 'Programming'});
mapc.set('m', {'value': 'Mantra'});
mapd.set('.', {'value': '2012'}).then(() => console.log('"." set'));
mapa.size.then((ans) => assert.equal(ans, 4));
mapb.size.then((ans) => assert.equal(ans, 4));
mapc.size.then((ans) => assert.equal(ans, 4));
mapd.size.then((ans) => assert.equal(ans, 4));
mapa.get('.').then((ans) => assert.equal(ans, '2012'));
mapb.get('m').then((ans) => assert.deepEqual(ans, {'value': 'Mantra'}));
mapc.get('p').then((ans) => assert.deepEqual(ans, {'key': 'p', 'value': 'Programming'}));
mapd.get({'key': 'n'}).then((ans) => assert.deepEqual(ans, {'key': 'n', 'value': 'Noble'}));
mapa.get('l').then((ans) => assert.equal(ans, undefined));
mapa.delete('m');
mapd.delete('x').then((ans) => assert.equal(ans, 0));
mapb.size.then((ans) => assert.equal(ans, 3));
done();
};