-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from syncpoint/auto-update
disable self-update with environment variable
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* | ||
* @param {String} name The environment variable name to check | ||
* @param {Boolean} defaultValue Can either be true or false. If omitted the default value is always true | ||
* @returns {Boolean} Either the value of the environment variable or the default value | ||
*/ | ||
export const isEnabled = (name, defaultValue = true) => { | ||
if (!process.env[name]) return defaultValue | ||
if (process.env[name].toUpperCase() === 'TRUE') return true | ||
if (process.env[name] === '1') return true | ||
return false | ||
} |
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,38 @@ | ||
import assert from 'assert' | ||
import { isEnabled } from './environment' | ||
|
||
describe('environment isEnabled', function () { | ||
it('return default=false if not set', function () { | ||
const value = isEnabled('TEST_SELF_UPDATE', false) | ||
assert.equal(value, false) | ||
}) | ||
|
||
it('return default=true if not set', function () { | ||
const value = isEnabled('TEST_SELF_UPDATE', true) | ||
assert.equal(value, true) | ||
}) | ||
|
||
it('return true if value=TRUE', function () { | ||
process.env.TEST_SELF_UPDATE = 'true' | ||
const value = isEnabled('TEST_SELF_UPDATE', false) | ||
assert.equal(value, true) | ||
}) | ||
|
||
it('return true if value=1', function () { | ||
process.env.TEST_SELF_UPDATE = '1' | ||
const value = isEnabled('TEST_SELF_UPDATE', false) | ||
assert.equal(value, true) | ||
}) | ||
|
||
it('return true if value=FALSE', function () { | ||
process.env.TEST_SELF_UPDATE = 'false' | ||
const value = isEnabled('TEST_SELF_UPDATE', true) | ||
assert.equal(value, false) | ||
}) | ||
|
||
it('return true if value=0', function () { | ||
process.env.TEST_SELF_UPDATE = '0' | ||
const value = isEnabled('TEST_SELF_UPDATE', true) | ||
assert.equal(value, false) | ||
}) | ||
}) |
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