Skip to content

Commit

Permalink
added local encoding support and updated system tests
Browse files Browse the repository at this point in the history
Signed-off-by: jace-roell <jace.roell@hotmail.com>
  • Loading branch information
jace-roell committed Nov 6, 2024
1 parent b05be48 commit a2494c8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1081,53 +1081,91 @@ describe.each([false, true])("Download Data Set - Encoded: %s", (encoded: boolea
expect(fileContents).toEqual(testData);

});

it("should upload and download file with correct encoding", async () => {
let response: any;

// Upload binary or encoded file
const uploadFile: string = encoded ? "downloadEncodingCheck.txt" : "downloadEncodingCheckBinary.txt";
let downloadResponse: any;
let error: any;

// Use text file as to get proper response from getRemoteEncoding()
const ussnameAsTxt = ussname + ".txt";
try {
response = runCliScript(__dirname +
`/__resources__/${encoded ? "upload_file_to_uss.sh" : "upload_file_to_uss_binary.sh"}`, testEnvironment, [
defaultSystem.tso.account,
defaultSystem.zosmf.host,
defaultSystem.zosmf.port,
defaultSystem.zosmf.user,
defaultSystem.zosmf.password,
defaultSystem.zosmf.rejectUnauthorized,
__dirname + "/__resources__/testfiles/" + uploadFile,
ussnameAsTxt,
encoded ? "1047" : true
]);
downloadResponse = runCliScript(__dirname + "/__resources__/download_file.sh", testEnvironment, [
defaultSystem.tso.account,
defaultSystem.zosmf.host,
defaultSystem.zosmf.port,
defaultSystem.zosmf.user,
defaultSystem.zosmf.password,
defaultSystem.zosmf.rejectUnauthorized,
ussnameAsTxt,
__dirname + `/__resources__/${encoded ? ".zosattributes" : ".zosattributes-binary"}`
]);
} catch (err) {
error = err;
}

expect(error).toBeFalsy();
expect(response).toBeTruthy();
expect(downloadResponse).toBeTruthy();

// Compare the downloaded contents to those uploaded
const fileContents = fs.readFileSync(`${testEnvironment.workingDir}/${posix.basename(ussnameAsTxt)}`).toString();
expect(fileContents).toEqual(fs.readFileSync(__dirname + "/__resources__/testfiles/" + uploadFile).toString());
});

describe.each([false, true])(
"Download Data Set - Binary: %s",
(binary: boolean) => {
it("should upload and download file with correct encoding", async () => {
let response: any;

// Upload binary or encoded file
const uploadFile: string = binary
? "downloadEncodingCheck.txt"
: "downloadEncodingCheckBinary.txt";
let downloadResponse: any;
let error: any;

// Use text file as to get proper response from getRemoteEncoding()
const ussnameAsTxt = ussname + ".txt";
try {
response = runCliScript(
__dirname +
`/__resources__/${
binary
? "upload_file_to_uss.sh"
: "upload_file_to_uss_binary.sh"
}`,
testEnvironment,
[
defaultSystem.tso.account,
defaultSystem.zosmf.host,
defaultSystem.zosmf.port,
defaultSystem.zosmf.user,
defaultSystem.zosmf.password,
defaultSystem.zosmf.rejectUnauthorized,
__dirname +
"/__resources__/testfiles/" +
uploadFile,
ussnameAsTxt,
binary ? "1047" : true,
]
);
downloadResponse = runCliScript(
__dirname + "/__resources__/download_file.sh",
testEnvironment,
[
defaultSystem.tso.account,
defaultSystem.zosmf.host,
defaultSystem.zosmf.port,
defaultSystem.zosmf.user,
defaultSystem.zosmf.password,
defaultSystem.zosmf.rejectUnauthorized,
ussnameAsTxt,
__dirname +
`/__resources__/${
binary
? ".zosattributes"
: ".zosattributes-binary"
}`,
]
);
} catch (err) {
error = err;
}

expect(error).toBeFalsy();
expect(response).toBeTruthy();
expect(downloadResponse).toBeTruthy();

// Compare the downloaded contents to those uploaded
const fileContents = fs
.readFileSync(
`${testEnvironment.workingDir}/${posix.basename(
ussnameAsTxt
)}`
)
.toString();
expect(fileContents).toEqual(
fs
.readFileSync(
__dirname +
"/__resources__/testfiles/" +
uploadFile
)
.toString()
);
});
}
);
// When requesting etag, z/OSMF has a limit on file size when it stops to return etag by default (>8mb)
// We are passing X-IBM-Return-Etag to force z/OSMF to always return etag, but testing here for case where it would be optional
it("should download a 10mb uss file and return Etag", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@ describe("z/OS Files - Download", () => {
expect(zosmfGetFullSpy).toHaveBeenCalledTimes(1);
expect(zosmfGetFullSpy).toHaveBeenCalledWith(dummySession, {
resource: endpoint,
reqHeaders: [{ "X-IBM-Data-Type": "text;fileEncoding=IBM-1047" }, ZosmfHeaders.ACCEPT_ENCODING, ZosmfHeaders.TEXT_PLAIN],
reqHeaders: [{ "X-IBM-Data-Type": "text;fileEncoding=IBM-1047" }, ZosmfHeaders.ACCEPT_ENCODING, {"Content-Type": "UTF-8"}],
responseStream: fakeStream,
normalizeResponseNewLines: true,
task: undefined /* no progress task */
Expand Down
6 changes: 2 additions & 4 deletions packages/zosfiles/src/methods/download/Download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,8 @@ export class Download {

if(options.attributes)
{
options.binary = options.attributes.getFileTransferMode(ussFileName, options.binary) === TransferMode.BINARY;
const remoteEncoding = options.attributes.getRemoteEncoding(ussFileName);
if(remoteEncoding === Tag.BINARY) options.encoding = undefined;
else if(remoteEncoding !== null) options.encoding = remoteEncoding;
options = { ...options, ...this.parseAttributeOptions(ussFileName,options)}

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (95% of all statements in
the enclosing function
have an explicit semicolon).
if(options.binary) options.encoding = undefined;
}

// If data type is not defined by user via encoding flag or attributes file, check for USS tags
Expand Down

0 comments on commit a2494c8

Please sign in to comment.