Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Dir to uss encoding flag #2350

Merged
merged 15 commits into from
Nov 8, 2024
4 changes: 4 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Zowe CLI package will be documented in this file.

## Recent Changes

- BugFix: Added support for `--encoding` flag to `zowe upload dir-to-uss` to allow for encoding uploaded directories for command group consistency. [#2337](https://github.com/zowe/zowe-cli/issues/2337)
jace-roell marked this conversation as resolved.
Show resolved Hide resolved

## `8.7.0`

- Enhancement: Added --wait-for-active and --wait-for-output to download options on zosjobs. [#2328](https://github.com/zowe/zowe-cli/pull/2328)
Expand Down

Large diffs are not rendered by default.

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 Down
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"
`;
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
],
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
examples: [
{
Expand Down
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
4 changes: 4 additions & 0 deletions packages/zosfiles/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Zowe z/OS files SDK package will be documented in this file.

## Recent Changes

- BugFix: Added support for `--encoding` flag to `zowe upload dir-to-uss` to allow for encoding uploaded directories for command group consistency. [#2337](https://github.com/zowe/zowe-cli/issues/2337)
jace-roell marked this conversation as resolved.
Show resolved Hide resolved

## `8.6.2`

- BugFix: Resolved issue where encoding argument was missing from `FileToUss.handler.ts` options object. [#2234](https://github.com/zowe/zowe-cli/pull/2334)
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 @@ -1127,7 +1128,34 @@ describe("Upload a local directory to USS directory", () => {
expect(isDirectoryExist).toBeDefined();
expect(isDirectoryExist).toBeTruthy();
});
it("should upload local directory to USS with an encoding", async () => {
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
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 !@#$% ^ [ ] $ £
2 changes: 1 addition & 1 deletion packages/zosfiles/src/methods/upload/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ export class Upload {
} else if(options.filesMap?.fileNames.indexOf(path.basename(localPath)) > -1) {
tempOptions.binary = options.filesMap.binary;

// Reset encoding to undefined if binary is true to avoid file tagging issues
//Reset encoding to undefined if binary is true to avoid file tagging issues
if(tempOptions.binary) tempOptions.encoding = undefined;
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down