Skip to content

Commit 476878f

Browse files
committed
use bundleid in remote dir
1 parent 1f14490 commit 476878f

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

__tests__/api/BundlePush/BundlePusher.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,51 @@ describe("BundlePusher01", () => {
325325
expect(readSpy).toHaveBeenCalledTimes(1);
326326
expect(uploadSpy).toHaveBeenCalledTimes(1);
327327
});
328+
it("should handle custom bundle id", async () => {
329+
uploadSpy.mockImplementationOnce(() => { throw new Error("Injected upload error"); });
330+
readSpy = jest.spyOn(fs, "readFileSync").mockImplementation((data: string) => {
331+
if (data.indexOf("cics.xml") > -1) {
332+
return "<manifest xmlns=\"http://www.ibm.com/xmlns/prod/cics/bundle\" id=\"InjectedBundleId\" ></manifest>";
333+
}
334+
});
335+
336+
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
337+
"A problem occurred uploading the bundle to the remote directory '/u/ThisDoesNotExist/InjectedBundleId_1.0.0'. Problem is: Injected upload error");
338+
339+
expect(zosMFSpy).toHaveBeenCalledTimes(1);
340+
expect(sshSpy).toHaveBeenCalledTimes(1);
341+
expect(listSpy).toHaveBeenCalledTimes(1);
342+
expect(createSpy).toHaveBeenCalledTimes(1);
343+
expect(shellSpy).toHaveBeenCalledTimes(0);
344+
expect(membersSpy).toHaveBeenCalledTimes(0);
345+
expect(submitSpy).toHaveBeenCalledTimes(0);
346+
expect(existsSpy).toHaveBeenCalledTimes(1);
347+
expect(readSpy).toHaveBeenCalledTimes(1);
348+
expect(uploadSpy).toHaveBeenCalledTimes(1);
349+
});
350+
it("should handle custom bundle id and version", async () => {
351+
uploadSpy.mockImplementationOnce(() => { throw new Error("Injected upload error"); });
352+
readSpy = jest.spyOn(fs, "readFileSync").mockImplementation((data: string) => {
353+
if (data.indexOf("cics.xml") > -1) {
354+
return "<manifest xmlns=\"http://www.ibm.com/xmlns/prod/cics/bundle\" id=\"InjectedBundleId\" " +
355+
" bundleMajorVer=\"33\" bundleMinorVer=\"22\" bundleMicroVer=\"11\"></manifest>";
356+
}
357+
});
358+
359+
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
360+
"A problem occurred uploading the bundle to the remote directory '/u/ThisDoesNotExist/InjectedBundleId_33.22.11'. Problem is: Injected upload error");
361+
362+
expect(zosMFSpy).toHaveBeenCalledTimes(1);
363+
expect(sshSpy).toHaveBeenCalledTimes(1);
364+
expect(listSpy).toHaveBeenCalledTimes(1);
365+
expect(createSpy).toHaveBeenCalledTimes(1);
366+
expect(shellSpy).toHaveBeenCalledTimes(0);
367+
expect(membersSpy).toHaveBeenCalledTimes(0);
368+
expect(submitSpy).toHaveBeenCalledTimes(0);
369+
expect(existsSpy).toHaveBeenCalledTimes(1);
370+
expect(readSpy).toHaveBeenCalledTimes(1);
371+
expect(uploadSpy).toHaveBeenCalledTimes(1);
372+
});
328373
it("should handle error with remote npm install", async () => {
329374
shellSpy.mockImplementation((session: any, cmd: string) => {
330375
if (cmd.indexOf("npm install") > -1) {

src/api/BundleContent/Bundle.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ export class Bundle {
110110
this.manifest.setBundleId(id);
111111
}
112112

113+
/**
114+
* Returns the Bundle's version value.
115+
* @returns {string}
116+
* @throws ImperativeError
117+
* @memberof Bundle
118+
*/
119+
public getVersion(): string {
120+
return this.manifest.getBundleVersion();
121+
}
122+
113123
/**
114124
* Set the Bundle's version number.
115125
* @param {number} majorVersion - The major version number.

src/api/BundleContent/Manifest.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,29 @@ export class Manifest {
237237
this.manifestAsJson.manifest.id = mangledId;
238238
}
239239

240+
/**
241+
* Returns the Bundle's version number.
242+
*
243+
* @returns {string}
244+
* @throws ImperativeError
245+
* @memberof Manifest
246+
*/
247+
public getBundleVersion(): string {
248+
if (this.manifestAsJson.manifest.bundleMajorVer === undefined) {
249+
this.manifestAsJson.manifest.bundleMajorVer = 1;
250+
}
251+
if (this.manifestAsJson.manifest.bundleMinorVer === undefined) {
252+
this.manifestAsJson.manifest.bundleMinorVer = 0;
253+
}
254+
if (this.manifestAsJson.manifest.bundleMicroVer === undefined) {
255+
this.manifestAsJson.manifest.bundleMicroVer = 0;
256+
}
257+
258+
return this.manifestAsJson.manifest.bundleMajorVer + "." +
259+
this.manifestAsJson.manifest.bundleMinorVer + "." +
260+
this.manifestAsJson.manifest.bundleMicroVer;
261+
}
262+
240263
/**
241264
* Set the Bundle's version number.
242265
* @param {number} majorVersion - The major version number.

src/api/BundlePush/BundlePusher.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class BundlePusher {
4444
this.localDirectory = localDirectory;
4545
this.validateParameters();
4646

47-
// Construct a bundledir from the targetdir and bundle name
47+
// Set an initial bundledir value for validation purposes (we'll replace it with a better value shortly)
4848
this.params.arguments.bundledir = this.path.posix.join(this.params.arguments.targetdir, this.params.arguments.name);
4949
}
5050

@@ -59,6 +59,12 @@ export class BundlePusher {
5959
const bundle = new Bundle(this.localDirectory, true, true);
6060
bundle.validate();
6161

62+
// If the bundle has an id, use it in the target directory name
63+
if (bundle.getId() !== undefined) {
64+
this.params.arguments.bundledir = this.path.posix.join(this.params.arguments.targetdir, bundle.getId()) +
65+
"_" + bundle.getVersion();
66+
}
67+
6268
// Create a zOSMF session
6369
const zosMFSession = await this.createZosMFSession();
6470
// Create an SSH session

0 commit comments

Comments
 (0)