Permalink
Browse files

Initial tests for util.initParam, passing.

  • Loading branch information...
1 parent 14c39cc commit c567f628c94383ece44585d704b9fc88e37f43a4 @markstos markstos committed Aug 23, 2016
Showing with 41 additions and 0 deletions.
  1. +41 −0 test/util.js
View
41 test/util.js
@@ -0,0 +1,41 @@
+
+// Tests for config.util functions
+
+// Dependencies
+var vows = require('vows'),
+ assert = require('assert'),
+ config = require('../lib/config'),
+ initParam = config.util.initParam;
+
+vows.describe('Tests for config util functions')
+.addBatch({
+ 'Tests for util.initParam': {
+ 'When no command line or env var is set, default value is returned.': function () {
+ assert(initParam('EMPTY','mydefault'),'mydefault');
+ },
+ 'When process.env is set and cmdline is not, process.env is used ': function () {
+ process.env.ENV_ONLY = 'in-the-env';
+ assert(initParam('ENV_ONLY','mydefault'),'in-the-env');
+ },
+ 'When process.env is set and cmdline *is* set, cmd-line is used ': function () {
+ process.env.BOTH = 'in-the-env';
+ process.argv=['--BOTH=in-the-argv'];
+ assert(initParam('BOTH','mydefault'),'in-the-argv');
+ },
+ 'After calling initParam, value is reflected in getEnv() even if it did not come from process.env': function () {
+ process.argv=['ignore','ignore','--FROMARG=in-the-argv'];
+ assert(initParam('FROMARG','mydefault'),'in-the-argv');
+ assert(config.util.getEnv('FROMARG'),'in-the-argv');
+ },
+ 'Setting a zero value in the process.env works (process.env inherently casts values to strings)': function () {
+ process.env.ENV_ONLY = '0';
+ assert.strictEqual(initParam('ENV_ONLY','mydefault'),'0');
+ },
+ 'Setting a zero value on the command line works. ': function () {
+ process.argv=['ignore','ignore','--FROMARG=0'];
+ assert.strictEqual(initParam('FROMARG','mydefault'),'0');
+ },
+ }
+})
+.export(module);
+

0 comments on commit c567f62

Please sign in to comment.