diff --git a/README.md b/README.md index 401de60..b9691bc 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,10 @@ In your application, you can filter credentials generated by the module based on var filtered_credentials = IBMCloudEnv.getCredentialsForService('tag', 'label', credentials)); // returns a Json with credentials for specified service tag and label ``` +### Reset + +`IBMCloudEnv.reset()` can be used to **reset** already initialized state, so that `IBMCloudEnv.init()` can be used afterwards. + ## Publishing Changes In order to publish changes, you will need to fork the repository or ask to join the `ibm-developer` org and branch off the `master` branch. diff --git a/lib/lib.js b/lib/lib.js index 8ebc4df..78a1e1c 100644 --- a/lib/lib.js +++ b/lib/lib.js @@ -23,8 +23,8 @@ const PREFIX_PATTERN_CF = "cloudfoundry"; const PREFIX_PATTERN_ENV = "env"; const PREFIX_PATTERN_USER = "user-provided"; -const loadedFiles = []; // keep track so we don't re-read the filesystem unnecessarily -const loadedMappings = {}; +let loadedFiles = []; // keep track so we don't re-read the filesystem unnecessarily +let loadedMappings = {}; function IBMCloudEnv() { @@ -293,12 +293,18 @@ function IBMCloudEnv() { } } + function reset() { + loadedFiles = []; + loadedMappings = {}; + } + return { init: init, getString: getString, getDictionary: getDictionary, setLogLevel: setLogLevel, getCredentialsForService, + reset }; } diff --git a/test/test.js b/test/test.js index addb539..73beb26 100644 --- a/test/test.js +++ b/test/test.js @@ -211,6 +211,20 @@ describe('App', function () { expect(IBMCloudEnv.getDictionary("env_var3").value).to.equal("env-var-json-username"); }); }) + + describe('Reset', () => { + before(() => { + require("./fake-env-vars"); + IBMCloudEnv.setLogLevel(Log4js.levels.TRACE); + IBMCloudEnv.init(path.join("/server", "config", "v1", "mappings.json")); + }); + + it('should reset loaded files and loaded mappings', () => { + expect(IBMCloudEnv.getString("file_var1")).to.equal("plain-text-string"); + IBMCloudEnv.reset(); + expect(IBMCloudEnv.getString("file_var1")).to.be.undefined; + }); + }); }); describe('Test credentials for Watson', function() {