Skip to content

Commit

Permalink
Merge pull request #2173 from zowe/fix/download-spool-error
Browse files Browse the repository at this point in the history
Fix error when downloading spool files with default encoding
  • Loading branch information
zFernand0 authored Jun 11, 2024
2 parents a46a2fd + 96c1d2b commit 4e822b2
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
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: Fixed `Get.dataSet` and `Get.USSFile` methods so that they return an empty buffer instead of null for empty files. [#2173](https://github.com/zowe/zowe-cli/pull/2173)

## `7.26.0`

- BugFix: Fixed error where `Get.dataSet` and `Get.USSFile` methods could silently fail when downloading large data sets or files. [#2167](https://github.com/zowe/zowe-cli/pull/2167)
Expand Down
52 changes: 52 additions & 0 deletions packages/zosfiles/__tests__/__unit__/methods/get/Get.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,32 @@ describe("z/OS Files - View", () => {
}));
});

it("should get data set content when empty", async () => {
let response;
let caughtError;
zosmfExpectSpy.mockImplementationOnce(async (_session, options) => {
options.responseStream?.end();
return {};
});

try {
response = await Get.dataSet(dummySession, dsname);
} catch (e) {
caughtError = e;
}

const endpoint = posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_DS_FILES, dsname);

expect(caughtError).toBeUndefined();
expect(response).toEqual(Buffer.alloc(0));

expect(zosmfExpectSpy).toHaveBeenCalledTimes(1);
expect(zosmfExpectSpy).toHaveBeenCalledWith(dummySession, expect.objectContaining({
reqHeaders: [ZosmfHeaders.ACCEPT_ENCODING, ZosmfHeaders.TEXT_PLAIN],
resource: endpoint
}));
});

it("should get data set content in binary mode", async () => {
let response;
let caughtError;
Expand Down Expand Up @@ -369,6 +395,32 @@ describe("z/OS Files - View", () => {
}));
});

it("should get uss file content when empty", async () => {
let response;
let caughtError;
zosmfExpectSpy.mockImplementationOnce(async (_session, options) => {
options.responseStream?.end();
return {};
});

try {
response = await Get.USSFile(dummySession, ussfile);
} catch (e) {
caughtError = e;
}

const endpoint = posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_USS_FILES, ussfile);

expect(caughtError).toBeUndefined();
expect(response).toEqual(Buffer.alloc(0));

expect(zosmfExpectSpy).toHaveBeenCalledTimes(1);
expect(zosmfExpectSpy).toHaveBeenCalledWith(dummySession, expect.objectContaining({
reqHeaders: [ZosmfHeaders.ACCEPT_ENCODING, ZosmfHeaders.TEXT_PLAIN],
resource: endpoint
}));
});

it("should get uss file content in binary mode", async () => {
let response;
let caughtError;
Expand Down
4 changes: 2 additions & 2 deletions packages/zosfiles/src/methods/get/Get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Get {
...options,
stream: responseStream
});
return responseStream.read();
return responseStream.read() ?? Buffer.alloc(0);
}

/**
Expand All @@ -64,6 +64,6 @@ export class Get {
...options,
stream: responseStream
});
return responseStream.read();
return responseStream.read() ?? Buffer.alloc(0);
}
}
4 changes: 4 additions & 0 deletions packages/zosjobs/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 jobs SDK package will be documented in this file.

## Recent Changes

- BugFix: Fixed error in `DownloadJobs.downloadSpoolContentCommon` method when encoding parameter is not specified. [#2173](https://github.com/zowe/zowe-cli/pull/2173)

## `7.25.0`

- Enhancement: Added the ability to set `internalReaderFileEncoding` on the `submitJcl`, `submitJclString`, `submitJclCommon`, `submitJclNotify`, and `submitJclNotifyCommon` Jobs APIs [#2139](https://github.com/zowe/zowe-cli/pull/2139)
Expand Down
5 changes: 5 additions & 0 deletions packages/zosjobs/__tests__/__unit__/DownloadJobs.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ describe("DownloadJobs", () => {

describe("downloadAllSpoolContentCommon", () => {
it("should allow users to call downloadAllSpoolContentCommon with correct parameters", async () => {
let uri: string = "";
ZosmfRestClient.getStreamed = jest.fn(async (session: AbstractSession, resource: string, reqHeaders?: any[]): Promise<any> => {
uri = resource;
});
const allSpoolParms: IDownloadAllSpoolContentParms = {
jobid: fakeJobID,
jobname: fakeJobName,
Expand All @@ -116,6 +120,7 @@ describe("DownloadJobs", () => {

expect(GetJobs.getSpoolFiles).toHaveBeenCalled();
expect(IO.createDirsSyncFromFilePath).toHaveBeenCalledWith(expectedFile);
expect(uri).not.toContain("fileEncoding");
});

it("should allow users to call downloadAllSpoolContentCommon with correct parameters and binary mode", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/zosjobs/src/DownloadJobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class DownloadJobs {
parameters += "?mode=record";
}

if (!parms.binary && !parms.record && parms.encoding?.trim() != "") {
if (!parms.binary && !parms.record && parms.encoding?.trim()) {
parameters += "?fileEncoding=" + parms.encoding;
}

Expand Down

0 comments on commit 4e822b2

Please sign in to comment.