-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests and allow nested params in Redis URI
- Loading branch information
Showing
15 changed files
with
158 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
const expect = require('chai').expect | ||
const unpackMongodbConfig = require('../lib/unpackMongodbConfig') | ||
|
||
const testURI = 'mongodb://[email protected]:password@mongohost:27017/innovation?ssl=false' | ||
|
||
describe('unpackMongodbConfig', function () { | ||
it('can decode a Mongodb URI from fallback URI', function () { | ||
const obj = unpackMongodbConfig('no-env-exists', testURI) | ||
expect(obj.username).to.equal('[email protected]') | ||
expect(obj.password).to.equal('password') | ||
expect(obj.uri).to.equal(testURI) | ||
expect(obj.ssl).to.equal(false) | ||
}) | ||
|
||
it('can decode a Mongodb URI from env var', function () { | ||
process.env['TEST_ENV_NOW_HERE'] = testURI | ||
const obj = unpackMongodbConfig('TEST_ENV_NOW_HERE') | ||
expect(obj.username).to.equal('[email protected]') | ||
expect(obj.password).to.equal('password') | ||
expect(obj.uri).to.equal(testURI) | ||
expect(obj.ssl).to.equal(false) | ||
}) | ||
|
||
it('can decode a Mongodb URI from fallback URI and merge with options', function () { | ||
const obj = unpackMongodbConfig('no-env-exists', testURI, { extraOption: true }) | ||
expect(obj.username).to.equal('[email protected]') | ||
expect(obj.password).to.equal('password') | ||
expect(obj.uri).to.equal(testURI) | ||
expect(obj.ssl).to.equal(false) | ||
expect(obj.extraOption).to.equal(true) | ||
}) | ||
|
||
it('should not expose protocol property', function () { | ||
const obj = unpackMongodbConfig('no-env-exists', testURI) | ||
expect(obj.protocol).to.equal(undefined) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
const expect = require('chai').expect | ||
const unpackNodeApiConfig = require('../lib/unpackNodeApiConfig') | ||
|
||
const testURI = 'http://node-api:3001/api/node' | ||
const testURIWithSSL = 'https://node-api:3001/api/node' | ||
|
||
describe('unpackNodeApiConfig', function () { | ||
it('can decode a Mongodb URI from fallback URI', function () { | ||
const obj = unpackNodeApiConfig('no-env-exists', testURI) | ||
expect(obj.https).to.equal(false) | ||
expect(obj.host).to.equal('node-api') | ||
expect(obj.port).to.equal(3001) | ||
expect(obj.proxyBasePath).to.equal('/api/node') | ||
}) | ||
|
||
it('can decode a Mongodb URI from env var', function () { | ||
process.env['TEST_ENV_NOW_HERE'] = testURI | ||
const obj = unpackNodeApiConfig('TEST_ENV_NOW_HERE') | ||
expect(obj.https).to.equal(false) | ||
expect(obj.host).to.equal('node-api') | ||
expect(obj.port).to.equal(3001) | ||
expect(obj.proxyBasePath).to.equal('/api/node') | ||
}) | ||
|
||
it('can decode a Mongodb URI from fallback URI and merge with options', function () { | ||
const obj = unpackNodeApiConfig('no-env-exists', testURI, { extraOption: true }) | ||
expect(obj.https).to.equal(false) | ||
expect(obj.host).to.equal('node-api') | ||
expect(obj.port).to.equal(3001) | ||
expect(obj.proxyBasePath).to.equal('/api/node') | ||
expect(obj.extraOption).to.equal(true) | ||
}) | ||
|
||
it('should not expose protocol property', function () { | ||
const obj = unpackNodeApiConfig('no-env-exists', testURI) | ||
expect(obj.protocol).to.equal(undefined) | ||
}) | ||
|
||
it('should not expose port if https', function () { | ||
const obj = unpackNodeApiConfig('no-env-exists', testURIWithSSL) | ||
expect(obj.port).to.equal(undefined) | ||
expect(obj.https).to.equal(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
const expect = require('chai').expect | ||
const unpackRedisConfig = require('../lib/unpackRedisConfig') | ||
|
||
const testURI = 'redis://localhost:6379/?auth=server.se&tsl[server]=tsl.server.se' | ||
|
||
describe('unpackRedisConfig', function () { | ||
it('can decode a Redis URI from fallback URI', function () { | ||
const obj = unpackRedisConfig('no-env-exists', testURI) | ||
expect(obj.host).to.equal('localhost') | ||
expect(obj.port).to.equal(6379) | ||
expect(obj.auth).to.equal('server.se') | ||
expect(obj.tsl.server).to.equal('tsl.server.se') | ||
}) | ||
|
||
it('can decode a Redis URI from env var', function () { | ||
process.env['TEST_ENV_NOW_HERE'] = testURI | ||
const obj = unpackRedisConfig('TEST_ENV_NOW_HERE') | ||
expect(obj.host).to.equal('localhost') | ||
expect(obj.port).to.equal(6379) | ||
expect(obj.auth).to.equal('server.se') | ||
expect(obj.tsl.server).to.equal('tsl.server.se') | ||
}) | ||
|
||
it('can decode a Redis URI from fallback URI and merge with options', function () { | ||
const obj = unpackRedisConfig('no-env-exists', testURI, { extraOption: true }) | ||
expect(obj.host).to.equal('localhost') | ||
expect(obj.port).to.equal(6379) | ||
expect(obj.auth).to.equal('server.se') | ||
expect(obj.tsl.server).to.equal('tsl.server.se') | ||
expect(obj.extraOption).to.equal(true) | ||
}) | ||
|
||
it('should not expose protocol property', function () { | ||
const obj = unpackRedisConfig('no-env-exists', testURI) | ||
expect(obj.protocol).to.equal(undefined) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.