|
| 1 | +/* |
| 2 | + * env-test.js: Tests for the nconf env store. |
| 3 | + * |
| 4 | + * (C) 2011, Charlie Robbins and the Contributors. |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +var nconf = require('../../lib/nconf'); |
| 9 | + |
| 10 | +process.env.DEEP__NESTED__VALUE = 'foo'; |
| 11 | +process.env.DEEP2__NESTED__VALUE = 'bar'; |
| 12 | + |
| 13 | +describe('nconf/stores/env, An instance of nconf.Env', () => { |
| 14 | + it("should have the correct methods defined", () => { |
| 15 | + var env = new nconf.Env(); |
| 16 | + expect(typeof env.loadSync).toBe('function'); |
| 17 | + expect(typeof env.loadEnv).toBe('function'); |
| 18 | + expect(env.whitelist instanceof Array).toBeTruthy(); |
| 19 | + expect(env.whitelist.length).toEqual(0); |
| 20 | + expect(env.inputSeparator).toEqual('__'); |
| 21 | + }); |
| 22 | + it("should have the correct methods defined and with readOnly false", () => { |
| 23 | + var env = new nconf.Env({readOnly: false}); |
| 24 | + expect(typeof env.loadSync).toBe('function'); |
| 25 | + expect(typeof env.loadEnv).toBe('function'); |
| 26 | + expect(env.whitelist instanceof Array).toBeTruthy(); |
| 27 | + expect(env.whitelist.length).toEqual(0); |
| 28 | + expect(env.inputSeparator).toEqual('__'); |
| 29 | + expect(env.readOnly).toBe(false); |
| 30 | + }); |
| 31 | + it("should be able to retrieve a value using the logical separator", () => { |
| 32 | + var env = new nconf.Env({accessSeparator: '.', inputSeparator: '__'}); |
| 33 | + env.loadSync(); |
| 34 | + |
| 35 | + expect(env.accessSeparator).toBe('.'); |
| 36 | + expect(env.get('DEEP.NESTED.VALUE')).toBe('foo'); |
| 37 | + }); |
| 38 | + it("should filter and strip prefix from environment variables", () => { |
| 39 | + var env = new nconf.Env({prefix: 'DEEP2__'}); |
| 40 | + env.loadSync(); |
| 41 | + expect(env.get('DEEP__NESTED__VALUE')).toBeUndefined(); |
| 42 | + expect(env.get('NESTED__VALUE')).toBe('bar'); |
| 43 | + }); |
| 44 | + it("should filter and strip prefix from environment variables with input and access separator", () => { |
| 45 | + var env = new nconf.Env({prefix: 'DEEP2__', accessSeparator: '.', inputSeparator: '__' }); |
| 46 | + env.loadSync(); |
| 47 | + expect(env.get('DEEP.NESTED.VALUE')).toBeUndefined(); |
| 48 | + expect(env.get('NESTED.VALUE')).toBe('bar'); |
| 49 | + }); |
| 50 | +}); |
0 commit comments