From 52cb3f1fb17d4a36ca0f1436c886b6bce15496a0 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Wed, 23 Oct 2024 10:05:52 -0400 Subject: [PATCH 01/15] poc Signed-off-by: jace-roell --- .../FileToUSS.definition.unit.test.ts.snap | 11 +++ .../upload/ftu/FileToUSS.definition.ts | 3 +- .../zosfiles/upload/ftu/FileToUSS.handler.ts | 91 +++++++++++++++---- .../zosfiles/src/methods/upload/Upload.ts | 10 +- 4 files changed, 89 insertions(+), 26 deletions(-) diff --git a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.definition.unit.test.ts.snap b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.definition.unit.test.ts.snap index c701260de3..985f225221 100644 --- a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.definition.unit.test.ts.snap +++ b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.definition.unit.test.ts.snap @@ -18,6 +18,17 @@ Array [ "name": "encoding", "type": "string", }, + Object { + "aliases": Array [ + "attrs", + ], + "conflictsWith": Array [ + "ascii-files, binary-files", + ], + "description": "Path of an attributes file to control how files are uploaded.", + "name": "attributes", + "type": "string", + }, ] `; diff --git a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.definition.ts b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.definition.ts index 1cd07d4b82..ea80d10433 100644 --- a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.definition.ts +++ b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.definition.ts @@ -48,7 +48,8 @@ export const FileToUSSDefinition: ICommandDefinition = { ], options: [ UploadOptions.binary, - UploadOptions.encoding + UploadOptions.encoding, + UploadOptions.attributes ], examples: [ { diff --git a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts index 2efe480004..d0f386ff10 100644 --- a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts +++ b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts @@ -1,42 +1,93 @@ /* -* This program and the accompanying materials are made available under the terms of the -* Eclipse Public License v2.0 which accompanies this distribution, and is available at -* https://www.eclipse.org/legal/epl-v20.html -* -* SPDX-License-Identifier: EPL-2.0 -* -* Copyright Contributors to the Zowe Project. -* -*/ + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + * + */ -import { AbstractSession, IHandlerParameters, ITaskWithStatus, TaskStage, TextUtils } from "@zowe/imperative"; +import { + AbstractSession, + IHandlerParameters, + ITaskWithStatus, + TaskStage, + TextUtils, +} from "@zowe/imperative"; import { Upload, IZosFilesResponse } from "@zowe/zos-files-for-zowe-sdk"; import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler"; +import { IUploadOptions } from "@zowe/zos-files-for-zowe-sdk"; +import { ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk"; +import { IUploadMap } from "@zowe/zos-files-for-zowe-sdk"; /** * Handler to upload content from a local file to a USS file * @export */ export default class FileToUSSHandler extends ZosFilesBaseHandler { - public async processWithSession(commandParameters: IHandlerParameters, - session: AbstractSession): Promise { + public async processWithSession( + commandParameters: IHandlerParameters, + session: AbstractSession + ): Promise { const task: ITaskWithStatus = { percentComplete: 0, statusMessage: "Uploading USS file", - stageName: TaskStage.IN_PROGRESS + stageName: TaskStage.IN_PROGRESS, }; commandParameters.response.progress.startBar({ task }); - const response = await Upload.fileToUssFile(session, commandParameters.arguments.inputfile, - commandParameters.arguments.USSFileName, { - binary: commandParameters.arguments.binary, - encoding: commandParameters.arguments.encoding, - task, - responseTimeout: commandParameters.arguments.responseTimeout - }); + const uploadOptions: IUploadOptions = { + binary: commandParameters.arguments.binary, + maxConcurrentRequests: + commandParameters.arguments.maxConcurrentRequests, + task: task, + responseTimeout: commandParameters.arguments.responseTimeout, + includeHidden: commandParameters.arguments.includeHidden, + }; + + const attributes = ZosFilesAttributes.loadFromFile( + commandParameters.arguments.attributes, + commandParameters.arguments.inputDir + ); + if (attributes != null) { + uploadOptions.attributes = attributes; + } else { + uploadOptions.filesMap = this.buildFilesMap(commandParameters); + } + + const response = await Upload.uploadFile( + session, + commandParameters.arguments.inputfile, + commandParameters.arguments.USSFileName, + uploadOptions + ); const formatMessage = TextUtils.prettyJson(response.apiResponse); commandParameters.response.console.log(formatMessage); return response; } + private buildFilesMap(commandParameters: IHandlerParameters) { + let filesMap: IUploadMap = null; + + // checking if binary-files or ascii-files are used, and update filesMap argument + if (commandParameters.arguments.binaryFiles) { + filesMap = { + binary: true, + fileNames: commandParameters.arguments.binaryFiles + .split(",") + .map((fileName: string) => fileName.trim()), + }; + } + if (commandParameters.arguments.asciiFiles) { + filesMap = { + binary: false, + fileNames: commandParameters.arguments.asciiFiles + .split(",") + .map((fileName: string) => fileName.trim()), + }; + } + return filesMap; + } } diff --git a/packages/zosfiles/src/methods/upload/Upload.ts b/packages/zosfiles/src/methods/upload/Upload.ts index 985cf0455c..1387a8c850 100644 --- a/packages/zosfiles/src/methods/upload/Upload.ts +++ b/packages/zosfiles/src/methods/upload/Upload.ts @@ -678,7 +678,7 @@ export class Upload { } const fileName = path.normalize(path.join(inputDirectory, file.fileName)); const ussFilePath = path.posix.join(ussname, file.fileName); - return this.uploadFile(fileName, ussFilePath, session, + return this.uploadFile(session,fileName, ussFilePath, { ...options, binary: file.binary }); }; @@ -831,7 +831,7 @@ export class Upload { } const filePath = path.normalize(path.join(inputDirectory, file.fileName)); const ussFilePath = path.posix.join(ussname, file.fileName); - return this.uploadFile(filePath, ussFilePath, session, + return this.uploadFile(session, filePath, ussFilePath, { ...options, binary: file.binary }); }; if (maxConcurrentRequests === 0) { @@ -854,8 +854,8 @@ export class Upload { }; } - private static async uploadFile(localPath: string, ussPath: string, - session: AbstractSession, options: IUploadOptions) { + public static async uploadFile(session: AbstractSession, localPath: string, ussPath: string, + options: IUploadOptions) { const tempOptions: Partial = {}; if (options.attributes) { @@ -882,7 +882,7 @@ export class Upload { } } - await this.fileToUssFile(session, localPath, ussPath, tempOptions); + return await this.fileToUssFile(session, localPath, ussPath, tempOptions); } /** From 9d4540664850b1f98f97783fde28e941105294d0 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Wed, 23 Oct 2024 11:05:21 -0400 Subject: [PATCH 02/15] start unit test Signed-off-by: jace-roell --- .../__unit__/methods/upload/Upload.unit.test.ts | 15 +++++++++++++++ 1 file changed, 15 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 9f232a790e..c8e537a0ff 100644 --- a/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts +++ b/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts @@ -2106,6 +2106,21 @@ describe("z/OS Files - Upload", () => { error = err; } + expect(USSresponse).toBeUndefined(); + expect(error).toBeDefined(); + expect(error.message).toContain(ZosFilesMessages.missingInputFile.message); + lstatSpy.mockClear(); + }); + it("should throw an error if local file name is not a valid file path", async () => { + lstatSpy.mockImplementationOnce((somePath, callback: any) => { + callback(null, {isFile: () => false}); + }); + try { + USSresponse = await Upload.fileToUssFile(dummySession, undefined, "file"); + } catch (err) { + error = err; + } + expect(USSresponse).toBeUndefined(); expect(error).toBeDefined(); expect(error.message).toContain(ZosFilesMessages.missingInputFile.message); From dc7028a1331facfd4fc96f7efb7a42fe25caddd1 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Wed, 23 Oct 2024 16:05:33 -0400 Subject: [PATCH 03/15] changelog, fixed existing unit tests Signed-off-by: jace-roell --- .../upload/ftu/FileToUSS.handler.unit.test.ts | 13 +++-- .../FileToUSS.handler.unit.test.ts.snap | 54 +++++++++++++++++++ packages/zosfiles/CHANGELOG.md | 4 ++ .../methods/upload/Upload.unit.test.ts | 15 ------ 4 files changed, 66 insertions(+), 20 deletions(-) diff --git a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts index c4eedd2bd4..507a7e69a7 100644 --- a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts +++ b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts @@ -29,7 +29,7 @@ describe("Upload file-to-uss handler", () => { let fakeSession = null; // Mock the submit JCL function - Upload.fileToUssFile = jest.fn(async (session, file, name, options = {}) => { + Upload.uploadFile = jest.fn(async (session, file, name, options = {}) => { fakeSession = session; return { success: true, @@ -79,20 +79,23 @@ describe("Upload file-to-uss handler", () => { } expect(error).toBeUndefined(); - expect(Upload.fileToUssFile).toHaveBeenCalledTimes(1); - expect(Upload.fileToUssFile).toHaveBeenCalledWith(fakeSession, inputfile, USSFileName, { + expect(Upload.uploadFile).toHaveBeenCalledTimes(1); + expect(Upload.uploadFile).toHaveBeenCalledWith(fakeSession, inputfile, USSFileName, { binary: undefined, encoding: undefined, task: { percentComplete: 0, stageName: 0, statusMessage: "Uploading USS file" - } + }, + filesMap: null, + includeHidden: undefined, + maxConcurrentRequests: undefined, + responseTimeout: undefined }); expect(jsonObj).toMatchSnapshot(); expect(apiMessage).toMatchSnapshot(); expect(logMessage).toMatchSnapshot(); }); - }); }); diff --git a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.handler.unit.test.ts.snap b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.handler.unit.test.ts.snap index 463337181f..86e6283ffe 100644 --- a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.handler.unit.test.ts.snap +++ b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.handler.unit.test.ts.snap @@ -1,5 +1,32 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Upload file-to-uss handler process method should upload a file to a uss if requested - zosattributes 1`] = ` +Object { + "apiResponse": Array [ + Object { + "from": "test-file", + "success": true, + "to": "testing", + }, + ], + "commandResponse": "uploaded", + "success": true, +} +`; + +exports[`Upload file-to-uss handler process method should upload a file to a uss if requested - zosattributes 2`] = `""`; + +exports[`Upload file-to-uss handler process method should upload a file to a uss if requested - zosattributes 3`] = ` +" +-  + success: true + from:  test-file + to:  testing + + +uploaded" +`; + exports[`Upload file-to-uss handler process method should upload a file to a uss if requested 1`] = ` Object { "apiResponse": Array [ @@ -26,3 +53,30 @@ exports[`Upload file-to-uss handler process method should upload a file to a uss uploaded" `; + +exports[`Upload file-to-uss handler process method should upload a file to a uss if requested 4`] = ` +Object { + "apiResponse": Array [ + Object { + "from": "test-file", + "success": true, + "to": "testing", + }, + ], + "commandResponse": "uploaded", + "success": true, +} +`; + +exports[`Upload file-to-uss handler process method should upload a file to a uss if requested 5`] = `""`; + +exports[`Upload file-to-uss handler process method should upload a file to a uss if requested 6`] = ` +" +-  + success: true + from:  test-file + to:  testing + + +uploaded" +`; diff --git a/packages/zosfiles/CHANGELOG.md b/packages/zosfiles/CHANGELOG.md index c34ceeb4fe..4c819c988a 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 + +- Enhancement: Added optional `--attributes` flag to `zowe zos-files upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319] (https://github.com/zowe/zowe-cli/pull/2319) + ## `8.2.0` - Enhancement: Added an optional `continueSearch` function to the `ISearchOptions` interface. After a data set listing is completed, the new function is called with the list of data sets about to be searched. This allows the extender or end users to continue with the search or cancel it. [#2300](https://github.com/zowe/zowe-cli/pull/2300) 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 c8e537a0ff..9f232a790e 100644 --- a/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts +++ b/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts @@ -2106,21 +2106,6 @@ describe("z/OS Files - Upload", () => { error = err; } - expect(USSresponse).toBeUndefined(); - expect(error).toBeDefined(); - expect(error.message).toContain(ZosFilesMessages.missingInputFile.message); - lstatSpy.mockClear(); - }); - it("should throw an error if local file name is not a valid file path", async () => { - lstatSpy.mockImplementationOnce((somePath, callback: any) => { - callback(null, {isFile: () => false}); - }); - try { - USSresponse = await Upload.fileToUssFile(dummySession, undefined, "file"); - } catch (err) { - error = err; - } - expect(USSresponse).toBeUndefined(); expect(error).toBeDefined(); expect(error.message).toContain(ZosFilesMessages.missingInputFile.message); From 9ac3e768a197d369ecd7cca9b40538ae38ec24f8 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Wed, 23 Oct 2024 16:17:58 -0400 Subject: [PATCH 04/15] changelog Signed-off-by: jace-roell --- packages/cli/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index b249587912..a8c0a33f4a 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the Zowe CLI package will be documented in this file. +## Recent Changes + +- Enhancement: Added optional `--attributes` flag to `zowe zos-files upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319] (https://github.com/zowe/zowe-cli/pull/2319) + ## `8.3.0` - Enhancement: Issue the `zowe files search data-sets` command with the new `encoding` option to use a different code page when searching data set contents. [#2161](https://github.com/zowe/zowe-cli/issues/2161) From 4b291d68fe292d05dbd3672948c23a82643cc4ee Mon Sep 17 00:00:00 2001 From: jace-roell Date: Thu, 24 Oct 2024 09:37:56 -0400 Subject: [PATCH 05/15] unit test and snapshot Signed-off-by: jace-roell --- .../upload/ftu/FileToUSS.handler.unit.test.ts | 91 +++++++++++++++++++ .../FileToUSS.handler.unit.test.ts.snap | 33 +------ 2 files changed, 94 insertions(+), 30 deletions(-) diff --git a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts index 507a7e69a7..e495566285 100644 --- a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts +++ b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts @@ -11,6 +11,7 @@ import { Upload } from "@zowe/zos-files-for-zowe-sdk"; import { UNIT_TEST_ZOSMF_PROF_OPTS } from "../../../../../../../__tests__/__src__/TestConstants"; +import { ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk"; describe("Upload file-to-uss handler", () => { describe("process method", () => { @@ -97,5 +98,95 @@ describe("Upload file-to-uss handler", () => { expect(apiMessage).toMatchSnapshot(); expect(logMessage).toMatchSnapshot(); }); + it("should upload a file to a USS if requested - zosattributes file", async () => { + // Require the handler and create a new instance + const handlerReq = require("../../../../../src/zosfiles/upload/ftu/FileToUSS.handler"); + const handler = new handlerReq.default(); + const inputfile = "test-file"; + const USSFileName = "testing"; + let zosAttributes: any; + + let error; + let apiMessage = ""; + let jsonObj; + let logMessage = ""; + let fakeSession = null; + + jest.spyOn(ZosFilesAttributes, "loadFromFile").mockImplementation(() => { + zosAttributes = Object.create(ZosFilesAttributes.prototype); + zosAttributes.attributes = new Map([ + ['*.json', { ignore: true }], + ['*.bin', { ignore: false, localEncoding: 'binary', remoteEncoding: 'binary' }], + ['*.jcl', { ignore: false, localEncoding: 'IBM-1047', remoteEncoding: 'IBM-1047' }], + ['*.md', { ignore: false, localEncoding: 'UTF-8', remoteEncoding: 'UTF-8' }], + ['*.txt', { ignore: false, localEncoding: 'UTF-8', remoteEncoding: 'IBM-1047' }] + ]); + zosAttributes.basePath = undefined; + return zosAttributes; + }); + Upload.uploadFile = jest.fn(async (session, file, name, options = {}) => { + fakeSession = session; + return { + success: true, + commandResponse: "uploaded", + apiResponse: [ + { success: true, from: inputfile, to: USSFileName } + ] + }; + }); + try { + await handler.process({ + arguments: { + $0: "fake", + _: ["fake"], + inputfile, + USSFileName, + ...UNIT_TEST_ZOSMF_PROF_OPTS + }, + response: { + data: { + setMessage: jest.fn((setMsgArgs) => { + apiMessage = setMsgArgs; + }), + setObj: jest.fn((setObjArgs) => { + jsonObj = setObjArgs; + }) + }, + console: { + log: jest.fn((logArgs) => { + logMessage += "\n" + logArgs; + }) + }, + progress: { + startBar: jest.fn(() => { + // do nothing + }), + endBar: jest.fn(() => { + // do nothing + }) + } + } + } as any); + } catch (e) { + error = e; + } + expect(error).toBeUndefined(); + expect(Upload.uploadFile).toHaveBeenCalledTimes(1); + expect(Upload.uploadFile).toHaveBeenCalledWith(fakeSession, inputfile, USSFileName, { + attributes: zosAttributes, + binary: undefined, + includeHidden: undefined, + maxConcurrentRequests: undefined, + responseTimeout: undefined, + task: { + percentComplete: 0, + stageName: 0, + statusMessage: "Uploading USS file" + } + }); + expect(jsonObj).toMatchSnapshot(); + expect(apiMessage).toMatchSnapshot(); + expect(logMessage).toMatchSnapshot(); + }); }); }); diff --git a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.handler.unit.test.ts.snap b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.handler.unit.test.ts.snap index 86e6283ffe..f13e49cc22 100644 --- a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.handler.unit.test.ts.snap +++ b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/__snapshots__/FileToUSS.handler.unit.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Upload file-to-uss handler process method should upload a file to a uss if requested - zosattributes 1`] = ` +exports[`Upload file-to-uss handler process method should upload a file to a USS if requested - zosattributes file 1`] = ` Object { "apiResponse": Array [ Object { @@ -14,9 +14,9 @@ Object { } `; -exports[`Upload file-to-uss handler process method should upload a file to a uss if requested - zosattributes 2`] = `""`; +exports[`Upload file-to-uss handler process method should upload a file to a USS if requested - zosattributes file 2`] = `""`; -exports[`Upload file-to-uss handler process method should upload a file to a uss if requested - zosattributes 3`] = ` +exports[`Upload file-to-uss handler process method should upload a file to a USS if requested - zosattributes file 3`] = ` " -  success: true @@ -53,30 +53,3 @@ exports[`Upload file-to-uss handler process method should upload a file to a uss uploaded" `; - -exports[`Upload file-to-uss handler process method should upload a file to a uss if requested 4`] = ` -Object { - "apiResponse": Array [ - Object { - "from": "test-file", - "success": true, - "to": "testing", - }, - ], - "commandResponse": "uploaded", - "success": true, -} -`; - -exports[`Upload file-to-uss handler process method should upload a file to a uss if requested 5`] = `""`; - -exports[`Upload file-to-uss handler process method should upload a file to a uss if requested 6`] = ` -" --  - success: true - from:  test-file - to:  testing - - -uploaded" -`; From ad419118beabe1fa391648b31e7d5090bbee3422 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Thu, 24 Oct 2024 09:45:35 -0400 Subject: [PATCH 06/15] snapshot Signed-off-by: jace-roell --- .../cli.files.upload.ftu.integration.test.ts.snap | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/cli/__tests__/zosfiles/__integration__/upload/ftu/__snapshots__/cli.files.upload.ftu.integration.test.ts.snap b/packages/cli/__tests__/zosfiles/__integration__/upload/ftu/__snapshots__/cli.files.upload.ftu.integration.test.ts.snap index 8d37ccd150..de432abd19 100644 --- a/packages/cli/__tests__/zosfiles/__integration__/upload/ftu/__snapshots__/cli.files.upload.ftu.integration.test.ts.snap +++ b/packages/cli/__tests__/zosfiles/__integration__/upload/ftu/__snapshots__/cli.files.upload.ftu.integration.test.ts.snap @@ -43,6 +43,10 @@ exports[`Upload uss file should display the help 1`] = ` Data content in encoding mode, which means that data conversion is performed according to the encoding specified. + --attributes | --attrs (string) + + Path of an attributes file to control how files are uploaded. + --response-timeout | --rto (number) The maximum amount of time in seconds the z/OSMF Files TSO servlet should run @@ -152,8 +156,8 @@ exports[`Upload uss file should display the help 1`] = ` \\"success\\": true, \\"exitCode\\": 0, \\"message\\": \\"The help was constructed for command: file-to-uss.\\", - \\"stdout\\": \\"\\\\n COMMAND NAME\\\\n ------------\\\\n\\\\n file-to-uss | ftu\\\\n\\\\n DESCRIPTION\\\\n -----------\\\\n\\\\n Upload content to a USS file from local file.\\\\n\\\\n USAGE\\\\n -----\\\\n\\\\n zowe zos-files upload file-to-uss [options]\\\\n\\\\n POSITIONAL ARGUMENTS\\\\n --------------------\\\\n\\\\n inputfile\\\\t\\\\t (string)\\\\n\\\\n The local file that you want to upload to a USS file\\\\n\\\\n USSFileName\\\\t\\\\t (string)\\\\n\\\\n The name of the USS file to which you want to upload the file\\\\n\\\\n OPTIONS\\\\n -------\\\\n\\\\n --binary | -b (boolean)\\\\n\\\\n Data content in binary mode, which means that no data conversion is performed.\\\\n The data transfer process returns each record as-is, without translation. No\\\\n delimiters are added between records.\\\\n\\\\n --encoding | --ec (string)\\\\n\\\\n Data content in encoding mode, which means that data conversion is performed\\\\n according to the encoding specified.\\\\n\\\\n --response-timeout | --rto (number)\\\\n\\\\n The maximum amount of time in seconds the z/OSMF Files TSO servlet should run\\\\n before returning a response. Any request exceeding this amount of time will be\\\\n terminated and return an error. Allowed values: 5 - 600\\\\n\\\\n ZOSMF CONNECTION OPTIONS\\\\n ------------------------\\\\n\\\\n --host | -H (string)\\\\n\\\\n The z/OSMF server host name.\\\\n\\\\n --port | -P (number)\\\\n\\\\n The z/OSMF server port.\\\\n\\\\n Default value: 443\\\\n\\\\n --user | -u (string)\\\\n\\\\n Mainframe (z/OSMF) user name, which can be the same as your TSO login.\\\\n\\\\n --password | --pass | --pw (string)\\\\n\\\\n Mainframe (z/OSMF) password, which can be the same as your TSO password.\\\\n\\\\n --reject-unauthorized | --ru (boolean)\\\\n\\\\n Reject self-signed certificates.\\\\n\\\\n Default value: true\\\\n\\\\n --base-path | --bp (string)\\\\n\\\\n The base path for your API mediation layer instance. Specify this option to\\\\n prepend the base path to all z/OSMF resources when making REST requests. Do not\\\\n specify this option if you are not using an API mediation layer.\\\\n\\\\n --protocol (string)\\\\n\\\\n The protocol used (HTTP or HTTPS)\\\\n\\\\n Default value: https\\\\n Allowed values: http, https\\\\n\\\\n --cert-file (local file path)\\\\n\\\\n The file path to a certificate file to use for authentication\\\\n\\\\n --cert-key-file (local file path)\\\\n\\\\n The file path to a certificate key file to use for authentication\\\\n\\\\n PROFILE OPTIONS\\\\n ---------------\\\\n\\\\n --zosmf-profile | --zosmf-p (string)\\\\n\\\\n The name of a (zosmf) profile to load for this command execution.\\\\n\\\\n --base-profile | --base-p (string)\\\\n\\\\n The name of a (base) profile to load for this command execution.\\\\n\\\\n BASE CONNECTION OPTIONS\\\\n -----------------------\\\\n\\\\n --token-type | --tt (string)\\\\n\\\\n The type of token to get and use for the API. Omit this option to use the\\\\n default token type, which is provided by 'zowe auth login'.\\\\n\\\\n --token-value | --tv (string)\\\\n\\\\n The value of the token to pass to the API.\\\\n\\\\n GLOBAL OPTIONS\\\\n --------------\\\\n\\\\n --show-inputs-only (boolean)\\\\n\\\\n Show command inputs and do not run the command\\\\n\\\\n --response-format-json | --rfj (boolean)\\\\n\\\\n Produce JSON formatted data from a command\\\\n\\\\n --help | -h (boolean)\\\\n\\\\n Display help text\\\\n\\\\n --help-web | --hw (boolean)\\\\n\\\\n Display HTML help in browser\\\\n\\\\n EXAMPLES\\\\n --------\\\\n\\\\n - Upload to the USS file \\\\\\"/a/ibmuser/my_text.txt\\\\\\" from the\\\\n file \\\\\\"file.txt\\\\\\":\\\\n\\\\n $ zowe zos-files upload file-to-uss \\\\\\"file.txt\\\\\\" \\\\\\"/a/ibmuser/my_text.txt\\\\\\"\\\\n\\\\n\\", + \\"stdout\\": \\"\\\\n COMMAND NAME\\\\n ------------\\\\n\\\\n file-to-uss | ftu\\\\n\\\\n DESCRIPTION\\\\n -----------\\\\n\\\\n Upload content to a USS file from local file.\\\\n\\\\n USAGE\\\\n -----\\\\n\\\\n zowe zos-files upload file-to-uss [options]\\\\n\\\\n POSITIONAL ARGUMENTS\\\\n --------------------\\\\n\\\\n inputfile\\\\t\\\\t (string)\\\\n\\\\n The local file that you want to upload to a USS file\\\\n\\\\n USSFileName\\\\t\\\\t (string)\\\\n\\\\n The name of the USS file to which you want to upload the file\\\\n\\\\n OPTIONS\\\\n -------\\\\n\\\\n --binary | -b (boolean)\\\\n\\\\n Data content in binary mode, which means that no data conversion is performed.\\\\n The data transfer process returns each record as-is, without translation. No\\\\n delimiters are added between records.\\\\n\\\\n --encoding | --ec (string)\\\\n\\\\n Data content in encoding mode, which means that data conversion is performed\\\\n according to the encoding specified.\\\\n\\\\n --attributes | --attrs (string)\\\\n\\\\n Path of an attributes file to control how files are uploaded.\\\\n\\\\n --response-timeout | --rto (number)\\\\n\\\\n The maximum amount of time in seconds the z/OSMF Files TSO servlet should run\\\\n before returning a response. Any request exceeding this amount of time will be\\\\n terminated and return an error. Allowed values: 5 - 600\\\\n\\\\n ZOSMF CONNECTION OPTIONS\\\\n ------------------------\\\\n\\\\n --host | -H (string)\\\\n\\\\n The z/OSMF server host name.\\\\n\\\\n --port | -P (number)\\\\n\\\\n The z/OSMF server port.\\\\n\\\\n Default value: 443\\\\n\\\\n --user | -u (string)\\\\n\\\\n Mainframe (z/OSMF) user name, which can be the same as your TSO login.\\\\n\\\\n --password | --pass | --pw (string)\\\\n\\\\n Mainframe (z/OSMF) password, which can be the same as your TSO password.\\\\n\\\\n --reject-unauthorized | --ru (boolean)\\\\n\\\\n Reject self-signed certificates.\\\\n\\\\n Default value: true\\\\n\\\\n --base-path | --bp (string)\\\\n\\\\n The base path for your API mediation layer instance. Specify this option to\\\\n prepend the base path to all z/OSMF resources when making REST requests. Do not\\\\n specify this option if you are not using an API mediation layer.\\\\n\\\\n --protocol (string)\\\\n\\\\n The protocol used (HTTP or HTTPS)\\\\n\\\\n Default value: https\\\\n Allowed values: http, https\\\\n\\\\n --cert-file (local file path)\\\\n\\\\n The file path to a certificate file to use for authentication\\\\n\\\\n --cert-key-file (local file path)\\\\n\\\\n The file path to a certificate key file to use for authentication\\\\n\\\\n PROFILE OPTIONS\\\\n ---------------\\\\n\\\\n --zosmf-profile | --zosmf-p (string)\\\\n\\\\n The name of a (zosmf) profile to load for this command execution.\\\\n\\\\n --base-profile | --base-p (string)\\\\n\\\\n The name of a (base) profile to load for this command execution.\\\\n\\\\n BASE CONNECTION OPTIONS\\\\n -----------------------\\\\n\\\\n --token-type | --tt (string)\\\\n\\\\n The type of token to get and use for the API. Omit this option to use the\\\\n default token type, which is provided by 'zowe auth login'.\\\\n\\\\n --token-value | --tv (string)\\\\n\\\\n The value of the token to pass to the API.\\\\n\\\\n GLOBAL OPTIONS\\\\n --------------\\\\n\\\\n --show-inputs-only (boolean)\\\\n\\\\n Show command inputs and do not run the command\\\\n\\\\n --response-format-json | --rfj (boolean)\\\\n\\\\n Produce JSON formatted data from a command\\\\n\\\\n --help | -h (boolean)\\\\n\\\\n Display help text\\\\n\\\\n --help-web | --hw (boolean)\\\\n\\\\n Display HTML help in browser\\\\n\\\\n EXAMPLES\\\\n --------\\\\n\\\\n - Upload to the USS file \\\\\\"/a/ibmuser/my_text.txt\\\\\\" from the\\\\n file \\\\\\"file.txt\\\\\\":\\\\n\\\\n $ zowe zos-files upload file-to-uss \\\\\\"file.txt\\\\\\" \\\\\\"/a/ibmuser/my_text.txt\\\\\\"\\\\n\\\\n\\", \\"stderr\\": \\"\\", - \\"data\\": \\"\\\\n COMMAND NAME\\\\n ------------\\\\n\\\\n file-to-uss | ftu\\\\n\\\\n DESCRIPTION\\\\n -----------\\\\n\\\\n Upload content to a USS file from local file.\\\\n\\\\n USAGE\\\\n -----\\\\n\\\\n zowe zos-files upload file-to-uss [options]\\\\n\\\\n POSITIONAL ARGUMENTS\\\\n --------------------\\\\n\\\\n inputfile\\\\t\\\\t (string)\\\\n\\\\n The local file that you want to upload to a USS file\\\\n\\\\n USSFileName\\\\t\\\\t (string)\\\\n\\\\n The name of the USS file to which you want to upload the file\\\\n\\\\n OPTIONS\\\\n -------\\\\n\\\\n --binary | -b (boolean)\\\\n\\\\n Data content in binary mode, which means that no data conversion is performed.\\\\n The data transfer process returns each record as-is, without translation. No\\\\n delimiters are added between records.\\\\n\\\\n --encoding | --ec (string)\\\\n\\\\n Data content in encoding mode, which means that data conversion is performed\\\\n according to the encoding specified.\\\\n\\\\n --response-timeout | --rto (number)\\\\n\\\\n The maximum amount of time in seconds the z/OSMF Files TSO servlet should run\\\\n before returning a response. Any request exceeding this amount of time will be\\\\n terminated and return an error. Allowed values: 5 - 600\\\\n\\\\n ZOSMF CONNECTION OPTIONS\\\\n ------------------------\\\\n\\\\n --host | -H (string)\\\\n\\\\n The z/OSMF server host name.\\\\n\\\\n --port | -P (number)\\\\n\\\\n The z/OSMF server port.\\\\n\\\\n Default value: 443\\\\n\\\\n --user | -u (string)\\\\n\\\\n Mainframe (z/OSMF) user name, which can be the same as your TSO login.\\\\n\\\\n --password | --pass | --pw (string)\\\\n\\\\n Mainframe (z/OSMF) password, which can be the same as your TSO password.\\\\n\\\\n --reject-unauthorized | --ru (boolean)\\\\n\\\\n Reject self-signed certificates.\\\\n\\\\n Default value: true\\\\n\\\\n --base-path | --bp (string)\\\\n\\\\n The base path for your API mediation layer instance. Specify this option to\\\\n prepend the base path to all z/OSMF resources when making REST requests. Do not\\\\n specify this option if you are not using an API mediation layer.\\\\n\\\\n --protocol (string)\\\\n\\\\n The protocol used (HTTP or HTTPS)\\\\n\\\\n Default value: https\\\\n Allowed values: http, https\\\\n\\\\n --cert-file (local file path)\\\\n\\\\n The file path to a certificate file to use for authentication\\\\n\\\\n --cert-key-file (local file path)\\\\n\\\\n The file path to a certificate key file to use for authentication\\\\n\\\\n PROFILE OPTIONS\\\\n ---------------\\\\n\\\\n --zosmf-profile | --zosmf-p (string)\\\\n\\\\n The name of a (zosmf) profile to load for this command execution.\\\\n\\\\n --base-profile | --base-p (string)\\\\n\\\\n The name of a (base) profile to load for this command execution.\\\\n\\\\n BASE CONNECTION OPTIONS\\\\n -----------------------\\\\n\\\\n --token-type | --tt (string)\\\\n\\\\n The type of token to get and use for the API. Omit this option to use the\\\\n default token type, which is provided by 'zowe auth login'.\\\\n\\\\n --token-value | --tv (string)\\\\n\\\\n The value of the token to pass to the API.\\\\n\\\\n GLOBAL OPTIONS\\\\n --------------\\\\n\\\\n --show-inputs-only (boolean)\\\\n\\\\n Show command inputs and do not run the command\\\\n\\\\n --response-format-json | --rfj (boolean)\\\\n\\\\n Produce JSON formatted data from a command\\\\n\\\\n --help | -h (boolean)\\\\n\\\\n Display help text\\\\n\\\\n --help-web | --hw (boolean)\\\\n\\\\n Display HTML help in browser\\\\n\\\\n EXAMPLES\\\\n --------\\\\n\\\\n - Upload to the USS file \\\\\\"/a/ibmuser/my_text.txt\\\\\\" from the\\\\n file \\\\\\"file.txt\\\\\\":\\\\n\\\\n $ zowe zos-files upload file-to-uss \\\\\\"file.txt\\\\\\" \\\\\\"/a/ibmuser/my_text.txt\\\\\\"\\\\n\\\\n\\" + \\"data\\": \\"\\\\n COMMAND NAME\\\\n ------------\\\\n\\\\n file-to-uss | ftu\\\\n\\\\n DESCRIPTION\\\\n -----------\\\\n\\\\n Upload content to a USS file from local file.\\\\n\\\\n USAGE\\\\n -----\\\\n\\\\n zowe zos-files upload file-to-uss [options]\\\\n\\\\n POSITIONAL ARGUMENTS\\\\n --------------------\\\\n\\\\n inputfile\\\\t\\\\t (string)\\\\n\\\\n The local file that you want to upload to a USS file\\\\n\\\\n USSFileName\\\\t\\\\t (string)\\\\n\\\\n The name of the USS file to which you want to upload the file\\\\n\\\\n OPTIONS\\\\n -------\\\\n\\\\n --binary | -b (boolean)\\\\n\\\\n Data content in binary mode, which means that no data conversion is performed.\\\\n The data transfer process returns each record as-is, without translation. No\\\\n delimiters are added between records.\\\\n\\\\n --encoding | --ec (string)\\\\n\\\\n Data content in encoding mode, which means that data conversion is performed\\\\n according to the encoding specified.\\\\n\\\\n --attributes | --attrs (string)\\\\n\\\\n Path of an attributes file to control how files are uploaded.\\\\n\\\\n --response-timeout | --rto (number)\\\\n\\\\n The maximum amount of time in seconds the z/OSMF Files TSO servlet should run\\\\n before returning a response. Any request exceeding this amount of time will be\\\\n terminated and return an error. Allowed values: 5 - 600\\\\n\\\\n ZOSMF CONNECTION OPTIONS\\\\n ------------------------\\\\n\\\\n --host | -H (string)\\\\n\\\\n The z/OSMF server host name.\\\\n\\\\n --port | -P (number)\\\\n\\\\n The z/OSMF server port.\\\\n\\\\n Default value: 443\\\\n\\\\n --user | -u (string)\\\\n\\\\n Mainframe (z/OSMF) user name, which can be the same as your TSO login.\\\\n\\\\n --password | --pass | --pw (string)\\\\n\\\\n Mainframe (z/OSMF) password, which can be the same as your TSO password.\\\\n\\\\n --reject-unauthorized | --ru (boolean)\\\\n\\\\n Reject self-signed certificates.\\\\n\\\\n Default value: true\\\\n\\\\n --base-path | --bp (string)\\\\n\\\\n The base path for your API mediation layer instance. Specify this option to\\\\n prepend the base path to all z/OSMF resources when making REST requests. Do not\\\\n specify this option if you are not using an API mediation layer.\\\\n\\\\n --protocol (string)\\\\n\\\\n The protocol used (HTTP or HTTPS)\\\\n\\\\n Default value: https\\\\n Allowed values: http, https\\\\n\\\\n --cert-file (local file path)\\\\n\\\\n The file path to a certificate file to use for authentication\\\\n\\\\n --cert-key-file (local file path)\\\\n\\\\n The file path to a certificate key file to use for authentication\\\\n\\\\n PROFILE OPTIONS\\\\n ---------------\\\\n\\\\n --zosmf-profile | --zosmf-p (string)\\\\n\\\\n The name of a (zosmf) profile to load for this command execution.\\\\n\\\\n --base-profile | --base-p (string)\\\\n\\\\n The name of a (base) profile to load for this command execution.\\\\n\\\\n BASE CONNECTION OPTIONS\\\\n -----------------------\\\\n\\\\n --token-type | --tt (string)\\\\n\\\\n The type of token to get and use for the API. Omit this option to use the\\\\n default token type, which is provided by 'zowe auth login'.\\\\n\\\\n --token-value | --tv (string)\\\\n\\\\n The value of the token to pass to the API.\\\\n\\\\n GLOBAL OPTIONS\\\\n --------------\\\\n\\\\n --show-inputs-only (boolean)\\\\n\\\\n Show command inputs and do not run the command\\\\n\\\\n --response-format-json | --rfj (boolean)\\\\n\\\\n Produce JSON formatted data from a command\\\\n\\\\n --help | -h (boolean)\\\\n\\\\n Display help text\\\\n\\\\n --help-web | --hw (boolean)\\\\n\\\\n Display HTML help in browser\\\\n\\\\n EXAMPLES\\\\n --------\\\\n\\\\n - Upload to the USS file \\\\\\"/a/ibmuser/my_text.txt\\\\\\" from the\\\\n file \\\\\\"file.txt\\\\\\":\\\\n\\\\n $ zowe zos-files upload file-to-uss \\\\\\"file.txt\\\\\\" \\\\\\"/a/ibmuser/my_text.txt\\\\\\"\\\\n\\\\n\\" }" `; From 6ec2809eaf16a8245eaf0c57c5fd90642376ad7d Mon Sep 17 00:00:00 2001 From: jace-roell Date: Thu, 24 Oct 2024 14:31:06 -0400 Subject: [PATCH 07/15] system tests Signed-off-by: jace-roell --- .../methods/upload/Upload.system.test.ts | 35 +++++++++++++++++++ .../upload/__resources__/.zosattributes | 5 +++ .../__resources__/upload_file_to_uss.sh | 13 +++++++ .../upload/testfiles/encodingCheck.txt | 1 + 4 files changed, 54 insertions(+) create mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/__resources__/.zosattributes create mode 100755 packages/zosfiles/__tests__/__system__/methods/upload/__resources__/upload_file_to_uss.sh create mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/encodingCheck.txt 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 e0797df365..4376ab4d9e 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -18,6 +18,7 @@ import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/prope import { deleteFiles, getUniqueDatasetName, stripNewLines, wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; import * as fs from "fs"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__packages__/cli-test-utils/src"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -25,8 +26,10 @@ let defaultSystem: ITestPropertiesSchema; let dsname: string; let ussname: string; const inputfile = __dirname + "/testfiles/upload.txt"; +const encodingCheck = __dirname + "/testfiles/encodingCheck.txt"; const testdata = "abcdefghijklmnopqrstuvwxyz"; const uploadOptions: IUploadOptions = {} as any; +let TEST_ENVIRONMENT: ITestEnvironment; describe("Upload Data Set", () => { @@ -848,6 +851,38 @@ describe("Upload USS file", () => { expect(uploadResponse.success).toBeTruthy(); expect(uploadResponse.apiResponse.etag).toBeDefined(); }); + it("should upload local file to USS using .zosattributes file", async () => { + TEST_ENVIRONMENT = await TestEnvironment.setUp({ + testName: "zos_files_file_to_uss", + }); + const systemProperties = TEST_ENVIRONMENT.systemTestProperties; + const ACCOUNT_NUMBER = systemProperties.tso.account; + let response: any; + let error; + let uploadResponse; + let getResponse; + let tagResponse; + try { + response = runCliScript(__dirname + "/__resources__/upload_file_to_uss.sh", TEST_ENVIRONMENT,[ + ACCOUNT_NUMBER, + defaultSystem.zosmf.host, + defaultSystem.zosmf.port, + defaultSystem.zosmf.user, + defaultSystem.zosmf.password, + defaultSystem.zosmf.rejectUnauthorized, + __dirname + "/testfiles/encodingCheck.txt", + "/u/users/jr897694/usstest.txt", + __dirname + "/__resources__/.zosattributes", + ]); + } + catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(response.stderr.toString()).toBe(""); + expect(response.stdout.toString()).toBeDefined(); + expect(response.stdout.toString()).toContain("USS file uploaded successfully."); + }); }); }); diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/.zosattributes b/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/.zosattributes new file mode 100644 index 0000000000..88a1b0f51f --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/.zosattributes @@ -0,0 +1,5 @@ +*.json - +*.bin binary binary +*.jcl IBM-1047 IBM-1047 +*.md UTF-8 UTF-8 +*.txt UTF-8 IBM-1047 \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/upload_file_to_uss.sh b/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/upload_file_to_uss.sh new file mode 100755 index 0000000000..ae60e4afa2 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/upload_file_to_uss.sh @@ -0,0 +1,13 @@ +#!/bin/bash +account=$1 +host=$2 +port=$3 +user=$4 +password=$5 +ru=$6 +inputFile=$7 +ussName=$8 +attributes=$9 + +zowe zos-files upload file-to-uss $inputFile $ussName --attributes $attributes --host $host --port $port --user $user --password $password --ru $ru +exit $? \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/encodingCheck.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/encodingCheck.txt new file mode 100644 index 0000000000..98ce8af41b --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/encodingCheck.txt @@ -0,0 +1 @@ +á é í ó ú ñ Ç ß 12345 !@#$% \ No newline at end of file From ddbaa2074116bec3b45d08fc888a8b84e670a67c Mon Sep 17 00:00:00 2001 From: jace-roell Date: Fri, 25 Oct 2024 09:22:53 -0400 Subject: [PATCH 08/15] system test Signed-off-by: jace-roell --- .../ussdir/__resources__/.zosattributes | 2 +- .../methods/upload/Upload.system.test.ts | 49 ++++++++++++++----- .../upload/__resources__/view_file_uss.sh | 11 +++++ 3 files changed, 49 insertions(+), 13 deletions(-) create mode 100755 packages/zosfiles/__tests__/__system__/methods/upload/__resources__/view_file_uss.sh diff --git a/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes b/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes index a121e51700..1740b9eb3e 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes +++ b/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes @@ -2,4 +2,4 @@ *.bin binary binary *.jcl IBM-1047 IBM-1047 *.md UTF-8 UTF-8 -*.txt UTF-8 IBM-1047 +*.txt UTF-8 UTF-8 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 4376ab4d9e..9517d9dd86 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -788,7 +788,6 @@ describe("Upload USS file", () => { expect(error).toBeFalsy(); expect(getResponse).toEqual(Buffer.from(testdata)); expect(tagResponse).toBe(false); - }); it("should upload a USS file from local file in binary mode", async () => { let error; @@ -852,36 +851,62 @@ describe("Upload USS file", () => { expect(uploadResponse.apiResponse.etag).toBeDefined(); }); it("should upload local file to USS using .zosattributes file", async () => { - TEST_ENVIRONMENT = await TestEnvironment.setUp({ - testName: "zos_files_file_to_uss", - }); - const systemProperties = TEST_ENVIRONMENT.systemTestProperties; - const ACCOUNT_NUMBER = systemProperties.tso.account; let response: any; let error; - let uploadResponse; - let getResponse; - let tagResponse; + let readResponseGood: any; + let readResponseBad: any; try { - response = runCliScript(__dirname + "/__resources__/upload_file_to_uss.sh", TEST_ENVIRONMENT,[ - ACCOUNT_NUMBER, + response = runCliScript(__dirname + "/__resources__/upload_file_to_uss.sh", testEnvironment,[ + defaultSystem.tso.account, defaultSystem.zosmf.host, defaultSystem.zosmf.port, defaultSystem.zosmf.user, defaultSystem.zosmf.password, defaultSystem.zosmf.rejectUnauthorized, __dirname + "/testfiles/encodingCheck.txt", - "/u/users/jr897694/usstest.txt", + ussname, __dirname + "/__resources__/.zosattributes", ]); + // View file with matching encoding + readResponseGood = runCliScript(__dirname + "/__resources__/view_file_uss.sh", testEnvironment,[ + defaultSystem.tso.account, + defaultSystem.zosmf.host, + defaultSystem.zosmf.port, + defaultSystem.zosmf.user, + defaultSystem.zosmf.password, + defaultSystem.zosmf.rejectUnauthorized, + ussname, + 1047 + ]); + // View file with not matching encoding + readResponseBad = runCliScript(__dirname + "/__resources__/view_file_uss.sh", testEnvironment,[ + defaultSystem.tso.account, + defaultSystem.zosmf.host, + defaultSystem.zosmf.port, + defaultSystem.zosmf.user, + defaultSystem.zosmf.password, + defaultSystem.zosmf.rejectUnauthorized, + ussname, + 1147 + ]); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } + // Get contents of file that was uploaded + const fileContents = fs.readFileSync(__dirname + "/testfiles/encodingCheck.txt").toString(); + + // Ensure upload was successful expect(response.stderr.toString()).toBe(""); expect(response.stdout.toString()).toBeDefined(); expect(response.stdout.toString()).toContain("USS file uploaded successfully."); + + // Compare file view with not matching upload and view encoding (1047 vs 1147). + expect(readResponseBad.stdout.toString()).not.toContain(fileContents); + + // Compare file view with matching upload and view encoding (1047). + expect(readResponseGood.stdout.toString()).toContain(fileContents); }); }); }); diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/view_file_uss.sh b/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/view_file_uss.sh new file mode 100755 index 0000000000..85c0abc375 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/view_file_uss.sh @@ -0,0 +1,11 @@ +#!/bin/bash +account=$1 +host=$2 +port=$3 +user=$4 +password=$5 +ru=$6 +ussName=$7 +encoding=$8 + +zowe zos-files view uf $ussName --encoding $encoding --host $host --port $port --user $user --password $password --ru $ru \ No newline at end of file From d024149601e717d223c40072f62d51166b5799fb Mon Sep 17 00:00:00 2001 From: jace-roell Date: Fri, 25 Oct 2024 09:25:20 -0400 Subject: [PATCH 09/15] fixed unintentionally changed file Signed-off-by: jace-roell --- .../__system__/download/ussdir/__resources__/.zosattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes b/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes index 1740b9eb3e..a121e51700 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes +++ b/packages/cli/__tests__/zosfiles/__system__/download/ussdir/__resources__/.zosattributes @@ -2,4 +2,4 @@ *.bin binary binary *.jcl IBM-1047 IBM-1047 *.md UTF-8 UTF-8 -*.txt UTF-8 UTF-8 +*.txt UTF-8 IBM-1047 From e5cef09113905a2cf872cf594b5c0233e196f82a Mon Sep 17 00:00:00 2001 From: jace-roell Date: Fri, 25 Oct 2024 09:31:47 -0400 Subject: [PATCH 10/15] removed unused variables in previous tests Signed-off-by: jace-roell --- .../__system__/methods/upload/Upload.system.test.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 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 9517d9dd86..a4c33cfd7e 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -26,10 +26,8 @@ let defaultSystem: ITestPropertiesSchema; let dsname: string; let ussname: string; const inputfile = __dirname + "/testfiles/upload.txt"; -const encodingCheck = __dirname + "/testfiles/encodingCheck.txt"; const testdata = "abcdefghijklmnopqrstuvwxyz"; const uploadOptions: IUploadOptions = {} as any; -let TEST_ENVIRONMENT: ITestEnvironment; describe("Upload Data Set", () => { @@ -772,12 +770,11 @@ describe("Upload USS file", () => { }); it("should upload a USS file from local file", async () => { let error; - let uploadResponse; let getResponse; let tagResponse; try { - uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname); + await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname); getResponse = await Get.USSFile(REAL_SESSION, ussname); tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); } catch (err) { @@ -791,12 +788,11 @@ describe("Upload USS file", () => { }); it("should upload a USS file from local file in binary mode", async () => { let error; - let uploadResponse; let getResponse; let tagResponse; try { - uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, { binary: true }); + await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, { binary: true }); getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); } catch (err) { @@ -835,11 +831,10 @@ describe("Upload USS file", () => { it("should upload a USS file and return Etag", async () => { let error; let uploadResponse; - let getResponse; try { uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {returnEtag: true}); - getResponse = await Get.USSFile(REAL_SESSION, ussname); + await Get.USSFile(REAL_SESSION, ussname); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); From 764d5332bc9d515cc3a991e611308c8bfdaad2b5 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Fri, 25 Oct 2024 09:40:49 -0400 Subject: [PATCH 11/15] exit shell line Signed-off-by: jace-roell --- .../__system__/methods/upload/__resources__/view_file_uss.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/view_file_uss.sh b/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/view_file_uss.sh index 85c0abc375..a1356ff9bf 100755 --- a/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/view_file_uss.sh +++ b/packages/zosfiles/__tests__/__system__/methods/upload/__resources__/view_file_uss.sh @@ -8,4 +8,5 @@ ru=$6 ussName=$7 encoding=$8 -zowe zos-files view uf $ussName --encoding $encoding --host $host --port $port --user $user --password $password --ru $ru \ No newline at end of file +zowe zos-files view uf $ussName --encoding $encoding --host $host --port $port --user $user --password $password --ru $ru +exit $? \ No newline at end of file From cdcb02e3f63ce52ed1588dcc502dc79e07b68f06 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Fri, 25 Oct 2024 10:36:18 -0400 Subject: [PATCH 12/15] removed unused function Signed-off-by: jace-roell --- .../upload/ftu/FileToUSS.handler.unit.test.ts | 2 -- .../zosfiles/upload/ftu/FileToUSS.handler.ts | 24 ------------------- 2 files changed, 26 deletions(-) diff --git a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts index e495566285..52cbac3cdf 100644 --- a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts +++ b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts @@ -83,13 +83,11 @@ describe("Upload file-to-uss handler", () => { expect(Upload.uploadFile).toHaveBeenCalledTimes(1); expect(Upload.uploadFile).toHaveBeenCalledWith(fakeSession, inputfile, USSFileName, { binary: undefined, - encoding: undefined, task: { percentComplete: 0, stageName: 0, statusMessage: "Uploading USS file" }, - filesMap: null, includeHidden: undefined, maxConcurrentRequests: undefined, responseTimeout: undefined diff --git a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts index d0f386ff10..306d935e46 100644 --- a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts +++ b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts @@ -53,8 +53,6 @@ export default class FileToUSSHandler extends ZosFilesBaseHandler { ); if (attributes != null) { uploadOptions.attributes = attributes; - } else { - uploadOptions.filesMap = this.buildFilesMap(commandParameters); } const response = await Upload.uploadFile( @@ -68,26 +66,4 @@ export default class FileToUSSHandler extends ZosFilesBaseHandler { commandParameters.response.console.log(formatMessage); return response; } - private buildFilesMap(commandParameters: IHandlerParameters) { - let filesMap: IUploadMap = null; - - // checking if binary-files or ascii-files are used, and update filesMap argument - if (commandParameters.arguments.binaryFiles) { - filesMap = { - binary: true, - fileNames: commandParameters.arguments.binaryFiles - .split(",") - .map((fileName: string) => fileName.trim()), - }; - } - if (commandParameters.arguments.asciiFiles) { - filesMap = { - binary: false, - fileNames: commandParameters.arguments.asciiFiles - .split(",") - .map((fileName: string) => fileName.trim()), - }; - } - return filesMap; - } } From eb489d7be190347d1a3aab376023bd411fff49f7 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Fri, 25 Oct 2024 10:42:35 -0400 Subject: [PATCH 13/15] unused import Signed-off-by: jace-roell --- packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts index 306d935e46..ac87340da0 100644 --- a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts +++ b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts @@ -20,7 +20,6 @@ import { Upload, IZosFilesResponse } from "@zowe/zos-files-for-zowe-sdk"; import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler"; import { IUploadOptions } from "@zowe/zos-files-for-zowe-sdk"; import { ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk"; -import { IUploadMap } from "@zowe/zos-files-for-zowe-sdk"; /** * Handler to upload content from a local file to a USS file From 7eeddb7cafc6ccec6883ea2f4f062f0ebda0e2f4 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Mon, 28 Oct 2024 11:57:38 -0400 Subject: [PATCH 14/15] expanded on encodingCheck.txt file, consolidated import lines, private -> public function signature Signed-off-by: jace-roell --- packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts | 3 +-- .../__system__/methods/upload/testfiles/encodingCheck.txt | 2 +- packages/zosfiles/src/methods/upload/Upload.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts index ac87340da0..9b4450278d 100644 --- a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts +++ b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts @@ -18,8 +18,7 @@ import { } from "@zowe/imperative"; import { Upload, IZosFilesResponse } from "@zowe/zos-files-for-zowe-sdk"; import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler"; -import { IUploadOptions } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk"; +import { IUploadOptions, ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk"; /** * Handler to upload content from a local file to a USS file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/encodingCheck.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/encodingCheck.txt index 98ce8af41b..ae3e63ebb9 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/encodingCheck.txt +++ b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/encodingCheck.txt @@ -1 +1 @@ -á é í ó ú ñ Ç ß 12345 !@#$% \ No newline at end of file +á é í ó ú ñ Ç ß 12345 !@#$% ^ [ ] $ £ € \ No newline at end of file diff --git a/packages/zosfiles/src/methods/upload/Upload.ts b/packages/zosfiles/src/methods/upload/Upload.ts index 1387a8c850..f13f4eb4bb 100644 --- a/packages/zosfiles/src/methods/upload/Upload.ts +++ b/packages/zosfiles/src/methods/upload/Upload.ts @@ -855,7 +855,7 @@ export class Upload { } public static async uploadFile(session: AbstractSession, localPath: string, ussPath: string, - options: IUploadOptions) { + options: IUploadOptions): Promise { const tempOptions: Partial = {}; if (options.attributes) { From 761d9600b9d581e645d7bee2d8988fd00cd5e7b5 Mon Sep 17 00:00:00 2001 From: jace-roell Date: Mon, 28 Oct 2024 11:59:46 -0400 Subject: [PATCH 15/15] duplicate import lines Signed-off-by: jace-roell --- .../__unit__/upload/ftu/FileToUSS.handler.unit.test.ts | 3 +-- packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts index 52cbac3cdf..e4a6582d25 100644 --- a/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts +++ b/packages/cli/__tests__/zosfiles/__unit__/upload/ftu/FileToUSS.handler.unit.test.ts @@ -9,9 +9,8 @@ * */ -import { Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { Upload, ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk"; import { UNIT_TEST_ZOSMF_PROF_OPTS } from "../../../../../../../__tests__/__src__/TestConstants"; -import { ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk"; describe("Upload file-to-uss handler", () => { describe("process method", () => { diff --git a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts index 9b4450278d..45cfe46971 100644 --- a/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts +++ b/packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts @@ -16,9 +16,8 @@ import { TaskStage, TextUtils, } from "@zowe/imperative"; -import { Upload, IZosFilesResponse } from "@zowe/zos-files-for-zowe-sdk"; +import { Upload, IZosFilesResponse, IUploadOptions, ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk"; import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler"; -import { IUploadOptions, ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk"; /** * Handler to upload content from a local file to a USS file