Skip to content

Commit

Permalink
Merge branch 'master' into copy-dsclp-large
Browse files Browse the repository at this point in the history
Signed-off-by: Jace Roell <111985297+jace-roell@users.noreply.github.com>
  • Loading branch information
jace-roell authored Jan 30, 2025
2 parents b124b45 + 591ebd5 commit 3236f3e
Show file tree
Hide file tree
Showing 27 changed files with 949 additions and 90 deletions.
2 changes: 2 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to the Zowe CLI package will be documented in this file.
## Recent Changes

- Enhancement: Added the `--data-set-type` flag to create sequential data set command to allow for creating extended and large formatted sequential data sets. [#2141](https://github.com/zowe/zowe-cli/issues/2141)
- Enhancement: Added `--recordRange` flag to `zowe jobs download output` command to allow users to select a specific range of records to output from a spool file. [#2411](https://github.com/zowe/zowe-cli/pull/2411)
- BugFix: The `zowe zos-files copy data-set` command overwrites the contents of the target data set without user confirmation. A `--safe-replace` option was added which prompts the user to confirm before overwriting the contents of the target data set. [#2369] (https://github.com/zowe/zowe-cli/issues/2369)

## `8.12.0`

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,24 @@ describe("DsHandler", () => {

const fromDataSetName = "ABCD";
const toDataSetName = "EFGH";
const enq = "SHR";
const replace = true;
const safeReplace = true;
const responseTimeout: any = undefined;


const commandParameters: any = {
arguments: {
fromDataSetName,
toDataSetName
toDataSetName,
enq,
replace,
safeReplace,
responseTimeout

},
response: {
console: { promptFn: jest.fn() }
}
};

Expand All @@ -49,7 +62,14 @@ describe("DsHandler", () => {
expect(copyDatasetSpy).toHaveBeenLastCalledWith(
dummySession,
{ dsn: commandParameters.arguments.toDataSetName },
{ "from-dataset": { dsn: commandParameters.arguments.fromDataSetName } }
{
"from-dataset": { dsn: commandParameters.arguments.fromDataSetName },
"enq": commandParameters.arguments.enq,
"replace": commandParameters.arguments.replace,
"responseTimeout": commandParameters.arguments.responseTimeout,
"safeReplace": commandParameters.arguments.safeReplace,
"promptFn": expect.any(Function)
}
);
expect(response).toBe(defaultReturn);
});
Expand All @@ -63,11 +83,22 @@ describe("DsHandler", () => {
const fromMemberName = "mem1";
const toDataSetName = "EFGH";
const toMemberName = "mem2";
const enq = "SHR";
const replace = true;
const safeReplace = true;
const responseTimeout: any = undefined;

const commandParameters: any = {
arguments: {
fromDataSetName: `${fromDataSetName}(${fromMemberName})`,
toDataSetName: `${toDataSetName}(${toMemberName})`
toDataSetName: `${toDataSetName}(${toMemberName})`,
enq,
replace,
safeReplace,
responseTimeout
},
response: {
console: { promptFn: jest.fn() }
}
};

Expand All @@ -79,7 +110,14 @@ describe("DsHandler", () => {
expect(copyDatasetSpy).toHaveBeenLastCalledWith(
dummySession,
{ dsn: toDataSetName, member: toMemberName },
{ "from-dataset": { dsn: fromDataSetName, member: fromMemberName } }
{
"from-dataset": { dsn: fromDataSetName, member: fromMemberName },
"enq": commandParameters.arguments.enq,
"replace": commandParameters.arguments.replace,
"responseTimeout": commandParameters.arguments.responseTimeout,
"safeReplace": commandParameters.arguments.safeReplace,
"promptFn": expect.any(Function)
}
);
expect(response).toBe(defaultReturn);
});
Expand All @@ -93,13 +131,20 @@ describe("DsHandler", () => {
const toDataSetName = "EFGH";
const enq = "SHR";
const replace = true;
const safeReplace = true;
const responseTimeout: any = undefined;

const commandParameters: any = {
arguments: {
fromDataSetName,
toDataSetName,
enq,
replace
replace,
safeReplace,
responseTimeout
},
response: {
console: { promptFn: jest.fn() }
}
};

Expand All @@ -114,9 +159,84 @@ describe("DsHandler", () => {
{
"from-dataset": { dsn: commandParameters.arguments.fromDataSetName },
"enq": commandParameters.arguments.enq,
"replace": commandParameters.arguments.replace
"replace": commandParameters.arguments.replace,
"responseTimeout": commandParameters.arguments.responseTimeout,
"safeReplace": commandParameters.arguments.safeReplace,
"promptFn": expect.any(Function)
}
);
expect(response).toBe(defaultReturn);
});
it("should prompt the user and return true when input is 'y'", async () => {
const handler = new DsHandler();

expect(handler).toBeInstanceOf(ZosFilesBaseHandler);
const fromDataSetName = "ABCD";
const toDataSetName = "EFGH";
const enq = "SHR";
const replace = true;
const safeReplace = true;
const responseTimeout: any = undefined;

const commandParameters: any = {
arguments: {
fromDataSetName,
toDataSetName,
enq,
replace,
safeReplace,
responseTimeout
},
response: {
console: { promptFn: jest.fn() }
}
};
const promptMock = jest.fn();
promptMock.mockResolvedValue("y");

const promptFn = (handler as any)["promptForSafeReplace"]({ prompt: promptMock });
const result = await promptFn(commandParameters.arguments.toDataSetName);

expect(promptMock).toHaveBeenCalledWith(
`The dataset '${toDataSetName}' exists on the target system. This copy will result in data loss.` +
` Are you sure you want to continue? [y/N]: `
);
expect(result).toBe(true);
});
it("should prompt the user and return true when input is 'N'", async () => {
const handler = new DsHandler();

expect(handler).toBeInstanceOf(ZosFilesBaseHandler);
const fromDataSetName = "ABCD";
const toDataSetName = "EFGH";
const enq = "SHR";
const replace = true;
const safeReplace = true;
const responseTimeout: any = undefined;

const commandParameters: any = {
arguments: {
fromDataSetName,
toDataSetName,
enq,
replace,
safeReplace,
responseTimeout
},
response: {
console: { promptFn: jest.fn() }
}
};
const promptMock = jest.fn();
promptMock.mockResolvedValue("N");

const promptFn = (handler as any)["promptForSafeReplace"]({ prompt: promptMock });
const result = await promptFn(commandParameters.arguments.toDataSetName);

expect(promptMock).toHaveBeenCalledWith(
`The dataset '${toDataSetName}' exists on the target system. This copy will result in data loss.` +
` Are you sure you want to continue? [y/N]: `
);
expect(result).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Array [
"name": "replace",
"type": "boolean",
},
Object {
"aliases": Array [
"safe-rep",
"--sr",
],
"description": "Specify this option as true if you wish to replace like-named members or the content of the target data set. This option will prompt to confirm.",
"name": "safe-replace",
"type": "boolean",
},
]
`;

Expand All @@ -35,5 +44,9 @@ Array [
"description": "Copy the data set named 'USER.FROM.SET' to the data set named 'USER.TO.SET' and replace like-named members",
"options": "\\"USER.FROM.SET\\" \\"USER.TO.SET\\" --replace",
},
Object {
"description": "Copy the partitioned data set named 'TEST.PDS1' to the partitioned data set named 'TEST.PDS2'",
"options": "\\"USER.FROM.SET\\" \\"USER.TO.SET\\" --safe-replace",
},
]
`;
Loading

0 comments on commit 3236f3e

Please sign in to comment.