Skip to content

Commit

Permalink
finishing cliZosjobsSubmit
Browse files Browse the repository at this point in the history
Signed-off-by: ATorrise <[email protected]>
  • Loading branch information
ATorrise committed Aug 23, 2024
1 parent e1f2ca2 commit 4ccaad5
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 () => {
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -82,26 +99,27 @@ 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");
expect(response.stdout.toString()).toContain("retcode");
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<ITestPropertiesSchema>;
let DEFAULT_SYSTEM_PROPS: ITestPropertiesSchema;
Expand All @@ -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);
});

Expand All @@ -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;
});
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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({
Expand All @@ -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", () => {
Expand All @@ -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 () => {
Expand All @@ -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"]);
Expand All @@ -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", "./"]);
Expand All @@ -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<ITestPropertiesSchema>;
let DEFAULT_SYSTEM_PROPS: ITestPropertiesSchema;
Expand All @@ -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);
});

Expand All @@ -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;
});
});
});
Expand Down

0 comments on commit 4ccaad5

Please sign in to comment.