Skip to content

Commit

Permalink
Merge pull request #2254 from zowe/quiet
Browse files Browse the repository at this point in the history
Add --ignore-not-found flag logic to zosfilesBase.handler and update command definitions and en.ts for delete operations
  • Loading branch information
ATorrise authored Nov 7, 2024
2 parents ca53021 + c61b943 commit fdf1e70
Show file tree
Hide file tree
Showing 33 changed files with 573 additions and 156 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CCS141/
src/brightside.iml
package-lock.json
/packages/cli/npm-shrinkwrap.json
/zowe-cli
/dist/
# Sonar Files
.sonar_lock
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Change Log

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

## Recent Changes
- Enhancement: Add the --ignore-not-found flag to avoid file-not-found error messages when deleting files so scripts are not interupted during automated batch processing. The flag bypasses warning prompts to confirm delete actions. [#2254](https://github.com/zowe/zowe-cli/pull/2254)

## `8.7.0`

- Enhancement: Added --wait-for-active and --wait-for-output to download options on zosjobs. [#2328](https://github.com/zowe/zowe-cli/pull/2328)
Expand All @@ -22,6 +24,7 @@ All notable changes to the Zowe CLI package will be documented in this file.

- Enhancement: Added optional `--attributes` flag to `zowe zos-files upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319](https://github.com/zowe/zowe-cli/pull/2319)


## `8.3.0`

- Enhancement: Issue the `zowe files search data-sets` command with the new `encoding` option to use a different code page when searching data set contents. [#2161](https://github.com/zowe/zowe-cli/issues/2161)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("Upload local dir to uss dir", () => {
expect(response.stderr.toString()).toContain("USSDir");
});

it("should fail when local directory does not exist", async () => {
it("should fail when local directory does not exist and no --inf flag", async () => {
const shellScript = path.join(__dirname, "__scripts__", "command", "command_upload_dtu.sh");
const response = runCliScript(shellScript, TEST_ENVIRONMENT, ["localDirThatDoesNotExist", "/a/uss/dir"]);
expect(stripNewLines(response.stderr.toString())).toContain("no such file or directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ describe("Delete Data Set", () => {
runCliScript(__dirname + "/__scripts__/command/command_delete_data_set.sh",
TEST_ENVIRONMENT, [dsname, "--for-sure", "--rfj"]);
});

it("should delete a data set with --ignore-not-found flag", async () => {
const createResponse = runCliScript(__dirname + '/__scripts__/command/command_create_data_set.sh',
TEST_ENVIRONMENT, [dsname]);
expect(createResponse.status).toBe(0); // Ensure data set is created successfully

// Now delete the data set, verify no output in ignore-not-found mode
const deleteResponse = runCliScript(__dirname + "/__scripts__/command/command_delete_data_set.sh",
TEST_ENVIRONMENT, [dsname, "--for-sure", "--ignore-not-found"]);
expect(deleteResponse.stderr.toString()).toBe("");

//delete again
const secondDelete = runCliScript(__dirname + "/__scripts__/command/command_delete_data_set.sh",
TEST_ENVIRONMENT, [dsname, "--for-sure", "--ignore-not-found"]);
expect(secondDelete.stderr.toString()).toBe("");
});
});

describe("Expected failures", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ USS File or directory deleted successfully.
"
`;

exports[`Delete File Success scenarios should delete a file with --ignore-not-found flag 1`] = `
"================Z/OS FILES DELETE FILE===============
USS File or directory deleted successfully.
"
`;

exports[`Delete File Success scenarios should delete a file with response timeout 1`] = `
"================Z/OS FILES DELETE FILE===============
USS File or directory deleted successfully.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,28 @@ describe("Delete File", () => {
expect(response.status).toBe(0);
expect(response.stdout.toString()).toMatchSnapshot();
});

it("should delete a file with response timeout", async () => {
const response = runCliScript(__dirname + "/__scripts__/command/command_delete_file.sh",
TEST_ENVIRONMENT, [ussname, "--for-sure", "--responseTimeout 5"]);
expect(response.stderr.toString()).toBe("");
expect(response.status).toBe(0);
expect(response.stdout.toString()).toMatchSnapshot();
});

it("should delete a file with --ignore-not-found flag", async () => {
const response = runCliScript(__dirname + "/__scripts__/command/command_delete_file.sh",
TEST_ENVIRONMENT, [ussname, "--for-sure", "--ignore-not-found"]);
expect(response.stderr.toString()).toBe("");
expect(response.status).toBe(0);
expect(response.stdout.toString()).toMatchSnapshot();

//delete this file a second time, it doesnt exist. ensure no output because --inf
const secondResponse = runCliScript(__dirname + "/__scripts__/command/command_delete_file.sh",
TEST_ENVIRONMENT, [ussname, "--for-sure", "--ignore-not-found"]);
expect(secondResponse.stderr.toString()).toBe("");
expect(secondResponse.status).toBe(0);
});
});

describe("Expected failures", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Data set deleted successfully.
"
`;

exports[`Delete VSAM Data Set Success scenarios should successfully delete a VSAM data set with --ignore-not-found flag 1`] = `
"================Z/OS FILES DELETE VSAM DATA SET===============
Data set deleted successfully.
"
`;

exports[`Delete VSAM Data Set without profiles should delete a data set 1`] = `
"Data set deleted successfully.
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ describe("Delete VSAM Data Set", () => {
expect(response.status).toBe(0);
expect(response.stdout.toString()).toMatchSnapshot();
});

it("should successfully delete a VSAM data set with --ignore-not-found flag", async () => {
// create vsam
const createResponse = runCliScript(__dirname + "/__scripts__/command/command_invoke_ams_define_statement.sh",
TEST_ENVIRONMENT, [dsname, volume]);
expect(createResponse.status).toBe(0);

// now delete
const deleteResponse = runCliScript(__dirname + "/__scripts__/command/command_delete_vsam_data_set.sh",
TEST_ENVIRONMENT, [dsname, "--for-sure", "--ignore-not-found"]);
expect(deleteResponse.stderr.toString()).toBe("");
expect(deleteResponse.status).toBe(0);
expect(deleteResponse.stdout.toString()).toMatchSnapshot();

//repeat and ensure no error
const repeatDelete = runCliScript(__dirname + "/__scripts__/command/command_delete_vsam_data_set.sh",
TEST_ENVIRONMENT, [dsname, "--for-sure", "--ignore-not-found"]);
expect(repeatDelete.stderr.toString()).toBe("");
expect(repeatDelete.status).toBe(0);
});
});

describe("Expected failures", () => {
Expand All @@ -137,6 +157,15 @@ describe("Delete VSAM Data Set", () => {
expect(response.status).toBe(1);
expect(stripNewLines(response.stderr.toString())).toContain(`ENTRY ${user}.DOES.NOT.EXIST NOT DELETED`);
});
it("should fail deleting a non-existent data set without a --ignore-not-found flag", async () => {
// Attempt to delete a non-existent VSAM dataset without the --ignore-not-found flag
const response = runCliScript(__dirname + "/__scripts__/command/command_delete_vsam_data_set.sh",
TEST_ENVIRONMENT, [user + ".DOES.NOT.EXIST", "--for-sure"]);

// Check that stderr contains the expected error message about the dataset not being found
expect(response.status).toBe(1);
expect(stripNewLines(response.stderr.toString())).toContain(`ENTRY ${user}.DOES.NOT.EXIST NOT FOUND`);
});

it("should fail due to retention period not being exceeded", async () => {
let response = runCliScript(__dirname + "/__scripts__/command/command_invoke_ams_define_for_statement.sh",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ z/OS file system deleted successfully.
"
`;

exports[`Delete z/OS File System Success scenarios should delete a ZFS with --ignore-not-found flag 1`] = `
"================Z/OS FILES DELETE Z/OS FILE SYSTEM===============
z/OS file system deleted successfully.
"
`;

exports[`Delete z/OS File System Success scenarios should delete a ZFS with response timeout 1`] = `
"================Z/OS FILES DELETE Z/OS FILE SYSTEM===============
z/OS file system deleted successfully.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe("Delete z/OS File System", () => {
expect(response.status).toBe(0);
expect(response.stdout.toString()).toMatchSnapshot();
});

it("should delete a ZFS with response timeout", async () => {
let response = runCliScript(__dirname + "/__scripts__/command/command_create_zfs.sh",
TEST_ENVIRONMENT, [fsname, volume, "--responseTimeout 5"]);
Expand All @@ -114,6 +115,26 @@ describe("Delete z/OS File System", () => {
expect(response.status).toBe(0);
expect(response.stdout.toString()).toMatchSnapshot();
});

it("should delete a ZFS with --ignore-not-found flag", async () => {
// first create zfs
const createResponse = runCliScript(__dirname + "/__scripts__/command/command_create_zfs.sh",
TEST_ENVIRONMENT, [fsname, volume]);
expect(createResponse.status).toBe(0);

const deleteResponse = runCliScript(__dirname + "/__scripts__/command/command_delete_zfs.sh",
TEST_ENVIRONMENT, [fsname, "--for-sure", "--ignore-not-found"]);
expect(deleteResponse.stderr.toString()).toBe("");
expect(deleteResponse.status).toBe(0);
expect(deleteResponse.stdout.toString()).toMatchSnapshot();

//repeat and ensure still no output because --inf
const deleteResp = runCliScript(__dirname + "/__scripts__/command/command_delete_zfs.sh",
TEST_ENVIRONMENT, [fsname, "--for-sure", "--ignore-not-found"]);
expect(deleteResp.stderr.toString()).toBe("");
expect(deleteResp.status).toBe(0);
});

});

describe("Expected failures", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { UNIT_TEST_ZOSMF_PROF_OPTS } from "../../../../../../../__tests__/__src_
const message: string = "Dummy error message";

describe("Create VSAM data set handler", () => {
beforeEach(() => {
jest.clearAllMocks();
Create.vsam = jest.fn(); // Ensure a fresh mock
});
describe("process method", () => {
it("should create a VSAM data set if requested", async () => {
// Require the handler and create a new instance
Expand Down Expand Up @@ -84,61 +88,35 @@ describe("Create VSAM data set handler", () => {
expect(logMessage).toMatchSnapshot();
});
});

it("should raise an error", async () => {
// Require the handler and create a new instance
const handlerReq = require("../../../../../src/zosfiles/create/vsam/vsam.handler");
const handler = new handlerReq.default();
const dataSetName = "testing";

// Vars populated by the mocked function
let error: any;
let apiMessage = "";
let jsonObj;
let logMessage = "";
let fakeSession = null;
// Ensure the spy works as intended
const createVsamSpy = jest.spyOn(Create, "vsam");

// Mock the vsam function
Create.vsam = jest.fn((session) => {
fakeSession = session;
const impErr = new ImperativeError({
msg: message
});
throw impErr;
createVsamSpy.mockImplementationOnce(() => {
throw new ImperativeError({ msg: message });
});

try {
// Invoke the handler with a full set of mocked arguments and response functions
await handler.process({
const commandParameters = {
arguments: {
dataSetName,
...UNIT_TEST_ZOSMF_PROF_OPTS,
},
response: {
data: { setObj: jest.fn() },
console: { log: jest.fn() },
progress: { endBar: jest.fn() }
},
};

arguments: {
$0: "fake",
_: ["fake"],
dataSetName,
...UNIT_TEST_ZOSMF_PROF_OPTS
},
response: {
data: {
setMessage: jest.fn((setMsgArgs) => {
apiMessage = setMsgArgs;
}),
setObj: jest.fn((setObjArgs) => {
jsonObj = setObjArgs;
})
},
console: {
log: jest.fn((logArgs) => {
logMessage += "\n" + logArgs;
})
}
}
} as any);
} catch (e) {
error = e;
}
// Ensure the error is thrown as expected
await expect(handler.process(commandParameters)).rejects.toThrow(ImperativeError);

expect(error).toBeDefined();
expect(Create.vsam).toHaveBeenCalledTimes(1);
expect(Create.vsam).toHaveBeenCalledWith(fakeSession, dataSetName, {});
// Validate that the function was called correctly
expect(createVsamSpy).toHaveBeenCalledTimes(1);
expect(createVsamSpy).toHaveBeenCalledWith(expect.any(Object), dataSetName, {});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,35 @@ describe("Create z/OS file system handler", () => {
throw impErr;
});

try {
// Invoke the handler with a full set of mocked arguments and response functions
await handler.process({

arguments: {
$0: "fake",
_: ["fake"],
fileSystemName,
...UNIT_TEST_ZOSMF_PROF_OPTS
const commandParameters = {
arguments: {
$0: "fake",
_: ["fake"],
fileSystemName,
...UNIT_TEST_ZOSMF_PROF_OPTS,
},
response: {
data: {
setMessage: jest.fn((setMsgArgs) => {
apiMessage = setMsgArgs;
}),
setObj: jest.fn((setObjArgs) => {
jsonObj = setObjArgs;
}),
},
response: {
data: {
setMessage: jest.fn((setMsgArgs) => {
apiMessage = setMsgArgs;
}),
setObj: jest.fn((setObjArgs) => {
jsonObj = setObjArgs;
})
},
console: {
log: jest.fn((logArgs) => {
logMessage += "\n" + logArgs;
})
}
}
} as any);
console: {
log: jest.fn((logArgs) => {
logMessage += "\n" + logArgs;
}),
},
progress: {
endBar: jest.fn(), // Mocking progress.endBar here
},
},
};

try {
await handler.process(commandParameters);
} catch (e) {
error = e;
}
Expand Down
Loading

0 comments on commit fdf1e70

Please sign in to comment.