Skip to content
This repository was archived by the owner on Nov 5, 2021. It is now read-only.

Add reset functionality #46

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions lib/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -293,12 +293,18 @@ function IBMCloudEnv() {
}
}

function reset() {
loadedFiles = [];
loadedMappings = {};
}

return {
init: init,
getString: getString,
getDictionary: getDictionary,
setLogLevel: setLogLevel,
getCredentialsForService,
reset
};
}

Expand Down
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down