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

Port recent SDK fixes to V2 #2288

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"audit:public": "npm audit --registry https://registry.npmjs.org/",
"bundle:webHelp": "cd packages/imperative/web-help && node build.js",
"prepare": "husky install && npm run bundle:webHelp",
"package": "node scripts/bundleCliTgz.js"
"package": "lerna run prepublishOnly && node scripts/bundleCliTgz.js"
},
"dependencies": {},
"devDependencies": {
Expand All @@ -57,7 +57,7 @@
"chalk": "^4.1.0",
"env-cmd": "^10.1.0",
"eslint": "^8.22.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-jest": "^26.8.0",
"eslint-plugin-unused-imports": "^2.0.0",
"fancy-log": "^1.3.3",
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: Fixed an issue with the `List.dataSetsMatchingPattern` method where migrated data sets could break fetching attributes for other data sets. [#2285](https://github.com/zowe/zowe-cli/issues/2285)

## `7.28.3`

- BugFix: Refactored code to reduce the use of deprecated functions to prepare for upcoming Node.js 22 support. [#2191](https://github.com/zowe/zowe-cli/issues/2191)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ describe("z/OS Files - List", () => {
});

expect(listDataSetSpy).toHaveBeenCalledTimes(3);
expect(listDataSetSpy).toHaveBeenCalledWith(dummySession, dataSetPS.dsname, {attributes: true});
expect(listDataSetSpy).toHaveBeenLastCalledWith(dummySession, dataSetPS.dsname, {attributes: true, maxLength: 1});
});

it("should handle an error when the exclude pattern is specified", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/zosfiles/src/methods/list/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export class List {
listsInitiated++;
}

return List.dataSet(session, dataSetObj.dsname, { attributes: true }).then(
return List.dataSet(session, dataSetObj.dsname, { attributes: true, maxLength: 1 }).then(
(tempResponse) => {
Object.assign(dataSetObj, tempResponse.apiResponse.items[0]);
},
Expand Down
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 causing binary spool files to be corrupted by newline normalization. [#2282](https://github.com/zowe/zowe-cli/issues/2282)

## `7.26.1`

- BugFix: Fixed error in `DownloadJobs.downloadSpoolContentCommon` method when encoding parameter is not specified. [#2173](https://github.com/zowe/zowe-cli/pull/2173)
Expand Down
33 changes: 17 additions & 16 deletions packages/zosjobs/__tests__/__unit__/DownloadJobs.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
*/

import { AbstractSession, ImperativeError, IO } from "@zowe/imperative";
import { AbstractSession, Headers, ImperativeError, IO } from "@zowe/imperative";
import { DownloadJobs, GetJobs, IDownloadAllSpoolContentParms, IDownloadSpoolContentParms, IJobFile } from "../../src";
import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk";
import { Writable } from "stream";
Expand Down Expand Up @@ -103,10 +103,7 @@ 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 getStreamedSpy = jest.spyOn(ZosmfRestClient, "getStreamed");
const allSpoolParms: IDownloadAllSpoolContentParms = {
jobid: fakeJobID,
jobname: fakeJobName,
Expand All @@ -120,14 +117,15 @@ describe("DownloadJobs", () => {

expect(GetJobs.getSpoolFiles).toHaveBeenCalled();
expect(IO.createDirsSyncFromFilePath).toHaveBeenCalledWith(expectedFile);
expect(uri).not.toContain("fileEncoding");
expect(getStreamedSpy).toHaveBeenCalledTimes(1);
const [_session, resource, reqHeaders, _responseStream, normalizeResponseNewLines] = getStreamedSpy.mock.calls[0];
expect(resource).not.toContain("fileEncoding");
expect(reqHeaders).toContain(Headers.TEXT_PLAIN_UTF8);
expect(normalizeResponseNewLines).toBe(true);
});

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

expect(GetJobs.getSpoolFiles).toHaveBeenCalled();
expect(IO.createDirsSyncFromFilePath).toHaveBeenCalledWith(expectedFile);
expect(uri).toContain("?mode=binary");
expect(getStreamedSpy).toHaveBeenCalledTimes(1);
const [_session, resource, _reqHeaders, _responseStream, normalizeResponseNewLines] = getStreamedSpy.mock.calls[0];
expect(resource).toContain("?mode=binary");
expect(normalizeResponseNewLines).toBe(false);
});

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

expect(GetJobs.getSpoolFiles).toHaveBeenCalled();
expect(IO.createDirsSyncFromFilePath).toHaveBeenCalledWith(expectedFile);
expect(uri).toContain("?mode=record");
expect(getStreamedSpy).toHaveBeenCalledTimes(1);
const [_session, resource, _reqHeaders, _responseStream, normalizeResponseNewLines] = getStreamedSpy.mock.calls[0];
expect(resource).toContain("?mode=record");
expect(normalizeResponseNewLines).toBe(false);
});

it("should allow users to call downloadAllSpoolContentCommon with a job containing duplicate step names", async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/zosjobs/src/DownloadJobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ export class DownloadJobs {
}

const writeStream = parms.stream ?? IO.createWriteStream(file);
const normalizeResponseNewLines = !(parms.binary || parms.record);
await ZosmfRestClient.getStreamed(session, JobsConstants.RESOURCE + parameters, [Headers.TEXT_PLAIN_UTF8], writeStream,
true);
normalizeResponseNewLines);
}

/**
Expand Down
Loading