-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: log global.GLOBAL_AGENT configuration changes
- Loading branch information
Showing
4 changed files
with
100 additions
and
1 deletion.
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,42 @@ | ||
// @flow | ||
|
||
import Logger from '../Logger'; | ||
|
||
const log = Logger.child({ | ||
namespace: 'bootstrap' | ||
}); | ||
|
||
const KNOWN_PROPERTY_NAMES = [ | ||
'bootstrapped', | ||
'HTTP_PROXY', | ||
'HTTPS_PROXY', | ||
'NO_PROXY' | ||
]; | ||
|
||
export default () => { | ||
// eslint-disable-next-line fp/no-proxy | ||
return new Proxy({ | ||
bootstrapped: false, | ||
HTTP_PROXY: '', | ||
HTTPS_PROXY: '', | ||
NO_PROXY: '' | ||
}, { | ||
set: (subject, name, value) => { | ||
if (!KNOWN_PROPERTY_NAMES.includes(name)) { | ||
throw new Error('Cannot set an unmapped property "' + name + '".'); | ||
} | ||
|
||
subject[name] = value; | ||
|
||
log.info({ | ||
change: { | ||
name, | ||
value | ||
}, | ||
newConfiguration: subject | ||
}, 'configuration changed'); | ||
|
||
return 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,3 @@ | ||
// @flow | ||
|
||
export {default as createGlobalAgentGlobal} from './createGlobalAgentGlobal'; |
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,51 @@ | ||
// @flow | ||
|
||
import test from 'ava'; | ||
import createGlobalAgentGlobal from '../../../src/factories/createGlobalAgentGlobal'; | ||
|
||
test('defaults bootstrapped to false', (t) => { | ||
const globalAgentGlobal = createGlobalAgentGlobal(); | ||
|
||
t.is(globalAgentGlobal.bootstrapped, false); | ||
}); | ||
|
||
test('sets bootstrapped', (t) => { | ||
const globalAgentGlobal = createGlobalAgentGlobal(); | ||
|
||
globalAgentGlobal.bootstrapped = true; | ||
|
||
t.is(globalAgentGlobal.bootstrapped, true); | ||
}); | ||
|
||
test('sets HTTP_PROXY', (t) => { | ||
const globalAgentGlobal = createGlobalAgentGlobal(); | ||
|
||
globalAgentGlobal.HTTP_PROXY = 'http://127.0.0.1'; | ||
|
||
t.is(globalAgentGlobal.HTTP_PROXY, 'http://127.0.0.1'); | ||
}); | ||
|
||
test('sets HTTPS_PROXY', (t) => { | ||
const globalAgentGlobal = createGlobalAgentGlobal(); | ||
|
||
globalAgentGlobal.HTTPS_PROXY = 'http://127.0.0.1'; | ||
|
||
t.is(globalAgentGlobal.HTTPS_PROXY, 'http://127.0.0.1'); | ||
}); | ||
|
||
test('sets NO_PROXY', (t) => { | ||
const globalAgentGlobal = createGlobalAgentGlobal(); | ||
|
||
globalAgentGlobal.NO_PROXY = '*'; | ||
|
||
t.is(globalAgentGlobal.NO_PROXY, '*'); | ||
}); | ||
|
||
test('throws an error if unknown property is set', (t) => { | ||
const globalAgentGlobal = createGlobalAgentGlobal(); | ||
|
||
t.throws(() => { | ||
// $FlowFixMe | ||
globalAgentGlobal.FOO = 'BAR'; | ||
}, 'Cannot set an unmapped property "FOO".'); | ||
}); |