Skip to content

Commit

Permalink
Merge pull request #365 from zowe/FixForIssue364
Browse files Browse the repository at this point in the history
add try catch on loadnamedprofile during initialization
  • Loading branch information
zFernand0 authored Dec 5, 2019
2 parents 92dbb96 + 575bed0 commit 6ab3ef8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
64 changes: 64 additions & 0 deletions __tests__/__unit__/DatasetTree.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,70 @@ describe("DatasetTree Unit Tests", () => {

});

it("tests the dataset filter prompt credentials, favorite route", async () => {
showQuickPick.mockReset();
showInputBox.mockReset();
const sessionwocred = new Session({
user: "",
password: "",
hostname: "fake",
port: 443,
protocol: "https",
type: "basic",
});
const sessNode = new ZoweNode("sestest", vscode.TreeItemCollapsibleState.Expanded, null, session);
sessNode.contextValue = extension.DS_SESSION_CONTEXT + extension.FAV_SUFFIX;
const dsNode = new ZoweNode("[testSess2]: node", vscode.TreeItemCollapsibleState.Expanded, sessNode, sessionwocred);
dsNode.contextValue = extension.DS_SESSION_CONTEXT + extension.FAV_SUFFIX;
testTree.mSessionNodes.push(dsNode);
const dsNode2 = new ZoweNode("testSess2", vscode.TreeItemCollapsibleState.Expanded, sessNode, sessionwocred);
dsNode2.contextValue = extension.DS_SESSION_CONTEXT + extension.FAV_SUFFIX;
testTree.mSessionNodes.push(dsNode2);
getConfiguration.mockReturnValue({
persistence: true,
get: (setting: string) => [
"[test]: brtvs99.public1.test{pds}",
"[test]: brtvs99.test{ds}",
"[test]: brtvs99.fail{fail}",
"[test]: brtvs99.test.search{session}",
"[test]: brtvs99.test.*{session}",
],
update: jest.fn(()=>{
return {};
})
});
Object.defineProperty(Profiles, "getInstance", {
value: jest.fn(() => {
return {
allProfiles: [{name: "firstName", profile: {user:undefined, password: undefined}}, {name: "secondName"}],
defaultProfile: {name: "firstName"},
loadNamedProfile: jest.fn(()=> {
return null;
}),
promptCredentials: jest.fn(()=> {
return ["", "", ""];
}),
};
})
});

const spyMe = new DatasetTree();
Object.defineProperty(spyMe, "datasetFilterPrompt", {
value: jest.fn(() => {
return {
tempNode: dsNode2,
mSessionNodes: {Session: {ISession: {user: "", password: "", base64EncodedAuth: ""}}}
};
})
});

testTree.initialize(Logger.getAppLogger());
await testTree.datasetFilterPrompt(dsNode);

expect(showInformationMessage.mock.calls[0][0]).toEqual("No selection made.");

});

it("tests the dataset filter prompt credentials error", async () => {
showQuickPick.mockReset();
showInputBox.mockReset();
Expand Down
2 changes: 2 additions & 0 deletions i18n/sample/src/DatasetTree.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"intializeFavorites.error.profile2": ". To resolve this, you can create a profile with this name, ",
"initializeFavorites.error.profile3": "or remove the favorites with this profile name from the Zowe-DS-Persistent setting, ",
"initializeFavorites.error.profile4": "which can be found in your VS Code user settings.",
"loadNamedProfile.error.profileName": "Initialization Error: Could not find profile named: ",
"loadNamedProfile.error.period": ".",
"initializeFavorites.fileCorrupted": "Favorites file corrupted: ",
"addFavorite": "PDS already in favorites",
"enterPattern.log.debug.prompt": "Prompting the user for a data set pattern",
Expand Down
10 changes: 9 additions & 1 deletion src/DatasetTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ export class DatasetTree implements vscode.TreeDataProvider<ZoweNode> {
}
} else if (favoriteSearchPattern.test(line)) {
const sesName = line.substring(1, line.lastIndexOf("]")).trim();
const zosmfProfile = Profiles.getInstance().loadNamedProfile(sesName);
let zosmfProfile: IProfileLoaded;
try {
zosmfProfile = Profiles.getInstance().loadNamedProfile(sesName);
} catch (error) {
vscode.window.showErrorMessage(localize("loadNamedProfile.error.profileName",
"Initialization Error: Could not find profile named: ")
+ sesName + localize("loadNamedProfile.error.period", "."));
continue;
}
const session = zowe.ZosmfSession.createBasicZosmfSession(zosmfProfile.profile);
const node = new ZoweNode(line.substring(0, line.lastIndexOf("{")),
vscode.TreeItemCollapsibleState.None, this.mFavoriteSession, session);
Expand Down

0 comments on commit 6ab3ef8

Please sign in to comment.