Skip to content

Commit

Permalink
Merge branch 'master' into zos-download-attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Jace Roell <[email protected]>
  • Loading branch information
jace-roell authored Nov 8, 2024
2 parents 8da7ea5 + 3004122 commit 6c381ed
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to the Zowe CLI package will be documented in this file.
## Recent Changes

- Enhancement: Pass a `.zosattributes` file path for the download encoding format by adding the new `--attributes` flag to the `zowe zos-files upload` command. [#2322](https://github.com/zowe/zowe-cli/issues/2322)
- BugFix: Added support for the `--encoding` flag to the `zowe upload dir-to-uss` to allow for encoding uploaded directories for command group consistency. [#2337](https://github.com/zowe/zowe-cli/issues/2337)
- BugFix: Improved output formatting for `zowe zos-tso start app` and `zowe zos-tso send app` commands by parsing and displaying relevant data rather than the entire JSON response. [#2347](https://github.com/zowe/zowe-cli/pull/2347)
- Enhancement: Add the --ignore-not-found flag to avoid file-not-found error messages when deleting files so scripts are not interupted during automated batch processing. The flag bypasses warning prompts to confirm delete actions. [#2254](https://github.com/zowe/zowe-cli/pull/2254)

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe("Delete Data Set", () => {
const deleteResponse = runCliScript(__dirname + "/__scripts__/command/command_delete_data_set.sh",
TEST_ENVIRONMENT, [dsname, "--for-sure", "--ignore-not-found"]);
expect(deleteResponse.stderr.toString()).toBe("");

//delete again
const secondDelete = runCliScript(__dirname + "/__scripts__/command/command_delete_data_set.sh",
TEST_ENVIRONMENT, [dsname, "--for-sure", "--ignore-not-found"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("Upload dir-to-uss handler", () => {
let fakeSession: any = null;
const inputDir = "/somedir/test_dir";
const USSDir = "USS_dir";
const encoding = "IBM-1047";
let handler: any;
const UPLOAD_OPTIONS_ARG_INDEX = 3;

Expand Down Expand Up @@ -64,6 +65,43 @@ describe("Upload dir-to-uss handler", () => {
}
}
};
const DEFAULT_ENCODING_PARAMETERS = {
arguments: {
$0: "fake",
_: ["fake"],
inputDir,
USSDir,
encoding,
// binary: boolean,
// recursive: boolean,
// asciiFiles: "a,b,c",
// binaryFiles: "a,b,c",
...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((parms) => {
// do nothing
}),
endBar: jest.fn(() => {
// do nothing
})
}
}
};

beforeEach(() => {

Expand Down Expand Up @@ -100,6 +138,23 @@ describe("Upload dir-to-uss handler", () => {
}
});
});
it("should upload a directory to a USS directory if requested with encoding flag", async () => {
const params = Object.assign({}, ...[DEFAULT_ENCODING_PARAMETERS]);
await testHandlerWorksWithParameters(params);
expect(Upload.dirToUSSDir).toHaveBeenCalledTimes(1);
expect(Upload.dirToUSSDir).toHaveBeenCalledWith(fakeSession, inputDir, USSDir, {
binary: undefined,
filesMap: null,
maxConcurrentRequests: undefined,
recursive: undefined,
task: {
percentComplete: 0,
stageName: 0,
statusMessage: "Uploading all files"
},
encoding: "IBM-1047"
});
});
it("should pass attributes when a .zosattributes file is present", async () => {
jest.spyOn(fs, "existsSync").mockReturnValueOnce(true);
const attributesContents = "foo.stuff -";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ The maximum number of TSO address spaces have been created. When you specify 0,
"name": "include-hidden",
"type": "boolean",
},
Object {
"aliases": Array [
"ec",
],
"description": "Data content in encoding mode, which means that data conversion is performed according to the encoding specified.",
"name": "encoding",
"type": "string",
},
]
`;

Expand All @@ -98,5 +106,9 @@ Array [
"description": "Recursively upload all files from the \\"local_dir\\" directory to the \\"/a/ibmuser/my_dir\\" USS directory, specifying files to ignore and file encodings in the local file my_global_attributes",
"options": "\\"local_dir\\" \\"/a/ibmuser/my_dir\\" --recursive --attributes my_global_attributes",
},
Object {
"description": "Upload all files from the \\"local_dir\\" directory to the \\"/a/ibmuser/my_dir\\" USS directory using IBM-1047 encoding",
"options": "\\"local_dir\\" \\"/a/ibmuser/my_dir\\" --encoding \\"IBM-1047\\"",
},
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ uploaded
to:  nowhere
uploaded
- 
success: true
from:  /somedir/test_dir
to:  USS_dir
- 
success: false
from:  testfrom
to:  testto
- 
from: dummy
to:  nowhere
uploaded"
`;

Expand Down Expand Up @@ -127,6 +141,20 @@ uploaded
to:  nowhere
uploaded
- 
success: true
from:  /somedir/test_dir
to:  USS_dir
- 
success: false
from:  testfrom
to:  testto
- 
from: dummy
to:  nowhere
uploaded"
`;

Expand Down Expand Up @@ -173,3 +201,61 @@ exports[`Upload dir-to-uss handler process method should upload a directory to a
uploaded"
`;

exports[`Upload dir-to-uss handler process method should upload a directory to a USS directory if requested with encoding flag 1`] = `
Object {
"apiResponse": Array [
Object {
"from": "/somedir/test_dir",
"success": true,
"to": "USS_dir",
},
Object {
"from": "testfrom",
"success": false,
"to": "testto",
},
Object {
"from": "dummy",
"success": undefined,
"to": "nowhere",
},
],
"commandResponse": "uploaded",
"success": false,
}
`;

exports[`Upload dir-to-uss handler process method should upload a directory to a USS directory if requested with encoding flag 2`] = `""`;

exports[`Upload dir-to-uss handler process method should upload a directory to a USS directory if requested with encoding flag 3`] = `
"
- 
success: true
from:  /somedir/test_dir
to:  USS_dir
- 
success: false
from:  testfrom
to:  testto
- 
from: dummy
to:  nowhere
uploaded
- 
success: true
from:  /somedir/test_dir
to:  USS_dir
- 
success: false
from:  testfrom
to:  testto
- 
from: dummy
to:  nowhere
uploaded"
`;
3 changes: 2 additions & 1 deletion packages/cli/src/zosfiles/-strings-/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,8 @@ export default {
EX4: `Upload all files from the "local_dir" directory to the "/a/ibmuser/my_dir" USS directory ` +
`in binary mode, while specifying a list of file names (without path) to be uploaded in ASCII mode`,
EX5: `Recursively upload all files from the "local_dir" directory to the "/a/ibmuser/my_dir" USS directory, ` +
`specifying files to ignore and file encodings in the local file my_global_attributes`
`specifying files to ignore and file encodings in the local file my_global_attributes`,
EX6: `Upload all files from the "local_dir" directory to the "/a/ibmuser/my_dir" USS directory using IBM-1047 encoding`,
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/zosfiles/ZosFilesBase.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ export abstract class ZosFilesBaseHandler implements ICommandHandler {
);
const session = new Session(sessCfgWithCreds);
const response = await this.processWithSession(commandParameters, session);

commandParameters.response.progress.endBar();
if (response.commandResponse) {
commandParameters.response.console.log(response.commandResponse);
}
// Return as an object when using --response-format-json
commandParameters.response.data.setObj(response);

// Ensure error gets thrown if request was unsuccessful.
// Sometimes it is useful to delay throwing an error until the end of the handler is
// reached, for example the upload API needs to return an API response even when it fails.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export const DirToUSSDirDefinition: ICommandDefinition = {
UploadOptions.asciiFiles,
UploadOptions.attributes,
UploadOptions.maxConcurrentRequests,
UploadOptions.includeHidden
UploadOptions.includeHidden,
UploadOptions.encoding
],
examples: [
{
Expand All @@ -74,6 +75,10 @@ export const DirToUSSDirDefinition: ICommandDefinition = {
{
description: strings.EXAMPLES.EX5,
options: `"local_dir" "/a/ibmuser/my_dir" --recursive --attributes my_global_attributes`
},
{
description: strings.EXAMPLES.EX6,
options: `"local_dir" "/a/ibmuser/my_dir" --encoding "IBM-1047"`
}
]
};
3 changes: 2 additions & 1 deletion packages/cli/src/zosfiles/upload/dtu/DirToUSSDir.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export default class DirToUSSDirHandler extends ZosFilesBaseHandler {
maxConcurrentRequests: commandParameters.arguments.maxConcurrentRequests,
task: status,
responseTimeout: commandParameters.arguments.responseTimeout,
includeHidden: commandParameters.arguments.includeHidden
includeHidden: commandParameters.arguments.includeHidden,
encoding: commandParameters.arguments.encoding
};

const attributes = ZosFilesAttributes.loadFromFile(commandParameters.arguments.attributes, inputDir);
Expand Down
1 change: 1 addition & 0 deletions packages/zosfiles/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to the Zowe z/OS files SDK package will be documented in thi
## Recent Changes

- Enhancement: Allows for passing a `.zosattributues` file path for the download encoding format via the `attributes` option on the `Download.ussFile` method. [#2322](https://github.com/zowe/zowe-cli/issues/2322)
- BugFix: Added support for the `--encoding` flag to the `zowe upload dir-to-uss` to allow for encoding uploaded directories for command group consistency. [#2337](https://github.com/zowe/zowe-cli/issues/2337)

## `8.6.2`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let dsname: string;
let ussname: string;
const inputfile = __dirname + "/testfiles/upload.txt";
const testdata = "abcdefghijklmnopqrstuvwxyz";
const encodedTestData = "á é í ó ú ñ Ç ß 12345 !@#$% ^ [ ] $ £";
const uploadOptions: IUploadOptions = {} as any;

describe("Upload Data Set", () => {
Expand Down Expand Up @@ -1128,6 +1129,34 @@ describe("Upload a local directory to USS directory", () => {
expect(isDirectoryExist).toBeTruthy();
});

it("should upload local directory to USS with an encoding", async () => {
let error;
let uploadResponse: IZosFilesResponse;
let isDirectoryExist: any;
let getResponse;
let getResponseBinary;
let getResponseDiffEncoding;
try {
uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname, {encoding: "IBM-1047"});
await wait(waitTime);
isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname);
getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/file4.txt`, {encoding: "IBM-1047"});
getResponseBinary = await Get.USSFile(REAL_SESSION, `${ussname}/file4.txt`, {binary: true});
getResponseDiffEncoding = await Get.USSFile(REAL_SESSION, `${ussname}/file4.txt`, {encoding: "IBM-1147"});
} catch (err) {
error = err;
Imperative.console.info("Error: " + inspect(error));
}

expect(error).toBeFalsy();
expect(uploadResponse).toBeDefined();
expect(uploadResponse.success).toBeTruthy();
expect(isDirectoryExist).toBeDefined();
expect(isDirectoryExist).toBeTruthy();
expect(getResponse).toEqual(Buffer.from(encodedTestData));
expect(getResponseBinary).not.toEqual(Buffer.from(encodedTestData));
expect(getResponseDiffEncoding).not.toEqual(Buffer.from(encodedTestData));
});
it("should upload local directory to USS in binary mode", async () => {
let error;
let uploadResponse: IZosFilesResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
á é í ó ú ñ Ç ß 12345 !@#$% ^ [ ] $ £

0 comments on commit 6c381ed

Please sign in to comment.