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

Add --ignore-not-found flag logic to zosfilesBase.handler and update command definitions and en.ts for delete operations #2254

Merged
merged 47 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
331fa25
logic added to zosfilesbase.handler and definitions and en.ts updated…
ATorrise Sep 5, 2024
aa55cb0
changelog
ATorrise Sep 5, 2024
4636824
fixing logic
ATorrise Sep 5, 2024
d687d8b
testing zfs handler unit test
ATorrise Sep 9, 2024
e86356b
tests: quick mock on imperative classes
zFernand0 Sep 9, 2024
5714a60
ty fernando for helping me figure out what exactly needs to be mocked…
ATorrise Sep 9, 2024
504a4f9
functioning agmented unit tests
ATorrise Sep 11, 2024
31cabab
system tests, integration tests dont seem necessary
ATorrise Sep 12, 2024
e3898b5
Merge remote-tracking branch 'origin/next' into quiet
ATorrise Sep 12, 2024
1503ea9
small modifications for quality
ATorrise Sep 12, 2024
9c9d32e
added logic for vsam in zosfilesbase
ATorrise Sep 12, 2024
c808a8f
updating name of flag
ATorrise Sep 12, 2024
0ac3486
Update packages/cli/src/zosfiles/ZosFilesBase.handler.ts
ATorrise Sep 12, 2024
7ac5610
changing aliases
ATorrise Sep 12, 2024
93ae21b
pushing so i can work on other branch. probably not in a complete sta…
ATorrise Sep 19, 2024
506d7fe
Delete test file
ATorrise Sep 23, 2024
de71d20
Delete test file
ATorrise Sep 23, 2024
de55a1a
Merge remote-tracking branch 'origin' into quiet
ATorrise Oct 7, 2024
a718e4c
changing 1 system test, all tests pass in zos files
ATorrise Oct 7, 2024
5b02695
Merge remote-tracking branch 'origin/master' into quiet
ATorrise Oct 17, 2024
4126574
pr should be gtg
ATorrise Oct 17, 2024
b56b002
addressing minor comments
ATorrise Oct 17, 2024
c649ee7
moving vsam specific check and updating tests
ATorrise Oct 22, 2024
fdc93a1
Merge remote-tracking branch 'origin/master' into quiet
ATorrise Oct 22, 2024
2e5c763
possibly fixed?
ATorrise Oct 24, 2024
e0119b0
addressing linting and code change requests
ATorrise Oct 24, 2024
bbb04d6
Update CHANGELOG.md
ATorrise Oct 24, 2024
c90c7e8
Merge branch 'master' into quiet
awharn Oct 28, 2024
d20417c
reordering logic in ZosFilesBaseHandler
ATorrise Nov 4, 2024
ee08a22
Merge branch 'master' into quiet
ATorrise Nov 4, 2024
688788a
Merge branch 'master' into quiet
ATorrise Nov 4, 2024
ceb4550
fixing lint but also typeof error
ATorrise Nov 5, 2024
61e2b36
Merge branch 'master' into quiet
ATorrise Nov 5, 2024
4248c3c
adding changelog to zosfiles
ATorrise Nov 5, 2024
7d2f05c
Merge branch 'quiet' of https://github.com/zowe/zowe-cli into quiet
ATorrise Nov 5, 2024
4c94be8
updating changelog and snaps
ATorrise Nov 5, 2024
b1c1fe1
removing weird zowe file that my env keeps adding
ATorrise Nov 5, 2024
2c448bb
fixing quality check for a 404
ATorrise Nov 5, 2024
ba21556
changing error message type in else statment for zosfilesbasehandler
ATorrise Nov 5, 2024
683644e
add ppf file back and remove zowe-cli submodule
zFernand0 Nov 5, 2024
d06b928
addressing timothy's comments but still need to add test for 2nd dele…
ATorrise Nov 6, 2024
09301d5
Merge branch 'quiet' of https://github.com/zowe/zowe-cli into quiet
ATorrise Nov 6, 2024
8b5bd10
modifying tests to include deletion when no file exists, whoops
ATorrise Nov 6, 2024
b83f756
attempting to remove code duplication?
ATorrise Nov 6, 2024
aeb025d
increasing changelog readibility
ATorrise Nov 7, 2024
04219f6
Merge branch 'master' into quiet
zFernand0 Nov 7, 2024
c61b943
Merge branch 'master' into quiet
ATorrise Nov 7, 2024
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
3 changes: 3 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to the Zowe CLI package will be documented in this file.

## Recent Changes
- Enhancement: Add --quiet flag logic to zosfilesBase.handler and update command definitions and en.ts for delete operations. [#2254](https://github.com/zowe/zowe-cli/pull/2254)

## `8.0.0-next.202408261543`

- BugFix: Updated `micromatch` dependency for technical currency. [#2242](https://github.com/zowe/zowe-cli/pull/2242)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,73 @@

import { Delete, IZosFilesResponse } from "@zowe/zos-files-for-zowe-sdk";
import ZfsHandler from "../../../../../src/zosfiles/delete/zfs/zfs.handler";
import { ZosFilesBaseHandler } from "../../../../../src/zosfiles/ZosFilesBase.handler";
import { AbstractSession, ConnectionPropsForSessCfg, ImperativeError } from "@zowe/imperative";
Fixed Show fixed Hide fixed

describe("ZfsHandler", () => {
const defaultReturn: IZosFilesResponse = {
success : true,
commandResponse: "THIS IS A TEST"
success: true,
commandResponse: "THIS IS A TEST",
};

const deleteZfs = jest.spyOn(Delete, "zfs");
const fileNotFoundError = new ImperativeError({
msg: "IDC3012I ENTRY HLQ.MYNEW.ZFS NOT FOUND",
additionalDetails: "",
errorCode: '404'
});

let deleteZfsSpy: any;
// let processWithSessionSpy: any;

beforeEach(() => {
deleteZfs.mockClear();
deleteZfs.mockImplementation(async () => defaultReturn);
jest.spyOn(ConnectionPropsForSessCfg, "addPropsOrPrompt").mockResolvedValue({
hostname: "example.com"
});
deleteZfsSpy = jest.spyOn(Delete, "zfs");
deleteZfsSpy.mockClear();
deleteZfsSpy.mockImplementation(async () => defaultReturn);
});

it("should call Delete.zfs", async () => {
const handler = new ZfsHandler();

expect(handler).toBeInstanceOf(ZosFilesBaseHandler);
it("should return success: true when --quiet (-fq) flag is used and file is not found", async () => {
deleteZfsSpy.mockImplementation(() => {
throw fileNotFoundError;
});

const handler = new ZfsHandler();
const commandParameters: any = {
arguments: {
fileSystemName: "ABCD",
responseTimeout: 5
forSure: true,
quiet: true,
},
response: {
progress: { endBar: jest.fn() },
data: { setObj: jest.fn() }
}
};

const dummySession = {
lazyness: "(n.) An important quality for a developer to have."
}; // I'm lazy and we don't actually need the object
const rtoObject = {responseTimeout: 5};
// const error = new ImperativeError({msg: "IDC3012I ENTRY HLQ.MYNEW.ZFS NOT FOUND"});
// await expect(handler.processWithSession(commandParameters, {} as any)).rejects.toThrow(ImperativeError);
// await expect(handler.processWithSession(commandParameters, {} as any)).rejects.toThrow(error);
// await expect(handler.processWithSession(commandParameters, {} as any)).resolves.toEqual({ success: true });
await expect(handler.process(commandParameters)).resolves.toBe(undefined);
// await expect(handler.process(commandParameters)).resolves.toEqual({ success: true });
});

it("should throw file not found error (404) when --quiet is not used (-f)", async () => {
deleteZfsSpy.mockImplementation(() => {
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
throw fileNotFoundError;
});

const response = await handler.processWithSession(commandParameters, dummySession as any);
const handler = new ZfsHandler();
const commandParameters: any = {
arguments: {
fileSystemName: "ABCD",
forSure: true // --forSure flag, no --quiet flag
}
};

expect(deleteZfs).toHaveBeenCalledTimes(1);
expect(deleteZfs).toHaveBeenLastCalledWith(
dummySession,
commandParameters.arguments.fileSystemName,
rtoObject
);
expect(response).toBe(defaultReturn);
const error = new ImperativeError({ msg: "IDC3012I ENTRY HLQ.MYNEW.ZFS NOT FOUND" });
// await expect(handler.processWithSession(commandParameters, {} as any)).rejects.toThrow(ImperativeError);
await expect(handler.processWithSession(commandParameters, {} as any)).rejects.toThrow(error);
});
});
26 changes: 18 additions & 8 deletions packages/cli/src/zosfiles/-strings-/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,13 @@ export default {
OPTIONS: {
VOLUME: "The volume serial (VOLSER) where the data set resides. The option is required only when the data set is not" +
" catalogued on the system.",
FOR_SURE: "Specify this option to confirm that you want to delete the data set permanently."
FOR_SURE: "Specify this option to confirm that you want to delete the data set permanently.",
QUIET: "Suppress errors if the data set does not exist."
},
EXAMPLES: {
EX1: "Delete the data set named 'ibmuser.cntl'",
EX2: "Delete the data set member named 'ibmuser.cntl(mem)'"
EX2: "Delete the data set member named 'ibmuser.cntl(mem)'",
EX3: "Quietly delete a data set, suppressing errors if it doesn't exist"
}
},
MIGRATED_DATA_SET: {
Expand Down Expand Up @@ -283,13 +285,15 @@ export default {
FOR_SURE: "Specify this option to confirm that you want to delete the VSAM cluster permanently.",
ERASE: "Specify this option to overwrite the data component for the cluster with binary zeros. This " +
"option is ignored if the NOERASE attribute was specified when the cluster was defined or altered.",
PURGE: "Specify this option to delete the VSAM cluster regardless of its retention period or date."
PURGE: "Specify this option to delete the VSAM cluster regardless of its retention period or date.",
QUIET: "Suppress errors if the VSAM data set does not exist."
},
EXAMPLES: {
EX1: "Delete the VSAM data set named 'ibmuser.cntl.vsam'",
EX2: "Delete all expired VSAM data sets that match 'ibmuser.AAA.**.FFF'",
EX3: "Delete a non-expired VSAM data set named 'ibmuser.cntl.vsam'",
EX4: "Delete an expired VSAM data set named 'ibmuser.cntl.vsam' by overwriting the components with zeros"
EX4: "Delete an expired VSAM data set named 'ibmuser.cntl.vsam' by overwriting the components with zeros",
EX5: "Quietly delete VSAM data set, suppressing errors if it doesn't exist"
}
},
USS: {
Expand All @@ -300,12 +304,14 @@ export default {
},
OPTIONS: {
FOR_SURE: "Specify this option to confirm that you want to delete the file or directory permanently.",
RECURSIVE: "Delete directories recursively."
RECURSIVE: "Delete directories recursively.",
QUIET: "Suppress errors if the file does not exist."
},
EXAMPLES: {
EX1: "Delete the empty directory '/u/ibmuser/testcases'",
EX2: "Delete the file named '/a/ibmuser/my_text.txt'",
EX3: "Recursively delete the directory named '/u/ibmuser/testcases'"
EX3: "Recursively delete the directory named '/u/ibmuser/testcases'",
EX4: "Quietly delete a file, suppressing errors if the file doesn't exist"
}
},
ZFS: {
Expand All @@ -315,10 +321,14 @@ export default {
FILESYSTEMNAME: "The name of the z/OS file system that you want to delete."
},
OPTIONS: {
FOR_SURE: "Specify this option to confirm that you want to delete the ZFS permanently."
FOR_SURE: "Specify this option to confirm that you want to delete the ZFS permanently.",
QUIET: "Suppress errors if the z/OS file does not exist."

},
EXAMPLES: {
EX1: "Delete the z/OS file system 'HLQ.MYNEW.ZFS'"
EX1: "Delete the z/OS file system 'HLQ.MYNEW.ZFS'",
EX2: "Quietly delete a z/OS file, suppressing errors if the file doesn't exist"

}
}
}
Expand Down
35 changes: 15 additions & 20 deletions packages/cli/src/zosfiles/ZosFilesBase.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,28 @@ export abstract class ZosFilesBaseHandler implements ICommandHandler {
*
* @returns {Promise<void>}
*/
public async process(commandParameters: IHandlerParameters) {
public async process(commandParameters: IHandlerParameters): Promise<void> {
const sessCfg: ISession = ZosmfSession.createSessCfgFromArgs(
commandParameters.arguments
);
const sessCfgWithCreds = await ConnectionPropsForSessCfg.addPropsOrPrompt<ISession>(
sessCfg, commandParameters.arguments, {parms: commandParameters}
sessCfg, commandParameters.arguments, { parms: commandParameters }
);

const session = new Session(sessCfgWithCreds);
const response = await this.processWithSession(commandParameters, session);

commandParameters.response.progress.endBar(); // end any progress bars
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
// Print out the response
if (response.commandResponse) {
commandParameters.response.console.log(response.commandResponse);
}

// Return as an object when using --response-format-json
commandParameters.response.data.setObj(response);

// Ensure error gets thrown if request was unsuccessful.
// Sometimes it is useful to delay throwing an error until the end of the handler is
// reached, for example the upload API needs to return an API response even when it fails.
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
if (!response.success && response.commandResponse) {
throw new ImperativeError({
msg: response.errorMessage || response.commandResponse
});
try {
const response = await this.processWithSession(commandParameters, session);
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
if (response.commandResponse) {
commandParameters.response.console.log(response.commandResponse);
}
} catch (error) {
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
if (commandParameters.arguments.quiet && error.errorCode === '404') {
commandParameters.response.data.setObj({ success: true });
} else {
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
throw new ImperativeError({
msg: error.mMessage
ATorrise marked this conversation as resolved.
Show resolved Hide resolved
});
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions packages/cli/src/zosfiles/delete/ds/Ds.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export const DsDefinition: ICommandDefinition = {
aliases: ["vol"],
description: strings.OPTIONS.VOLUME,
type: "string"
},
{
name: "quiet",
aliases: ["q"],
description: strings.OPTIONS.QUIET,
type: "boolean",
required: false
}
] as ICommandOptionDefinition[]).sort((a, b) => a.name.localeCompare(b.name)),
examples: [
Expand All @@ -63,6 +70,10 @@ export const DsDefinition: ICommandDefinition = {
{
description: strings.EXAMPLES.EX2,
options: `"ibmuser.cntl(mem)" -f`
},
{
description: strings.EXAMPLES.EX3,
options: `"ibmuser.cntl(mem)" -q`
}
]
};
11 changes: 11 additions & 0 deletions packages/cli/src/zosfiles/delete/uss/Uss.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export const UssDefinition: ICommandDefinition = {
description: strings.OPTIONS.RECURSIVE,
type: "boolean",
required: false
},
{
name: "quiet",
aliases: ["q"],
description: strings.OPTIONS.QUIET,
type: "boolean",
required: false
}
],
examples: [
Expand All @@ -68,6 +75,10 @@ export const UssDefinition: ICommandDefinition = {
{
description: strings.EXAMPLES.EX3,
options: `"/a/ibmuser/testcases" -rf`
},
{
description: strings.EXAMPLES.EX4,
options: `"/a/ibmuser/testcases" -q`
}
]
};
13 changes: 12 additions & 1 deletion packages/cli/src/zosfiles/delete/vsam/Vsam.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export const VsamDefinition: ICommandDefinition = {
description: strings.OPTIONS.PURGE,
type: "boolean",
defaultValue: false
},
{
name: "quiet",
aliases: ["q"],
description: strings.OPTIONS.QUIET,
type: "boolean",
required: false
}
] as ICommandOptionDefinition[]).sort((a, b) => a.name.localeCompare(b.name)),
examples: [
Expand All @@ -79,6 +86,10 @@ export const VsamDefinition: ICommandDefinition = {
{
description: strings.EXAMPLES.EX4,
options: `"ibmuser.cntl.vsam" -f --erase`
}
},
{
description: strings.EXAMPLES.EX2,
options: `"ibmuser.cntl.vsam" -q`
},
]
};
11 changes: 11 additions & 0 deletions packages/cli/src/zosfiles/delete/zfs/zfs.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,23 @@ export const ZfsDefinition: ICommandDefinition = {
description: strings.OPTIONS.FOR_SURE,
type: "boolean",
required: true
},
{
name: "quiet",
aliases: ["q"],
description: strings.OPTIONS.QUIET,
type: "boolean",
required: false
}
] as ICommandOptionDefinition[]).sort((a, b) => a.name.localeCompare(b.name)),
examples: [
{
description: strings.EXAMPLES.EX1,
options: `"HLQ.MYNEW.ZFS" -f`
},
{
description: strings.EXAMPLES.EX1,
options: `"HLQ.MYNEW.ZFS" -q`
}
]
};
Loading