|
|
@ -5,6 +5,24 @@ import {NcConfigFactory} from "../../lib"; |
|
|
|
|
|
|
|
|
|
|
|
describe('Config Factory Tests', () => { |
|
|
|
describe('Config Factory Tests', () => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expectedObject = { |
|
|
|
|
|
|
|
client: 'pg', |
|
|
|
|
|
|
|
connection: { |
|
|
|
|
|
|
|
host: 'localhost', |
|
|
|
|
|
|
|
port: 5432, |
|
|
|
|
|
|
|
user: 'postgres', |
|
|
|
|
|
|
|
password: 'xgene', |
|
|
|
|
|
|
|
database: 'abcde' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
pool: { |
|
|
|
|
|
|
|
min: 1, |
|
|
|
|
|
|
|
max: 2 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
ssl: { |
|
|
|
|
|
|
|
rejectUnauthorized: false |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
acquireConnectionTimeout: 600000 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
before(function (done) { |
|
|
|
before(function (done) { |
|
|
|
done(); |
|
|
|
done(); |
|
|
@ -17,27 +35,35 @@ describe('Config Factory Tests', () => { |
|
|
|
|
|
|
|
|
|
|
|
it('Generate config from string', function (done) { |
|
|
|
it('Generate config from string', function (done) { |
|
|
|
const config = NcConfigFactory.metaUrlToDbConfig(`pg://localhost:5432?u=postgres&p=xgene&d=abcde`); |
|
|
|
const config = NcConfigFactory.metaUrlToDbConfig(`pg://localhost:5432?u=postgres&p=xgene&d=abcde`); |
|
|
|
expect(config.client).to.be.eq('pg') |
|
|
|
const { pool, ssl, ...rest } = expectedObject; |
|
|
|
expect(config.connection).to.be.a('object') |
|
|
|
expect(config).to.deep.equal(rest); |
|
|
|
expect(config.connection.user).to.be.eq('postgres') |
|
|
|
|
|
|
|
expect(config.connection.port).to.be.eq(5432) |
|
|
|
|
|
|
|
expect(config.connection.password).to.be.eq('xgene') |
|
|
|
|
|
|
|
expect(config.connection.database).to.be.eq('abcde') |
|
|
|
|
|
|
|
done(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
it('Connection string with nested property', function (done) { |
|
|
|
it('Connection string with nested property', function (done) { |
|
|
|
const config = NcConfigFactory.metaUrlToDbConfig(`pg://localhost:5432?u=postgres&p=xgene&d=abcde&pool.min=1&pool.max=2&ssl.rejectUnauthorized=false`); |
|
|
|
const config = NcConfigFactory.metaUrlToDbConfig(`pg://localhost:5432?u=postgres&p=xgene&d=abcde&pool.min=1&pool.max=2&ssl.rejectUnauthorized=false`); |
|
|
|
expect(config.client).to.be.eq('pg') |
|
|
|
expect(config).to.deep.equal(expectedObject); |
|
|
|
expect(config.connection).to.be.a('object') |
|
|
|
|
|
|
|
expect(config.connection.user).to.be.eq('postgres') |
|
|
|
|
|
|
|
expect(config.connection.port).to.be.eq(5432) |
|
|
|
|
|
|
|
expect(config.connection.password).to.be.eq('xgene') |
|
|
|
|
|
|
|
expect(config.connection.database).to.be.eq('abcde') |
|
|
|
|
|
|
|
expect(config.pool).to.be.a('object') |
|
|
|
|
|
|
|
expect(config.pool.min).to.be.eq(1) |
|
|
|
|
|
|
|
expect(config.pool.max).to.be.eq(2) |
|
|
|
|
|
|
|
expect(config.ssl).to.be.a('object') |
|
|
|
|
|
|
|
expect(config.ssl.rejectUnauthorized).to.be.eq(false) |
|
|
|
|
|
|
|
done(); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Allow creating config from JSON string', function(done) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
process.env.NC_DB_JSON = JSON.stringify(expectedObject); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { meta: { db: config } } = NcConfigFactory.make(); |
|
|
|
|
|
|
|
expect(config).to.deep.equal(expectedObject); |
|
|
|
|
|
|
|
done(); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
delete process.env.NC_DB_JSON; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
it('Allow creating config from JSON file', function(done) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
process.env.NC_DB_JSON_FILE = `${__dirname}/dbConfig.json`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { meta: { db: config } } = NcConfigFactory.make(); |
|
|
|
|
|
|
|
expect(config).to.deep.equal(expectedObject); |
|
|
|
|
|
|
|
done(); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
delete process.env.NC_DB_JSON_FILE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|