Skip to content

Commit 2979cda

Browse files
committed
tolerate errors from profiles.get()
Signed-off-by: Paul Cooper <[email protected]>
1 parent 0013630 commit 2979cda

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

__tests__/api/BundleDeploy/BundleDeployer.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const DEFAULT_PARAMTERS: IHandlerParameters = {
2323
},
2424
profiles: {
2525
get: (type: string) => {
26+
if (profileError === true) {
27+
throw new Error("Profile Error");
28+
}
2629
return { host: "testname", user: "testuser", password: "testpwd" };
2730
}
2831
} as any,
@@ -57,14 +60,15 @@ const DEFAULT_PARAMTERS: IHandlerParameters = {
5760
let createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementation(() => ({}));
5861
let listSpy = jest.spyOn(List, "allMembers").mockImplementation(() => ({}));
5962
let submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementation(() => ({}));
60-
63+
let profileError = false;
6164

6265
describe("BundleDeployer01", () => {
6366

6467
beforeEach(() => {
6568
createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementation(() => ({}));
6669
listSpy = jest.spyOn(List, "allMembers").mockImplementation(() => ( { val: "DFHDPLOY EYU9ABSI" }));
6770
submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementation(() => ({}));
71+
profileError = false;
6872
});
6973
afterEach(() => {
7074
jest.restoreAllMocks();
@@ -78,6 +82,12 @@ describe("BundleDeployer01", () => {
7882

7983
expect(createSpy).toHaveBeenCalledTimes(1);
8084
});
85+
it("should complain with error during profile load for deploy", async () => {
86+
profileError = true;
87+
await runDeployTestWithError();
88+
89+
expect(createSpy).toHaveBeenCalledTimes(0);
90+
});
8191
it("should complain with missing zOSMF profile for undeploy", async () => {
8292
createSpy.mockImplementationOnce(() => { throw new Error( "Injected Create error" ); });
8393
await runUndeployTestWithError();

__tests__/api/BundleDeploy/__snapshots__/BundleDeployer.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ exports[`BundleDeployer01 should complain if status can't be determined 1`] = `"
1818

1919
exports[`BundleDeployer01 should complain if status can't be determined 2`] = `"DFHDPLOY command completed for jobid UNKNOWN, but status cannot be determined."`;
2020

21+
exports[`BundleDeployer01 should complain with error during profile load for deploy 1`] = `"Required parameter --zosmf-host is not set."`;
22+
2123
exports[`BundleDeployer01 should complain with missing zOSMF profile for deploy 1`] = `"Injected Create error"`;
2224

2325
exports[`BundleDeployer01 should complain with missing zOSMF profile for undeploy 1`] = `"Injected Create error"`;

__tests__/api/BundlePush/BundlePusher.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ const DEFAULT_PARAMTERS: IHandlerParameters = {
2525
},
2626
profiles: {
2727
get: (type: string) => {
28+
29+
if (profileError === true) {
30+
throw new Error("Profile Error");
31+
}
32+
2833
if (type === "zosmf") {
2934
return zosmfProfile;
3035
}
@@ -73,6 +78,7 @@ let consoleText = "";
7378
let zosmfProfile = {};
7479
let sshProfile = {};
7580
let cicsProfile = {};
81+
let profileError = false;
7682

7783
let zosMFSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementation(() => ({}));
7884
let sshSpy = jest.spyOn(SshSession, "createBasicSshSession").mockImplementation(() => ({}));
@@ -114,6 +120,7 @@ describe("BundlePusher01", () => {
114120
zosmfProfile = { host: "wibble", user: "user", password: "thisIsntReal", port: 443, rejectUnauthorized: true };
115121
sshProfile = { host: "wibble", user: "user", password: "thisIsntReal", port: 22 };
116122
cicsProfile = undefined;
123+
profileError = false;
117124
});
118125
afterEach(() => {
119126
jest.restoreAllMocks();
@@ -199,6 +206,12 @@ describe("BundlePusher01", () => {
199206

200207
expect(zosMFSpy).toHaveBeenCalledTimes(1);
201208
});
209+
it("should complain with error during profile load for push", async () => {
210+
profileError = true;
211+
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false, "Required parameter --zosmf-host is not set.");
212+
213+
expect(zosMFSpy).toHaveBeenCalledTimes(0);
214+
});
202215
it("should implement --zosmf-* overrides" , async () => {
203216
const parms = getCommonParmsForPushTests();
204217
parms.arguments.zh = "overrideHost";

src/api/BundleDeploy/BundleDeployer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,13 @@ export class BundleDeployer {
225225

226226
private async createZosMFSession(): Promise<AbstractSession> {
227227
// Create a zosMF session
228-
let zosmfProfile = this.params.profiles.get("zosmf");
228+
let zosmfProfile;
229+
try {
230+
zosmfProfile = this.params.profiles.get("zosmf");
231+
}
232+
catch (error) {
233+
// No-op, we can cope with there being no profile.
234+
}
229235

230236
if (zosmfProfile === undefined) {
231237
zosmfProfile = {};

src/api/BundlePush/BundlePusher.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ export class BundlePusher {
7575
"_" + bundle.getVersion();
7676
}
7777

78+
if (this.params.arguments.silent === undefined) {
79+
const logger = Logger.getAppLogger();
80+
logger.debug("Loading profiles");
81+
}
82+
7883
// Get the profiles
7984
const zosMFProfile = this.getProfile("zosmf");
8085
const sshProfile = this.getProfile("ssh");
@@ -92,6 +97,11 @@ export class BundlePusher {
9297
this.validateProfiles(zosMFProfile, sshProfile, cicsProfile);
9398

9499

100+
if (this.params.arguments.silent === undefined) {
101+
const logger = Logger.getAppLogger();
102+
logger.debug("Creating sessions");
103+
}
104+
95105
// Create a zOSMF session
96106
const zosMFSession = await this.createZosMFSession(zosMFProfile);
97107
// Create an SSH session
@@ -199,7 +209,13 @@ export class BundlePusher {
199209
}
200210

201211
private getProfile(type: string): IProfile {
202-
let profile = this.params.profiles.get(type);
212+
let profile;
213+
try {
214+
profile = this.params.profiles.get(type);
215+
}
216+
catch (error) {
217+
// Tolerate errors
218+
}
203219

204220
if (profile === undefined) {
205221
profile = {};

0 commit comments

Comments
 (0)