From 8e7cdc7aee215a3de06d4090c4e4e6f1fbce5006 Mon Sep 17 00:00:00 2001 From: Vadym Yatsyuk Date: Thu, 7 Nov 2019 19:53:44 +0100 Subject: [PATCH 1/2] feat: add reset functionality --- lib/lib.js | 10 ++++++++-- test/test.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/lib.js b/lib/lib.js index 2d36095..c9a34ea 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() { @@ -291,12 +291,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() { From aee659c14708ecd7b0182262b1dc1dba9f769d16 Mon Sep 17 00:00:00 2001 From: Vadym Yatsyuk Date: Thu, 7 Nov 2019 20:10:34 +0100 Subject: [PATCH 2/2] docs: add reset description --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 31ab2a6..8ee203a 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.getCredentialsForServiceLabel('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.