Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 70d39f7

Browse files
Add unit test for boolean config environment variables (#557)
Signed-off-by: Mark S. Lewis <[email protected]>
1 parent 348f7d9 commit 70d39f7

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

fabric-common/test/Config.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,20 @@ describe('Config', () => {
137137
Object.assign(process.env, originalEnv);
138138
});
139139

140-
it('should convert number-like strings to numbers', () => {
141-
process.env.testnumberproperty = '101';
140+
const tests = [
141+
{name: 'should convert number-like strings to numbers', envName: 'testnumber', value: '101', expected: 101},
142+
{name: 'should convert underscores to hyphens', envName: 'test_underscore', value: 'PASS', configName: 'test-underscore'},
143+
{name: 'should convert to lowercase', envName: 'TESTUPPERCASE', value: 'PASS', configName: 'testuppercase'},
144+
{name: 'should convert boolean-like strings to booleans', envName: 'testboolean', value: 'true', expected: true},
145+
];
146+
147+
tests.forEach(test => it(`${test.name}`, () => {
148+
process.env[test.envName] = test.value;
142149
const config = new Config();
143-
const result = config.get('testnumberproperty');
150+
const result = config.get(test.configName || test.envName);
144151
should.exist(result);
145-
result.should.equal(101);
146-
});
147-
148-
it('should convert underscores to hyphens', () => {
149-
process.env.test_underscore_property = 'PASS';
150-
const config = new Config();
151-
const result = config.get('test-underscore-property');
152-
should.exist(result);
153-
result.should.equal('PASS');
154-
});
155-
156-
it('should convert to lowercase', () => {
157-
process.env.TESTUPPERCASEPROPERTY = 'PASS';
158-
const config = new Config();
159-
const result = config.get('testuppercaseproperty');
160-
should.exist(result);
161-
result.should.equal('PASS');
162-
});
152+
result.should.equal(test.expected || test.value);
153+
}));
163154
});
164155

165156
describe('#set', () => {

0 commit comments

Comments
 (0)