diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/local-file/cli.zos-jobs.submit.local-file.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/local-file/cli.zos-jobs.submit.local-file.system.test.ts index 8458d2fe76..ad2d28d772 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/local-file/cli.zos-jobs.submit.local-file.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/local-file/cli.zos-jobs.submit.local-file.system.test.ts @@ -13,9 +13,9 @@ import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { IO, Session } from "@zowe/imperative"; +import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; import { Get } from "../../../../../../zosfiles/src/methods/get"; - process.env.FORCE_COLOR = "0"; // Test Environment populated in the beforeAll(); @@ -24,6 +24,8 @@ let REAL_SESSION: Session; let systemProps: ITestPropertiesSchema; let account: string; let jcl: string; +let JOB_NAME: string; + describe("zos-jobs submit local-file command", () => { // Create the unique test environment beforeAll(async () => { @@ -33,37 +35,51 @@ describe("zos-jobs submit local-file command", () => { }); systemProps = TEST_ENVIRONMENT.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = systemProps.tso.account; - const maxJobNamePrefixLength = 5; + // JCL to submit jcl = (await Get.dataSet(REAL_SESSION, systemProps.zosjobs.iefbr14Member)).toString(); - // Create an local file with JCL to submit + // Create a local file with JCL to submit const bufferJCL: Buffer = Buffer.from(jcl); IO.createFileSync(__dirname + "/testFileOfLocalJCL.txt"); IO.writeFile(__dirname + "/testFileOfLocalJCL.txt", bufferJCL); + + // Add the local file to resources for cleanup + TEST_ENVIRONMENT.resources.localFiles.push(__dirname + "/testFileOfLocalJCL.txt"); }); afterAll(async () => { + // Cleanup jobs before the environment is torn down + if (JOB_NAME) { + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); + TEST_ENVIRONMENT.resources.jobs.push(...jobs); + } + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); - IO.deleteFile(__dirname + "/testFileOfLocalJCL.txt"); }); describe("Live system tests", () => { it("should submit a job in an existing valid local file", async () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_local_file.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt"]); + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("jobname"); expect(response.stdout.toString()).toContain("jobid"); + + // Set jobname for cleanup of all jobs + const jobidRegex = /jobname: (\w+)/; + const match = response.stdout.toString().match(jobidRegex); + JOB_NAME = match ? match[1] : null; }); it("should submit a job in an existing valid local file with explicit RECFM, LRECL, and encoding", async () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_local_file.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt", "--job-encoding IBM-037 --job-record-format F --job-record-length 80"]); + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("jobname"); @@ -73,6 +89,7 @@ describe("zos-jobs submit local-file command", () => { it("should submit a job in an existing valid local file with 'view-all-spool-content' option", async () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_local_file_vasc.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt", "--vasc"]); + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Spool file"); @@ -82,6 +99,7 @@ describe("zos-jobs submit local-file command", () => { it("should submit a job and wait for it to reach output status", async () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_local_file_wait.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt"]); + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("jobname"); @@ -89,19 +107,19 @@ describe("zos-jobs submit local-file command", () => { expect(response.stdout.toString()).toContain("CC 0000"); expect(response.stdout.toString()).not.toContain("null"); // retcode should not be null }); + it("should submit a job in an existing valid local file with 'directory' option", async () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_local_file_with_directory.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt", "--directory", "./"]); + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("jobname"); expect(response.stdout.toString()).toContain("jobid"); expect(response.stdout.toString()).toContain("Successfully downloaded output to ./"); - expect(new RegExp("JOB\\d{5}", "g").test(response.stdout.toString())).toBe(true); }); describe("without profiles", () => { - // Create a separate test environment for no profiles let TEST_ENVIRONMENT_NO_PROF: ITestEnvironment; let DEFAULT_SYSTEM_PROPS: ITestPropertiesSchema; @@ -115,6 +133,12 @@ describe("zos-jobs submit local-file command", () => { }); afterAll(async () => { + // Cleanup jobs before the environment is torn down + if (JOB_NAME) { + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); + TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(...jobs); + } + await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); @@ -140,8 +164,12 @@ describe("zos-jobs submit local-file command", () => { expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("jobname"); expect(response.stdout.toString()).toContain("jobid"); + + // Set jobname for cleanup of all jobs + const jobidRegex = /jobname: (\w+)/; + const match = response.stdout.toString().match(jobidRegex); + JOB_NAME = match ? match[1] : null; }); }); }); - }); diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/stdin/cli.zos-jobs.submit.stdin.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/stdin/cli.zos-jobs.submit.stdin.system.test.ts index c697e8fcc5..a15e16bf82 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/stdin/cli.zos-jobs.submit.stdin.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/stdin/cli.zos-jobs.submit.stdin.system.test.ts @@ -13,9 +13,9 @@ import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { IO, Session } from "@zowe/imperative"; +import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; import { Get } from "../../../../../../zosfiles/src/methods/get"; - process.env.FORCE_COLOR = "0"; // Test Environment populated in the beforeAll(); @@ -24,6 +24,8 @@ let REAL_SESSION: Session; let systemProps: ITestPropertiesSchema; let account: string; let jcl: string; +let JOB_NAME: string; + describe("zos-jobs submit stdin command", () => { beforeAll(async () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ @@ -35,19 +37,27 @@ describe("zos-jobs submit stdin command", () => { REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = systemProps.tso.account; - const maxJobNamePrefixLength = 5; + // JCL to submit jcl = (await Get.dataSet(REAL_SESSION, systemProps.zosjobs.iefbr14Member)).toString(); - // Create an local file with JCL to submit + // Create a local file with JCL to submit const bufferJCL: Buffer = Buffer.from(jcl); IO.createFileSync(__dirname + "/testFileOfLocalJCL.txt"); IO.writeFile(__dirname + "/testFileOfLocalJCL.txt", bufferJCL); + + // Add the local file to resources for cleanup + TEST_ENVIRONMENT.resources.localFiles.push(__dirname + "/testFileOfLocalJCL.txt"); }); afterAll(async () => { + // Cleanup jobs before the environment is torn down + if (JOB_NAME) { + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); + TEST_ENVIRONMENT.resources.jobs.push(...jobs); + } + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); - IO.deleteFile(__dirname + "/testFileOfLocalJCL.txt"); }); describe("Live system tests", () => { @@ -58,6 +68,11 @@ describe("zos-jobs submit stdin command", () => { expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("jobname"); expect(response.stdout.toString()).toContain("jobid"); + + // Set jobname for cleanup of all jobs + const jobidRegex = /jobname: (\w+)/; + const match = response.stdout.toString().match(jobidRegex); + JOB_NAME = match ? match[1] : null; }); it("should submit a job using JCL on stdin with explicit LRECL, RECFM, and encoding", async () => { @@ -77,6 +92,7 @@ describe("zos-jobs submit stdin command", () => { expect(response.stdout.toString()).toContain("Spool file"); expect(response.stdout.toString()).toContain("JES2"); }); + it("should submit a job and wait for it to reach output status", async () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_stdin_wait.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt"]); @@ -87,6 +103,7 @@ describe("zos-jobs submit stdin command", () => { expect(response.stdout.toString()).toContain("CC 0000"); expect(response.stdout.toString()).not.toContain("null"); // retcode should not be null }); + it("should submit a job using JCL on stdin with 'directory' option", async () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_stdin_with_directory.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt", "--directory", "./"]); @@ -95,11 +112,9 @@ describe("zos-jobs submit stdin command", () => { expect(response.stdout.toString()).toContain("jobname"); expect(response.stdout.toString()).toContain("jobid"); expect(response.stdout.toString()).toContain("Successfully downloaded output to ./"); - expect(new RegExp("JOB\\d{5}", "g").test(response.stdout.toString())).toBe(true); }); describe("without profiles", () => { - // Create a separate test environment for no profiles let TEST_ENVIRONMENT_NO_PROF: ITestEnvironment; let DEFAULT_SYSTEM_PROPS: ITestPropertiesSchema; @@ -113,6 +128,12 @@ describe("zos-jobs submit stdin command", () => { }); afterAll(async () => { + // Cleanup jobs before the environment is torn down + if (JOB_NAME) { + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); + TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(...jobs); + } + await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); @@ -138,6 +159,11 @@ describe("zos-jobs submit stdin command", () => { expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("jobname"); expect(response.stdout.toString()).toContain("jobid"); + + // Set jobname for cleanup of all jobs + const jobidRegex = /jobname: (\w+)/; + const match = response.stdout.toString().match(jobidRegex); + JOB_NAME = match ? match[1] : null; }); }); });