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

Copying a PDS into existing PDS w/ no members #2386

Merged
merged 18 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions packages/zosfiles/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to the Zowe z/OS files SDK package will be documented in this file.

## Recent Changes
-Enhancement: `Copy.dataset` method now recognizes Partioned data sets and can copy members of source PDS into an existing target PDS. [#2386](https://github.com/zowe/zowe-cli/pull/2386)

- Enhancement: Added a `List.membersMatchingPattern` method to download all members that match a specific pattern.[#2359](https://github.com/zowe/zowe-cli/pull/2359)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
*/

import { Create, Upload, Delete, CreateDataSetTypeEnum, Copy, ZosFilesMessages, Get, IDataSet,
ICrossLparCopyDatasetOptions, IGetOptions, IZosFilesResponse } from "../../../../src";
import { Imperative, Session } from "@zowe/imperative";
ICrossLparCopyDatasetOptions, IGetOptions, IZosFilesResponse,
ZosFilesUtils} from "../../../../src";
import { Imperative, IO, Session } from "@zowe/imperative";
import { inspect } from "util";
import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment";
import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema";
import { join } from "path";
import { readFileSync } from "fs";
import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment";
import { tmpdir } from "os";
import path = require("path");
import * as fs from "fs";

let REAL_SESSION: Session;
let REAL_TARGET_SESSION: Session;
Expand Down Expand Up @@ -98,6 +102,56 @@
expect(contents1.toString()).toEqual(contents2.toString());
});
});
describe("Partioned > Partioned", () => {
beforeEach(async () => {
try {
const downloadDir = path.join(tmpdir(), fromDataSetName);
fs.mkdirSync(downloadDir, { recursive: true });
const mockFile = path.join(downloadDir, "mockFile.txt");
fs.writeFileSync(mockFile, "test file content");
Dismissed Show dismissed Hide dismissed

const uploadFileList: string[] = ZosFilesUtils.getFileListFromPath(downloadDir);
const stream = IO.createReadStream(uploadFileList[0]);
await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, fromDataSetName);
await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, toDataSetName);
await Upload.streamToDataSet(REAL_SESSION, stream, fromDataSetName);
} catch (err) {
Imperative.console.info(`Error: ${inspect(err)}`);
}
});
it("Should copy a partitioned data set", async () => {
let error;
let response;
let contents1;
let contents2;

try {
response = await Copy.dataSet(
REAL_SESSION,
{dsn: toDataSetName},
{"from-dataset": {
dsn:fromDataSetName
}}
);
contents1 = await Get.dataSet(REAL_SESSION, fromDataSetName);
contents2 = await Get.dataSet(REAL_SESSION, toDataSetName);
Imperative.console.info(`Response: ${inspect(response)}`);
} catch (err) {
error = err;
Imperative.console.info(`Error: ${inspect(err)}`);
}

expect(error).toBeFalsy();

expect(response).toBeTruthy();
expect(response.success).toBe(true);
expect(response.commandResponse).toContain(ZosFilesMessages.datasetCopiedSuccessfully.message);

expect(contents1).toBeTruthy();
expect(contents2).toBeTruthy();
expect(contents1.toString()).toEqual(contents2.toString());
});
});
describe("Member > Member", () => {
beforeEach(async () => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

import { Session, ImperativeError } from "@zowe/imperative";
import { posix } from "path";

import * as fs from "fs";
Fixed Show fixed Hide fixed
import { error } from "console";

import { Copy, Create, Get, List, Upload, ZosFilesConstants, ZosFilesMessages, IZosFilesResponse } from "../../../../src";
import { Copy, Create, Get, List, Upload, ZosFilesConstants, ZosFilesMessages, IZosFilesResponse, Download, ZosFilesUtils } from "../../../../src";
Fixed Show fixed Hide fixed
import { ZosmfHeaders, ZosmfRestClient } from "@zowe/core-for-zowe-sdk";
import { tmpdir } from "os";
Fixed Show fixed Hide fixed
import path = require("path");
Fixed Show fixed Hide fixed

describe("Copy", () => {
const dummySession = new Session({
Expand All @@ -29,6 +31,8 @@

describe("Data Set", () => {
const copyExpectStringSpy = jest.spyOn(ZosmfRestClient, "putExpectString");
let copyPDSSpy = jest.spyOn(Copy, "copyPDS");
let isPDSSpy: jest.SpyInstance;
const fromDataSetName = "USER.DATA.FROM";
const fromMemberName = "mem1";
const toDataSetName = "USER.DATA.TO";
Expand All @@ -39,6 +43,12 @@
copyExpectStringSpy.mockImplementation(async () => {
return "";
});
copyPDSSpy.mockClear();
copyPDSSpy = jest.spyOn(Copy, "copyPDS").mockResolvedValue({
success:true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message,
});
isPDSSpy = jest.spyOn(Copy as any, "isPDS").mockResolvedValue(true);
});

describe("Success Scenarios", () => {
Expand Down Expand Up @@ -71,7 +81,7 @@
success: true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message
});
expect(copyExpectStringSpy).toHaveBeenCalledTimes(1);

Check failure on line 84 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:84:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 84 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:84:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 84 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:84:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 84 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:84:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 84 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:84:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 84 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:84:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)
expect(copyExpectStringSpy).toHaveBeenLastCalledWith(
dummySession,
expectedEndpoint,
Expand Down Expand Up @@ -109,7 +119,7 @@
success: true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message
});
expect(copyExpectStringSpy).toHaveBeenCalledTimes(1);

Check failure on line 122 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request with timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:122:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 122 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request with timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:122:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 122 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request with timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:122:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 122 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request with timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:122:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 122 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request with timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:122:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 122 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Copy › Data Set › Success Scenarios › Sequential > Sequential › should send a request with timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:122:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)
expect(copyExpectStringSpy).toHaveBeenLastCalledWith(
dummySession,
expectedEndpoint,
Expand Down Expand Up @@ -148,7 +158,7 @@
success: true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message
});
expect(copyExpectStringSpy).toHaveBeenCalledTimes(1);

Check failure on line 161 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

Copy › Data Set › Success Scenarios › Member > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:161:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 161 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Member > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:161:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 161 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

Copy › Data Set › Success Scenarios › Member > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:161:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 161 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Member > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:161:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 161 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Copy › Data Set › Success Scenarios › Member > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:161:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 161 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Copy › Data Set › Success Scenarios › Member > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:161:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)
expect(copyExpectStringSpy).toHaveBeenLastCalledWith(
dummySession,
expectedEndpoint,
Expand Down Expand Up @@ -187,7 +197,7 @@
success: true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message
});
expect(copyExpectStringSpy).toHaveBeenCalledTimes(1);

Check failure on line 200 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

Copy › Data Set › Success Scenarios › Member > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:200:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 200 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Member > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:200:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 200 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

Copy › Data Set › Success Scenarios › Member > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:200:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 200 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Member > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:200:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 200 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Copy › Data Set › Success Scenarios › Member > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:200:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 200 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Copy › Data Set › Success Scenarios › Member > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:200:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)
expect(copyExpectStringSpy).toHaveBeenLastCalledWith(
dummySession,
expectedEndpoint,
Expand Down Expand Up @@ -225,7 +235,7 @@
success: true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message
});
expect(copyExpectStringSpy).toHaveBeenCalledTimes(1);

Check failure on line 238 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:238:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 238 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:238:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 238 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:238:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 238 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:238:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 238 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:238:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 238 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:238:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)
expect(copyExpectStringSpy).toHaveBeenLastCalledWith(
dummySession,
expectedEndpoint,
Expand Down Expand Up @@ -263,7 +273,7 @@
success: true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message
});
expect(copyExpectStringSpy).toHaveBeenCalledTimes(1);

Check failure on line 276 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:276:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 276 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:276:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 276 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:276:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 276 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:276:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 276 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:276:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 276 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Copy › Data Set › Success Scenarios › Sequential > Member › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:276:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)
expect(copyExpectStringSpy).toHaveBeenLastCalledWith(
dummySession,
expectedEndpoint,
Expand Down Expand Up @@ -302,7 +312,7 @@
success: true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message
});
expect(copyExpectStringSpy).toHaveBeenCalledTimes(1);

Check failure on line 315 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:315:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 315 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:315:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 315 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:315:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 315 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:315:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 315 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:315:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 315 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:315:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)
expect(copyExpectStringSpy).toHaveBeenLastCalledWith(
dummySession,
expectedEndpoint,
Expand Down Expand Up @@ -341,7 +351,7 @@
success: true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message
});
expect(copyExpectStringSpy).toHaveBeenCalledTimes(1);

Check failure on line 354 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:354:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 354 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:354:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 354 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:354:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 354 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:354:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 354 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:354:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 354 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Copy › Data Set › Success Scenarios › Member > Sequential › should send a request with a timeout

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:354:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)
expect(copyExpectStringSpy).toHaveBeenLastCalledWith(
dummySession,
expectedEndpoint,
Expand All @@ -358,7 +368,7 @@
{ "from-dataset": { dsn: fromDataSetName } }
);

expect(copyExpectStringSpy).toHaveBeenCalledTimes(1);

Check failure on line 371 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

Copy › Data Set › Success Scenarios › enq option › should not contain enq in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:371:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 371 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › enq option › should not contain enq in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:371:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 371 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

Copy › Data Set › Success Scenarios › enq option › should not contain enq in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:371:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 371 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › enq option › should not contain enq in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:371:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 371 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Copy › Data Set › Success Scenarios › enq option › should not contain enq in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:371:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 371 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Copy › Data Set › Success Scenarios › enq option › should not contain enq in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:371:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)
const argumentsOfCall = copyExpectStringSpy.mock.calls[0];
const lastArgumentOfCall = argumentsOfCall[argumentsOfCall.length - 1];
expect(lastArgumentOfCall).not.toHaveProperty("enq");
Expand All @@ -373,7 +383,7 @@
}
);

expect(copyExpectStringSpy).toHaveBeenCalledTimes(1);

Check failure on line 386 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

Copy › Data Set › Success Scenarios › enq option › should contain valid enq value in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:386:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 386 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › enq option › should contain valid enq value in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:386:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 386 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

Copy › Data Set › Success Scenarios › enq option › should contain valid enq value in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:386:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 386 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

Copy › Data Set › Success Scenarios › enq option › should contain valid enq value in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:386:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 386 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Copy › Data Set › Success Scenarios › enq option › should contain valid enq value in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:386:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)

Check failure on line 386 in packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Copy › Data Set › Success Scenarios › enq option › should contain valid enq value in payload

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 1 Received number of calls: 0 at packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:386:49 at fulfilled (packages/zosfiles/__tests__/__unit__/methods/copy/Copy.unit.test.ts:15:58)
const argumentsOfCall = copyExpectStringSpy.mock.calls[0];
const lastArgumentOfCall = argumentsOfCall[argumentsOfCall.length - 1];
expect(lastArgumentOfCall).toHaveProperty("enq", "SHR");
Expand Down Expand Up @@ -438,6 +448,28 @@
expect(lastArgumentOfCall).toHaveProperty("replace", false);
});
});
describe("Partitioned > Partitioned", () => {
it("should call copyPDS to copy members of source PDS to target PDS", async () => {
const response = await Copy.dataSet(
dummySession,
{dsn: toDataSetName},
{"from-dataset": {
dsn:fromDataSetName
}}
);
expect(isPDSSpy).toHaveBeenCalledTimes(2);
expect(isPDSSpy).toHaveBeenNthCalledWith(1, dummySession, fromDataSetName);
expect(isPDSSpy).toHaveBeenNthCalledWith(2, dummySession, toDataSetName);

expect(copyPDSSpy).toHaveBeenCalledTimes(1);
expect(copyPDSSpy).toHaveBeenCalledWith(dummySession, fromDataSetName, toDataSetName);

expect(response).toEqual({
success: true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message
});
});
});
});
describe("Failure Scenarios", () => {
it("should fail if the zOSMF REST client fails", async () => {
Expand Down Expand Up @@ -515,6 +547,41 @@
});
});

// describe("Copy Partitioned Data Set", () => {
// const listAllMembersSpy = jest.spyOn(List, "allMembers");
// const downloadAllMembersSpy = jest.spyOn(Download, "allMembers");
// const uploadSpy = jest.spyOn(Upload, "streamToDataSet");
// const fileListPathSpy = jest.spyOn(ZosFilesUtils, "getFileListFromPath");
// const fromDataSetName = "USER.DATA.FROM";
// const toDataSetName = "USER.DATA.TO";
// it("should successfully copy members from source to target PDS", async () => {
// listAllMembersSpy.mockImplementation(async (): Promise<any> => ({
// apiResponse: {
// items: [
// {member: "mem1"},
// {member: "mem2"}
// ]
// }
// }));
// downloadAllMembersSpy.mockImplementation(async (): Promise<any> => undefined);

// uploadSpy.mockImplementation(async (): Promise<any> => undefined);

// const response = await Copy.copyPDS(dummySession, fromDataSetName, toDataSetName);
// // const downloadDir = path.join(tmpdir(), fromDataSetName);
// expect(listAllMembersSpy).toHaveBeenCalledWith(dummySession, fromDataSetName);
// expect(downloadAllMembersSpy).toHaveBeenCalled();
// // expect(fileListPathSpy).toHaveBeenCalledWith(path.join(tmpdir(), fromDataSetName));
// expect(uploadSpy).toHaveBeenCalledTimes(2);

// // expect(fs.rmSync).toHaveBeenCalled();
// expect(response).toEqual({
// success: true,
// commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message,
// });
// });
// });

describe("Data Set Cross LPAR", () => {
const getDatasetSpy = jest.spyOn(Get, "dataSet");
const listDatasetSpy = jest.spyOn(List, "dataSet");
Expand Down
86 changes: 83 additions & 3 deletions packages/zosfiles/src/methods/copy/Copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
*
*/

import { AbstractSession, ImperativeError, ImperativeExpect, ITaskWithStatus, Logger, Headers,
IHeaderContent, TaskStage } from "@zowe/imperative";
import { AbstractSession, ImperativeError, ImperativeExpect, ITaskWithStatus,
Logger, Headers, IHeaderContent, TaskStage, IO} from "@zowe/imperative";
import { posix } from "path";

import * as fs from "fs";
import { Create, CreateDataSetTypeEnum, ICreateDataSetOptions } from "../create";
import { Get } from "../get";
import { Upload } from "../upload";
Expand All @@ -26,6 +26,10 @@
import { IDataSet } from "../../doc/IDataSet";
import { ICopyDatasetOptions } from "./doc/ICopyDatasetOptions";
import { ICrossLparCopyDatasetOptions } from "./doc/ICrossLparCopyDatasetOptions";
import { Download } from "../download";
import { ZosFilesUtils } from "../../utils/ZosFilesUtils";
import { tmpdir } from "os";
import path = require("path");
/**
* This class holds helper functions that are used to copy the contents of datasets through the
* z/OSMF APIs.
Expand Down Expand Up @@ -53,6 +57,12 @@
ImperativeExpect.toBeDefinedAndNonBlank(options["from-dataset"].dsn, "fromDataSetName");
ImperativeExpect.toBeDefinedAndNonBlank(toDataSetName, "toDataSetName");

const sourceIsPds = await Copy.isPDS(session, options["from-dataset"].dsn);
const targetIsPds = await Copy.isPDS(session, toDataSetName);

if(sourceIsPds && targetIsPds) {
return await Copy.copyPDS(session, options["from-dataset"].dsn, toDataSetName);
}
const endpoint: string = posix.join(
ZosFilesConstants.RESOURCE,
ZosFilesConstants.RES_DS_FILES,
Expand Down Expand Up @@ -93,6 +103,76 @@
}
}

/**
* Private function that checks if a dataset is type PDS
**/
private static async isPDS(

Check warning on line 109 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L109

Added line #L109 was not covered by tests
session: AbstractSession,
dataSetName: string

Check warning on line 111 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L111

Added line #L111 was not covered by tests
): Promise<boolean> {
try {
const response = await List.dataSet(session, dataSetName, {attributes: true});
const dsntp = response.apiResponse.items[0].dsntp;
const dsorg = response.apiResponse.items[0].dsorg;

Check warning on line 116 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L113-L116

Added lines #L113 - L116 were not covered by tests
return dsntp === "PDS" && dsorg === "PO";
}
catch(error) {
Logger.getAppLogger().error(error);
throw error;

Check warning on line 121 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L120-L121

Added lines #L120 - L121 were not covered by tests
}
}

/**
* Copy the members of a Partitioned dataset into another Partitioned dataset
*
* @param {AbstractSession} session - z/OSMF connection info
* @param {IDataSet} toDataSet - The data set to copy to
* @param {IDataSetOptions} options - Options
*
* @returns {Promise<IZosFilesResponse>} A response indicating the status of the copying
*
* @throws {ImperativeError} Data set name must be specified as a non-empty string
* @throws {Error} When the {@link ZosmfRestClient} throws an error
*
* @see https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.izua700/IZUHPINFO_API_PutDataSetMemberUtilities.htm
*/

public static async copyPDS (

Check warning on line 140 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L140

Added line #L140 was not covered by tests
session: AbstractSession,
fromPds: string,
toPds: string

Check warning on line 143 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L143

Added line #L143 was not covered by tests
): Promise<IZosFilesResponse> {
try {
const sourceResponse = await List.allMembers(session, fromPds);
const sourceMemberList: Array<{ member: string }> = sourceResponse.apiResponse.items;

Check warning on line 147 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L145-L147

Added lines #L145 - L147 were not covered by tests

if(sourceMemberList.length == 0) {
return {

Check warning on line 150 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L150

Added line #L150 was not covered by tests
success: false,
pujal0909 marked this conversation as resolved.
Show resolved Hide resolved
commandResponse: `Source dataset (${fromPds}) - ` + ZosFilesMessages.noMembersFound.message
};
}

const downloadDir = path.join(tmpdir(), fromPds);
await Download.allMembers(session, fromPds, {directory:downloadDir});
const uploadFileList: string[] = ZosFilesUtils.getFileListFromPath(downloadDir);

Check warning on line 158 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L156-L158

Added lines #L156 - L158 were not covered by tests

for (const file of uploadFileList) {
const uploadingDsn = `${toPds}(${ZosFilesUtils.generateMemberName(file)})`;
const uploadStream = IO.createReadStream(file);
await Upload.streamToDataSet(session, uploadStream, uploadingDsn);

Check warning on line 163 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L160-L163

Added lines #L160 - L163 were not covered by tests
}
fs.rmSync(downloadDir, {recursive: true});
return {

Check warning on line 166 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L165-L166

Added lines #L165 - L166 were not covered by tests
success:true,
commandResponse: ZosFilesMessages.datasetCopiedSuccessfully.message
};
}
catch (error) {
pujal0909 marked this conversation as resolved.
Show resolved Hide resolved
Logger.getAppLogger().error(error);
throw error;

Check warning on line 173 in packages/zosfiles/src/methods/copy/Copy.ts

View check run for this annotation

Codecov / codecov/patch

packages/zosfiles/src/methods/copy/Copy.ts#L172-L173

Added lines #L172 - L173 were not covered by tests
}
}

/**
* Copy the contents of a dataset from one LPAR to another LPAR
Expand Down
Loading