From f8f0021934757e1cfa1d0641e3d0028b9a8d1dfe Mon Sep 17 00:00:00 2001 From: jace-roell Date: Tue, 26 Nov 2024 09:23:14 -0500 Subject: [PATCH 01/10] add tagging for bufferToUss Signed-off-by: jace-roell --- .../__system__/methods/upload/Upload.system.test.ts | 7 +++++-- packages/zosfiles/src/methods/upload/Upload.ts | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index de22e9569..b0e4c4b76 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -719,7 +719,7 @@ describe("Upload USS file", () => { }); afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); + //await TestEnvironment.cleanUp(testEnvironment); }); describe("Success Scenarios", () => { @@ -755,11 +755,14 @@ describe("Upload USS file", () => { let error; let uploadResponse; let getResponse; + let tagResponse; + const data: Buffer = Buffer.from(testdata); try { uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data, { binary: true }); getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); + tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -767,7 +770,7 @@ describe("Upload USS file", () => { expect(error).toBeFalsy(); expect(getResponse).toEqual(Buffer.from(data.toString())); - + expect(tagResponse).toBe(true); }); it("should upload a USS file from local file", async () => { let error; diff --git a/packages/zosfiles/src/methods/upload/Upload.ts b/packages/zosfiles/src/methods/upload/Upload.ts index 528150b96..02c4cc57a 100644 --- a/packages/zosfiles/src/methods/upload/Upload.ts +++ b/packages/zosfiles/src/methods/upload/Upload.ts @@ -457,6 +457,7 @@ export class Upload { ImperativeExpect.toNotBeEqual(options.record, true, ZosFilesMessages.unsupportedDataType.message); options.binary = options.binary ? options.binary : false; ImperativeExpect.toNotBeNullOrUndefined(ussname, ZosFilesMessages.missingUSSFileName.message); + const origUssname = ussname; ussname = ZosFilesUtils.sanitizeUssPathForRestCall(ussname); const endpoint = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + "/" + ussname; @@ -487,6 +488,12 @@ export class Upload { apiResponse.etag = uploadRequest.response.headers.etag; } + if (options.encoding != null) { + await Utilities.chtag(session, origUssname, Tag.TEXT, options.encoding); + } else if (options.binary) { + await Utilities.chtag(session, origUssname, Tag.BINARY); + } + return { success: true, commandResponse: ZosFilesMessages.dataSetUploadedSuccessfully.message, From d44c75f5575c650d810790c044c416bddb53b00f Mon Sep 17 00:00:00 2001 From: jace-roell Date: Tue, 26 Nov 2024 09:32:12 -0500 Subject: [PATCH 02/10] changelog Signed-off-by: jace-roell --- packages/zosfiles/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/zosfiles/CHANGELOG.md b/packages/zosfiles/CHANGELOG.md index c113aa555..55ffffcc1 100644 --- a/packages/zosfiles/CHANGELOG.md +++ b/packages/zosfiles/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the Zowe z/OS files SDK package will be documented in this file. +## Recent Changes + +- BugFix: Corrected `Upload.BufferToUssFile` to properly tag uploaded files. [#2378](https://github.com/zowe/zowe-cli/pull/2378) + ## `8.9.0` - Enhancement: Added a `List.membersMatchingPattern` method to download all members that match a specific pattern.[#2359](https://github.com/zowe/zowe-cli/pull/2359) From c0d3c5f60e8a4a9069522ddeb6129b8086a357d3 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Tue, 26 Nov 2024 09:32:41 -0500 Subject: [PATCH 03/10] Fix Signed-off-by: jace-roell --- .../__tests__/__system__/methods/upload/Upload.system.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index b0e4c4b76..158729d6c 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -719,7 +719,7 @@ describe("Upload USS file", () => { }); afterAll(async () => { - //await TestEnvironment.cleanUp(testEnvironment); + await TestEnvironment.cleanUp(testEnvironment); }); describe("Success Scenarios", () => { From 3d5e7c26780e92dc2c033df3677c09c08d34b7fb Mon Sep 17 00:00:00 2001 From: jace-roell Date: Tue, 26 Nov 2024 10:11:49 -0500 Subject: [PATCH 04/10] chtag mock in unit tests Signed-off-by: jace-roell --- .../__tests__/__unit__/methods/upload/Upload.unit.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts b/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts index 7e7e8bf36..603d7181a 100644 --- a/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts +++ b/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts @@ -1661,6 +1661,9 @@ describe("z/OS Files - Upload", () => { expect(zosmfExpectSpy).toHaveBeenCalledWith(dummySession, { reqHeaders: headers, resource: endpoint, writeData: data }); }); it("should return with proper response when upload USS file in binary", async () => { + const chtagSpy = jest.spyOn(Utilities, "chtag"); + chtagSpy.mockImplementation(async (): Promise => null); + const data: Buffer = Buffer.from("testing"); const endpoint = path.posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_USS_FILES, dsName); const headers = [ZosmfHeaders.OCTET_STREAM, ZosmfHeaders.X_IBM_BINARY, ZosmfHeaders.ACCEPT_ENCODING]; From 6f098f38f81c7fe2e2d9f0d984919358076d52f0 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Fri, 6 Dec 2024 14:24:54 -0500 Subject: [PATCH 05/10] changelog and test expect Signed-off-by: jace-roell --- packages/zosfiles/CHANGELOG.md | 2 +- .../__tests__/__unit__/methods/upload/Upload.unit.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/zosfiles/CHANGELOG.md b/packages/zosfiles/CHANGELOG.md index 55ffffcc1..4667f7ffc 100644 --- a/packages/zosfiles/CHANGELOG.md +++ b/packages/zosfiles/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to the Zowe z/OS files SDK package will be documented in thi ## Recent Changes -- BugFix: Corrected `Upload.BufferToUssFile` to properly tag uploaded files. [#2378](https://github.com/zowe/zowe-cli/pull/2378) +- BugFix: Corrected `Upload.BufferToUssFile()` SDK function to properly tag uploaded files. [#2378](https://github.com/zowe/zowe-cli/pull/2378) ## `8.9.0` diff --git a/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts b/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts index 603d7181a..28812678c 100644 --- a/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts +++ b/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts @@ -1676,7 +1676,7 @@ describe("z/OS Files - Upload", () => { expect(error).toBeUndefined(); expect(USSresponse).toBeDefined(); - + expect(chtagSpy).toHaveBeenCalled(); expect(zosmfExpectSpy).toHaveBeenCalledTimes(1); expect(zosmfExpectSpy).toHaveBeenCalledWith(dummySession, { reqHeaders: headers, resource: endpoint, writeData: data }); }); From 49ff82f473ed06ed3701a4b9c167b3fcdc16e961 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Mon, 9 Dec 2024 09:50:40 -0500 Subject: [PATCH 06/10] remove comment, add apiResponse Signed-off-by: jace-roell --- packages/zosfiles/src/methods/upload/Upload.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/zosfiles/src/methods/upload/Upload.ts b/packages/zosfiles/src/methods/upload/Upload.ts index 02c4cc57a..a7311da3e 100644 --- a/packages/zosfiles/src/methods/upload/Upload.ts +++ b/packages/zosfiles/src/methods/upload/Upload.ts @@ -481,7 +481,11 @@ export class Upload { const uploadRequest: IRestClientResponse = await ZosmfRestClient.putExpectFullResponse(session, requestOptions); // By default, apiResponse is empty when uploading - const apiResponse: any = {}; + const apiResponse: any = { + success: true, + buffer: fileBuffer, + to: ussname + };; // Return Etag in apiResponse, if requested if (options.returnEtag) { @@ -897,7 +901,6 @@ export class Upload { */ private static get log(): Logger { return Logger.getAppLogger(); - // return Logger.getConsoleLogger(); } @@ -922,7 +925,6 @@ export class Upload { const response: IUploadDir[] = []; if (Upload.hasDirs(dirPath)) { const directories = fs.readdirSync(dirPath).filter((file) => IO.isDir(path.normalize(path.join(dirPath, file)))); - // directories = directories.filter((file) => IO.isDir(path.normalize(path.join(dirPath, file)))); for (let index = 0; index < directories.length; index++) { const dirFullPath = path.normalize(path.join(dirPath, directories[index])); response.push({ From ab2a72e7de7e07e1c29d2810c4383ba70ffa8af4 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Mon, 9 Dec 2024 10:13:59 -0500 Subject: [PATCH 07/10] buffer -> buffer.toString() on apiResponse Signed-off-by: jace-roell --- packages/zosfiles/src/methods/upload/Upload.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zosfiles/src/methods/upload/Upload.ts b/packages/zosfiles/src/methods/upload/Upload.ts index a7311da3e..3ddfc6f70 100644 --- a/packages/zosfiles/src/methods/upload/Upload.ts +++ b/packages/zosfiles/src/methods/upload/Upload.ts @@ -483,7 +483,7 @@ export class Upload { // By default, apiResponse is empty when uploading const apiResponse: any = { success: true, - buffer: fileBuffer, + bufferContents: fileBuffer.toString(), to: ussname };; From 57187569793bbd10fe61bf725827c60a8d3ca284 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Mon, 9 Dec 2024 10:28:39 -0500 Subject: [PATCH 08/10] lint Signed-off-by: jace-roell --- packages/zosfiles/src/methods/upload/Upload.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zosfiles/src/methods/upload/Upload.ts b/packages/zosfiles/src/methods/upload/Upload.ts index 3ddfc6f70..0df9ad25a 100644 --- a/packages/zosfiles/src/methods/upload/Upload.ts +++ b/packages/zosfiles/src/methods/upload/Upload.ts @@ -485,7 +485,7 @@ export class Upload { success: true, bufferContents: fileBuffer.toString(), to: ussname - };; + }; // Return Etag in apiResponse, if requested if (options.returnEtag) { From beb94e792f041d7e4ef04689027caeaf3e8c47a0 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Mon, 9 Dec 2024 12:23:35 -0500 Subject: [PATCH 09/10] seperate apiResponse for different PR Signed-off-by: jace-roell --- packages/zosfiles/src/methods/upload/Upload.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/zosfiles/src/methods/upload/Upload.ts b/packages/zosfiles/src/methods/upload/Upload.ts index 0df9ad25a..2f984eded 100644 --- a/packages/zosfiles/src/methods/upload/Upload.ts +++ b/packages/zosfiles/src/methods/upload/Upload.ts @@ -481,11 +481,7 @@ export class Upload { const uploadRequest: IRestClientResponse = await ZosmfRestClient.putExpectFullResponse(session, requestOptions); // By default, apiResponse is empty when uploading - const apiResponse: any = { - success: true, - bufferContents: fileBuffer.toString(), - to: ussname - }; + const apiResponse: any = {}; // Return Etag in apiResponse, if requested if (options.returnEtag) { From f2aac76da50a49c0cbfc3fa7d602ddaa5c57d0ab Mon Sep 17 00:00:00 2001 From: jace-roell Date: Mon, 9 Dec 2024 16:40:50 -0500 Subject: [PATCH 10/10] changelog Signed-off-by: jace-roell --- packages/zosfiles/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zosfiles/CHANGELOG.md b/packages/zosfiles/CHANGELOG.md index 4667f7ffc..e9715b05a 100644 --- a/packages/zosfiles/CHANGELOG.md +++ b/packages/zosfiles/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to the Zowe z/OS files SDK package will be documented in thi ## Recent Changes -- BugFix: Corrected `Upload.BufferToUssFile()` SDK function to properly tag uploaded files. [#2378](https://github.com/zowe/zowe-cli/pull/2378) +- BugFix: Corrected the `Upload.BufferToUssFile()` SDK function to properly tag uploaded files. [#2378](https://github.com/zowe/zowe-cli/pull/2378) ## `8.9.0`