forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrivers.js
More file actions
103 lines (93 loc) · 3.43 KB
/
Copy pathdrivers.js
File metadata and controls
103 lines (93 loc) · 3.43 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const assert = require('assert');
const drivers = require('../drivers');
describe('drivers', function() {
it('loads and exposes api', function() {
// This test doesn't test much will expand later
assert(drivers);
assert(typeof drivers.getSchema === 'function');
assert(typeof drivers.runQuery === 'function');
assert(typeof drivers.testConnection === 'function');
});
it('getDrivers()', function() {
const driverItems = drivers.getDrivers();
assert(Array.isArray(driverItems), 'driverItems is array');
assert(driverItems.find(item => item.id === 'crate'));
assert(driverItems.find(item => item.id === 'hdb'));
assert(driverItems.find(item => item.id === 'mysql'));
assert(driverItems.find(item => item.id === 'postgres'));
assert(driverItems.find(item => item.id === 'presto'));
assert(driverItems.find(item => item.id === 'sqlserver'));
assert(driverItems.find(item => item.id === 'vertica'));
const postgres = driverItems.find(item => item.id === 'postgres');
assert.equal(postgres.id, 'postgres');
assert.equal(postgres.name, 'Postgres');
assert(Array.isArray(postgres.fields));
assert(
postgres.fields.find(field => field.key === 'postgresSsl'),
'has postgres specific field'
);
assert(
!postgres.fields.find(field => field.key === 'sqlserverEncrypt'),
'Does not have a SQL Server field'
);
});
it('validateConnection()', function() {
const validPostgres = drivers.validateConnection({
name: 'testname',
driver: 'postgres',
host: 'host',
port: 'port',
postgresSsl: true,
somethingStripped: 'shouldnotmakeit'
});
assert.equal(Object.keys(validPostgres).length, 5, 'only 5 keys valid');
assert.equal(validPostgres.name, 'testname');
assert.equal(validPostgres.driver, 'postgres');
assert.equal(validPostgres.host, 'host');
assert.equal(validPostgres.port, 'port');
assert.equal(validPostgres.postgresSsl, true);
assert.throws(() => {
drivers.validateConnection({ name: 'name' });
}, 'missing driver throws error');
assert.throws(() => {
drivers.validateConnection({ driver: 'postgres' });
}, 'missing name throws error');
assert.throws(() => {
drivers.validateConnection({ name: 'name', driver: 'not exist' });
}, 'missing driver imp throws error');
assert.throws(() => {
drivers.validateConnection({
name: 'name',
driver: 'postgres',
postgresSsl: 'notboolean'
});
}, 'boolean not convertable throws error');
});
it('renders connection with user', function() {
const secret = '123<>!@#$%^&*()-_+=';
const user = {
data: {
secret
}
};
const connection = {
connectionString: '{{user.data.secret}}',
singleStache: '{single}',
port: 6543
};
const rendered = drivers.renderConnection(connection, user);
assert.strictEqual(rendered.connectionString, secret);
assert.strictEqual(rendered.singleStache, '{single}', 'single left alone');
assert.strictEqual(rendered.port, 6543, 'number left alone');
});
it('renders connection without user', function() {
const connection = {
connectionString: 'test',
singleStache: '{single}',
port: 6543
};
const rendered = drivers.renderConnection(connection);
assert.strictEqual(rendered.connectionString, 'test');
assert.strictEqual(rendered.singleStache, '{single}');
});
});