From d993866fa333ddc2d54956475f83cd1bc0d527ed Mon Sep 17 00:00:00 2001 From: ATorrise Date: Tue, 6 Aug 2024 09:32:02 -0400 Subject: [PATCH 01/65] keeping track of resources created during tests and adding cleanup Signed-off-by: ATorrise --- .../cli-test-utils/src/TestUtils.ts | 30 ++++++++++++++++++- .../src/environment/TestEnvironment.ts | 22 +++++++++++--- .../doc/response/ITestEnvironment.ts | 5 ++++ 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts index bda522b7b1..9c96fd4673 100644 --- a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts +++ b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts @@ -10,10 +10,38 @@ */ import * as fs from "fs"; -import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process"; +import { spawnSync, SpawnSyncReturns, ExecFileException, execSync } from "child_process"; import { ITestEnvironment } from "./environment/doc/response/ITestEnvironment"; import { CommandProfiles, ICommandDefinition, IHandlerParameters } from "@zowe/imperative"; +/** + * Delete a uss file from the mainframe + * @param {string} filePath - The USS path to the file + */ +export function deleteFiles(filePath: string): void { + if (fs.existsSync(filePath)) { + fs.unlinkSync(filePath); + } + execSync(`zowe zos-files delete uss-file "${filePath}" -f`); + +} + +/** + * Delete a job by job ID + * @param {string} jobId - The ID of the job + */ +export function deleteJob(jobId: string): void { + execSync(`zowe zos-jobs delete job ${jobId}`); +} + +/** + * Delete a dataset by name + * @param {string} datasetName - The name of the dataset + */ +export function deleteDataset(datasetName: string): void { + execSync(`zowe zos-files delete data-set "${datasetName}" -f`); +} + /** * Execute a CLI script * @export diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index 2ebefad416..623a06b845 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -11,16 +11,14 @@ import * as fs from "fs"; import * as nodePath from "path"; - import * as yaml from "js-yaml"; import { v4 as uuidv4 } from "uuid"; import { ImperativeError, ImperativeExpect, IO, Logger, LoggingConfigurer, TextUtils } from "@zowe/imperative"; - import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; import { PROJECT_ROOT_DIR, TEST_RESOURCE_DIR, TEST_RESULT_DATA_DIR, TEST_USING_WORKSPACE } from "../TestConstants"; -import { runCliScript } from "../TestUtils"; +import { runCliScript, deleteFiles, deleteJob, deleteDataset } from "../TestUtils"; /** * Use the utility methods here to setup the test environment for running APIs @@ -66,7 +64,12 @@ export class TestEnvironment { const result: ITestEnvironment = { workingDir: testDirectory, systemTestProperties: systemProps, - env + env, + resources: { + files: [], + jobs: [], + datasets: [] + } }; if (params.installPlugin) { @@ -102,6 +105,17 @@ export class TestEnvironment { const pluginDir = testEnvironment.workingDir + "/plugins"; require("rimraf").sync(pluginDir); } + + // Clean up resources + for (const file of testEnvironment.resources.files) { + deleteFiles(file); + } + for (const job of testEnvironment.resources.jobs) { + deleteJob(job); + } + for (const dataset of testEnvironment.resources.datasets) { + deleteDataset(dataset); + } } /** diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts index 2859aea890..35247ecc2c 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts @@ -15,6 +15,11 @@ * @interface ITestEnvironment */ export interface ITestEnvironment { + resources: { + files: string[]; + jobs: string[]; + datasets: string[]; + }; /** * The working directory for your test environment. It is a unique (uuid) area where your tests can create * their home folders (for imperative, etc.) and you can use the area as scratch for any files, etc. that From 3b01d28f7b9ccf42459eecf493ea03205c9a2ae6 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 14 Aug 2024 17:04:18 -0400 Subject: [PATCH 02/65] tests that ive been preoccupied with Signed-off-by: ATorrise --- .../cli-test-utils/src/TestUtils.ts | 26 +- .../src/environment/TestEnvironment.ts | 30 +- .../doc/response/ITestEnvironment.ts | 6 +- .../job/search_string_spool_content.sh | 28 +- .../__system__/CancelJobs.system.test.ts | 33 +- .../__system__/DownloadJobs.system.test.ts | 20 +- .../__system__/GetJobs.system.test.ts | 2585 +++++++++-------- .../__snapshots__/GetJobs.system.test.ts.snap | 19 - 8 files changed, 1403 insertions(+), 1344 deletions(-) delete mode 100644 packages/zosjobs/__tests__/__system__/__snapshots__/GetJobs.system.test.ts.snap diff --git a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts index 9c96fd4673..e7cb4a45cf 100644 --- a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts +++ b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts @@ -12,7 +12,8 @@ import * as fs from "fs"; import { spawnSync, SpawnSyncReturns, ExecFileException, execSync } from "child_process"; import { ITestEnvironment } from "./environment/doc/response/ITestEnvironment"; -import { CommandProfiles, ICommandDefinition, IHandlerParameters } from "@zowe/imperative"; +import { AbstractSession, CommandProfiles, ICommandDefinition, IHandlerParameters } from "@zowe/imperative"; +import { DeleteJobs, IDeleteJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; /** * Delete a uss file from the mainframe @@ -27,11 +28,26 @@ export function deleteFiles(filePath: string): void { } /** - * Delete a job by job ID - * @param {string} jobId - The ID of the job + * Delete a job from the mainframe using Zowe SDKs - IJob + * @param {AbstractSession} session - z/OSMF connection info + * @param {IJob} job - the job that you want to delete */ -export function deleteJob(jobId: string): void { - execSync(`zowe zos-jobs delete job ${jobId}`); +export function deleteJob(session: AbstractSession, job: IJob): void { + DeleteJobs.deleteJobForJob(session, job); +} + +/** + * Delete a job from the mainframe using Zowe SDKs - jobid, jobname + * @param {AbstractSession} session - z/OSMF connection info + * @param {jobName} string - jobname for job to delete + * @param {jobId} string - jobid for job to delete + */ +export function deleteJobCommon(session: AbstractSession, job: IJob): void { + const parms: IDeleteJobParms = { + jobid: job.jobid, // job ID + jobname: job.jobname, // job name + }; + DeleteJobs.deleteJobCommon(session, parms); } /** diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index 623a06b845..c3542c6729 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -13,7 +13,7 @@ import * as fs from "fs"; import * as nodePath from "path"; import * as yaml from "js-yaml"; import { v4 as uuidv4 } from "uuid"; -import { ImperativeError, ImperativeExpect, IO, Logger, LoggingConfigurer, TextUtils } from "@zowe/imperative"; +import { AbstractSession, ImperativeError, ImperativeExpect, IO, Logger, LoggingConfigurer, ProfileInfo, Session, TextUtils } from "@zowe/imperative"; import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; @@ -41,7 +41,7 @@ export class TestEnvironment { * @returns {Promise} * @memberof TestEnvironment */ - public static async setUp(params: ISetupEnvironmentParms): Promise> { + public static async setUp(params: ISetupEnvironmentParms, session?: AbstractSession): Promise> { // Validate the input parameters ImperativeExpect.toNotBeNullOrUndefined(params, `${TestEnvironment.ERROR_TAG} createTestEnv(): No parameters supplied.`); @@ -68,7 +68,8 @@ export class TestEnvironment { resources: { files: [], jobs: [], - datasets: [] + datasets: [], + ...(session && { session }) // Only include session if it is passed in } }; @@ -88,6 +89,24 @@ export class TestEnvironment { return result; } + /** + * Create a session using the default z/OSMF profile (if a session has not been added to test) + * @returns {Promise} - A promise that resolves to the created session object + * @throws Will throw an error if reading profiles or creating the session fails + * @memberof TestEnvironment + */ + public static async createSession(): Promise { + // Load connection info from default z/OSMF profile + const profInfo = new ProfileInfo("zowe"); + await profInfo.readProfilesFromDisk(); + const zosmfProfAttrs = profInfo.getDefaultProfile("zosmf"); + if (!zosmfProfAttrs) { + throw new Error("Default z/OSMF profile not found."); + } + const zosmfMergedArgs = profInfo.mergeArgsForProfile(zosmfProfAttrs, { getSecureVals: true }); + return ProfileInfo.createSession(zosmfMergedArgs.knownArgs); + } + /** * Clean up your test environment. * Deletes any temporary profiles that have been created @@ -107,11 +126,14 @@ export class TestEnvironment { } // Clean up resources + // Check if session exists; if not, create one + const session = testEnvironment.resources.session || await TestEnvironment.createSession(); + for (const file of testEnvironment.resources.files) { deleteFiles(file); } for (const job of testEnvironment.resources.jobs) { - deleteJob(job); + deleteJob(session, job); } for (const dataset of testEnvironment.resources.datasets) { deleteDataset(dataset); diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts index 35247ecc2c..2ec63762a9 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts @@ -9,6 +9,9 @@ * */ +import { AbstractSession } from "@zowe/imperative"; +import { IJob } from "@zowe/zos-jobs-for-zowe-sdk"; + /** * The test environment for your test. * @export @@ -17,8 +20,9 @@ export interface ITestEnvironment { resources: { files: string[]; - jobs: string[]; + jobs: IJob[]; datasets: string[]; + session?: AbstractSession; }; /** * The working directory for your test environment. It is a unique (uuid) area where your tests can create diff --git a/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_string_spool_content.sh b/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_string_spool_content.sh index 4ee6abe2a9..832ba5067a 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_string_spool_content.sh +++ b/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_string_spool_content.sh @@ -1,21 +1,27 @@ #!/bin/bash -# TODO - delete the job from spool + # Submit the job and ensure the RC is 0 JOBID="$(zowe jobs submit ds "$1" --wfo true --rff jobid --rft string)" CMDRC=$? -if [ $CMDRC -gt 0 ] -then - echo $JOBID 1>&2 - echo "Submit returned a non-zero return code" 1>&2 +echo "Job ID: $JOBID" +if [ $CMDRC -gt 0 ]; then + echo "Job submission failed with return code $CMDRC" 1>&2 exit $CMDRC fi -zowe jobs search job "$2" --search-string "$3" +# Ensure the job ID is valid +if [ -z "$JOBID" ]; then + echo "Job ID is empty, cannot proceed with the search." 1>&2 + exit 1 +fi + +# Wait for a few seconds to ensure job output is available +sleep 5 + +# Search the job's spool files +zowe jobs search job "$JOBID" --search-string "$3" RC=$? -if [ $RC -gt 0 ] -then - echo $STATUS 1>&2 +if [ $RC -gt 0 ]; then echo "The search spool job command returned a non-zero rc: $RC" 1>&2 exit $RC -fi - +fi \ No newline at end of file diff --git a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts index 06822f259d..62b320bb4b 100644 --- a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts @@ -11,10 +11,9 @@ import { ImperativeError, Session, RestClientError } from "@zowe/imperative"; import { CancelJobs, SubmitJobs, IJob } from "../../src"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { JobTestsUtils } from "./JobTestsUtils"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let sleepJCL: string; @@ -28,23 +27,26 @@ describe("CancelJobs System tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); systemProps = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer sleepJCL = JobTestsUtils.getSleepJCL(REAL_SESSION.ISession.user, ACCOUNT, systemProps.zosjobs.jobclass, maxStepNum); }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + describe("Positive tests", () => { it("should be able to cancel a job using cancelJob (modify version 1)", async () => { const job = await SubmitJobs.submitJclNotifyCommon(REAL_SESSION, {jcl: sleepJCL, status: "INPUT"}); expect(job.retcode).toBeNull(); // job is not complete, no CC const response = await CancelJobs.cancelJob(REAL_SESSION, job.jobname, job.jobid, "1.0"); expect(response).toBeUndefined(); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJob (modify version 2)", async () => { @@ -53,6 +55,7 @@ describe("CancelJobs System tests", () => { const response = await CancelJobs.cancelJob(REAL_SESSION, job.jobname, job.jobid, "2.0"); expect(response).not.toBeUndefined(); expect(response?.status).toEqual("0"); // intermittent failure + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJob (modify version default)", async () => { @@ -61,6 +64,7 @@ describe("CancelJobs System tests", () => { const response = await CancelJobs.cancelJob(REAL_SESSION, job.jobname, job.jobid); expect(response).not.toBeUndefined(); expect(response?.status).toEqual("0"); // intermittent failure + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJobForJob (modify version 1)", async () => { @@ -68,6 +72,7 @@ describe("CancelJobs System tests", () => { expect(job.retcode).toBeNull(); // job is not complete, no CC const response = await CancelJobs.cancelJobForJob(REAL_SESSION, job, "1.0"); expect(response).toBeUndefined(); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJobForJob (modify version 2)", async () => { @@ -76,6 +81,7 @@ describe("CancelJobs System tests", () => { const response = await CancelJobs.cancelJobForJob(REAL_SESSION, job, "2.0"); expect(response).not.toBeUndefined(); expect(response?.status).toEqual("0"); // intermittent failure + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJobForJob (modify version default)", async () => { @@ -84,6 +90,7 @@ describe("CancelJobs System tests", () => { const response = await CancelJobs.cancelJobForJob(REAL_SESSION, job); expect(response).not.toBeUndefined(); expect(response?.status).toEqual("0"); // intermittent failure + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJobCommon (job version 1)", async () => { @@ -91,6 +98,7 @@ describe("CancelJobs System tests", () => { expect(job.retcode).toBeNull(); // job is not complete, no CC const response = await CancelJobs.cancelJobCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid, version: "1.0"}); expect(response).toBeUndefined(); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJobCommon (job version 2.0 - synchronous)", async () => { @@ -99,6 +107,7 @@ describe("CancelJobs System tests", () => { const response = await CancelJobs.cancelJobCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid, version: "2.0"}); expect(response).toBeDefined(); expect(response?.status).toEqual("0"); // intermittent failure + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJobCommon (job version default)", async () => { @@ -106,6 +115,7 @@ describe("CancelJobs System tests", () => { expect(job.retcode).toBeNull(); // job is not complete, no CC const response = await CancelJobs.cancelJobCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); expect(response?.status).toEqual("0"); // intermittent failure + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJobCommon (job version 2.0 - synchronous) and return an error feedback object", async () => { @@ -115,6 +125,7 @@ describe("CancelJobs System tests", () => { expect(response?.status).toEqual("0"); response = await CancelJobs.cancelJobCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid, version: "2.0"}); expect(response?.status).toEqual("156"); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); }); @@ -177,17 +188,19 @@ describe("CancelJobs System tests - encoded", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs_encoded" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); systemProps = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer sleepJCL = JobTestsUtils.getSleepJCL(REAL_SESSION.ISession.user, ACCOUNT, systemProps.zosjobs.jobclass, maxStepNum, true); }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + describe("Positive tests", () => { it("should be able to cancel a job using cancelJob (modify version default)", async () => { const job = await SubmitJobs.submitJclNotifyCommon(REAL_SESSION, {jcl: sleepJCL, status: "INPUT"}); @@ -195,6 +208,7 @@ describe("CancelJobs System tests - encoded", () => { const response = await CancelJobs.cancelJob(REAL_SESSION, job.jobname, job.jobid); expect(response).not.toBeUndefined(); expect(response?.status).toEqual("0"); // intermittent failure + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJobForJob (modify version default)", async () => { @@ -203,6 +217,7 @@ describe("CancelJobs System tests - encoded", () => { const response = await CancelJobs.cancelJobForJob(REAL_SESSION, job); expect(response).not.toBeUndefined(); expect(response?.status).toEqual("0"); // intermittent failure + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJobCommon (job version default)", async () => { @@ -210,6 +225,7 @@ describe("CancelJobs System tests - encoded", () => { expect(job.retcode).toBeNull(); // job is not complete, no CC const response = await CancelJobs.cancelJobCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); expect(response?.status).toEqual("0"); // intermittent failure + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should be able to cancel a job using cancelJobCommon (job version 2.0 - synchronous) and return an error feedback object", async () => { @@ -219,6 +235,7 @@ describe("CancelJobs System tests - encoded", () => { expect(response?.status).toEqual("0"); response = await CancelJobs.cancelJobCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid, version: "2.0"}); expect(response?.status).toEqual("156"); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); }); }); diff --git a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts index ce1e1bedaa..7a1e029bfe 100644 --- a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts @@ -11,8 +11,7 @@ import { DeleteJobs, DownloadJobs, GetJobs, IJobFile, SubmitJobs } from "../../src"; import { ImperativeError, IO, Session, TextUtils } from "@zowe/imperative"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Get } from "@zowe/zos-files-for-zowe-sdk"; import { MonitorJobs } from "../../src/MonitorJobs"; @@ -43,12 +42,11 @@ describe("Download Jobs - System tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); + outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - // download the valid IEFBR14 from the data set specified in the properties file iefbr14DataSet = testEnvironment.systemTestProperties.zosjobs.iefbr14Member; iefbr14JCL = (await Get.dataSet(REAL_SESSION, iefbr14DataSet)).toString(); @@ -56,6 +54,7 @@ describe("Download Jobs - System tests", () => { const job = await SubmitJobs.submitJclNotifyCommon(REAL_SESSION, { jcl: iefbr14JCL }); + testEnvironment.resources.jobs.push(job); jobid = job.jobid; jobname = job.jobname; jobFiles = await GetJobs.getSpoolFiles(REAL_SESSION, jobname, jobid); @@ -79,6 +78,7 @@ describe("Download Jobs - System tests", () => { afterAll(async () => { await DeleteJobs.deleteJob(REAL_SESSION, jobname, jobid); + await TestEnvironment.cleanUp(testEnvironment); }); describe("Special Positive tests", () => { @@ -91,6 +91,7 @@ describe("Download Jobs - System tests", () => { const job = await SubmitJobs.submitJclNotifyCommon(REAL_SESSION, { jcl: iefbr14JCLAltered }); + testEnvironment.resources.jobs.push(job); alteredjobid = job.jobid; alteredjobname = job.jobname; alteredjobFiles = await GetJobs.getSpoolFiles(REAL_SESSION, alteredjobname, alteredjobid); @@ -259,6 +260,8 @@ describe("Download Jobs - System tests", () => { const job: IJob = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + testEnvironment.resources.jobs.push(job); + await MonitorJobs.waitForJobOutputStatus(REAL_SESSION, job); await DownloadJobs.downloadAllSpoolContentCommon(REAL_SESSION, { @@ -352,11 +355,11 @@ describe("Download Jobs - System tests - Encoded", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs_encoded" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); + outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); const ACCOUNT = defaultSystem.tso.account; const iefbr14JCL = JobTestsUtils.getIefbr14JCL(REAL_SESSION.ISession.user, ACCOUNT, defaultSystem.zosjobs.jobclass, 1, true); @@ -364,6 +367,7 @@ describe("Download Jobs - System tests - Encoded", () => { const job = await SubmitJobs.submitJclNotifyCommon(REAL_SESSION, { jcl: iefbr14JCL }); + testEnvironment.resources.jobs.push(job); jobid = job.jobid; jobname = job.jobname; jobFiles = await GetJobs.getSpoolFiles(REAL_SESSION, jobname, jobid); @@ -386,6 +390,7 @@ describe("Download Jobs - System tests - Encoded", () => { afterAll(async () => { await DeleteJobs.deleteJob(REAL_SESSION, jobname, jobid); + await TestEnvironment.cleanUp(testEnvironment); }); describe("Positive tests", () => { @@ -498,6 +503,7 @@ describe("Download Jobs - System tests - Encoded", () => { {JOBNAME: DOWNLOAD_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); const job: IJob = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + testEnvironment.resources.jobs.push(job); await MonitorJobs.waitForJobOutputStatus(REAL_SESSION, job); diff --git a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts index 5a65c75ec6..b31d81a580 100644 --- a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts @@ -10,51 +10,34 @@ */ import { JOB_STATUS } from "./../../src/types/JobStatus"; -import { ImperativeError, Session, TextUtils } from "@zowe/imperative"; -import { DeleteJobs, GetJobs, IJob, JOB_STATUS_ORDER, SubmitJobs } from "../../src"; +import { AbstractSession, ImperativeError, Session, TextUtils } from "@zowe/imperative"; import * as fs from "fs"; -import { TEST_RESOURCES_DIR } from "../__src__/ZosJobsTestConstants"; import { join } from "path"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { TEST_RESOURCES_DIR } from "../__src__/ZosJobsTestConstants"; +import { GetJobs, DeleteJobs, IJob, JOB_STATUS_ORDER, SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; /**********************************************************************************/ let ACCOUNT: string; -// The job class for holding jobs on the input queue let JOBCLASS: string; let SYSAFF: string; -// Session to use for the tests -let REAL_SESSION: Session; +let REAL_SESSION: AbstractSession; +let defaultSystem: ITestPropertiesSchema; +let testEnvironment: ITestEnvironment; -// Invalid credentials session let INVALID_SESSION: Session; -// The job name - should be the same for cleanup, etc. -const SIX_CHARS = 6; let MONITOR_JOB_NAME: string; const TEST_JOB_NAME = "TSTMB"; -// Sample JCL - TODO replace by JCL resources -let JCL: string; +let JCL: string; //TODO: replace by JCL resources const trimMessage = (message: string) => { // don't use more than one space or tab when checking error details // this allows us to expect things like "reason: 6" regardless of how prettyjson aligns the text return message.replace(/( {2,})|\t/g, " "); }; -const waitThreeSeconds = () => { - return new Promise((resolveWaitTime) => { - const threeSeconds = 3000; - setTimeout(() => { - resolveWaitTime(); - }, threeSeconds); - } - ); -}; - -let defaultSystem: ITestPropertiesSchema; -let testEnvironment: ITestEnvironment; // Utility function to cleanup async function cleanTestJobs(prefix: string) { @@ -63,7 +46,7 @@ async function cleanTestJobs(prefix: string) { if (jobs.length > 0) { for (const job of jobs) { try { - const response = await DeleteJobs.deleteJob(REAL_SESSION, job.jobname, job.jobid); + await DeleteJobs.deleteJob(REAL_SESSION, job.jobname, job.jobid); } catch (e) { // Don't worry about it } @@ -73,61 +56,59 @@ async function cleanTestJobs(prefix: string) { const LONG_TIMEOUT = 200000; -describe("Get Jobs - System Tests", () => { +describe("Get Jobs System Tests", () => { + describe("Non-Encoded System Tests", () => { + beforeAll(async () => { + REAL_SESSION = await TestEnvironment.createSession(); - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_get_jobs" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - - INVALID_SESSION = new Session({ - user: "fakeuser", - password: "fake", - hostname: defaultSystem.zosmf.host, - port: defaultSystem.zosmf.port, - basePath: defaultSystem.zosmf.basePath, - type: "basic", - rejectUnauthorized: false - }); + testEnvironment = await TestEnvironment.setUp({ + testName: "get_jobs_system_test" + }, REAL_SESSION); + + defaultSystem = testEnvironment.systemTestProperties; - ACCOUNT = defaultSystem.tso.account; - MONITOR_JOB_NAME = REAL_SESSION.ISession.user?.toUpperCase().substring(0, SIX_CHARS) + "G"; + INVALID_SESSION = new Session({ + user: "fakeuser", + password: "fake", + hostname: defaultSystem.zosmf.host, + port: defaultSystem.zosmf.port, + type: "basic", + rejectUnauthorized: false + }); - JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; - SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; + ACCOUNT = defaultSystem.tso.account; + MONITOR_JOB_NAME = REAL_SESSION.ISession.user?.toUpperCase().substring(0, 5) + "#G"; - // TODO: What string goes in the removed section? - JCL = - "//" + MONITOR_JOB_NAME + " JOB '" + ACCOUNT + "',CLASS=" + JOBCLASS + "\n" + - "//IEFBR14 EXEC PGM=IEFBR14"; // GetJobs - }); + JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; + SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; - // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently - // outstanding) when the tests run - beforeEach(async () => { - await cleanTestJobs(MONITOR_JOB_NAME); - await cleanTestJobs(TEST_JOB_NAME); - }); - afterEach(async () => { - await cleanTestJobs(MONITOR_JOB_NAME); - await cleanTestJobs(TEST_JOB_NAME); - }); + JCL = `//${MONITOR_JOB_NAME} JOB '${ACCOUNT}',CLASS=${JOBCLASS}\n//IEFBR14 EXEC PGM=IEFBR14`; + }); + + afterAll(async () => { + // For deleting jobs/resources + await TestEnvironment.cleanUp(testEnvironment); + }); - /**********************************************/ - // API methods "getJobs..." system tests - describe("Get Jobs APIs", () => { + // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently + // outstanding) when the tests run + beforeEach(async () => { + await cleanTestJobs(MONITOR_JOB_NAME); + await cleanTestJobs(TEST_JOB_NAME); + }); + afterEach(async () => { + await cleanTestJobs(MONITOR_JOB_NAME); + await cleanTestJobs(TEST_JOB_NAME); + }); /**********************************************/ - // API methods "getJobs" system tests - describe("get jobs API", () => { - describe("invalid request error handling", () => { + // API methods "getJobsByPrefix" system tests + describe("get jobs by prefix API", () => { + describe("invalid request handling", () => { it("should detect and surface an error for an invalid user", async () => { let err; try { - await GetJobs.getJobs(INVALID_SESSION); + const resp = await GetJobs.getJobsByPrefix(INVALID_SESSION, "TEST"); } catch (e) { err = e; } @@ -135,10 +116,28 @@ describe("Get Jobs - System Tests", () => { expect(err instanceof ImperativeError).toBe(true); expect(err.message).toContain("status 401"); // unauthorized - bad credentials }); + + it("should detect and surface an error for an invalid prefix (by z/OS standards)", async () => { + let err; + try { + await GetJobs.getJobsByPrefix(REAL_SESSION, "~~~~~"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(4); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("prefix query parameter"); + }); }); describe("list jobs", () => { - it("should return all jobs for the user in the session", async () => { + it("should return all jobs for the prefix of the user id and the owner is the session user id", async () => { // Read the JCL template file const NUM_JOBS = 3; const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); @@ -157,13 +156,14 @@ describe("Get Jobs - System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); jobs.push(job); + testEnvironment.resources.jobs.push(job); } - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); - // Obtain all jobs for the user - const allJobs: IJob[] = await GetJobs.getJobs(REAL_SESSION); + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + + // Obtain the three jobs submitted + const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, MONITOR_JOB_NAME + "*"); expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); // Search all jobs returned for each of the submitted jobs @@ -179,894 +179,991 @@ describe("Get Jobs - System Tests", () => { }); }, LONG_TIMEOUT); - it("should be able to get a single job by job ID", async () => { + it("should throw an error if we specify a job ID that doesn't exist", async () => { + let err: ImperativeError; + try { + await GetJobs.getJob(REAL_SESSION, "J999999"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err.causeErrors).toContain("Zero jobs"); + }); + + it("should return no jobs for a prefix that doesn't match anything", async () => { + const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, "FAKENE"); + expect(allJobs.length).toBe(0); + }); + + it("should return all jobs for the non user id prefix specified and the owner is the session user id", async () => { // Read the JCL template file + const NUM_JOBS = 3; const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - // submit a job that we can list - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Submit a few jobs to list + const jobs: IJob[] = []; + for (let x = 0; x < NUM_JOBS; x++) { - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: TEST_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + jobs.push(job); + testEnvironment.resources.jobs.push(job); + } + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); + // Obtain the three jobs submitted + const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, TEST_JOB_NAME + "*"); + expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); // Search all jobs returned for each of the submitted jobs - const foundJob = await GetJobs.getJob(REAL_SESSION, job.jobid); - expect(foundJob).toBeDefined(); - expect(foundJob.jobid).toEqual(job.jobid); - expect(foundJob.jobname).toEqual(job.jobname); + jobs.forEach((submittedJob) => { + let found = false; + for (const returnedJob of allJobs) { + if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { + found = true; + break; + } + } + expect(found).toBe(true); + }); }, LONG_TIMEOUT); }); - - it("should be able to get a single job by job ID with jobid parm on the getJobs API", async () => { - // Read the JCL template file - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - - // submit a job that we can list - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); - - - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); - - // Search all jobs returned for each of the submitted jobs - const foundJobs = await GetJobs.getJobsCommon(REAL_SESSION, {jobid: job.jobid}); - expect(foundJobs).toBeDefined(); - expect(foundJobs.length).toEqual(1); - expect(foundJobs[0].jobid).toEqual(job.jobid); - expect(foundJobs[0].jobname).toEqual(job.jobname); - }, LONG_TIMEOUT); - }); - }); - - /**********************************************/ - // API methods "getJobsByPrefix" system tests - describe("get jobs by prefix API", () => { - describe("invalid request handling", () => { - it("should detect and surface an error for an invalid user", async () => { - let err; - try { - const resp = await GetJobs.getJobsByPrefix(INVALID_SESSION, "TEST"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - expect(err.message).toContain("status 401"); // unauthorized - bad credentials - }); - - it("should detect and surface an error for an invalid prefix (by z/OS standards)", async () => { - let err; - try { - await GetJobs.getJobsByPrefix(REAL_SESSION, "~~~~~"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(4); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("prefix query parameter"); - }); }); + /**********************************************/ + // API methods "getJobs..." system tests + describe("Get Jobs APIs", () => { + + /**********************************************/ + // API methods "getJobs" system tests + describe("get jobs API", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for an invalid user", async () => { + let err; + try { + await GetJobs.getJobs(INVALID_SESSION); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + expect(err.message).toContain("status 401"); // unauthorized - bad credentials + }); + }); - describe("list jobs", () => { - it("should return all jobs for the prefix of the user id and the owner is the session user id", async () => { - // Read the JCL template file - const NUM_JOBS = 3; - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - - // Submit a few jobs to list - const jobs: IJob[] = []; - for (let x = 0; x < NUM_JOBS; x++) { + describe("list jobs", () => { + it("should return all jobs for the user in the session", async () => { + // Read the JCL template file + const NUM_JOBS = 3; + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + + // Submit a few jobs to list + const jobs: IJob[] = []; + for (let x = 0; x < NUM_JOBS; x++) { + + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + jobs.push(job); + testEnvironment.resources.jobs.push(job); + } + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + + // Obtain all jobs for the user + const allJobs: IJob[] = await GetJobs.getJobs(REAL_SESSION); + expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); + + // Search all jobs returned for each of the submitted jobs + jobs.forEach((submittedJob) => { + let found = false; + for (const returnedJob of allJobs) { + if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { + found = true; + break; + } + } + expect(found).toBe(true); + }); + }, LONG_TIMEOUT); - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should be able to get a single job by job ID", async () => { + // Read the JCL template file + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); - jobs.push(job); - } + // submit a job that we can list + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); - // Obtain the three jobs submitted - const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, MONITOR_JOB_NAME + "*"); - expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds - // Search all jobs returned for each of the submitted jobs - jobs.forEach((submittedJob) => { - let found = false; - for (const returnedJob of allJobs) { - if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { - found = true; - break; - } - } - expect(found).toBe(true); + // Search all jobs returned for each of the submitted jobs + const foundJob = await GetJobs.getJob(REAL_SESSION, job.jobid); + expect(foundJob).toBeDefined(); + expect(foundJob.jobid).toEqual(job.jobid); + expect(foundJob.jobname).toEqual(job.jobname); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); }); - }, LONG_TIMEOUT); - - it("should throw an error if we specify a job ID that doesn't exist", async () => { - let err: ImperativeError; - try { - await GetJobs.getJob(REAL_SESSION, "J999999"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err.causeErrors).toContain("Zero jobs"); - }); - - it("should return no jobs for a prefix that doesn't match anything", async () => { - const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, "FAKENE"); - expect(allJobs.length).toBe(0); - }); - - it("should return all jobs for the non user id prefix specified and the owner is the session user id", async () => { - // Read the JCL template file - const NUM_JOBS = 3; - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - // Submit a few jobs to list - const jobs: IJob[] = []; - for (let x = 0; x < NUM_JOBS; x++) { + it("should be able to get a single job by job ID with jobid parm on the getJobs API", async () => { + // Read the JCL template file + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + // submit a job that we can list // Render the job with increasing job name const jobRender = iefbr14JclTemplate; const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: TEST_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); // Submit the job const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); - jobs.push(job); - } - - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); - - // Obtain the three jobs submitted - const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, TEST_JOB_NAME + "*"); - expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); - - // Search all jobs returned for each of the submitted jobs - jobs.forEach((submittedJob) => { - let found = false; - for (const returnedJob of allJobs) { - if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { - found = true; - break; - } - } - expect(found).toBe(true); - }); - }, LONG_TIMEOUT); - }); - }); - /**********************************************/ - // API methods "getJobsByPrefix" system tests - describe("get jobs by owner API", () => { - describe("invalid request handling", () => { - it("should detect and surface an error for an invalid user", async () => { - let err; - try { - await GetJobs.getJobsByPrefix(INVALID_SESSION, "TEST"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - expect(err.message).toContain("status 401"); // unauthorized - bad credentials - }); + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds - it("should detect and surface an error for an invalid owner (by z/OS standards)", async () => { - let err; - try { - await GetJobs.getJobsByOwner(REAL_SESSION, "~~~~~"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(4); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("owner query parameter"); + // Search all jobs returned for each of the submitted jobs + const foundJobs = await GetJobs.getJobsCommon(REAL_SESSION, {jobid: job.jobid}); + expect(foundJobs).toBeDefined(); + expect(foundJobs.length).toEqual(1); + expect(foundJobs[0].jobid).toEqual(job.jobid); + expect(foundJobs[0].jobname).toEqual(job.jobname); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); }); }); - describe("list jobs", () => { - it("should return no jobs for a nonexistent owner", async () => { - // Obtain the three jobs submitted - const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, "FAKENE"); - expect(allJobs.length).toBe(0); - }); - - it("should return all jobs for the user (of the session) when specified as the owner", async () => { - // Read the JCL template file - const NUM_JOBS = 3; - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - - // Submit a few jobs to list - const jobs: IJob[] = []; - for (let x = 0; x < NUM_JOBS; x++) { - - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); - jobs.push(job); - } - - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); - // Obtain all jobs for ***REMOVED*** - const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, REAL_SESSION.ISession.user); - expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); - - // Search all jobs returned for each of the submitted jobs - jobs.forEach((submittedJob) => { - let found = false; - for (const returnedJob of allJobs) { - if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { - found = true; - break; - } - } - expect(found).toBe(true); - }); - }, LONG_TIMEOUT); - }); - }); -}); - -/**********************************************/ -// API methods "getStatus..." system tests -describe("Get Status APIs", () => { - - /**********************************************/ - // API methods "getStatus" system tests - describe("get status API", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for an invalid user", - async () => { + /**********************************************/ + // API methods "getJobsByPrefix" system tests + describe("get jobs by owner API", () => { + describe("invalid request handling", () => { + it("should detect and surface an error for an invalid user", async () => { let err; try { - await GetJobs.getStatus(INVALID_SESSION, "FAKE", "FAKE"); + await GetJobs.getJobsByPrefix(INVALID_SESSION, "TEST"); } catch (e) { err = e; } expect(err).toBeDefined(); expect(err instanceof ImperativeError).toBe(true); expect(err.message).toContain("status 401"); // unauthorized - bad credentials - } - ); - - it("should detect and surface an error for an invalid jobname", async () => { - let err; - try { - await GetJobs.getStatus(REAL_SESSION, "))))))))", "JOB123"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - }); + }); - it("should detect and surface an error for an invalid jobid", async () => { - let err; - try { - await GetJobs.getStatus(REAL_SESSION, "***REMOVED***1", "))))))))))"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); + it("should detect and surface an error for an invalid owner (by z/OS standards)", async () => { + let err; + try { + await GetJobs.getJobsByOwner(REAL_SESSION, "~~~~~"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(4); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("owner query parameter"); + }); }); - }); - - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + describe("list jobs", () => { + it("should return no jobs for a nonexistent owner", async () => { + // Obtain the three jobs submitted + const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, "FAKENE"); + expect(allJobs.length).toBe(0); + }); - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + it("should return all jobs for the user (of the session) when specified as the owner", async () => { + // Read the JCL template file + const NUM_JOBS = 3; + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - }); + // Submit a few jobs to list + const jobs: IJob[] = []; + for (let x = 0; x < NUM_JOBS; x++) { - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + jobs.push(job); + testEnvironment.resources.jobs.push(job); + } - // Expect the jobname to match - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + // Obtain all jobs for ***REMOVED*** + const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, REAL_SESSION.ISession.user); + expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); + // Search all jobs returned for each of the submitted jobs + jobs.forEach((submittedJob) => { + let found = false; + for (const returnedJob of allJobs) { + if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { + found = true; + break; + } + } + expect(found).toBe(true); + }); + }, LONG_TIMEOUT); }); + }); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + /**********************************************/ + // API methods "getStatus..." system tests + describe("Get Status APIs", () => { + + /**********************************************/ + // API methods "getStatus" system tests + describe("get status API", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for an invalid user", + async () => { + let err; + try { + await GetJobs.getStatus(INVALID_SESSION, "FAKE", "FAKE"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + expect(err.message).toContain("status 401"); // unauthorized - bad credentials + } + ); + + it("should detect and surface an error for an invalid jobname", async () => { + let err; + try { + await GetJobs.getStatus(REAL_SESSION, "))))))))", "JOB123"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + }); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + it("should detect and surface an error for an invalid jobid", async () => { + let err; + try { + await GetJobs.getStatus(REAL_SESSION, "***REMOVED***1", "))))))))))"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + }); + }); - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - }, LONG_TIMEOUT); - }); - }); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - /**********************************************/ - // API methods "getStatusCommon" system tests - describe("get status common API", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for an invalid user", async () => { - let err; - try { - await GetJobs.getStatusCommon(INVALID_SESSION, {jobname: "FAKE", jobid: "FAKE"}); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - expect(err.message).toContain("status 401"); // unauthorized - bad credentials - }); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - it("should detect and surface an error for an invalid jobname", async () => { - let err; - try { - await GetJobs.getStatusCommon(REAL_SESSION, {jobname: "))))))))", jobid: "JOB123"}); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("JOB123"); - }); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - it("should detect and surface an error for an invalid jobid", async () => { - let err; - try { - await GetJobs.getStatusCommon(REAL_SESSION, {jobname: "***REMOVED***1", jobid: "))))))))))"}); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - }); - }); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + testEnvironment.resources.jobs.push(job); + }); - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + // Expect the jobname to match + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - }); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); + testEnvironment.resources.jobs.push(job); + }); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - // Expect that the status is input - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + }); }); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + /**********************************************/ + // API methods "getStatusCommon" system tests + describe("get status common API", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for an invalid user", async () => { + let err; + try { + await GetJobs.getStatusCommon(INVALID_SESSION, {jobname: "FAKE", jobid: "FAKE"}); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + expect(err.message).toContain("status 401"); // unauthorized - bad credentials + }); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + it("should detect and surface an error for an invalid jobname", async () => { + let err; + try { + await GetJobs.getStatusCommon(REAL_SESSION, {jobname: "))))))))", jobid: "JOB123"}); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("JOB123"); + }); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + it("should detect and surface an error for an invalid jobid", async () => { + let err; + try { + await GetJobs.getStatusCommon(REAL_SESSION, {jobname: "***REMOVED***1", jobid: "))))))))))"}); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + }); + }); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - }, LONG_TIMEOUT); - }); - }); + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - /**********************************************/ - // API methods "getStatusForJob" system tests - describe("get status for job API", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for an invalid user", async () => { - let err; - try { - const job: any = {jobname: "FAKE", jobid: "fake"}; - await GetJobs.getStatusForJob(INVALID_SESSION, job); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - expect(trimmedErrorMessage).toContain("status 401"); - }); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - it("should be able to get a job that was submitted and get proper error when the job is deleted", async () => { - const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); - const jobStatus = await GetJobs.getStatusForJob(REAL_SESSION, job); - - await DeleteJobs.deleteJobForJob(REAL_SESSION, job); - await waitThreeSeconds(); // make sure jobs is deleted - let error; - try { - await GetJobs.getStatusForJob(REAL_SESSION, job); - } catch (thrownError) { - error = thrownError; - } - expect(error).toBeDefined(); - expect(JSON.parse(error.causeErrors).rc).toMatchSnapshot(); - expect(JSON.parse(error.causeErrors).reason).toMatchSnapshot(); - expect(JSON.parse(error.causeErrors).category).toMatchSnapshot(); - }, LONG_TIMEOUT); - - it("should detect and surface an error for an invalid jobname", async () => { - let err; - try { - await GetJobs.getStatusForJob(REAL_SESSION, {jobname: "))))))))", jobid: "JOB123"} as any); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - }); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - it("should detect and surface an error for an invalid jobid", async () => { - let err; - try { - await GetJobs.getStatusForJob(REAL_SESSION, {jobname: "***REMOVED***1", jobid: "))))))))))"} as any); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - }); - }); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + testEnvironment.resources.jobs.push(job); + }); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + // Expect that the status is input + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - }); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); + testEnvironment.resources.jobs.push(job); + }); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - // Expect that the status is input - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + }); }); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + /**********************************************/ + // API methods "getStatusForJob" system tests + describe("get status for job API", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for an invalid user", async () => { + let err; + try { + const job: any = {jobname: "FAKE", jobid: "fake"}; + await GetJobs.getStatusForJob(INVALID_SESSION, job); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + expect(trimmedErrorMessage).toContain("status 401"); + }); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + it("should be able to get a job that was submitted and get proper error when the job is deleted", async () => { + const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + await DeleteJobs.deleteJobForJob(REAL_SESSION, job); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + // Add a delay to ensure job deletion is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - }, LONG_TIMEOUT); - }); - }); -}); - -/**********************************************/ -// API methods "getSpool..." system tests -describe("Get spool APIs", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for getting spool content that doesnt exist", async () => { - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - await DeleteJobs.deleteJobForJob(REAL_SESSION, job); - await waitThreeSeconds(); - let error; - try { - const content = await GetJobs.getSpoolContent(REAL_SESSION, files[0]); - } catch (thrownError) { - error = thrownError; - } - expect(error).toBeDefined(); - expect(JSON.parse(error.causeErrors).rc).toMatchSnapshot(); - expect(JSON.parse(error.causeErrors).reason).toMatchSnapshot(); - expect(JSON.parse(error.causeErrors).category).toMatchSnapshot(); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - }, LONG_TIMEOUT); - }); + let error; + try { + await GetJobs.getStatusForJob(REAL_SESSION, job); + } catch (thrownError) { + error = thrownError; + } + expect(error).toBeDefined(); + const trimmedErrorMessage = trimMessage(error.message); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain(job.jobid); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + + it("should detect and surface an error for an invalid jobname", async () => { + let err; + try { + await GetJobs.getStatusForJob(REAL_SESSION, {jobname: "))))))))", jobid: "JOB123"} as any); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + }); + + it("should detect and surface an error for an invalid jobid", async () => { + let err; + try { + await GetJobs.getStatusForJob(REAL_SESSION, {jobname: "***REMOVED***1", jobid: "))))))))))"} as any); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + }); + }); - describe("list spool files/dds", () => { - it("should be able to get all spool files in a job", async () => { - const NUM_OF_SPOOL_FILES = 3; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - files.forEach((file) => { - expect(file.jobname).toEqual(job.jobname); // verify jobname is in each jobfile + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + testEnvironment.resources.jobs.push(job); + }); + + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + + // Expect that the status is input + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); + + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); + testEnvironment.resources.jobs.push(job); + }); + + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); + + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + }); }); - await DeleteJobs.deleteJobForJob(REAL_SESSION, job); }); - }); - describe("download spool files", () => { - it("Should get spool content from a job", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - let found = false; - - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file); - expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - found = true; - } - } - expect(found).toBe(true); - }, LONG_TIMEOUT); - - it("Should get spool content from a job with encoding", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY¬¬"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - let found = false; - - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file, "IBM-037"); - expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - expect(dataContent).toContain("PUTTYPUTTYPUTTY"); - expect(dataContent).not.toContain("¬¬"); - expect(dataContent).toContain("^^"); - found = true; - } - } - expect(found).toBe(true); - }, LONG_TIMEOUT); - - it("Should get spool content for a single job", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id); - expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - break; - } - } - }, LONG_TIMEOUT); - - it("Should get spool content for a single job with encoding", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY¬¬"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id, "IBM-037"); - expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - expect(content).toContain("PUTTYPUTTYPUTTY"); - expect(content).not.toContain("¬¬"); - expect(content).toContain("^^"); - break; - } - } - }, LONG_TIMEOUT); - }); -}); - -/**********************************************/ -// API methods "getJcl..." system tests -describe("Get JCL APIs", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for getting JCL that doesnt exist", async () => { - const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); - await DeleteJobs.deleteJobForJob(REAL_SESSION, job); - await waitThreeSeconds(); - let error; - try { - await GetJobs.getJclForJob(REAL_SESSION, job); - } catch (thrownError) { - error = thrownError; - } - expect(error).toBeDefined(); - expect(JSON.parse(error.causeErrors).rc).toMatchSnapshot(); - expect(JSON.parse(error.causeErrors).reason).toMatchSnapshot(); - expect(JSON.parse(error.causeErrors).category).toMatchSnapshot(); - const trimmedErrorMessage = trimMessage(error.message); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain(job.jobid); + /**********************************************/ + // API methods "getSpool..." system tests + describe("Get spool APIs", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for getting spool content that doesnt exist", async () => { + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + + await DeleteJobs.deleteJobForJob(REAL_SESSION, job); + + // Add a delay to ensure job deletion is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + + let error; + try { + await GetJobs.getSpoolContent(REAL_SESSION, files[0]); + } catch (thrownError) { + error = thrownError; + } + expect(error).toBeDefined(); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + }); + + describe("list spool files/dds", () => { + it("should be able to get all spool files in a job", async () => { + const NUM_OF_SPOOL_FILES = 3; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + files.forEach((file) => { + expect(file.jobname).toEqual(job.jobname); // verify jobname is in each jobfile + }); + testEnvironment.resources.jobs.push(job); + }); + }); + + describe("download spool files", () => { + it("Should get spool content from a job", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + let found = false; + + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file); + expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + found = true; + } + } + expect(found).toBe(true); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + + it("Should get spool content from a job with encoding", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY¬¬"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + let found = false; + + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file, "IBM-037"); + expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + expect(dataContent).toContain("PUTTYPUTTYPUTTY"); + expect(dataContent).not.toContain("¬¬"); + expect(dataContent).toContain("^^"); + found = true; + } + } + expect(found).toBe(true); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + + it("Should get spool content for a single job", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id); + expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + break; + } + } + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + + it("Should get spool content for a single job with encoding", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY¬¬"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id, "IBM-037"); + expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + expect(content).toContain("PUTTYPUTTYPUTTY"); + expect(content).not.toContain("¬¬"); + expect(content).toContain("^^"); + break; + } + } + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + }); }); - }); - describe("download JCL", () => { - it("should be able to get jcl from a job that was submitted", async () => { - const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); - const jcl = await GetJobs.getJclForJob(REAL_SESSION, job); - expect(jcl).toContain("EXEC PGM=IEFBR14"); - expect(jcl).toContain("JOB"); + /**********************************************/ + // API methods "getJcl..." system tests + describe("Get JCL APIs", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for getting JCL that doesnt exist", async () => { + const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); + + await DeleteJobs.deleteJobForJob(REAL_SESSION, job); + + // Add a delay to ensure job deletion is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + + let error; + try { + await GetJobs.getJclForJob(REAL_SESSION, job); + } catch (thrownError) { + error = thrownError; + } + expect(error).toBeDefined(); + const trimmedErrorMessage = trimMessage(error.message); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain(job.jobid); + testEnvironment.resources.jobs.push(job); + }); + }); + + describe("download JCL", () => { + it("should be able to get jcl from a job that was submitted", async () => { + const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); + const jcl = await GetJobs.getJclForJob(REAL_SESSION, job); + expect(jcl).toContain("EXEC PGM=IEFBR14"); + expect(jcl).toContain("JOB"); + testEnvironment.resources.jobs.push(job); + }); + }); }); }); -}); + describe("Encoded System Tests", () => { -describe("Get Jobs - System Tests - Encoded", () => { + beforeAll(async () => { + const REAL_SESSION = await TestEnvironment.createSession(); - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_get_jobs_encoded" - }); - defaultSystem = testEnvironment.systemTestProperties; + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_get_jobs_encoded" + }, REAL_SESSION); + defaultSystem = testEnvironment.systemTestProperties; + + INVALID_SESSION = new Session({ + user: "fakeuser", + password: "fake", + hostname: defaultSystem.zosmf.host, + port: defaultSystem.zosmf.port, + type: "basic", + rejectUnauthorized: false + }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + ACCOUNT = defaultSystem.tso.account; + MONITOR_JOB_NAME = REAL_SESSION.ISession.user?.toUpperCase().substring(0, 5) + "#G"; - INVALID_SESSION = new Session({ - user: "fakeuser", - password: "fake", - hostname: defaultSystem.zosmf.host, - port: defaultSystem.zosmf.port, - type: "basic", - rejectUnauthorized: false + JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; + SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; + + // TODO: What string goes in the removed section? + JCL = + "//" + MONITOR_JOB_NAME + " JOB '" + ACCOUNT + "',CLASS=" + JOBCLASS + "\n" + + "//IEFBR14 EXEC PGM=IEFBR14"; // GetJobs + }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); }); - ACCOUNT = defaultSystem.tso.account; - MONITOR_JOB_NAME = REAL_SESSION.ISession.user?.toUpperCase().substring(0, 5) + "#G"; + /**********************************************/ + // API methods "getJobs..." system tests + describe("Get Jobs APIs - Encoded", () => { + + /**********************************************/ + // API methods "getJobs" system tests + describe("get jobs API", () => { + describe("list jobs", () => { + it("should return all jobs for the user in the session", async () => { + // Read the JCL template file + const NUM_JOBS = 3; + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + + // Submit a few jobs to list + const jobs: IJob[] = []; + for (let x = 0; x < NUM_JOBS; x++) { + + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + jobs.push(job); + testEnvironment.resources.jobs.push(job); + } - JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; - SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + + // Obtain all jobs for the user + const allJobs: IJob[] = await GetJobs.getJobs(REAL_SESSION); + expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); + + // Search all jobs returned for each of the submitted jobs + jobs.forEach((submittedJob) => { + let found = false; + for (const returnedJob of allJobs) { + if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { + found = true; + break; + } + } + expect(found).toBe(true); + }); + }, LONG_TIMEOUT); - // TODO: What string goes in the removed section? - JCL = - "//" + MONITOR_JOB_NAME + " JOB '" + ACCOUNT + "',CLASS=" + JOBCLASS + "\n" + - "//IEFBR14 EXEC PGM=IEFBR14"; // GetJobs - }); + it("should be able to get a single job by job ID", async () => { + // Read the JCL template file + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently - // outstanding) when the tests run - beforeEach(async () => { - await cleanTestJobs(MONITOR_JOB_NAME); - await cleanTestJobs(TEST_JOB_NAME); - }); - afterEach(async () => { - await cleanTestJobs(MONITOR_JOB_NAME); - await cleanTestJobs(TEST_JOB_NAME); - }); + // submit a job that we can list + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + + // Search all jobs returned for each of the submitted jobs + const foundJob = await GetJobs.getJob(REAL_SESSION, job.jobid); + expect(foundJob).toBeDefined(); + expect(foundJob.jobid).toEqual(job.jobid); + expect(foundJob.jobname).toEqual(job.jobname); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + }); + + it("should be able to get a single job by job ID with jobid parm on the getJobs API", async () => { + // Read the JCL template file + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + + // submit a job that we can list + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - /**********************************************/ - // API methods "getJobs..." system tests - describe("Get Jobs APIs", () => { + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + + // Search all jobs returned for each of the submitted jobs + const foundJobs = await GetJobs.getJobsCommon(REAL_SESSION, {jobid: job.jobid}); + expect(foundJobs).toBeDefined(); + expect(foundJobs.length).toEqual(1); + expect(foundJobs[0].jobid).toEqual(job.jobid); + expect(foundJobs[0].jobname).toEqual(job.jobname); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + }); + }); /**********************************************/ - // API methods "getJobs" system tests - describe("get jobs API", () => { + // API methods "getJobsByPrefix" system tests + describe("get jobs by prefix API - Encoded", () => { describe("list jobs", () => { - it("should return all jobs for the user in the session", async () => { + it("should return all jobs for the prefix of the user id and the owner is the session user id", async () => { // Read the JCL template file const NUM_JOBS = 3; const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); @@ -1085,13 +1182,14 @@ describe("Get Jobs - System Tests - Encoded", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); jobs.push(job); + testEnvironment.resources.jobs.push(job); } - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); - // Obtain all jobs for the user - const allJobs: IJob[] = await GetJobs.getJobs(REAL_SESSION); + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + + // Obtain the three jobs submitted + const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, MONITOR_JOB_NAME + "*"); expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); // Search all jobs returned for each of the submitted jobs @@ -1107,510 +1205,419 @@ describe("Get Jobs - System Tests - Encoded", () => { }); }, LONG_TIMEOUT); - it("should be able to get a single job by job ID", async () => { + it("should throw an error if we specify a job ID that doesn't exist", async () => { + let err: ImperativeError; + try { + await GetJobs.getJob(REAL_SESSION, "J999999"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err.causeErrors).toContain("Zero jobs"); + }); + + it("should return no jobs for a prefix that doesn't match anything", async () => { + const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, "FAKENE"); + expect(allJobs.length).toBe(0); + }); + + it("should return all jobs for the non user id prefix specified and the owner is the session user id", async () => { // Read the JCL template file + const NUM_JOBS = 3; const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - // submit a job that we can list - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Submit a few jobs to list + const jobs: IJob[] = []; + for (let x = 0; x < NUM_JOBS; x++) { - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: TEST_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + jobs.push(job); + testEnvironment.resources.jobs.push(job); + } + + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); + // Obtain the three jobs submitted + const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, TEST_JOB_NAME + "*"); + expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); // Search all jobs returned for each of the submitted jobs - const foundJob = await GetJobs.getJob(REAL_SESSION, job.jobid); - expect(foundJob).toBeDefined(); - expect(foundJob.jobid).toEqual(job.jobid); - expect(foundJob.jobname).toEqual(job.jobname); + jobs.forEach((submittedJob) => { + let found = false; + for (const returnedJob of allJobs) { + if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { + found = true; + break; + } + } + expect(found).toBe(true); + }); }, LONG_TIMEOUT); }); - - it("should be able to get a single job by job ID with jobid parm on the getJobs API", async () => { - // Read the JCL template file - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - - // submit a job that we can list - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); - - - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); - - // Search all jobs returned for each of the submitted jobs - const foundJobs = await GetJobs.getJobsCommon(REAL_SESSION, {jobid: job.jobid}); - expect(foundJobs).toBeDefined(); - expect(foundJobs.length).toEqual(1); - expect(foundJobs[0].jobid).toEqual(job.jobid); - expect(foundJobs[0].jobname).toEqual(job.jobname); - }, LONG_TIMEOUT); }); - }); - /**********************************************/ - // API methods "getJobsByPrefix" system tests - describe("get jobs by prefix API", () => { - describe("list jobs", () => { - it("should return all jobs for the prefix of the user id and the owner is the session user id", async () => { - // Read the JCL template file - const NUM_JOBS = 3; - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + /**********************************************/ + // API methods "getJobsByPrefix" system tests + describe("get jobs by owner API - Encoded", () => { + describe("list jobs", () => { + it("should return no jobs for a nonexistent owner", async () => { + // Obtain the three jobs submitted + const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, "FAKENE"); + expect(allJobs.length).toBe(0); + }); - // Submit a few jobs to list - const jobs: IJob[] = []; - for (let x = 0; x < NUM_JOBS; x++) { + it("should return all jobs for the user (of the session) when specified as the owner", async () => { + // Read the JCL template file + const NUM_JOBS = 3; + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Submit a few jobs to list + const jobs: IJob[] = []; + for (let x = 0; x < NUM_JOBS; x++) { - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); - jobs.push(job); - } + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + jobs.push(job); + testEnvironment.resources.jobs.push(job); + } - // Obtain the three jobs submitted - const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, MONITOR_JOB_NAME + "*"); - expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds - // Search all jobs returned for each of the submitted jobs - jobs.forEach((submittedJob) => { - let found = false; - for (const returnedJob of allJobs) { - if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { - found = true; - break; + // Obtain all jobs for ***REMOVED*** + const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, REAL_SESSION.ISession.user); + expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); + + // Search all jobs returned for each of the submitted jobs + jobs.forEach((submittedJob) => { + let found = false; + for (const returnedJob of allJobs) { + if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { + found = true; + break; + } } - } - expect(found).toBe(true); - }); - }, LONG_TIMEOUT); - - it("should throw an error if we specify a job ID that doesn't exist", async () => { - let err: ImperativeError; - try { - await GetJobs.getJob(REAL_SESSION, "J999999"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err.causeErrors).toContain("Zero jobs"); + expect(found).toBe(true); + }); + }, LONG_TIMEOUT); }); + }); - it("should return no jobs for a prefix that doesn't match anything", async () => { - const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, "FAKENE"); - expect(allJobs.length).toBe(0); - }); + describe("Get Status APIs - Encoded", () => { + /**********************************************/ + // API methods "getStatus" system tests + describe("get status API", () => { + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - it("should return all jobs for the non user id prefix specified and the owner is the session user id", async () => { - // Read the JCL template file - const NUM_JOBS = 3; - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - // Submit a few jobs to list - const jobs: IJob[] = []; - for (let x = 0; x < NUM_JOBS; x++) { + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: TEST_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + testEnvironment.resources.jobs.push(job); + }); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); - jobs.push(job); - } + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Obtain the three jobs submitted - const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, TEST_JOB_NAME + "*"); - expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); + // Expect the jobname to match + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Search all jobs returned for each of the submitted jobs - jobs.forEach((submittedJob) => { - let found = false; - for (const returnedJob of allJobs) { - if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { - found = true; - break; - } - } - expect(found).toBe(true); - }); - }, LONG_TIMEOUT); - }); - }); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - /**********************************************/ - // API methods "getJobsByPrefix" system tests - describe("get jobs by owner API", () => { - describe("list jobs", () => { - it("should return no jobs for a nonexistent owner", async () => { - // Obtain the three jobs submitted - const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, "FAKENE"); - expect(allJobs.length).toBe(0); - }); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); + testEnvironment.resources.jobs.push(job); + }); - it("should return all jobs for the user (of the session) when specified as the owner", async () => { - // Read the JCL template file - const NUM_JOBS = 3; - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit a few jobs to list - const jobs: IJob[] = []; - for (let x = 0; x < NUM_JOBS; x++) { + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); - jobs.push(job); - } - - // TODO: this is a workaround for an issue where listing jobs immediately after they are completed - // results in the jobs being omitted from the results - await waitThreeSeconds(); - // Obtain all jobs for ***REMOVED*** - const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, REAL_SESSION.ISession.user); - expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); - - // Search all jobs returned for each of the submitted jobs - jobs.forEach((submittedJob) => { - let found = false; - for (const returnedJob of allJobs) { - if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { - found = true; - break; - } - } - expect(found).toBe(true); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); }); - }, LONG_TIMEOUT); - }); - }); -}); - -describe("Get Status APIs - Encoded", () => { - - /**********************************************/ - // API methods "getStatus" system tests - describe("get status API", () => { - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); }); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + /**********************************************/ + // API methods "getStatusCommon" system tests + describe("get status common API", () => { + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Expect the jobname to match - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); - }); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + testEnvironment.resources.jobs.push(job); + }); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + // Expect that the status is input + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - }, LONG_TIMEOUT); - }); - }); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - /**********************************************/ - // API methods "getStatusCommon" system tests - describe("get status common API", () => { - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - }); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); + testEnvironment.resources.jobs.push(job); + }); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - // Expect that the status is input - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + }); }); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + /**********************************************/ + // API methods "getStatusForJob" system tests + describe("get status for job API", () => { + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - }, LONG_TIMEOUT); - }); - }); + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); - /**********************************************/ - // API methods "getStatusForJob" system tests - describe("get status for job API", () => { - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); - - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - }); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + testEnvironment.resources.jobs.push(job); + }); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is input - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is input + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); - }); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); + testEnvironment.resources.jobs.push(job); + }); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - }, LONG_TIMEOUT); - }); - }); -}); - -describe("Get spool APIs - encoded", () => { - describe("list spool files/dds", () => { - it("should be able to get all spool files in a job", async () => { - const NUM_OF_SPOOL_FILES = 3; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - files.forEach((file) => { - expect(file.jobname).toEqual(job.jobname); // verify jobname is in each jobfile + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + }); }); - await DeleteJobs.deleteJobForJob(REAL_SESSION, job); }); - }); - describe("download spool files", () => { - it("Should get spool content from a job", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - let found = false; - - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file); - expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - found = true; - } - } - expect(found).toBe(true); - }, LONG_TIMEOUT); - - it("Should get spool content for a single job", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id); - expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - break; - } - } - }, LONG_TIMEOUT); - }); -}); - -/**********************************************/ -// API methods "getJcl..." system tests -describe("Get JCL APIs - encoded", () => { - describe("download JCL", () => { - it("should be able to get jcl from a job that was submitted", async () => { - const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); - const jcl = await GetJobs.getJclForJob(REAL_SESSION, job); - expect(jcl).toContain("EXEC PGM=IEFBR14"); - expect(jcl).toContain("JOB"); + describe("Get spool APIs - encoded", () => { + describe("list spool files/dds", () => { + it("should be able to get all spool files in a job", async () => { + const NUM_OF_SPOOL_FILES = 3; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + files.forEach((file) => { + expect(file.jobname).toEqual(job.jobname); // verify jobname is in each jobfile + }); + testEnvironment.resources.jobs.push(job); + }); + }); + + describe("download spool files", () => { + it("Should get spool content from a job", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + let found = false; + + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file); + expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + found = true; + } + } + expect(found).toBe(true); + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + + it("Should get spool content for a single job", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id); + expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + break; + } + } + testEnvironment.resources.jobs.push(job); + }, LONG_TIMEOUT); + }); + + /**********************************************/ + // API methods "getJcl..." system tests + describe("Get JCL APIs - encoded", () => { + describe("download JCL", () => { + it("should be able to get jcl from a job that was submitted", async () => { + const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); + const jcl = await GetJobs.getJclForJob(REAL_SESSION, job); + expect(jcl).toContain("EXEC PGM=IEFBR14"); + expect(jcl).toContain("JOB"); + testEnvironment.resources.jobs.push(job); + }); + }); + }); }); }); }); \ No newline at end of file diff --git a/packages/zosjobs/__tests__/__system__/__snapshots__/GetJobs.system.test.ts.snap b/packages/zosjobs/__tests__/__system__/__snapshots__/GetJobs.system.test.ts.snap deleted file mode 100644 index 26d7179d5a..0000000000 --- a/packages/zosjobs/__tests__/__system__/__snapshots__/GetJobs.system.test.ts.snap +++ /dev/null @@ -1,19 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Get JCL APIs invalid request error handling should detect and surface an error for getting JCL that doesnt exist 1`] = `4`; - -exports[`Get JCL APIs invalid request error handling should detect and surface an error for getting JCL that doesnt exist 2`] = `10`; - -exports[`Get JCL APIs invalid request error handling should detect and surface an error for getting JCL that doesnt exist 3`] = `6`; - -exports[`Get Status APIs get status for job API invalid request error handling should be able to get a job that was submitted and get proper error when the job is deleted 1`] = `4`; - -exports[`Get Status APIs get status for job API invalid request error handling should be able to get a job that was submitted and get proper error when the job is deleted 2`] = `10`; - -exports[`Get Status APIs get status for job API invalid request error handling should be able to get a job that was submitted and get proper error when the job is deleted 3`] = `6`; - -exports[`Get spool APIs invalid request error handling should detect and surface an error for getting spool content that doesnt exist 1`] = `4`; - -exports[`Get spool APIs invalid request error handling should detect and surface an error for getting spool content that doesnt exist 2`] = `10`; - -exports[`Get spool APIs invalid request error handling should detect and surface an error for getting spool content that doesnt exist 3`] = `6`; From fb156dee2bf257b86f7eca293b0711fdbb111352 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 15 Aug 2024 12:30:16 -0400 Subject: [PATCH 03/65] fixing these was hardgit add . Signed-off-by: ATorrise --- .../__system__/SearchJobs.system.test.ts | 11 +- .../__system__/SubmitJobs.system.test.ts | 129 +++++++++++------- 2 files changed, 86 insertions(+), 54 deletions(-) diff --git a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts index 5d9c45e593..dff4d2c272 100644 --- a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts @@ -11,8 +11,7 @@ import { ImperativeError, Session } from "@zowe/imperative"; import { DeleteJobs, GetJobs, IJob, SearchJobs } from "../../src"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; /**********************************************************************************/ @@ -57,11 +56,9 @@ describe("Search Jobs - System Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_search_jobs" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); defaultSystem = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - INVALID_SESSION = new Session({ user: "fakeuser", password: "fake", @@ -83,6 +80,10 @@ describe("Search Jobs - System Tests", () => { "//" + MONITOR_JOB_NAME + " JOB '" + ACCOUNT + "',CLASS=" + JOBCLASS + "\n" + "//IEFBR14 EXEC PGM=IEFBR14"; // GetJobs }); +s + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently // outstanding) when the tests run diff --git a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts index a97bfd2b68..f0b8979537 100644 --- a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts @@ -10,14 +10,12 @@ */ import { ImperativeError, Session } from "@zowe/imperative"; -import { DeleteJobs, IJob, SubmitJobs } from "../../src"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; +import { GetJobs, IJob, ISpoolFile, SubmitJobs } from "../../src"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { existsSync } from "fs"; import { ZosJobsMessages } from "../../src/JobsMessages"; -const rimraf = require("rimraf").sync; - +import { promisify } from 'util'; let testEnvironment: ITestEnvironment; let systemProps: ITestPropertiesSchema; @@ -32,25 +30,16 @@ const badUSSFile = "/tmp/does/not/exist/fake.txt"; const LONG_TIMEOUT = 100000; // 100 second timeout - jobs could take a while to complete due to system load -const waitThreeSeconds = () => { - return new Promise((resolveWaitTime) => { - const threeSeconds = 3000; - setTimeout(() => { - resolveWaitTime(); - }, threeSeconds); - } - ); -}; +const wait = promisify(setTimeout); describe("Submit Jobs - System Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_submit_jobs" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); systemProps = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); account = systemProps.tso.account; jobDataSet = testEnvironment.systemTestProperties.zosjobs.iefbr14PSDataSet; jobUSSFile = testEnvironment.systemTestProperties.zosjobs.iefbr14USSFile; @@ -64,10 +53,6 @@ describe("Submit Jobs - System Tests", () => { await TestEnvironment.cleanUp(testEnvironment); }); - // helper to delete a job - const deleteJob = async (job: IJob) => { - await DeleteJobs.deleteJob(REAL_SESSION, job.jobname, job.jobid); - }; describe("Positive tests", () => { it("should allow users to call submitJCLCommon with correct parameters", async () => { const job = await SubmitJobs.submitJclCommon(REAL_SESSION, { @@ -75,7 +60,7 @@ describe("Submit Jobs - System Tests", () => { }); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }); it("should allow users to call submitJCLCommon with correct extended parameters", async () => { @@ -87,7 +72,7 @@ describe("Submit Jobs - System Tests", () => { }); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }); @@ -98,7 +83,7 @@ describe("Submit Jobs - System Tests", () => { ); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }); @@ -115,8 +100,8 @@ describe("Submit Jobs - System Tests", () => { ); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await waitThreeSeconds(); - await deleteJob(job); + await wait(3000); // Waits for 3 seconds + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); @@ -136,7 +121,7 @@ describe("Submit Jobs - System Tests", () => { ); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should allow users to call submitJobCommon with correct parameters (with data set)", async () => { @@ -145,7 +130,7 @@ describe("Submit Jobs - System Tests", () => { }); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }); it("should allow users to call submitJobCommon with correct parameters (with uss file)", async () => { @@ -154,7 +139,7 @@ describe("Submit Jobs - System Tests", () => { }); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }); it("should allow users to call submitJobNotifyCommon with correct parameters (using a data set)", async () => { @@ -163,7 +148,7 @@ describe("Submit Jobs - System Tests", () => { }); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should allow users to call submitJobNotifyCommon with correct parameters (using a uss file)", async () => { @@ -172,7 +157,7 @@ describe("Submit Jobs - System Tests", () => { }); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should allow users to call submitJCLNotify with correct parameters", async () => { @@ -185,7 +170,7 @@ describe("Submit Jobs - System Tests", () => { "IBM-037"); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should allow users to call submitJobNotify with correct parameters", async () => { @@ -194,7 +179,7 @@ describe("Submit Jobs - System Tests", () => { ); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should allow users to call submitUSSJobNotify with correct parameters", async () => { @@ -203,7 +188,7 @@ describe("Submit Jobs - System Tests", () => { ); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); it("should allow users to call submitJob with correct parameters", async () => { @@ -212,7 +197,7 @@ describe("Submit Jobs - System Tests", () => { ); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }); it("should allow users to call submitUSSJob with correct parameters", async () => { @@ -221,13 +206,23 @@ describe("Submit Jobs - System Tests", () => { ); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); - await deleteJob(job); + testEnvironment.resources.jobs.push(job); }); - it("should return the job info of a submitted JCL string", async () => { - const job: any = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", {jclSource: "stdin"}); + const jobOrSpoolFiles = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", { jclSource: "stdin" }); + + // Check if the returned value is an array of spool files or a single job object + if (Array.isArray(jobOrSpoolFiles)) { + throw new Error("Expected a single job object, but received spool files."); + } + + // Now `jobOrSpoolFiles` is guaranteed to be of type `IJob` + const job: IJob = jobOrSpoolFiles; + + // Ensure jobid and jobname are defined before proceeding expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); + testEnvironment.resources.jobs.push(job); }); it("should return the job info of a submitted JCL string with extended options", async () => { @@ -239,27 +234,63 @@ describe("Submit Jobs - System Tests", () => { }); expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); + testEnvironment.resources.jobs.push(job); }); it("should return an array of spool content", async () => { - const job: any = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", {jclSource: "stdin", viewAllSpoolContent: true}); - expect(job.constructor === Array).toBe(true); - expect(job[0].data.toString()).toContain("J E S 2 J O B L O G"); + // Submit the JCL and request spool content to be returned + const result = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", { + jclSource: "stdin", + viewAllSpoolContent: true + }); + + let job: IJob; + let spoolFiles: ISpoolFile[]; + + if (Array.isArray(result)) { + // result is an array of spool files + spoolFiles = result as ISpoolFile[]; + + // Ensure the first spool file contains the expected content + expect(spoolFiles[0].data.toString()).toContain("J E S 2 J O B L O G"); + + // Extract job ID from the spool file content + const jobLogContent = spoolFiles[0].data.toString(); + const jobIdMatch = jobLogContent.match(/JOB\d{5}/).toString(); + + job = await GetJobs.getJob(REAL_SESSION, jobIdMatch); + } else { + // result is a job + job = result as IJob; + } + + testEnvironment.resources.jobs.push(job); }); it("should download spool content to a local directory", async () => { - const job: any = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", - { - jclSource: "stdin", - viewAllSpoolContent: false, - directory: "./" - }); - // check if the file was created + const jobOrSpoolFiles = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", { + jclSource: "stdin", + viewAllSpoolContent: false, + directory: "./" + }); + + // Check if the returned value is an array of spool files or a single job object + if (Array.isArray(jobOrSpoolFiles)) { + throw new Error("Expected a single job object, but received spool files."); + } + + // Now `jobOrSpoolFiles` is guaranteed to be of type `IJob` + const job: IJob = jobOrSpoolFiles; + + // Ensure jobid and jobname and file are defined before proceeding + expect(job.jobid).toBeDefined(); + expect(job.jobname).toBeDefined(); expect(existsSync(`${job.jobid}/JES2`)).toBeTruthy(); - // delete locally created directory - require("rimraf").sync(job.jobid, {maxBusyTries: 10}); + testEnvironment.resources.jobs.push(job); + // Delete the locally created directory + require("rimraf").sync(job.jobid, { maxBusyTries: 10 }); }); }); From 960777b3c80d6eb92319ff2e334f74b171f91ad0 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 15 Aug 2024 12:47:59 -0400 Subject: [PATCH 04/65] ensuring more tests delete jobs from mf, also fixing delete operations Signed-off-by: ATorrise --- .../cli-test-utils/src/TestUtils.ts | 28 +++++++++---------- .../src/environment/TestEnvironment.ts | 2 +- .../__system__/ModifyJobs.system.test.ts | 17 +++++++---- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts index e7cb4a45cf..55a03fbab5 100644 --- a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts +++ b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts @@ -10,21 +10,28 @@ */ import * as fs from "fs"; -import { spawnSync, SpawnSyncReturns, ExecFileException, execSync } from "child_process"; +import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process"; import { ITestEnvironment } from "./environment/doc/response/ITestEnvironment"; import { AbstractSession, CommandProfiles, ICommandDefinition, IHandlerParameters } from "@zowe/imperative"; import { DeleteJobs, IDeleteJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; +import { Delete } from "@zowe/zos-files-for-zowe-sdk" /** * Delete a uss file from the mainframe - * @param {string} filePath - The USS path to the file + * @param {AbstractSession} session - z/OSMF connection info + * @param {string} fileName - The name of the USS file */ -export function deleteFiles(filePath: string): void { - if (fs.existsSync(filePath)) { - fs.unlinkSync(filePath); - } - execSync(`zowe zos-files delete uss-file "${filePath}" -f`); +export function deleteFiles(session: AbstractSession, fileName: string): void { + Delete.ussFile(session, fileName) +} +/** + * Delete a dataset from the mainframe + * @param {AbstractSession} session - z/OSMF connection info + * @param {string} datasetName - The name of the dataset + */ +export function deleteDataset(session: AbstractSession, dataSetName: string): void { + Delete.dataSet(session, dataSetName); } /** @@ -50,13 +57,6 @@ export function deleteJobCommon(session: AbstractSession, job: IJob): void { DeleteJobs.deleteJobCommon(session, parms); } -/** - * Delete a dataset by name - * @param {string} datasetName - The name of the dataset - */ -export function deleteDataset(datasetName: string): void { - execSync(`zowe zos-files delete data-set "${datasetName}" -f`); -} /** * Execute a CLI script diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index c3542c6729..464453e600 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -13,7 +13,7 @@ import * as fs from "fs"; import * as nodePath from "path"; import * as yaml from "js-yaml"; import { v4 as uuidv4 } from "uuid"; -import { AbstractSession, ImperativeError, ImperativeExpect, IO, Logger, LoggingConfigurer, ProfileInfo, Session, TextUtils } from "@zowe/imperative"; +import { AbstractSession, ImperativeError, ImperativeExpect, IO, Logger, LoggingConfigurer, ProfileInfo, TextUtils } from "@zowe/imperative"; import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; diff --git a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts index f2bb072a1a..d4a828525f 100644 --- a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts @@ -11,8 +11,7 @@ import { ImperativeError, Session } from "@zowe/imperative"; import { IJob, SubmitJobs, ModifyJobs, CancelJobs } from "../../src"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { JobTestsUtils } from "./JobTestsUtils"; @@ -31,9 +30,9 @@ describe("Modify Jobs - System Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); + systemProps = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); account = systemProps.tso.account; jobclass = testEnvironment.systemTestProperties.zosjobs.jobclass; modifiedJobClass = testEnvironment.systemTestProperties.zosjobs.modifiedJobclass; @@ -56,6 +55,7 @@ describe("Modify Jobs - System Tests", () => { ); expect(job.jobid).toMatch(iefbr14Job.jobid); expect(job.message).toContain("Request was successful"); + testEnvironment.resources.jobs.push(job); }); it("should return a success message once hold has been added to job", async () => { @@ -66,6 +66,7 @@ describe("Modify Jobs - System Tests", () => { ); expect(job.jobid).toMatch(iefbr14Job.jobid); expect(job.message).toContain("Request was successful"); + testEnvironment.resources.jobs.push(job); }); it("should return a success message once job has been released", async () => { @@ -76,6 +77,7 @@ describe("Modify Jobs - System Tests", () => { ); expect(job.jobid).toMatch(iefbr14Job.jobid); expect(job.message).toContain("Request was successful"); + testEnvironment.resources.jobs.push(job); }); }); @@ -104,9 +106,9 @@ describe("Modify Jobs - System Tests - Encoded", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs_encoded" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); + systemProps = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); account = systemProps.tso.account; jobclass = testEnvironment.systemTestProperties.zosjobs.jobclass; modifiedJobClass = testEnvironment.systemTestProperties.zosjobs.modifiedJobclass; @@ -129,6 +131,7 @@ describe("Modify Jobs - System Tests - Encoded", () => { ); expect(job.jobid).toMatch(sleepJCLJob.jobid); expect(job.message).toContain("Request was successful"); + testEnvironment.resources.jobs.push(job); }); it("should return a success message once hold has been added to job", async () => { @@ -139,6 +142,7 @@ describe("Modify Jobs - System Tests - Encoded", () => { ); expect(job.jobid).toMatch(sleepJCLJob.jobid); expect(job.message).toContain("Request was successful"); + testEnvironment.resources.jobs.push(job); }); it("should return a success message once job has been released", async () => { @@ -149,6 +153,7 @@ describe("Modify Jobs - System Tests - Encoded", () => { ); expect(job.jobid).toMatch(sleepJCLJob.jobid); expect(job.message).toContain("Request was successful"); + testEnvironment.resources.jobs.push(job); }); }); }); \ No newline at end of file From 4f059e623959d76df75f22fc315ecfc1ffea6e85 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Fri, 16 Aug 2024 11:26:10 -0400 Subject: [PATCH 05/65] finished zosjobs sdk tests and starting zosfiles sdk tests Signed-off-by: ATorrise --- .../__system__/methods/get/Get.system.test.ts | 16 +- .../__system__/MonitorJobs.system.test.ts | 1934 +++++++++-------- .../__system__/SubmitJobs.system.test.ts | 2 +- 3 files changed, 976 insertions(+), 976 deletions(-) diff --git a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts index 5fff2be222..4e9a86a553 100644 --- a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts @@ -11,8 +11,7 @@ import { Create, CreateDataSetTypeEnum, Delete, Get, IGetOptions, List, ZosFilesConstants } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getRandomBytes, getUniqueDatasetName, stripNewLines } from "../../../../../../__tests__/__src__/TestUtils"; import { ZosmfRestClient, ZosmfHeaders } from "@zowe/core-for-zowe-sdk"; @@ -29,11 +28,9 @@ describe("Get", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_view" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + }, REAL_SESSION = await TestEnvironment.createSession()); + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`); Imperative.console.info("Using dsname:" + dsname); @@ -354,6 +351,7 @@ describe("Get", () => { expect(response).toBeFalsy(); expect(error).toBeTruthy(); expect(stripNewLines(error.message)).toContain("Unsupported data type 'record' specified for USS file operation."); + testEnvironment.resources.files.push(ussname); }); }); }); @@ -365,11 +363,9 @@ describe("Get - encoded", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_view" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + }, REAL_SESSION = await TestEnvironment.createSession()); + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`, true); Imperative.console.info("Using dsname:" + dsname); diff --git a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts index 427fa943f4..882ae4296b 100644 --- a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts @@ -15,8 +15,7 @@ import { ImperativeError, Session, TextUtils } from "@zowe/imperative"; import * as fs from "fs"; import { join } from "path"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; // long running test timeout @@ -67,1113 +66,1118 @@ const trimMessage = (message: string) => { }; describe("System Tests - Monitor Jobs", () => { + describe("Unencoded", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_monitor_jobs" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_monitor_jobs" + }, REAL_SESSION = await TestEnvironment.createSession()); - ACCOUNT = defaultSystem.tso.account; - const JOB_LENGTH = 6; - MONITOR_JOB_NAME = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + "MJ"; - - JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; - SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; - }); - - // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently - // outstanding) when the tests run - beforeEach(async () => { - GetJobs.getStatusCommon = ORIG_JOBS_STATUS; - await cleanTestJobs(); - }); - afterEach(async () => { - GetJobs.getStatusCommon = ORIG_JOBS_STATUS; - await cleanTestJobs(); - }); + defaultSystem = testEnvironment.systemTestProperties; + ACCOUNT = defaultSystem.tso.account; + const JOB_LENGTH = 6; + MONITOR_JOB_NAME = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + "MJ"; - /**********************************************/ - // API method "waitForOutputStatus" system tests - describe("api method wait for output status", () => { - - // Single error situation - the majority are tested via the common method (which this method invokes) - describe("invalid request error handling", () => { - it("should detect and surface an error if the job requested is not found", async () => { - let error; - try { - const response = await MonitorJobs.waitForOutputStatus(REAL_SESSION, "JOB1", "JOB123"); - } catch (e) { - error = e; - } - expect(error).toBeDefined(); - expect(error instanceof ImperativeError).toBe(true); - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No job found for reference"); - }); + JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; + SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; }); - // Single polling situation - the majority are tested via the common method (which this method invokes) - describe("polling/transitions", () => { - // eslint-disable-next-line jest/no-done-callback - it("should detect when a job transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently + // outstanding) when the tests run + beforeEach(async () => { + GetJobs.getStatusCommon = ORIG_JOBS_STATUS; + await cleanTestJobs(); + }); + afterEach(async () => { + GetJobs.getStatusCommon = ORIG_JOBS_STATUS; + await cleanTestJobs(); + }); - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForOutputStatus(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); + /**********************************************/ + // API method "waitForOutputStatus" system tests + describe("api method wait for output status", () => { + + // Single error situation - the majority are tested via the common method (which this method invokes) + describe("invalid request error handling", () => { + it("should detect and surface an error if the job requested is not found", async () => { + let error; + try { + const response = await MonitorJobs.waitForOutputStatus(REAL_SESSION, "JOB1", "JOB123"); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error instanceof ImperativeError).toBe(true); + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No job found for reference"); + }); + }); - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { + // Single polling situation - the majority are tested via the common method (which this method invokes) + describe("polling/transitions", () => { + // eslint-disable-next-line jest/no-done-callback + it("should detect when a job transitions from INPUT to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); + + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForOutputStatus(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + done(); + }).catch((error) => { if (!doneCalled) { doneCalled = true; - done(`Release error: ${releaseErr.message}`); + done(`wait for status error: ${error.message}`); } }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - }); - }); - /**********************************************/ - // API method "waitForJobOutputStatus" system tests - describe("api method wait for job output status", () => { - - // Single error situation - the majority are tested via the common method (which this method invokes) - describe("invalid request error handling", () => { - it("should detect and surface an error if the job requested is not found", async () => { - let error; - try { - const params: any = {jobname: "JOB1", jobid: "JOB123"}; - const response = await MonitorJobs.waitForJobOutputStatus(REAL_SESSION, params); - } catch (e) { - error = e; - } - expect(error).toBeDefined(); - expect(error instanceof ImperativeError).toBe(true); - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No job found for reference"); + // Change the jobclass after a period of time + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" + } + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { + if (!doneCalled) { + doneCalled = true; + done(`Release error: ${releaseErr.message}`); + } + }); + }, TIMEOUT_TEST_CHECK); + + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); }); }); - // Single polling situation - the majority are tested via the common method (which this method invokes) - describe("polling/transitions", () => { - // eslint-disable-next-line jest/no-done-callback - it("should detect when the job submitted transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); - - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForJobOutputStatus(REAL_SESSION, jobInfo).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); + /**********************************************/ + // API method "waitForJobOutputStatus" system tests + describe("api method wait for job output status", () => { + + // Single error situation - the majority are tested via the common method (which this method invokes) + describe("invalid request error handling", () => { + it("should detect and surface an error if the job requested is not found", async () => { + let error; + try { + const params: any = {jobname: "JOB1", jobid: "JOB123"}; + const response = await MonitorJobs.waitForJobOutputStatus(REAL_SESSION, params); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error instanceof ImperativeError).toBe(true); + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No job found for reference"); + }); + }); - // Release the job - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { + // Single polling situation - the majority are tested via the common method (which this method invokes) + describe("polling/transitions", () => { + // eslint-disable-next-line jest/no-done-callback + it("should detect when the job submitted transitions from INPUT to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); + + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForJobOutputStatus(REAL_SESSION, jobInfo).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + done(); + }).catch((error) => { if (!doneCalled) { doneCalled = true; - done(`Release error: ${releaseErr.message}`); + done(`wait for status error: ${error.message}`); } }); - }, TIMEOUT_TEST_CHECK); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + // Release the job + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" + } + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { + if (!doneCalled) { + doneCalled = true; + done(`Release error: ${releaseErr.message}`); + } + }); + }, TIMEOUT_TEST_CHECK); + + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); + }); }); - }); - /**********************************************/ - // API method "waitForStatusCommon" system tests - describe("api method wait for output status common", () => { - - // All error situations/scenarios - negative system - describe("invalid request error handling", () => { - it("should detect and surface an error message if an invalid jobname is specified", async () => { - let error; - try { - const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "JOB123", jobname: "((((("}); - } catch (e) { - error = e; - } - expect(error).toBeDefined(); - expect(error instanceof ImperativeError).toBe(true); - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/invalid_jobname.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"(((((\" jobid \"JOB123\""); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No match for method GET and pathInfo"); - }); + /**********************************************/ + // API method "waitForStatusCommon" system tests + describe("api method wait for output status common", () => { + + // All error situations/scenarios - negative system + describe("invalid request error handling", () => { + it("should detect and surface an error message if an invalid jobname is specified", async () => { + let error; + try { + const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "JOB123", jobname: "((((("}); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error instanceof ImperativeError).toBe(true); + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/invalid_jobname.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"(((((\" jobid \"JOB123\""); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No match for method GET and pathInfo"); + }); - it("should detect and surface an error message if an invalid jobid is specified", async () => { - let error; - try { - const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "(", jobname: "JOB1"}); - } catch (e) { - error = e; - } - expect(error).toBeDefined(); - expect(error instanceof ImperativeError).toBe(true); - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/invalid_jobid.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"(\""); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No match for method GET and pathInfo"); - }); + it("should detect and surface an error message if an invalid jobid is specified", async () => { + let error; + try { + const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "(", jobname: "JOB1"}); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error instanceof ImperativeError).toBe(true); + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/invalid_jobid.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"(\""); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No match for method GET and pathInfo"); + }); - it("should detect and surface an error if the job requested is not found", async () => { - let error; - try { - const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "JOB123", jobname: "JOB1"}); - } catch (e) { - error = e; - } - expect(error).toBeDefined(); - expect(error instanceof ImperativeError).toBe(true); - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No job found for reference"); + it("should detect and surface an error if the job requested is not found", async () => { + let error; + try { + const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "JOB123", jobname: "JOB1"}); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error instanceof ImperativeError).toBe(true); + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No job found for reference"); + }); }); - }); - // Tests that do not initiate polling - should return immediately from a request - describe("initial status checks", () => { - it("should detect that a job is in INPUT status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - expect(jobInfo.status).toBe("INPUT"); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is input - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "INPUT" + // Tests that do not initiate polling - should return immediately from a request + describe("initial status checks", () => { + it("should detect that a job is in INPUT status", async () => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + + // submit the job + const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + expect(jobInfo.status).toBe("INPUT"); + + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); }); + GetJobs.getStatusCommon = mockedGetJobs; + + // check that the status is input + const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, + { + jobname: jobInfo.jobname, + jobid: jobInfo.jobid, + status: "INPUT" + }); - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("INPUT"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }); + // verify that the status and info is correct + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("INPUT"); + expect(mockedGetJobs).toHaveBeenCalledTimes(1); + }); - it("should detect that a job is in ACTIVE status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should detect that a job is in ACTIVE status", async () => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // submit the job + const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Wait for the job to become active indefinitely - jest timeout will occur eventually - let jobCheck: IJob; - do { - jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); - } while (jobCheck.status !== "ACTIVE"); + // Wait for the job to become active indefinitely - jest timeout will occur eventually + let jobCheck: IJob; + do { + jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); + } while (jobCheck.status !== "ACTIVE"); - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is active - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "ACTIVE" + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); }); + GetJobs.getStatusCommon = mockedGetJobs; + + // check that the status is active + const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, + { + jobname: jobInfo.jobname, + jobid: jobInfo.jobid, + status: "ACTIVE" + }); - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }, LONG_TIMEOUT); - - it("should detect that a job is in OUTPUT status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - - // Wait for the job to become active indefinitely - jest timeout will occur eventually - let jobCheck: IJob; - do { - jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); - } while (jobCheck.status !== "OUTPUT"); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is output - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "OUTPUT" + // verify that the status and info is correct + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("ACTIVE"); + expect(mockedGetJobs).toHaveBeenCalledTimes(1); + }, LONG_TIMEOUT); + + it("should detect that a job is in OUTPUT status", async () => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // submit the job + const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + + // Wait for the job to become active indefinitely - jest timeout will occur eventually + let jobCheck: IJob; + do { + jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); + } while (jobCheck.status !== "OUTPUT"); + + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); }); + GetJobs.getStatusCommon = mockedGetJobs; + + // check that the status is output + const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, + { + jobname: jobInfo.jobname, + jobid: jobInfo.jobid, + status: "OUTPUT" + }); - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }, LONG_TIMEOUT); - }); + // verify that the status and info is correct + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + expect(mockedGetJobs).toHaveBeenCalledTimes(1); + }, LONG_TIMEOUT); + }); - // All tests that perform polling, etc to eventually obtain the status - describe("polling/transitions", () => { - /* eslint-disable jest/no-done-callback */ - it("should detect and surface an error if the job is purged/deleted while waiting for status", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((status) => { - if (!doneCalled) { - doneCalled = true; - done(`Error - we should not have received a status of OUTPUT`); - } - }).catch((error) => { - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/polling_job_deleted.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname"); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No job found for reference"); - if (!doneCalled) { - doneCalled = true; - done(); - } + // All tests that perform polling, etc to eventually obtain the status + describe("polling/transitions", () => { + /* eslint-disable jest/no-done-callback */ + it("should detect and surface an error if the job is purged/deleted while waiting for status", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); }); + GetJobs.getStatusCommon = mockedGetJobs; - // Cancel and purge the job after a period of time - setTimeout(() => { - DeleteJobs.deleteJob(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).catch((error) => { + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" + }).then((status) => { + if (!doneCalled) { + doneCalled = true; + done(`Error - we should not have received a status of OUTPUT`); + } + }).catch((error) => { + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/polling_job_deleted.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname"); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No job found for reference"); if (!doneCalled) { doneCalled = true; - done(`Error deleting the job: ${error.message}`); + done(); } }); - }, TIMEOUT_TEST_CHECK); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + // Cancel and purge the job after a period of time + setTimeout(() => { + DeleteJobs.deleteJob(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).catch((error) => { + if (!doneCalled) { + doneCalled = true; + done(`Error deleting the job: ${error.message}`); + } + }); + }, TIMEOUT_TEST_CHECK); + + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); - it("should detect and surface an error if the max poll attempts are exceeded", (done) => { - // Attempts - const ATTEMPTS = 3; + it("should detect and surface an error if the max poll attempts are exceeded", (done) => { + // Attempts + const ATTEMPTS = 3; - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // start checking the job status - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT", attempts: ATTEMPTS - }).then((status) => { - done(`Error - we should not have received a status of OUTPUT`); - }).catch((error) => { - expect(error instanceof ImperativeError).toBe(true); - expect(error.message).toContain("Error obtaining status for jobname"); - expect(error.message).toContain("Error Details: Reached max poll attempts of \"3\""); - expect(mockedGetJobs).toHaveBeenCalledTimes(ATTEMPTS); - done(); + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); }); + GetJobs.getStatusCommon = mockedGetJobs; - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // start checking the job status + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT", attempts: ATTEMPTS + }).then((status) => { + done(`Error - we should not have received a status of OUTPUT`); + }).catch((error) => { + expect(error instanceof ImperativeError).toBe(true); + expect(error.message).toContain("Error obtaining status for jobname"); + expect(error.message).toContain("Error Details: Reached max poll attempts of \"3\""); + expect(mockedGetJobs).toHaveBeenCalledTimes(ATTEMPTS); + done(); + }); - it("should detect when a job transitions from INPUT to ACTIVE", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + it("should detect when a job transitions from INPUT to ACTIVE", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" + }).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("ACTIVE"); + done(); + }).catch((error) => { if (!doneCalled) { doneCalled = true; - done(`Release error: ${releaseErr.message}`); + done(`wait for status error: ${error.message}`); } }); - }, TIMEOUT_TEST_CHECK); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - - it("should detect when a job transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + // Change the jobclass after a period of time + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" + } + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { + if (!doneCalled) { + doneCalled = true; + done(`Release error: ${releaseErr.message}`); + } + }); + }, TIMEOUT_TEST_CHECK); + + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + it("should detect when a job transitions from INPUT to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" + }).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + done(); + }).catch((error) => { if (!doneCalled) { doneCalled = true; - done(`Release error: ${releaseErr.message}`); + done(`wait for status error: ${error.message}`); } }); - }, TIMEOUT_TEST_CHECK); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - - it("should detect when a job transitions from INPUT to ACTIVE to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Wait for the status to be active - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - - // Wait for the status to be output + // Change the jobclass after a period of time + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" + } + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { + if (!doneCalled) { + doneCalled = true; + done(`Release error: ${releaseErr.message}`); + } + }); + }, TIMEOUT_TEST_CHECK); + + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); + + it("should detect when a job transitions from INPUT to ACTIVE to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // Wait for the status to be active MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((nextStatus) => { - expect(nextStatus.jobid).toEqual(jobInfo.jobid); - expect(nextStatus.jobname).toEqual(jobInfo.jobname); - expect(nextStatus.status).toBe("OUTPUT"); - done(); + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" + }).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("ACTIVE"); + + // Wait for the status to be output + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" + }).then((nextStatus) => { + expect(nextStatus.jobid).toEqual(jobInfo.jobid); + expect(nextStatus.jobname).toEqual(jobInfo.jobname); + expect(nextStatus.status).toBe("OUTPUT"); + done(); + }).catch((error) => { + done(`wait for status error: ${error.message}`); + }); }).catch((error) => { done(`wait for status error: ${error.message}`); }); - }).catch((error) => { - done(`wait for status error: ${error.message}`); + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); }); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - /* eslint-enable jest/no-done-callback */ + }, LONG_TIMEOUT); + /* eslint-enable jest/no-done-callback */ + }); }); }); -}); - -describe("System Tests - Monitor Jobs - Encoded", () => { - - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_monitor_jobs_encoded" - }); - defaultSystem = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + describe("Encoded", () => { - ACCOUNT = defaultSystem.tso.account; - const JOB_LENGTH = 5; - MONITOR_JOB_NAME = REAL_SESSION.ISession.user?.substring(0, JOB_LENGTH).toUpperCase() + "#MJ"; + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_monitor_jobs_encoded" + }, REAL_SESSION = await TestEnvironment.createSession()); - JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; - SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; - }); + defaultSystem = testEnvironment.systemTestProperties; + ACCOUNT = defaultSystem.tso.account; + const JOB_LENGTH = 5; + MONITOR_JOB_NAME = REAL_SESSION.ISession.user?.substring(0, JOB_LENGTH).toUpperCase() + "#MJ"; - // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently - // outstanding) when the tests run - beforeEach(async () => { - GetJobs.getStatusCommon = ORIG_JOBS_STATUS; - await cleanTestJobs(); - }); - afterEach(async () => { - GetJobs.getStatusCommon = ORIG_JOBS_STATUS; - await cleanTestJobs(); - }); + JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; + SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; + }); - /**********************************************/ - // API method "waitForOutputStatus" system tests - describe("api method wait for output status", () => { - // Single polling situation - the majority are tested via the common method (which this method invokes) - describe("polling/transitions", () => { - // eslint-disable-next-line jest/no-done-callback - it("should detect when a job transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForOutputStatus(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); + // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently + // outstanding) when the tests run + beforeEach(async () => { + GetJobs.getStatusCommon = ORIG_JOBS_STATUS; + await cleanTestJobs(); + }); + afterEach(async () => { + GetJobs.getStatusCommon = ORIG_JOBS_STATUS; + await cleanTestJobs(); + }); - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { + /**********************************************/ + // API method "waitForOutputStatus" system tests + describe("api method wait for output status", () => { + // Single polling situation - the majority are tested via the common method (which this method invokes) + describe("polling/transitions", () => { + // eslint-disable-next-line jest/no-done-callback + it("should detect when a job transitions from INPUT to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); + + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForOutputStatus(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + done(); + }).catch((error) => { if (!doneCalled) { doneCalled = true; - done(`Release error: ${releaseErr.message}`); + done(`wait for status error: ${error.message}`); } }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - }); - }); - /**********************************************/ - // API method "waitForJobOutputStatus" system tests - describe("api method wait for job output status", () => { - // Single polling situation - the majority are tested via the common method (which this method invokes) - describe("polling/transitions", () => { - // eslint-disable-next-line jest/no-done-callback - it("should detect when the job submitted transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); - - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForJobOutputStatus(REAL_SESSION, jobInfo).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } + // Change the jobclass after a period of time + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" + } + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { + if (!doneCalled) { + doneCalled = true; + done(`Release error: ${releaseErr.message}`); + } + }); + }, TIMEOUT_TEST_CHECK); + + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); }); + }, LONG_TIMEOUT); + }); + }); - // Release the job - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { + /**********************************************/ + // API method "waitForJobOutputStatus" system tests + describe("api method wait for job output status", () => { + // Single polling situation - the majority are tested via the common method (which this method invokes) + describe("polling/transitions", () => { + // eslint-disable-next-line jest/no-done-callback + it("should detect when the job submitted transitions from INPUT to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); + + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForJobOutputStatus(REAL_SESSION, jobInfo).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + done(); + }).catch((error) => { if (!doneCalled) { doneCalled = true; - done(`Release error: ${releaseErr.message}`); + done(`wait for status error: ${error.message}`); } }); - }, TIMEOUT_TEST_CHECK); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + // Release the job + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" + } + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { + if (!doneCalled) { + doneCalled = true; + done(`Release error: ${releaseErr.message}`); + } + }); + }, TIMEOUT_TEST_CHECK); + + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); + }); }); - }); - /**********************************************/ - // API method "waitForStatusCommon" system tests - describe("api method wait for output status common", () => { - // Tests that do not initiate polling - should return immediately from a request - describe("initial status checks", () => { - it("should detect that a job is in INPUT status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - expect(jobInfo.status).toBe("INPUT"); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is input - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "INPUT" + /**********************************************/ + // API method "waitForStatusCommon" system tests + describe("api method wait for output status common", () => { + // Tests that do not initiate polling - should return immediately from a request + describe("initial status checks", () => { + it("should detect that a job is in INPUT status", async () => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + + // submit the job + const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + expect(jobInfo.status).toBe("INPUT"); + + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); }); + GetJobs.getStatusCommon = mockedGetJobs; + + // check that the status is input + const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, + { + jobname: jobInfo.jobname, + jobid: jobInfo.jobid, + status: "INPUT" + }); - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("INPUT"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }); + // verify that the status and info is correct + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("INPUT"); + expect(mockedGetJobs).toHaveBeenCalledTimes(1); + }); - it("should detect that a job is in ACTIVE status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should detect that a job is in ACTIVE status", async () => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // submit the job + const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Wait for the job to become active indefinitely - jest timeout will occur eventually - let jobCheck: IJob; - do { - jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); - } while (jobCheck.status !== "ACTIVE"); + // Wait for the job to become active indefinitely - jest timeout will occur eventually + let jobCheck: IJob; + do { + jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); + } while (jobCheck.status !== "ACTIVE"); - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is active - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "ACTIVE" + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); }); + GetJobs.getStatusCommon = mockedGetJobs; + + // check that the status is active + const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, + { + jobname: jobInfo.jobname, + jobid: jobInfo.jobid, + status: "ACTIVE" + }); - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }, LONG_TIMEOUT); - - it("should detect that a job is in OUTPUT status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - - // Wait for the job to become active indefinitely - jest timeout will occur eventually - let jobCheck: IJob; - do { - jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); - } while (jobCheck.status !== "OUTPUT"); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is output - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "OUTPUT" + // verify that the status and info is correct + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("ACTIVE"); + expect(mockedGetJobs).toHaveBeenCalledTimes(1); + }, LONG_TIMEOUT); + + it("should detect that a job is in OUTPUT status", async () => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // submit the job + const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + + // Wait for the job to become active indefinitely - jest timeout will occur eventually + let jobCheck: IJob; + do { + jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); + } while (jobCheck.status !== "OUTPUT"); + + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); }); + GetJobs.getStatusCommon = mockedGetJobs; + + // check that the status is output + const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, + { + jobname: jobInfo.jobname, + jobid: jobInfo.jobid, + status: "OUTPUT" + }); - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }, LONG_TIMEOUT); - }); + // verify that the status and info is correct + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + expect(mockedGetJobs).toHaveBeenCalledTimes(1); + }, LONG_TIMEOUT); + }); - // All tests that perform polling, etc to eventually obtain the status - describe("polling/transitions", () => { - /* eslint-disable jest/no-done-callback */ - it("should detect and surface an error if the job is purged/deleted while waiting for status", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((status) => { - if (!doneCalled) { - doneCalled = true; - done(`Error - we should not have received a status of OUTPUT`); - } - }).catch((error) => { - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/polling_job_deleted.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname"); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No job found for reference"); - if (!doneCalled) { - doneCalled = true; - done(); - } + // All tests that perform polling, etc to eventually obtain the status + describe("polling/transitions", () => { + /* eslint-disable jest/no-done-callback */ + it("should detect and surface an error if the job is purged/deleted while waiting for status", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); }); + GetJobs.getStatusCommon = mockedGetJobs; + + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // Cancel and purge the job after a period of time - setTimeout(() => { - DeleteJobs.deleteJob(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).catch((error) => { + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" + }).then((status) => { + if (!doneCalled) { + doneCalled = true; + done(`Error - we should not have received a status of OUTPUT`); + } + }).catch((error) => { + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/polling_job_deleted.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname"); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No job found for reference"); if (!doneCalled) { doneCalled = true; - done(`Error deleting the job: ${error.message}`); + done(); } }); - }, TIMEOUT_TEST_CHECK); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + // Cancel and purge the job after a period of time + setTimeout(() => { + DeleteJobs.deleteJob(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).catch((error) => { + if (!doneCalled) { + doneCalled = true; + done(`Error deleting the job: ${error.message}`); + } + }); + }, TIMEOUT_TEST_CHECK); + + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); - it("should detect and surface an error if the max poll attempts are exceeded", (done) => { - // Attempts - const ATTEMPTS = 3; + it("should detect and surface an error if the max poll attempts are exceeded", (done) => { + // Attempts + const ATTEMPTS = 3; - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // start checking the job status - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT", attempts: ATTEMPTS - }).then((status) => { - done(`Error - we should not have received a status of OUTPUT`); - }).catch((error) => { - expect(error instanceof ImperativeError).toBe(true); - expect(error.message).toContain("Error obtaining status for jobname"); - expect(error.message).toContain("Error Details: Reached max poll attempts of \"3\""); - expect(mockedGetJobs).toHaveBeenCalledTimes(ATTEMPTS); - done(); + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); }); + GetJobs.getStatusCommon = mockedGetJobs; - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - it("should detect when a job transitions from INPUT to ACTIVE", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + // start checking the job status + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT", attempts: ATTEMPTS + }).then((status) => { + done(`Error - we should not have received a status of OUTPUT`); + }).catch((error) => { + expect(error instanceof ImperativeError).toBe(true); + expect(error.message).toContain("Error obtaining status for jobname"); + expect(error.message).toContain("Error Details: Reached max poll attempts of \"3\""); + expect(mockedGetJobs).toHaveBeenCalledTimes(ATTEMPTS); + done(); + }); - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); + it("should detect when a job transitions from INPUT to ACTIVE", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); + + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" + }).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("ACTIVE"); + done(); + }).catch((error) => { if (!doneCalled) { doneCalled = true; - done(`Release error: ${releaseErr.message}`); + done(`wait for status error: ${error.message}`); } }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - it("should detect when a job transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + // Change the jobclass after a period of time + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" + } + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { + if (!doneCalled) { + doneCalled = true; + done(`Release error: ${releaseErr.message}`); + } + }); + }, TIMEOUT_TEST_CHECK); + + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + it("should detect when a job transitions from INPUT to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" + }).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + done(); + }).catch((error) => { if (!doneCalled) { doneCalled = true; - done(`Release error: ${releaseErr.message}`); + done(`wait for status error: ${error.message}`); } }); - }, TIMEOUT_TEST_CHECK); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - - it("should detect when a job transitions from INPUT to ACTIVE to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Wait for the status to be active - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - - // Wait for the status to be output + // Change the jobclass after a period of time + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" + } + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { + if (!doneCalled) { + doneCalled = true; + done(`Release error: ${releaseErr.message}`); + } + }); + }, TIMEOUT_TEST_CHECK); + + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); + + it("should detect when a job transitions from INPUT to ACTIVE to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // Wait for the status to be active MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((nextStatus) => { - expect(nextStatus.jobid).toEqual(jobInfo.jobid); - expect(nextStatus.jobname).toEqual(jobInfo.jobname); - expect(nextStatus.status).toBe("OUTPUT"); - done(); + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" + }).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("ACTIVE"); + + // Wait for the status to be output + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" + }).then((nextStatus) => { + expect(nextStatus.jobid).toEqual(jobInfo.jobid); + expect(nextStatus.jobname).toEqual(jobInfo.jobname); + expect(nextStatus.status).toBe("OUTPUT"); + done(); + }).catch((error) => { + done(`wait for status error: ${error.message}`); + }); }).catch((error) => { done(`wait for status error: ${error.message}`); }); - }).catch((error) => { - done(`wait for status error: ${error.message}`); + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); }); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - /* eslint-enable jest/no-done-callback */ + }, LONG_TIMEOUT); + /* eslint-enable jest/no-done-callback */ + }); }); }); }); \ No newline at end of file diff --git a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts index f0b8979537..c7024a6a7d 100644 --- a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts @@ -38,8 +38,8 @@ describe("Submit Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_submit_jobs" }, REAL_SESSION = await TestEnvironment.createSession()); - systemProps = testEnvironment.systemTestProperties; + systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobDataSet = testEnvironment.systemTestProperties.zosjobs.iefbr14PSDataSet; jobUSSFile = testEnvironment.systemTestProperties.zosjobs.iefbr14USSFile; From 81048a70de28896744e4d9c602223fd8bc1be27b Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 21 Aug 2024 12:42:51 -0400 Subject: [PATCH 06/65] modifying upload.system.test took the longest... removing some test files from permanent residency, ,instead creating them from scratch everytime Signed-off-by: ATorrise --- .../cli-test-utils/src/TestUtils.ts | 20 +- .../src/environment/TestEnvironment.ts | 11 +- .../doc/response/ITestEnvironment.ts | 1 + .../search/cli.zos-jobs.search.job.test.ts | 83 +- .../methods/invoke/Invoke.system.test.ts | 24 +- .../methods/upload/Upload.system.test.ts | 2276 +++++++++-------- .../methods/upload/testfiles/file1.txt | 1 - .../methods/upload/testfiles/file2.txt | 1 - .../methods/upload/testfiles/file3.txt | 1 - .../upload/testfiles/longline/longline.txt | 1 - .../upload/testfiles/space dir/file4.txt | 1 - .../methods/upload/testfiles/upload.txt | 1 - .../utilities/Utilities.system.test.ts | 37 +- 13 files changed, 1286 insertions(+), 1172 deletions(-) delete mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file1.txt delete mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file2.txt delete mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file3.txt delete mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/longline/longline.txt delete mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/space dir/file4.txt delete mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt diff --git a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts index 9e56e7501e..be1feb9a44 100644 --- a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts +++ b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts @@ -12,9 +12,27 @@ import * as fs from "fs"; import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process"; import { ITestEnvironment } from "./environment/doc/response/ITestEnvironment"; -import { AbstractSession, CommandProfiles, ICommandDefinition, IHandlerParameters } from "@zowe/imperative"; +import { AbstractSession, CommandProfiles, ICommandDefinition, IHandlerParameters, IO } from "@zowe/imperative"; import { DeleteJobs, IDeleteJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; import { Delete } from "@zowe/zos-files-for-zowe-sdk" +import { posix } from "path"; + +/** + * Delete a local testing file after use + * @param {string} filePath - File path of temporary file + */ +export function deleteLocalFile(filePath: string): void { + try { + fs.unlinkSync(filePath); + } catch { + // If fs.unlinkSync fails, try to delete it with IO.deleteFile + try { + IO.deleteFile(posix.basename(filePath)); + } catch { + throw new Error(`Error deleting local file: ${filePath}`); + } + } +} /** * Delete a uss file from the mainframe diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index 464453e600..35df225101 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -18,7 +18,7 @@ import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; import { PROJECT_ROOT_DIR, TEST_RESOURCE_DIR, TEST_RESULT_DATA_DIR, TEST_USING_WORKSPACE } from "../TestConstants"; -import { runCliScript, deleteFiles, deleteJob, deleteDataset } from "../TestUtils"; +import { runCliScript, deleteFiles, deleteJob, deleteDataset, deleteLocalFile } from "../TestUtils"; /** * Use the utility methods here to setup the test environment for running APIs @@ -66,6 +66,7 @@ export class TestEnvironment { systemTestProperties: systemProps, env, resources: { + localFiles: [], files: [], jobs: [], datasets: [], @@ -126,17 +127,19 @@ export class TestEnvironment { } // Clean up resources + for (const file of testEnvironment.resources.localFiles) { + deleteLocalFile(file); + } // Check if session exists; if not, create one const session = testEnvironment.resources.session || await TestEnvironment.createSession(); - for (const file of testEnvironment.resources.files) { - deleteFiles(file); + deleteFiles(session, file); } for (const job of testEnvironment.resources.jobs) { deleteJob(session, job); } for (const dataset of testEnvironment.resources.datasets) { - deleteDataset(dataset); + deleteDataset(session, dataset); } } diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts index 2ec63762a9..babbd4ad11 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts @@ -19,6 +19,7 @@ import { IJob } from "@zowe/zos-jobs-for-zowe-sdk"; */ export interface ITestEnvironment { resources: { + localFiles: string[]; files: string[]; jobs: IJob[]; datasets: string[]; diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index 75e39a2d73..bed23278ce 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -9,38 +9,40 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { Session } from "@zowe/imperative"; +import { AbstractSession } from "@zowe/imperative"; +import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; // Test Environment populated in the beforeAll(); -let TEST_ENVIRONMENT: ITestEnvironment; +let testEnvironment: ITestEnvironment; let IEFBR14_JOB: string; -let REAL_SESSION: Session; +let REAL_SESSION: AbstractSession; let ACCOUNT: string; let JOB_NAME: string; let NON_HELD_JOBCLASS: string; let SEARCH_STRING: string; let REGEX_STRING: string; let BAD_SEARCH_STRING: string; +let defaultSystem: ITestPropertiesSchema; describe("zos-jobs search job command", () => { - // Create the unique test environment beforeAll(async () => { - TEST_ENVIRONMENT = await TestEnvironment.setUp({ + // Initialize testEnvironment first! + testEnvironment = await TestEnvironment.setUp({ testName: "zos_jobs_search_job_command", tempProfileTypes: ["zosmf"] - }); + }, REAL_SESSION = await TestEnvironment.createSession()); + + // Use testEnvironment for accessing properties + defaultSystem = testEnvironment.systemTestProperties; - IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; - const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + IEFBR14_JOB = defaultSystem.zosjobs.iefbr14Member; ACCOUNT = defaultSystem.tso.account; - const JOB_LENGTH = 6; - JOB_NAME = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + "SF"; - NON_HELD_JOBCLASS = TEST_ENVIRONMENT.systemTestProperties.zosjobs.jobclass; + // TODO: fix this test to run with any job name + JOB_NAME = "IEFBR14T"//REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase(); + NON_HELD_JOBCLASS = defaultSystem.zosjobs.jobclass; SEARCH_STRING = "PGM=IEFBR14"; REGEX_STRING = "IEFBR14|RC=0000"; BAD_SEARCH_STRING = "bluhbluh"; @@ -48,59 +50,84 @@ describe("zos-jobs search job command", () => { }); afterAll(async () => { - await TestEnvironment.cleanUp(TEST_ENVIRONMENT); + // Retrieve jobs by prefix + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, IEFBR14_JOB); + testEnvironment.resources.jobs = jobs; + + await TestEnvironment.cleanUp(testEnvironment); }); describe("Successful response", () => { - it("should be able to search for a string in every spool file for a job", () => { + it("should be able to search for a string in every spool file for a job", async () => { const response = runCliScript(__dirname + "/__scripts__/job/search_string_spool_content.sh", - TEST_ENVIRONMENT, [IEFBR14_JOB, JOB_NAME, SEARCH_STRING]); + testEnvironment, [IEFBR14_JOB, JOB_NAME, SEARCH_STRING]); + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain(SEARCH_STRING); }); - it("should be able to search for a regex in every spool file for a job", () => { + it("should be able to search for a regex in every spool file for a job", async () => { const argString = "--search-regex \"" + REGEX_STRING + "\""; const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", - TEST_ENVIRONMENT, [JOB_NAME, argString]); + testEnvironment, [JOB_NAME, argString]); + + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("IEFBR14"); expect(response.stdout.toString()).toContain("RC=0000"); }); - it("should limit the search when the --search-limit and --file-limit options are specified", () => { + it("should limit the search when the --search-limit and --file-limit options are specified", async () => { const argString = "--search-string \"" + SEARCH_STRING + "\" --search-limit 5 --file-limit 3"; const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", - TEST_ENVIRONMENT, [JOB_NAME, argString]); + testEnvironment, [JOB_NAME, argString]); + + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain(SEARCH_STRING); }); }); - describe("error handling", () => { - it("should return a status code of 1 if the string is not found", () => { + describe("error handling", () => { // Removed async from describe + it("should return a status code of 1 if the string is not found", async () => { const argString = "--search-string \"" + BAD_SEARCH_STRING + "\""; const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", - TEST_ENVIRONMENT, [JOB_NAME, argString]); + testEnvironment, [JOB_NAME, argString]); + + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + expect(response.stderr.toString()).toContain("The search spool job command returned a non-zero rc: 1"); expect(response.status).toBe(1); expect(response.stdout.toString()).toBe(""); }); - it("should fail if no parameters are passed", () => { + it("should fail if no parameters are passed", async () => { const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", - TEST_ENVIRONMENT, [JOB_NAME, ""]); + testEnvironment, [JOB_NAME, ""]); + + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + expect(response.stderr.toString()).toContain("You must specify either the `--search-string` or `--search-regex` option"); expect(response.status).toBe(1); }); - it("should fail if --search-string and --search-regex parameters are passed", () => { + it("should fail if --search-string and --search-regex parameters are passed", async () => { const argString = "--search-regex \"" + REGEX_STRING +"\" --search-string \"" + SEARCH_STRING + "\""; const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", - TEST_ENVIRONMENT, [JOB_NAME, argString]); + testEnvironment, [JOB_NAME, argString]); + + // Add a delay to ensure job is recognized + await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + expect(response.stderr.toString()).toContain("You must specify either the `--search-string` or `--search-regex` option"); expect(response.status).toBe(1); }); diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts index 273503352a..db73254af7 100644 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts @@ -10,15 +10,15 @@ */ import * as fs from "fs"; -import { Imperative, Session, TextUtils } from "@zowe/imperative"; +import { Imperative, IO, Session, TextUtils } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { ZosFilesMessages } from "../../../../src/constants/ZosFiles.messages"; import { Invoke } from "../../../../src/methods/invoke/Invoke"; import { getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; +import { posix } from "path"; let testEnvironment: ITestEnvironment; let systemProps: ITestPropertiesSchema; @@ -32,11 +32,9 @@ describe("Invoke AMS", () => { testEnvironment = await TestEnvironment.setUp({ tempProfileTypes: ["zosmf"], testName: "zos_create_VSAM_dataset" - }); - systemProps = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + }, REAL_SESSION = await TestEnvironment.createSession()); + systemProps = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); }); @@ -76,7 +74,7 @@ describe("Invoke AMS", () => { expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); // Delete the temp file - fs.unlinkSync(controlStatementFile); + IO.deleteFile(posix.basename(controlStatementFile)); // create a temporary file from the template file that has the proper high level qualifier to delete the VSAM file controlStatementFile = @@ -96,8 +94,8 @@ describe("Invoke AMS", () => { expect(response.success).toBe(true); expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - // Delete the temp file - fs.unlinkSync(controlStatementFile); + // Delete created temp local file + IO.deleteFile(posix.basename(controlStatementFile)); }); it("should create and delete a VSAM data set from command statement in files with response timeout", async () => { @@ -210,11 +208,9 @@ describe("Invoke AMS - encoded", () => { testEnvironment = await TestEnvironment.setUp({ tempProfileTypes: ["zosmf"], testName: "zos_create_VSAM_dataset" - }); - systemProps = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + }, REAL_SESSION = await TestEnvironment.createSession()); + systemProps = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.ENCO#ED.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); }); diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index 48d6d257a7..3e2241ccad 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -13,8 +13,7 @@ import { Create, CreateDataSetTypeEnum, Delete, IUploadOptions, IZosFilesRespons Upload, ZosFilesMessages, Download, Get, ZosFilesConstants, IUploadMap, Utilities } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName, stripNewLines, delay } from "../../../../../../__tests__/__src__/TestUtils"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; @@ -30,168 +29,260 @@ const inputfile = __dirname + "/testfiles/upload.txt"; const testdata = "abcdefghijklmnopqrstuvwxyz"; const uploadOptions: IUploadOptions = {} as any; -describe("Upload Data Set", () => { +describe("All Upload Tests", () => { + const localDir = `${__dirname}/testfiles`; + const localDirWithSpaces = `${__dirname}/testfiles/space dir`; + const failedTestFilesDir = `${__dirname}/failtestfiles`; beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + }, REAL_SESSION = await TestEnvironment.createSession()); + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); Imperative.console.info("Using dsname:" + dsname); + + try { + // Create test file directories + + if (!fs.existsSync(localDir)) { + fs.mkdirSync(localDir, { recursive: true }); + testEnvironment.resources.localFiles.push(localDir); + } + if (!fs.existsSync(localDirWithSpaces)) { + fs.mkdirSync(localDirWithSpaces, { recursive: true }); + testEnvironment.resources.localFiles.push(localDirWithSpaces); + } + if (!fs.existsSync(failedTestFilesDir)) { + fs.mkdirSync(failedTestFilesDir, { recursive: true }); + testEnvironment.resources.localFiles.push(failedTestFilesDir); + } + if (!fs.existsSync(`${localDir}/longline`)) { + fs.mkdirSync(`${localDir}/longline`, { recursive: true }); + testEnvironment.resources.localFiles.push(`${localDir}/longline`); + } + + // Create and write files with their contents + + // failedtestfiles/test1.txt + const test1FilePath = `${failedTestFilesDir}/test1.txt`; + fs.writeFileSync(test1FilePath, "fake data"); + testEnvironment.resources.localFiles.push(test1FilePath); + + // longline/longline.txt + const longlineFilePath = `${localDir}/longline/longline.txt`; + fs.writeFileSync(longlineFilePath, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); + testEnvironment.resources.localFiles.push(longlineFilePath); + + // space dir/file4.txt + const file4Path = `${localDirWithSpaces}/file4.txt`; + fs.writeFileSync(file4Path, "abcdefghijklmnopqrstuvwxyz"); + testEnvironment.resources.localFiles.push(file4Path); + + // file1.txt, file2.txt, file3.txt, and upload.txt + const filesToCreate = [ + `${localDir}/file1.txt`, + `${localDir}/file2.txt`, + `${localDir}/file3.txt`, + `${localDir}/upload.txt` + ]; + + filesToCreate.forEach((filepath) => { + fs.writeFileSync(filepath, "abcdefghijklmnopqrstuvwxyz"); + testEnvironment.resources.localFiles.push(filepath); + }); + + // main.exe is too complex to build from scratch + + } catch (err) { + console.error("Error setting up test files and directories:", err); + } }); afterAll(async () => { await TestEnvironment.cleanUp(testEnvironment); + + // Delete directories + const dirsToDelete = [localDir, localDirWithSpaces]; + dirsToDelete.forEach((dir) => { + try { + if (fs.existsSync(dir)) { + fs.rmdirSync(dir, { recursive: true }); + } + } catch (err) { + console.error(`Error deleting directory: ${dir}`, err); + } + }); }); - describe("Success Scenarios", () => { + describe("Upload Data Set", () => { - describe("Physical sequential", () => { + describe("Success Scenarios", () => { - beforeEach(async () => { - let error; - let response; - uploadOptions.etag = undefined; - uploadOptions.returnEtag = undefined; + describe("Physical sequential", () => { - try { - response = await Create.dataSet(REAL_SESSION, - CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - } catch (err) { - error = err; - } - }); + beforeEach(async () => { + let error; + let response; + uploadOptions.etag = undefined; + uploadOptions.returnEtag = undefined; - afterEach(async () => { - let error; - let response; + try { + response = await Create.dataSet(REAL_SESSION, + CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + } catch (err) { + error = err; + } + }); - try { - response = await Delete.dataSet(REAL_SESSION, dsname); - } catch (err) { - error = err; - } - }); + afterEach(async () => { + let error; + let response; - it("should upload a file to a physical sequential data set using full path", async () => { - let error; - let response: IZosFilesResponse; + try { + response = await Delete.dataSet(REAL_SESSION, dsname); + } catch (err) { + error = err; + } + }); - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + it("should upload a file to a physical sequential data set using full path", async () => { + let error; + let response: IZosFilesResponse; - it("should upload a file to a physical sequential data set with response timeout", async () => { - let error; - let response: IZosFilesResponse; + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname, {responseTimeout: 5}); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + it("should upload a file to a physical sequential data set with response timeout", async () => { + let error; + let response: IZosFilesResponse; - it("should upload a file to a physical sequential data set while passing correct Etag", async () => { - let error; - let response: IZosFilesResponse; + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname, {responseTimeout: 5}); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - // first we have to get the Etag, so we can compare it. We do it by preemtively downloading the file and requesting Etag - await Upload.fileToDataset(REAL_SESSION, __dirname + "/testfiles/upload.txt", dsname); - const downloadOptions = {file: __dirname + "/testfiles/upload.txt", returnEtag: true}; - const downloadResponse = await Download.dataSet(REAL_SESSION, dsname, downloadOptions); - expect(downloadResponse.success).toBeTruthy(); - expect(downloadResponse.apiResponse.etag).toBeDefined(); + it("should upload a file to a physical sequential data set while passing correct Etag", async () => { + let error; + let response: IZosFilesResponse; - try { - uploadOptions.etag = downloadResponse.apiResponse.etag; - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, __dirname + "/testfiles/upload.txt", dsname, uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + // first we have to get the Etag, so we can compare it. We do it by preemtively downloading the file and requesting Etag + await Upload.fileToDataset(REAL_SESSION, __dirname + "/testfiles/upload.txt", dsname); + const downloadOptions = {file: __dirname + "/testfiles/upload.txt", returnEtag: true}; + const downloadResponse = await Download.dataSet(REAL_SESSION, dsname, downloadOptions); + expect(downloadResponse.success).toBeTruthy(); + expect(downloadResponse.apiResponse.etag).toBeDefined(); - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + try { + uploadOptions.etag = downloadResponse.apiResponse.etag; + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, __dirname + "/testfiles/upload.txt", dsname, uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should upload a file to a physical sequential data set and return the Etag", async () => { - let error; - let response: IZosFilesResponse; - uploadOptions.returnEtag = true; + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname, uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - expect(response.apiResponse[0].etag).toBeDefined(); - }); + it("should upload a file to a physical sequential data set and return the Etag", async () => { + let error; + let response: IZosFilesResponse; + uploadOptions.returnEtag = true; - it("should upload a file to a physical sequential data set using relative path", async () => { - let error; - let response: IZosFilesResponse; + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname, uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + expect(response.apiResponse[0].etag).toBeDefined(); + }); - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - "./packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + it("should upload a file to a physical sequential data set using relative path", async () => { + let error; + let response: IZosFilesResponse; - // Since this test is platform specific, only run it on Windows - (process.platform === "win32" ? it : it.skip)("should upload a file to a physical sequential data set using Windows relative path", - async () => { + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + "./packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); + + // Since this test is platform specific, only run it on Windows + (process.platform === "win32" ? it : it.skip)("should upload a file to a physical sequential data set using Windows relative path", + async () => { + let error; + let response: IZosFilesResponse; + + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + ".\\packages\\zosfiles\\__tests__\\__system__\\methods\\upload\\testfiles\\upload.txt", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); + + it("should upload a file to a physical sequential data set in binary mode", async () => { let error; let response: IZosFilesResponse; + uploadOptions.binary = true; + try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ + // packages/zosfiles/__tests__/__system__/api/methods/upload/ response = await Upload.fileToDataset(REAL_SESSION, - ".\\packages\\zosfiles\\__tests__\\__system__\\methods\\upload\\testfiles\\upload.txt", dsname); + __dirname + "/testfiles/upload.txt", dsname, uploadOptions); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -203,179 +294,240 @@ describe("Upload Data Set", () => { expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should upload a file to a physical sequential data set in binary mode", async () => { - let error; - let response: IZosFilesResponse; + it("should upload a file to a physical sequential data set in binary mode with record specified", async () => { + let error; + let response: IZosFilesResponse; - uploadOptions.binary = true; + uploadOptions.binary = true; + uploadOptions.record = true; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname, uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname, uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - it("should upload a file to a physical sequential data set in binary mode with record specified", async () => { - let error; - let response: IZosFilesResponse; + it("should upload a file to a physical sequential data set in record mode", async () => { + let error; + let response: IZosFilesResponse; - uploadOptions.binary = true; - uploadOptions.record = true; + uploadOptions.record = true; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname, uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname, uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); + + it("should display proper error when specifying dir instead of a file", async () => { + let error; + let response: IZosFilesResponse; + + try { + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); + }); }); - it("should upload a file to a physical sequential data set in record mode", async () => { - let error; - let response: IZosFilesResponse; + describe("Partitioned data set", () => { - uploadOptions.record = true; + beforeEach(async () => { + let error; + let response; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname, uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + try { + response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + } catch (err) { + error = err; + } + }); - it("should display proper error when specifying dir instead of a file", async () => { - let error; - let response: IZosFilesResponse; + afterEach(async () => { + let error; + let response; - try { - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); - }); - }); + try { + response = await Delete.dataSet(REAL_SESSION, dsname); + } catch (err) { + error = err; + } + }); - describe("Partitioned data set", () => { + it("should upload a file to a partitioned data set member using full path", async () => { + let error; + let response: IZosFilesResponse; - beforeEach(async () => { - let error; - let response; + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname + "(member)"); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); + + it("should upload a file to a partitioned data set member with response timeout", async () => { + let error; + let response: IZosFilesResponse; + + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname + "(member)", {responseTimeout: 5}); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); + + it("should upload a file to a partitioned data set member using relative path", async () => { + let error; + let response: IZosFilesResponse; + + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + "./packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt", dsname + "(member)"); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - try { - response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - } catch (err) { - error = err; - } - }); + // Since this test is platform specific, only run it on Windows + (process.platform === "win32" ? it : it.skip)("should upload a file to a partitioned data set member using Windows relative path", + async () => { + let error; + let response: IZosFilesResponse; + + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + ".\\packages\\zosfiles\\__tests__\\__system__\\methods\\upload\\testfiles\\upload.txt", dsname + "(member)"); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); + + it("should upload a file to a partitioned data set member in binary mode", async () => { + let error; + let response: IZosFilesResponse; - afterEach(async () => { - let error; - let response; + uploadOptions.binary = true; - try { - response = await Delete.dataSet(REAL_SESSION, dsname); - } catch (err) { - error = err; - } - }); + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - it("should upload a file to a partitioned data set member using full path", async () => { - let error; - let response: IZosFilesResponse; + it("should upload a file to a partitioned data set member in binary mode with record specified", async () => { + let error; + let response: IZosFilesResponse; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)"); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + uploadOptions.binary = true; + uploadOptions.record = true; - it("should upload a file to a partitioned data set member with response timeout", async () => { - let error; - let response: IZosFilesResponse; + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)", {responseTimeout: 5}); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + it("should upload a file to a partitioned data set member in record mode", async () => { + let error; + let response: IZosFilesResponse; - it("should upload a file to a partitioned data set member using relative path", async () => { - let error; - let response: IZosFilesResponse; + uploadOptions.record = true; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - "./packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt", dsname + "(member)"); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - // Since this test is platform specific, only run it on Windows - (process.platform === "win32" ? it : it.skip)("should upload a file to a partitioned data set member using Windows relative path", - async () => { + it("should upload files in a directory to a partitioned data set member using full path", async () => { let error; let response: IZosFilesResponse; try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - ".\\packages\\zosfiles\\__tests__\\__system__\\methods\\upload\\testfiles\\upload.txt", dsname + "(member)"); + + response = await Upload.dirToPds(REAL_SESSION, __dirname + "/testfiles", dsname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -386,1025 +538,937 @@ describe("Upload Data Set", () => { expect(response.success).toBeTruthy(); expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); + }); + }); - it("should upload a file to a partitioned data set member in binary mode", async () => { - let error; - let response: IZosFilesResponse; + describe("Failure Scenarios", () => { - uploadOptions.binary = true; + beforeEach(async () => { + let error; + let response; try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); - Imperative.console.info("Response: " + inspect(response)); + response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); } catch (err) { error = err; - Imperative.console.info("Error: " + inspect(error)); } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should upload a file to a partitioned data set member in binary mode with record specified", async () => { + afterEach(async () => { let error; - let response: IZosFilesResponse; - - uploadOptions.binary = true; - uploadOptions.record = true; + let response; try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); - Imperative.console.info("Response: " + inspect(response)); + response = await Delete.dataSet(REAL_SESSION, dsname); } catch (err) { error = err; - Imperative.console.info("Error: " + inspect(error)); } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should upload a file to a partitioned data set member in record mode", async () => { + it("should display proper error when not specifying file", async () => { let error; let response: IZosFilesResponse; - uploadOptions.record = true; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); + __dirname + "/testfiles", dsname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); }); - it("should upload files in a directory to a partitioned data set member using full path", async () => { + it("should display proper error when not specifying data set", async () => { let error; let response: IZosFilesResponse; try { - - response = await Upload.dirToPds(REAL_SESSION, __dirname + "/testfiles", dsname); + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.text", ""); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingDatasetName.message); }); - }); - }); - - describe("Failure Scenarios", () => { - - beforeEach(async () => { - let error; - let response; - - try { - response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - } catch (err) { - error = err; - } - }); - - afterEach(async () => { - let error; - let response; - - try { - response = await Delete.dataSet(REAL_SESSION, dsname); - } catch (err) { - error = err; - } - }); - - it("should display proper error when not specifying file", async () => { - let error; - let response: IZosFilesResponse; - - try { - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); - }); - - it("should display proper error when not specifying data set", async () => { - let error; - let response: IZosFilesResponse; - - try { - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.text", ""); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingDatasetName.message); - }); - - it("should display proper error when specifying file instead of directory", async () => { - let error; - let response: IZosFilesResponse; - - try { - response = await Upload.dirToPds(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("is not a directory"); // pathIsNotDirectory error - }); - - it("should display proper error when specifying dir instead of a file", async () => { - let error; - let response: IZosFilesResponse; - - try { - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); - }); - - it("should display proper error when uploading the contents of a dir to a partitioned data set member", async () => { - let error; - let response: IZosFilesResponse; - - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.dirToPds(REAL_SESSION, - __dirname + "/testfiles", dsname + "(member)"); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.uploadDirectoryToDatasetMember.message); - }); - - it("should display proper error is line in file exceeds record length of data set", async () => { - let error; - let response: IZosFilesResponse; - try { - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles//longline/longline.txt", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(response).toBeTruthy(); - expect(response.success).toBeFalsy(); - expect(stripNewLines(response.commandResponse)).toContain("Truncation of a record occurred during an I/O operation"); - }); - }); -}); - -describe("Upload Data Set - encoded", () => { - - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); - Imperative.console.info("Using dsname:" + dsname); - }); - - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - - describe("Success Scenarios", () => { - - describe("Physical sequential", () => { - - beforeEach(async () => { - uploadOptions.etag = undefined; - uploadOptions.returnEtag = undefined; - - try { - await Create.dataSet(REAL_SESSION, - CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - } catch (err) { - // Do nothing - } - }); + it("should display proper error when specifying file instead of directory", async () => { + let error; + let response: IZosFilesResponse; - afterEach(async () => { try { - await Delete.dataSet(REAL_SESSION, dsname); + response = await Upload.dirToPds(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname); + Imperative.console.info("Response: " + inspect(response)); } catch (err) { - // Do nothing + error = err; + Imperative.console.info("Error: " + inspect(error)); } + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("is not a directory"); // pathIsNotDirectory error }); - it("should upload a file to a physical sequential data set using full path", async () => { + it("should display proper error when specifying dir instead of a file", async () => { let error; let response: IZosFilesResponse; try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname); + __dirname + "/testfiles", dsname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); }); - }); - describe("Partitioned data set", () => { - - beforeEach(async () => { - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - } catch (err) { - // Do nothing - } - }); + it("should display proper error when uploading the contents of a dir to a partitioned data set member", async () => { + let error; + let response: IZosFilesResponse; - afterEach(async () => { try { - await Delete.dataSet(REAL_SESSION, dsname); + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.dirToPds(REAL_SESSION, + __dirname + "/testfiles", dsname + "(member)"); + Imperative.console.info("Response: " + inspect(response)); } catch (err) { - // Do nothing + error = err; + Imperative.console.info("Error: " + inspect(error)); } + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.uploadDirectoryToDatasetMember.message); }); - it("should upload a file to a partitioned data set member using full path", async () => { + it("should display proper error is line in file exceeds record length of data set", async () => { let error; let response: IZosFilesResponse; try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)"); + __dirname + "/testfiles//longline/longline.txt", dsname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + expect(response.success).toBeFalsy(); + expect(stripNewLines(response.commandResponse)).toContain("Truncation of a record occurred during an I/O operation"); }); }); }); -}); -describe("Upload USS file", () => { + describe("Upload Data Set - encoded", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload_uss" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload" + }, REAL_SESSION = await TestEnvironment.createSession()); - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); - ussname = dsname.replace(/\./g, ""); - ussname = `${defaultSystem.unix.testdir}/${ussname}`; - Imperative.console.info("Using ussfile:" + ussname); - }); + defaultSystem = testEnvironment.systemTestProperties; + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); + Imperative.console.info("Using dsname:" + dsname); + }); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - describe("Success Scenarios", () => { + describe("Success Scenarios", () => { - beforeEach(async () => { - uploadOptions.etag = undefined; - fs.writeFileSync(inputfile, testdata); - }); + describe("Physical sequential", () => { - afterEach(async () => { - let error; - let response; + beforeEach(async () => { + uploadOptions.etag = undefined; + uploadOptions.returnEtag = undefined; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; + try { + await Create.dataSet(REAL_SESSION, + CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + } catch (err) { + // Do nothing + } + }); - try { - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - } catch (err) { - error = err; - } - }); + afterEach(async () => { + try { + await Delete.dataSet(REAL_SESSION, dsname); + } catch (err) { + // Do nothing + } + }); - it("should upload a USS file", async () => { - let error; - let uploadResponse; - let getResponse; - const data: Buffer = Buffer.from(testdata); + it("should upload a file to a physical sequential data set using full path", async () => { + let error; + let response: IZosFilesResponse; - try { - uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data); - getResponse = await Get.USSFile(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); + }); - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(data.toString())); + describe("Partitioned data set", () => { - }); - it("should upload a USS file in binary mode", async () => { - let error; - let uploadResponse; - let getResponse; - const data: Buffer = Buffer.from(testdata); + beforeEach(async () => { + try { + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + } catch (err) { + // Do nothing + } + }); - try { - uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data, { binary: true }); - getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + afterEach(async () => { + try { + await Delete.dataSet(REAL_SESSION, dsname); + } catch (err) { + // Do nothing + } + }); - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(data.toString())); + it("should upload a file to a partitioned data set member using full path", async () => { + let error; + let response: IZosFilesResponse; + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname + "(member)"); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); + }); }); - it("should upload a USS file from local file", async () => { - let error; - let uploadResponse; - let getResponse; - let tagResponse; + }); - try { - uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname); - getResponse = await Get.USSFile(REAL_SESSION, ussname); - tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + describe("Upload USS file", () => { - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(testdata)); - expect(tagResponse).toBe(false); + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload_uss" + }, REAL_SESSION = await TestEnvironment.createSession()); + defaultSystem = testEnvironment.systemTestProperties; + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); + ussname = dsname.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/${ussname}`; + Imperative.console.info("Using ussfile:" + ussname); }); - it("should upload a USS file from local file in binary mode", async () => { - let error; - let uploadResponse; - let getResponse; - let tagResponse; - - try { - uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, { binary: true }); - getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); - tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(testdata)); - expect(tagResponse).toBe(true); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); }); - it("should upload a USS file while passing correct Etag", async () => { - let error; - let uploadResponse; - // first we have to get the Etag, so we can compare it. We do it by preemtively downloading the file and requesting Etag - await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {returnEtag: false}); - const downloadResponse = await Download.ussFile(REAL_SESSION, ussname, {file: inputfile, returnEtag: true}); - expect(downloadResponse.success).toBeTruthy(); - expect(downloadResponse.apiResponse.etag).toBeDefined(); + describe("Success Scenarios", () => { - try { - uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {etag: downloadResponse.apiResponse.etag}); - Imperative.console.info("Response: " + inspect(uploadResponse)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + beforeEach(async () => { + uploadOptions.etag = undefined; + fs.writeFileSync(inputfile, testdata); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeTruthy(); - expect(uploadResponse.success).toBeTruthy(); - expect(uploadResponse.commandResponse).toContain(ZosFilesMessages.ussFileUploadedSuccessfully.message); - }); - it("should upload a USS file and return Etag", async () => { - let error; - let uploadResponse; - let getResponse; + afterEach(async () => { + let error; + let response; - try { - uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {returnEtag: true}); - getResponse = await Get.USSFile(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - expect(error).toBeFalsy(); - expect(uploadResponse).toBeTruthy(); - expect(uploadResponse.success).toBeTruthy(); - expect(uploadResponse.apiResponse.etag).toBeDefined(); - }); - }); -}); + try { + response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); + } catch (err) { + error = err; + } + }); -describe("Upload USS file - encoded", () => { + it("should upload a USS file", async () => { + let error; + let uploadResponse; + let getResponse; + const data: Buffer = Buffer.from(testdata); - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload_uss" - }); - defaultSystem = testEnvironment.systemTestProperties; + try { + uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data); + getResponse = await Get.USSFile(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(data.toString())); - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); - ussname = dsname.replace(/\./g, ""); - ussname = `${defaultSystem.unix.testdir}/ENCO#ED${ussname}`; - Imperative.console.info("Using ussfile:" + ussname); - }); + }); + it("should upload a USS file in binary mode", async () => { + let error; + let uploadResponse; + let getResponse; + const data: Buffer = Buffer.from(testdata); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); + try { + uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data, { binary: true }); + getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - describe("Success Scenarios", () => { + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(data.toString())); - beforeEach(async () => { - uploadOptions.etag = undefined; - fs.writeFileSync(inputfile, testdata); - }); + }); + it("should upload a USS file from local file", async () => { + let error; + let uploadResponse; + let getResponse; + let tagResponse; + + try { + uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname); + getResponse = await Get.USSFile(REAL_SESSION, ussname); + tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - afterEach(async () => { - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(testdata)); + expect(tagResponse).toBe(false); - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - } catch (err) { - // Do nothing - } - }); + }); + it("should upload a USS file from local file in binary mode", async () => { + let error; + let uploadResponse; + let getResponse; + let tagResponse; - it("should upload a USS file", async () => { - let error; - let getResponse; - const data: Buffer = Buffer.from(testdata); + try { + uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, { binary: true }); + getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); + tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - try { - await Upload.bufferToUssFile(REAL_SESSION, ussname, data); - getResponse = await Get.USSFile(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(testdata)); + expect(tagResponse).toBe(true); - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(data.toString())); + }); + it("should upload a USS file while passing correct Etag", async () => { + let error; + let uploadResponse; - }); + // first we have to get the Etag, so we can compare it. We do it by preemtively downloading the file and requesting Etag + await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {returnEtag: false}); + const downloadResponse = await Download.ussFile(REAL_SESSION, ussname, {file: inputfile, returnEtag: true}); + expect(downloadResponse.success).toBeTruthy(); + expect(downloadResponse.apiResponse.etag).toBeDefined(); - it("should upload a USS file from local file", async () => { - let error; - let getResponse; - let tagResponse; + try { + uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {etag: downloadResponse.apiResponse.etag}); + Imperative.console.info("Response: " + inspect(uploadResponse)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - try { - await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname); - getResponse = await Get.USSFile(REAL_SESSION, ussname); - tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(uploadResponse).toBeTruthy(); + expect(uploadResponse.success).toBeTruthy(); + expect(uploadResponse.commandResponse).toContain(ZosFilesMessages.ussFileUploadedSuccessfully.message); + }); + it("should upload a USS file and return Etag", async () => { + let error; + let uploadResponse; + let getResponse; - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(testdata)); - expect(tagResponse).toBe(false); + try { + uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {returnEtag: true}); + getResponse = await Get.USSFile(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(uploadResponse).toBeTruthy(); + expect(uploadResponse.success).toBeTruthy(); + expect(uploadResponse.apiResponse.etag).toBeDefined(); + }); }); }); -}); -describe("Upload a local directory to USS directory", () => { - describe("Success scenarios", () => { - const localDir = `${__dirname}/testfiles`; - const localDirWithSpaces = `${__dirname}/testfiles/space dir`; + describe("Upload USS file - encoded", () => { + beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload_dir_to_uss" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testName: "zos_file_upload_uss" + }, REAL_SESSION = await TestEnvironment.createSession()); - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); + defaultSystem = testEnvironment.systemTestProperties; + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); ussname = dsname.replace(/\./g, ""); - ussname = `${defaultSystem.unix.testdir}/${ussname}`; + ussname = `${defaultSystem.unix.testdir}/ENCO#ED${ussname}`; Imperative.console.info("Using ussfile:" + ussname); }); afterAll(async () => { - let error; await TestEnvironment.cleanUp(testEnvironment); - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, - ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname + " space dir"), - [{"X-IBM-Option": "recursive"}]); - } catch (err) { - error = err; - } }); - afterEach(async () => { - let error; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); - await delay(delayTime); - } catch (err) { - error = err; - } + describe("Success Scenarios", () => { + + beforeEach(async () => { + uploadOptions.etag = undefined; + fs.writeFileSync(inputfile, testdata); + }); + + afterEach(async () => { + const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); + + try { + await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); + } catch (err) { + // Do nothing + } + }); + + it("should upload a USS file", async () => { + let error; + let getResponse; + const data: Buffer = Buffer.from(testdata); + + try { + await Upload.bufferToUssFile(REAL_SESSION, ussname, data); + getResponse = await Get.USSFile(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(data.toString())); + + }); + + it("should upload a USS file from local file", async () => { + let error; + let getResponse; + let tagResponse; + + try { + await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname); + getResponse = await Get.USSFile(REAL_SESSION, ussname); + tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(testdata)); + expect(tagResponse).toBe(false); + + }); }); + }); + + describe("Upload a local directory to USS directory", () => { + describe("Success scenarios", () => { + const localDir = `${__dirname}/testfiles`; + const localDirWithSpaces = `${__dirname}/testfiles/space dir`; + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload_dir_to_uss" + }, REAL_SESSION = await TestEnvironment.createSession()); + + defaultSystem = testEnvironment.systemTestProperties; + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); + ussname = dsname.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/${ussname}`; + Imperative.console.info("Using ussfile:" + ussname); + }); + + afterAll(async () => { + let error; + await TestEnvironment.cleanUp(testEnvironment); + try { + await ZosmfRestClient.deleteExpectString(REAL_SESSION, + ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname + " space dir"), + [{"X-IBM-Option": "recursive"}]); + } catch (err) { + error = err; + } + }); - it("should upload local directory to USS", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: boolean; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname); - await delay(delayTime); - Imperative.console.info(`THIS IS USS ${ussname}/testfiles`); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + afterEach(async () => { + let error; + const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); + try { + await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); + await delay(delayTime); + } catch (err) { + error = err; + } + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + it("should upload local directory to USS", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: boolean; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname); + await delay(delayTime); + Imperative.console.info(`THIS IS USS ${ussname}/testfiles`); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should upload local directory (with space in name) to USS", async () => { - let error; - let tempUssname; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: boolean; - try { - tempUssname = ussname + " space dir"; - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDirWithSpaces, tempUssname); - await delay(delayTime); - Imperative.console.info(`THIS IS USS ${tempUssname}`); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, tempUssname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + it("should upload local directory (with space in name) to USS", async () => { + let error; + let tempUssname; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: boolean; + try { + tempUssname = ussname + " space dir"; + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDirWithSpaces, tempUssname); + await delay(delayTime); + Imperative.console.info(`THIS IS USS ${tempUssname}`); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, tempUssname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should upload local directory to USS recursively", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: any; - try { - uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false}); - await delay(delayTime); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + it("should upload local directory to USS recursively", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: any; + try { + uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false}); + await delay(delayTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should upload local directory to USS in binary mode", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: any; - let getResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname, {binary: true}); - await delay(delayTime); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); - getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: true}); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - expect(getResponse).toEqual(Buffer.from(testdata)); - }); + it("should upload local directory to USS in binary mode", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: any; + let getResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname, {binary: true}); + await delay(delayTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); + getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: true}); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should upload local directory to USS recursively and all files in binary mode", async () => { - let error; - let uploadResponse: IZosFilesResponse; - const magicNum = 6; - let isDirectoryExist: any; - let getResponse; - let longResponse: string = ""; - try { - uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: true}); - await delay(delayTime); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); - getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: true}); - for (let i = 0; i < magicNum; i++) { - longResponse += testdata; + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + expect(getResponse).toEqual(Buffer.from(testdata)); + }); + + it("should upload local directory to USS recursively and all files in binary mode", async () => { + let error; + let uploadResponse: IZosFilesResponse; + const magicNum = 6; + let isDirectoryExist: any; + let getResponse; + let longResponse: string = ""; + try { + uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: true}); + await delay(delayTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); + getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: true}); + for (let i = 0; i < magicNum; i++) { + longResponse += testdata; + } + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); } - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - expect(getResponse).toEqual(Buffer.from(longResponse)); - }); + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + expect(getResponse).toEqual(Buffer.from(longResponse)); + }); - it("should upload local directory to USS some files need to be uploaded as binary", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: any; - let getResponseFile3; - let getResponseFile1; - let getResponseLongFile; - let longResponse: string = ""; - const magicNum = 6; - const fileMap: IUploadMap = {binary: true, fileNames: ["file3.txt", "longline.txt"]}; - try { - uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false, filesMap: fileMap}); - await delay(delayTime); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); - // file3.txt should be binary as it is mentioned in filesMap - getResponseFile3 = await Get.USSFile(REAL_SESSION, `${ussname}/file3.txt`, {binary: true}); - // longline/longline.txt should be binary as it is mentioned in filesMap - getResponseLongFile = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: true}); - // file1.txt should be ASCII like other files not mentioned in filesMap - getResponseFile1 = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: false}); - for (let i = 0; i < magicNum; i++) { - longResponse += testdata; + it("should upload local directory to USS some files need to be uploaded as binary", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: any; + let getResponseFile3; + let getResponseFile1; + let getResponseLongFile; + let longResponse: string = ""; + const magicNum = 6; + const fileMap: IUploadMap = {binary: true, fileNames: ["file3.txt", "longline.txt"]}; + try { + uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false, filesMap: fileMap}); + await delay(delayTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); + // file3.txt should be binary as it is mentioned in filesMap + getResponseFile3 = await Get.USSFile(REAL_SESSION, `${ussname}/file3.txt`, {binary: true}); + // longline/longline.txt should be binary as it is mentioned in filesMap + getResponseLongFile = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: true}); + // file1.txt should be ASCII like other files not mentioned in filesMap + getResponseFile1 = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: false}); + for (let i = 0; i < magicNum; i++) { + longResponse += testdata; + } + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); } - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - expect(getResponseFile3).toEqual(Buffer.from(testdata)); - expect(getResponseLongFile).toEqual(Buffer.from(longResponse)); - expect(getResponseFile1.toString()).toEqual(testdata); - }); + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + expect(getResponseFile3).toEqual(Buffer.from(testdata)); + expect(getResponseLongFile).toEqual(Buffer.from(longResponse)); + expect(getResponseFile1.toString()).toEqual(testdata); + }); - it("should upload local directory to USS some files need to be uploaded as ASCII", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: any; - let getResponseFile3; - let getResponseFile1; - let getResponseLongFile; - let longResponse: string = ""; - const magicNum = 6; - const filesMap: IUploadMap = {binary: false, fileNames: ["file3.txt", "longline.txt"]}; - try { - uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: true, filesMap}); - await delay(delayTime); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); - // file3.txt should be ASCII as it is mentioned in filesMap - getResponseFile3 = await Get.USSFile(REAL_SESSION, `${ussname}/file3.txt`, {binary: false}); - // longline/longline.txt should be ASCII as it is mentioned in filesMap - getResponseLongFile = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: false}); - // file1.txt should be binary like other files not mentioned in filesMap - getResponseFile1 = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: true}); - for (let i = 0; i < magicNum; i++) { - longResponse += testdata; + it("should upload local directory to USS some files need to be uploaded as ASCII", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: any; + let getResponseFile3; + let getResponseFile1; + let getResponseLongFile; + let longResponse: string = ""; + const magicNum = 6; + const filesMap: IUploadMap = {binary: false, fileNames: ["file3.txt", "longline.txt"]}; + try { + uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: true, filesMap}); + await delay(delayTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); + // file3.txt should be ASCII as it is mentioned in filesMap + getResponseFile3 = await Get.USSFile(REAL_SESSION, `${ussname}/file3.txt`, {binary: false}); + // longline/longline.txt should be ASCII as it is mentioned in filesMap + getResponseLongFile = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: false}); + // file1.txt should be binary like other files not mentioned in filesMap + getResponseFile1 = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: true}); + for (let i = 0; i < magicNum; i++) { + longResponse += testdata; + } + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); } - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - expect(getResponseFile3).toEqual(Buffer.from(testdata)); - expect(getResponseLongFile).toEqual(Buffer.from(longResponse)); - expect(getResponseFile1).toEqual(Buffer.from(testdata)); + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + expect(getResponseFile3).toEqual(Buffer.from(testdata)); + expect(getResponseLongFile).toEqual(Buffer.from(longResponse)); + expect(getResponseFile1).toEqual(Buffer.from(testdata)); + }); }); - }); - describe("Fail scenarios", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload_dir_to_uss" - }); - defaultSystem = testEnvironment.systemTestProperties; + describe("Fail scenarios", () => { + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload_dir_to_uss" + }, REAL_SESSION = await TestEnvironment.createSession()); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + defaultSystem = testEnvironment.systemTestProperties; + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); - Imperative.console.info("Using ussfile:" + ussname); - }); + // Initialize `ussname` properly + ussname = dsname.replace(/\./g, ""); // Removing dots to avoid issues in path + ussname = `${defaultSystem.unix.testdir}/${ussname}`; + Imperative.console.info("Using ussfile:" + ussname); + }); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - let error; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); - } catch (err) { - error = err; - } - }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + let error; + const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; + try { + await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); + } catch (err) { + error = err; + } + }); - it("should throw an error if local directory is null", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, null, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + it("should throw an error if local directory is null", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, null, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); - expect(uploadResponse).not.toBeDefined(); - }); + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); + expect(uploadResponse).not.toBeDefined(); + }); - it("should throw an error if local directory is empty string", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "", ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + it("should throw an error if local directory is empty string", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "", ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); - expect(uploadResponse).not.toBeDefined(); - }); + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); + expect(uploadResponse).not.toBeDefined(); + }); - it("should throw an error if passed local directory doesn't exist", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + it("should throw an error if passed local directory doesn't exist", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain("no such file or directory"); - expect(uploadResponse).not.toBeDefined(); - }); + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain("no such file or directory"); + expect(uploadResponse).not.toBeDefined(); + }); - it("should throw an error if passed local directory is file", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, `${__dirname}/testfiles/file1.txt`, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + it("should throw an error if passed local directory is file", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, `${__dirname}/testfiles/file1.txt`, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); - expect(uploadResponse).not.toBeDefined(); - }); + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); + expect(uploadResponse).not.toBeDefined(); + }); - it("should throw an error if USS directory path is null", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", null); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + it("should throw an error if USS directory path is null", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", null); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingUSSDirectoryName.message); - expect(uploadResponse).not.toBeDefined(); - }); + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingUSSDirectoryName.message); + expect(uploadResponse).not.toBeDefined(); + }); - it("should throw an error if USS directory path is empty string", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", ""); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + it("should throw an error if USS directory path is empty string", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", ""); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingUSSDirectoryName.message); - expect(uploadResponse).not.toBeDefined(); - }); + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingUSSDirectoryName.message); + expect(uploadResponse).not.toBeDefined(); + }); - it("should throw an error if uploading file is binary but we are uploading it as ASCII", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, `${__dirname}/failtestfiles`, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + it("should throw an error if uploading file is binary but we are uploading it as ASCII", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, `${__dirname}/failtestfiles`, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeDefined(); - expect(error.message).toContain("Illegal character sequence detected by iconv()"); - expect(uploadResponse).toBeUndefined(); + expect(error).toBeDefined(); + expect(error.message).toContain("Illegal character sequence detected by iconv()"); + expect(uploadResponse).toBeUndefined(); + }); }); }); -}); -describe("Upload a local directory to USS directory - encoded", () => { - describe("Success scenarios", () => { - const localDir = `${__dirname}/testfiles`; - const localDirWithSpaces = `${__dirname}/testfiles/space dir`; - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload_dir_to_uss" + describe("Upload a local directory to USS directory - encoded", () => { + describe("Success scenarios", () => { + const localDir = `${__dirname}/testfiles`; + const localDirWithSpaces = `${__dirname}/testfiles/space dir`; + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload_dir_to_uss" + }, REAL_SESSION = await TestEnvironment.createSession()); + + defaultSystem = testEnvironment.systemTestProperties; + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); + ussname = dsname.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/ENCO#ED${ussname}`; + Imperative.console.info("Using ussfile:" + ussname); }); - defaultSystem = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); - ussname = dsname.replace(/\./g, ""); - ussname = `${defaultSystem.unix.testdir}/ENCO#ED${ussname}`; - Imperative.console.info("Using ussfile:" + ussname); - }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + try { + await ZosmfRestClient.deleteExpectString(REAL_SESSION, + ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname + " space dir"), + [{"X-IBM-Option": "recursive"}]); + } catch (err) { + // Do nothing + } + }); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, - ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname + " space dir"), - [{"X-IBM-Option": "recursive"}]); - } catch (err) { - // Do nothing - } - }); + afterEach(async () => { + const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); + try { + await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); + await delay(delayTime); + } catch (err) { + // Do nothing + } + }); - afterEach(async () => { - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); - await delay(delayTime); - } catch (err) { - // Do nothing - } - }); + it("should upload local directory to USS", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: boolean; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname); + await delay(delayTime); + Imperative.console.info(`THIS IS USS ${ussname}/testfiles`); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should upload local directory to USS", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: boolean; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname); - await delay(delayTime); - Imperative.console.info(`THIS IS USS ${ussname}/testfiles`); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + it("should upload local directory (with space in name) to USS", async () => { + let error; + let tempUssname; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: boolean; + try { + tempUssname = ussname + " space dir"; + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDirWithSpaces, tempUssname); + await delay(delayTime); + Imperative.console.info(`THIS IS USS ${tempUssname}`); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, tempUssname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should upload local directory (with space in name) to USS", async () => { - let error; - let tempUssname; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: boolean; - try { - tempUssname = ussname + " space dir"; - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDirWithSpaces, tempUssname); - await delay(delayTime); - Imperative.console.info(`THIS IS USS ${tempUssname}`); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, tempUssname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + it("should upload local directory to USS recursively", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: any; + try { + uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false}); + await delay(delayTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should upload local directory to USS recursively", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: any; - try { - uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false}); - await delay(delayTime); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); }); - }); -}); \ No newline at end of file +}); diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file1.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file1.txt deleted file mode 100644 index e85d5b4528..0000000000 --- a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file1.txt +++ /dev/null @@ -1 +0,0 @@ -abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file2.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file2.txt deleted file mode 100644 index e85d5b4528..0000000000 --- a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file2.txt +++ /dev/null @@ -1 +0,0 @@ -abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file3.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file3.txt deleted file mode 100644 index e85d5b4528..0000000000 --- a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file3.txt +++ /dev/null @@ -1 +0,0 @@ -abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/longline/longline.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/longline/longline.txt deleted file mode 100644 index 4c96ed84c3..0000000000 --- a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/longline/longline.txt +++ /dev/null @@ -1 +0,0 @@ -abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/space dir/file4.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/space dir/file4.txt deleted file mode 100644 index e85d5b4528..0000000000 --- a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/space dir/file4.txt +++ /dev/null @@ -1 +0,0 @@ -abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt deleted file mode 100644 index e85d5b4528..0000000000 --- a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt +++ /dev/null @@ -1 +0,0 @@ -abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts index d3a6bb3263..b5440681b8 100644 --- a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts @@ -10,67 +10,70 @@ */ import { posix } from "path"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { AbstractSession, Imperative, IO } from "@zowe/imperative"; -import { Utilities, Tag, Upload, Create, Download, Delete } from "../../../../src"; +import { Utilities, Tag, Upload, Create, Download } from "../../../../src"; import { getUniqueDatasetName, getTag } from "../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: AbstractSession; let testEnvironment: ITestEnvironment; describe("USS Utilities", () => { - const localfile = __dirname + "/__data__/tagfile.txt"; let ussname: string; + beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ tempProfileTypes: ["zosmf"], testName: "zos_files_utilities" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); + const defaultSystem = testEnvironment.systemTestProperties; let dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); dsname = dsname.replace(/\./g, ""); ussname = `${defaultSystem.unix.testdir}/${dsname}`; Imperative.console.info("Using ussDir:" + ussname); - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - }); + afterAll(async () => { - await Delete.ussFile(REAL_SESSION, ussname); await TestEnvironment.cleanUp(testEnvironment); }); it("should tag a binary file", async () => { - await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); + const fileResponse = await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); + const fileName = fileResponse.apiResponse.to; await Utilities.chtag(REAL_SESSION, ussname, Tag.BINARY); const tag = await getTag(REAL_SESSION, ussname); expect(tag).toMatch("b binary"); const isBin = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); expect(isBin).toBe(true); + testEnvironment.resources.files.push(fileName); }); it("should tag a text file", async () => { - await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); + const fileResponse = await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); + const fileName = fileResponse.apiResponse.to; await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "ISO8859-1"); const tag = await getTag(REAL_SESSION, ussname); expect(tag).toMatch("t ISO8859-1"); const isBin = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); expect(isBin).toBe(true); + testEnvironment.resources.files.push(fileName); }); it("should flag an EBCDIC file as text", async () => { - await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); + const fileResponse = await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); + const fileName = fileResponse.apiResponse.to; await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "IBM-1047"); const tag = await getTag(REAL_SESSION, ussname); expect(tag).toMatch("t IBM-1047"); const isBin = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); expect(isBin).toBe(false); + testEnvironment.resources.files.push(fileName); }); it("should rename USS file", async () => { @@ -93,6 +96,7 @@ describe("USS Utilities", () => { // Delete created local file IO.deleteFile(posix.basename(newName)); + testEnvironment.resources.files.push(newName); }); it("should rename USS file - encoded", async () => { @@ -115,11 +119,18 @@ describe("USS Utilities", () => { // Delete created local file IO.deleteFile(posix.basename(newName)); + testEnvironment.resources.files.push(newName); }); describe("applyTaggedEncoding", () => { + let fileName: string; beforeAll(async () => { - await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); + const fileResponse = await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); + fileName = fileResponse.apiResponse.to; + }); + + afterAll(async () => { + testEnvironment.resources.files.push(fileName); }); it("should set binary property if file is tagged as binary", async () => { From a505c0d53ddce448f4ec2ce58e6a2567a3a372d3 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 22 Aug 2024 11:11:30 -0400 Subject: [PATCH 07/65] took awhile to see the difference in regex between v1 and v2 that i was matching for this test. also took a while to identify which shell script was populating 2 jobs Signed-off-by: ATorrise --- .../cli-test-utils/src/TestUtils.ts | 13 ++--- .../src/environment/TestEnvironment.ts | 14 +++-- .../doc/response/ITestEnvironment.ts | 3 +- .../cli.zos-jobs.cancel.job.system.test.ts | 51 ++++++++++++++++--- 4 files changed, 61 insertions(+), 20 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts index be1feb9a44..014b1db6b7 100644 --- a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts +++ b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts @@ -13,7 +13,7 @@ import * as fs from "fs"; import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process"; import { ITestEnvironment } from "./environment/doc/response/ITestEnvironment"; import { AbstractSession, CommandProfiles, ICommandDefinition, IHandlerParameters, IO } from "@zowe/imperative"; -import { DeleteJobs, IDeleteJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; +import { DeleteJobs, ICommonJobParms, IDeleteJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; import { Delete } from "@zowe/zos-files-for-zowe-sdk" import { posix } from "path"; @@ -64,15 +64,10 @@ export function deleteJob(session: AbstractSession, job: IJob): void { /** * Delete a job from the mainframe using Zowe SDKs - jobid, jobname * @param {AbstractSession} session - z/OSMF connection info - * @param {jobName} string - jobname for job to delete - * @param {jobId} string - jobid for job to delete + * @param {params} ICommonJobParms - constains jobname and jobid for job to delete */ -export function deleteJobCommon(session: AbstractSession, job: IJob): void { - const parms: IDeleteJobParms = { - jobid: job.jobid, // job ID - jobname: job.jobname, // job name - }; - DeleteJobs.deleteJobCommon(session, parms); +export function deleteJobCommon(session: AbstractSession, params: ICommonJobParms): void { + DeleteJobs.deleteJobCommon(session, params as IDeleteJobParms); } diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index 35df225101..2297fa64f6 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -18,7 +18,7 @@ import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; import { PROJECT_ROOT_DIR, TEST_RESOURCE_DIR, TEST_RESULT_DATA_DIR, TEST_USING_WORKSPACE } from "../TestConstants"; -import { runCliScript, deleteFiles, deleteJob, deleteDataset, deleteLocalFile } from "../TestUtils"; +import { runCliScript, deleteFiles, deleteJob, deleteDataset, deleteLocalFile, deleteJobCommon } from "../TestUtils"; /** * Use the utility methods here to setup the test environment for running APIs @@ -68,9 +68,10 @@ export class TestEnvironment { resources: { localFiles: [], files: [], - jobs: [], + jobs: [], // Array of IJob objects + jobData: [], // Array of objects with jobid and jobname datasets: [], - ...(session && { session }) // Only include session if it is passed in + ...(session && { session }) // Only include session if it is passed in } }; @@ -138,6 +139,13 @@ export class TestEnvironment { for (const job of testEnvironment.resources.jobs) { deleteJob(session, job); } + for (const jobData of testEnvironment.resources.jobData) { + if (jobData.jobname && jobData.jobid) { + deleteJobCommon(session, jobData); + } else { + console.error('Error: Missing jobname or jobid for jobData:', jobData); + } + } for (const dataset of testEnvironment.resources.datasets) { deleteDataset(session, dataset); } diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts index babbd4ad11..9d2e305c06 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts @@ -10,7 +10,7 @@ */ import { AbstractSession } from "@zowe/imperative"; -import { IJob } from "@zowe/zos-jobs-for-zowe-sdk"; +import { ICommonJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; /** * The test environment for your test. @@ -22,6 +22,7 @@ export interface ITestEnvironment { localFiles: string[]; files: string[]; jobs: IJob[]; + jobData: ICommonJobParms[]; // Contains jobname and jobid datasets: string[]; session?: AbstractSession; }; diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index f83b35c13a..01a96aee2e 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -9,15 +9,17 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, runCliScript, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { JobTestsUtils } from "../../../../../zosjobs/__tests__/__system__/JobTestsUtils"; -import { IO } from "@zowe/imperative"; +import { AbstractSession, IO } from "@zowe/imperative"; // Test Environment populated in the beforeAll(); +let REAL_SESSION: AbstractSession; let TEST_ENVIRONMENT: ITestEnvironment; const LOCAL_JCL_FILE: string = __dirname + "/" + "testFileOfLocalJCL.txt"; +const jobDataRegexV1 = /Successfully submitted request to cancel job (\w+) \((JOB\d+)\)/; +const jobDataRegex = /Successfully canceled job (\w+) \((JOB\d+)\)/; describe("zos-jobs cancel job command", () => { // Create the unique test environment @@ -25,23 +27,25 @@ describe("zos-jobs cancel job command", () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_cancel_job_command", tempProfileTypes: ["zosmf"] - }); - const systemProps = TEST_ENVIRONMENT.systemTestProperties; + }, REAL_SESSION = await TestEnvironment.createSession()); + const systemProps = TEST_ENVIRONMENT.systemTestProperties; const jcl = JobTestsUtils.getSleepJCL(systemProps.zosmf.user, systemProps.tso.account, systemProps.zosjobs.jobclass); const bufferJCL: Buffer = Buffer.from(jcl); IO.createFileSync(LOCAL_JCL_FILE); IO.writeFile(LOCAL_JCL_FILE, bufferJCL); + TEST_ENVIRONMENT.resources.localFiles.push(LOCAL_JCL_FILE); }); afterAll(async () => { - IO.deleteFile(LOCAL_JCL_FILE); + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); describe("error handling", () => { it("should surface an error from z/OSMF if the jobid doesn't exist", () => { const response = runCliScript(__dirname + "/__scripts__/job/not_found.sh", TEST_ENVIRONMENT); + expect(response.status).toBe(1); expect(response.stdout.toString()).toBe(""); expect(response.stderr.toString()).toContain("Cannot obtain job info for job id = JOB00000"); @@ -51,6 +55,14 @@ describe("zos-jobs cancel job command", () => { it("should surface an error from z/OSMF if the jobid was already canceled", () => { runCliScript(__dirname + "/__scripts__/job/submit_job.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); const response = runCliScript(__dirname + "/__scripts__/job/cancel_job_v2_bad.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); + const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; + TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid }); + + // Calculate the previous job ID (one less) + const jobidNumber = parseInt(jobid.replace('JOB', ''), 10); //Extract the numeric part of the job ID + const previousJobid = 'JOB' + String(jobidNumber - 1).padStart(5, '0'); // then decrement by 1, assuming 5 digits in the job ID + TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid: previousJobid } ); + expect(response.status).toBe(1); expect(response.stderr.toString()).toContain("Failed to cancel job"); expect(response.stderr.toString()).toContain("Job not cancellable or purgeable"); @@ -62,25 +74,38 @@ describe("zos-jobs cancel job command", () => { describe("successful scenario", () => { it("should cancel a job v1", () => { const response = runCliScript(__dirname + "/__scripts__/job/cancel_job_v1.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); + const [, jobname, jobid] = response.stdout.toString().match(jobDataRegexV1) || []; + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully submitted request to cancel job"); + + TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid }); }); it("should cancel a job v2", () => { const response = runCliScript(__dirname + "/__scripts__/job/cancel_job_v2.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); + const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully canceled job"); expect(response.stdout.toString()).not.toContain("Failed to cancel job"); + + TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid }); }); it("should cancel a job default", () => { const response = runCliScript(__dirname + "/__scripts__/job/cancel_job.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); + const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully canceled job"); expect(response.stdout.toString()).not.toContain("Failed to cancel job"); + expect(response.stdout.toString()).not.toContain("Failed to cancel job"); + + TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid }); }); describe("without profiles", () => { @@ -92,7 +117,7 @@ describe("zos-jobs cancel job command", () => { beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_cancel_job_without_profiles" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); @@ -111,9 +136,13 @@ describe("zos-jobs cancel job command", () => { DEFAULT_SYSTEM_PROPS.zosmf.user, DEFAULT_SYSTEM_PROPS.zosmf.password, ]); + const [, jobname, jobid] = response.stdout.toString().match(jobDataRegexV1) || []; + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully submitted request to cancel job"); + + TEST_ENVIRONMENT_NO_PROF.resources.jobData.push({ jobname, jobid }); }); it("cancel a job without a profile 2.0", async () => { @@ -126,9 +155,13 @@ describe("zos-jobs cancel job command", () => { DEFAULT_SYSTEM_PROPS.zosmf.user, DEFAULT_SYSTEM_PROPS.zosmf.password, ]); + const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully canceled job"); + + TEST_ENVIRONMENT_NO_PROF.resources.jobData.push({ jobname, jobid }); }); it("cancel a job without a profile default", async () => { @@ -141,9 +174,13 @@ describe("zos-jobs cancel job command", () => { DEFAULT_SYSTEM_PROPS.zosmf.user, DEFAULT_SYSTEM_PROPS.zosmf.password, ]); + const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully canceled job"); + + TEST_ENVIRONMENT_NO_PROF.resources.jobData.push({ jobname, jobid }); }); }); }); From 56f0e9a1a537ad39ca32f43945ab1f9a00a97569 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 22 Aug 2024 11:27:33 -0400 Subject: [PATCH 08/65] providing more clarity in a comment about calculating previous jobid Signed-off-by: ATorrise --- .../__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index 01a96aee2e..6fc43e4e07 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -58,7 +58,7 @@ describe("zos-jobs cancel job command", () => { const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid }); - // Calculate the previous job ID (one less) + // Calculate the previous job ID (one less) - jobid created by test before, inaccessible until now const jobidNumber = parseInt(jobid.replace('JOB', ''), 10); //Extract the numeric part of the job ID const previousJobid = 'JOB' + String(jobidNumber - 1).padStart(5, '0'); // then decrement by 1, assuming 5 digits in the job ID TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid: previousJobid } ); From c458433709578e4febe56e160b46b7f098a5100f Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 22 Aug 2024 11:51:56 -0400 Subject: [PATCH 09/65] fixing cli.zos-jobs.download and its accompanying scripts Signed-off-by: ATorrise --- .../__scripts__/download-output/download.sh | 3 ++ .../download_fully_qualified.sh | 5 ++- ...li.zos-jobs.download.output.system.test.ts | 43 ++++++++++++++++--- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download.sh b/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download.sh index a8f477a047..8563a01a94 100755 --- a/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download.sh +++ b/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download.sh @@ -16,6 +16,9 @@ then exit $RC fi +# Echo the job ID for further use +echo "Submitted job ID: $JOBID" + # Loop until the job goes to the output queue until [ $ATTEMPTS -gt 0 ] do diff --git a/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download_fully_qualified.sh b/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download_fully_qualified.sh index f86e5b1d36..6a2ec9e2aa 100755 --- a/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download_fully_qualified.sh +++ b/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download_fully_qualified.sh @@ -22,8 +22,11 @@ then exit $RC fi +# Echo the job ID for further use +echo "Submitted job ID: $JOBID" + # Loop until the job goes to the output queue -until [ $ATTEMPTS -gt 0 ] +until [ $ATTEMPTS -le 0 ] do STATUS=`zowe jobs view job-status-by-jobid $JOBID --host $HOST --port $PORT --user $USER --password $PASS --ru=false --rff status --rft string` RC=$? diff --git a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts index f553570fc9..63a4dff4ef 100644 --- a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts @@ -9,12 +9,14 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { AbstractSession, IO } from "@zowe/imperative"; import * as fs from "fs"; +import { GetJobs, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; // Test Environment populated in the beforeAll(); +let REAL_SESSION: AbstractSession; let TEST_ENVIRONMENT: ITestEnvironment; let IEFBR14_JCL: string; @@ -24,10 +26,15 @@ describe("zos-jobs download output command", () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_download_output_command", tempProfileTypes: ["zosmf"] - }); + }, REAL_SESSION = await TestEnvironment.createSession()); + IEFBR14_JCL = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; }); + afterAll(async () => { + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); + }); + describe("error handling", () => { it("should surface an error from z/OSMF if the jobid doesn't exist", () => { const response = runCliScript(__dirname + "/__scripts__/download-output/not_found.sh", TEST_ENVIRONMENT); @@ -39,16 +46,29 @@ describe("zos-jobs download output command", () => { }); describe("output", () => { - it("should download all spool files of a job", () => { + it("should download all spool files of a job", async () => { const outdir: string = TEST_ENVIRONMENT.workingDir + "/output/JES2"; const response = runCliScript(__dirname + "/__scripts__/download-output/download.sh", TEST_ENVIRONMENT, [IEFBR14_JCL]); + + // Extract the JOBID from the response output + const jobidRegex = /Submitted job ID: (JOB\d+)/; + const match = response.stdout.toString().match(jobidRegex); + const jobid = match ? match[1] : null; + + // Ensure the job ID was captured correctly + expect(jobid).not.toBeNull(); + + const job: IJob = await GetJobs.getJob(REAL_SESSION, jobid); + expect(response.status).toBe(0); expect(response.stderr.toString()).toBe(""); expect(fs.existsSync(`${outdir}/JESMSGLG.txt`)).toBeTruthy(); expect(fs.existsSync(`${outdir}/JESJCL.txt`)).toBeTruthy(); expect(fs.existsSync(`${outdir}/JESYSMSG.txt`)).toBeTruthy(); expect(response.stdout.toString()).toContain("Successfully downloaded"); + + TEST_ENVIRONMENT.resources.jobs.push(job); }); describe("without profiles", () => { @@ -60,7 +80,7 @@ describe("zos-jobs download output command", () => { beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_download_output_without_profiles" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); @@ -88,12 +108,25 @@ describe("zos-jobs download output command", () => { DEFAULT_SYSTEM_PROPS.zosmf.user, DEFAULT_SYSTEM_PROPS.zosmf.password, ]); + + // Extract the JOBID from the response output + const jobidRegex = /Submitted job ID: (JOB\d+)/; + const match = response.stdout.toString().match(jobidRegex); + const jobid = match ? match[1] : null; + + // Ensure the job ID was captured correctly + expect(jobid).not.toBeNull(); + + const job: IJob = await GetJobs.getJob(REAL_SESSION, jobid); + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(fs.existsSync(`${outdir}/JESMSGLG.txt`)).toBeTruthy(); expect(fs.existsSync(`${outdir}/JESJCL.txt`)).toBeTruthy(); expect(fs.existsSync(`${outdir}/JESYSMSG.txt`)).toBeTruthy(); expect(response.stdout.toString()).toContain("Successfully downloaded"); + + TEST_ENVIRONMENT.resources.jobs.push(job); }); }); }); From e356ac8f88369a7f4d712f9d7d72d68f4dd4963b Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 22 Aug 2024 13:48:37 -0400 Subject: [PATCH 10/65] more cli sytem tests and ammended shell scripts Signed-off-by: ATorrise --- ...li.zos-jobs.download.output.system.test.ts | 2 +- .../list-jobs/submit_and_list_jobs.sh | 10 +- .../submit_and_list_jobs_fully_qualified.sh | 12 ++- .../submit_and_list_jobs_no_match.sh | 6 +- .../cli.zos-jobs.list.jobs.system.test.ts | 97 ++++++++++++++----- 5 files changed, 91 insertions(+), 36 deletions(-) diff --git a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts index 63a4dff4ef..96c393dd2a 100644 --- a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts @@ -11,7 +11,7 @@ import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { AbstractSession, IO } from "@zowe/imperative"; +import { AbstractSession } from "@zowe/imperative"; import * as fs from "fs"; import { GetJobs, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs.sh b/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs.sh index 524086b7b8..fc6f6e9979 100755 --- a/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs.sh +++ b/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs.sh @@ -1,8 +1,7 @@ #!/bin/bash set -e -# arguments: $1 is a data set name with JCL inside to submit - +# Submit two jobs and capture their IDs JOBID1=`zowe zos-jobs submit data-set $1 --rff jobid --rft string` JOBID2=`zowe zos-jobs submit data-set $1 --rff jobid --rft string` @@ -21,6 +20,9 @@ if echo $LIST_JOB_OUTPUT | grep -q $JOBID2 then echo "Second job ID $JOBID2 found" else - echo "Could not find secon job ID $JOBID2" + echo "Could not find second job ID $JOBID2" exit 1 -fi \ No newline at end of file +fi + +# Echo both job IDs for later retrieval +echo "Submitted jobs: $JOBID1 $JOBID2" \ No newline at end of file diff --git a/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs_fully_qualified.sh b/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs_fully_qualified.sh index 198dcf8b91..922016bd87 100755 --- a/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs_fully_qualified.sh +++ b/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs_fully_qualified.sh @@ -7,8 +7,7 @@ PORT=$3 USER=$4 PASS=$5 -# arguments: $1 is a data set name with JCL inside to submit - +# Submit two jobs and capture their IDs JOBID1=`zowe zos-jobs submit data-set $JCL --host $HOST --port $PORT --user $USER --password $PASS --ru=false --rff jobid --rft string` JOBID2=`zowe zos-jobs submit data-set $JCL --host $HOST --port $PORT --user $USER --password $PASS --ru=false --rff jobid --rft string` @@ -24,10 +23,13 @@ else exit 1 fi -if echo $LIST_JOB_OUTPUT | grep -q $JOBID1 +if echo $LIST_JOB_OUTPUT | grep -q $JOBID2 then echo "Second job ID $JOBID2 found" else - echo "Could not find secon job ID $JOBID2" + echo "Could not find second job ID $JOBID2" exit 1 -fi \ No newline at end of file +fi + +# Echo both job IDs for later retrieval +echo "Submitted jobs: $JOBID1 $JOBID2" \ No newline at end of file diff --git a/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs_no_match.sh b/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs_no_match.sh index 3b1463f3c4..9f7ca8ba04 100755 --- a/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs_no_match.sh +++ b/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/list-jobs/submit_and_list_jobs_no_match.sh @@ -1,8 +1,7 @@ #!/bin/bash set -e -# arguments: $1 is a data set name with JCL inside to submit - +# Submit one job and capture its ID JOBID1=`zowe zos-jobs submit data-set $1 --rff jobid --rft string` echo "Listing jobs to find job IDs $JOBID1" @@ -15,3 +14,6 @@ then else echo "No match - test passed" fi + +# Echo the job ID for later retrieval +echo "Submitted job: $JOBID1" \ No newline at end of file diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts index 54327bf0da..069b568d1b 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts @@ -9,15 +9,15 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { Session } from "@zowe/imperative"; +import { AbstractSession } from "@zowe/imperative"; +import { IJob, GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; let IEFBR14_JOB: string; -let REAL_SESSION: Session; +let REAL_SESSION: AbstractSession; let ACCOUNT: string; let JOB_NAME: string; let NON_HELD_JOBCLASS; @@ -38,10 +38,10 @@ describe("zos-jobs list jobs command", () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_list_jobs_command", tempProfileTypes: ["zosmf"] - }); + }, REAL_SESSION = await TestEnvironment.createSession()); + const systemProps = TEST_ENVIRONMENT.systemTestProperties; IEFBR14_JOB = systemProps.zosjobs.iefbr14Member; - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); ACCOUNT = systemProps.tso.account; const JOB_LENGTH = 6; @@ -55,24 +55,54 @@ describe("zos-jobs list jobs command", () => { describe("positive tests", () => { - it("should be able to submit two jobs and then find both in the output", - () => { - const response = runCliScript(scriptDir + "/submit_and_list_jobs.sh", TEST_ENVIRONMENT, - [TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member]); - expect(response.stderr.toString()).toBe(""); - expect(response.status).toBe(0); - expect(response.stdout.toString()).toContain("found"); - }); + it("should be able to submit two jobs and then find both in the output", async () => { + const response = runCliScript(scriptDir + "/submit_and_list_jobs.sh", TEST_ENVIRONMENT, + [TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member]); - it("should be able to submit one job and then not see the job if we list jobs for a different user", - () => { - // note: this test could fail if your user Id starts with "FAKE" - const response = runCliScript(scriptDir + "/submit_and_list_jobs_no_match.sh", TEST_ENVIRONMENT, - [TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member]); - expect(response.stderr.toString()).toBe(""); - expect(response.status).toBe(0); - expect(response.stdout.toString()).toContain("test passed"); - }); + // Regex to extract both JOBIDs + const jobidRegex = /(?:First|Second) job ID (JOB\d+) found/g; + + // Extract all matching job IDs + const jobIds = [...response.stdout.toString().matchAll(jobidRegex)].map(match => match[1]); + + // Ensure both job IDs were captured correctly + expect(jobIds.length).toBe(2); + const [job1Id, job2Id] = jobIds; + + // Retrieve job details using the Zowe SDK + const job1: IJob = await GetJobs.getJob(REAL_SESSION, job1Id); + const job2: IJob = await GetJobs.getJob(REAL_SESSION, job2Id); + + expect(job1 && job2).toBeDefined(); + expect(response.stderr.toString()).toBe(""); + expect(response.status).toBe(0); + expect(response.stdout.toString()).toContain("found"); + + TEST_ENVIRONMENT.resources.jobs.push(job1, job2); + }); + + it("should be able to submit one job and then not see the job if we list jobs for a different user", async () => { + // note: this test could fail if your user Id starts with "FAKE" + const response = runCliScript(scriptDir + "/submit_and_list_jobs_no_match.sh", TEST_ENVIRONMENT, + [TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member]); + + // Regex to extract the JOBID + const jobidRegex = /Submitted job: (JOB\d+)/; + const match = response.stdout.toString().match(jobidRegex); + const jobId = match ? match[1] : null; + + expect(jobId).not.toBeNull(); + + // Retrieve job details using the Zowe SDK + const job: IJob = await GetJobs.getJob(REAL_SESSION, jobId); + expect(job).toBeDefined(); + + expect(response.stderr.toString()).toBe(""); + expect(response.status).toBe(0); + expect(response.stdout.toString()).toContain("test passed"); + + TEST_ENVIRONMENT.resources.jobs.push(job); + }); describe("without profiles", () => { @@ -83,7 +113,8 @@ describe("zos-jobs list jobs command", () => { beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_job_without_profiles" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); + SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); @@ -109,9 +140,27 @@ describe("zos-jobs list jobs command", () => { SYSTEM_PROPS.zosmf.user, SYSTEM_PROPS.zosmf.password, ]); + + // Regex to extract both JOBIDs + const jobidRegex = /(?:First|Second) job ID (JOB\d+) found/g; + + // Extract all matching job IDs + const jobIds = [...response.stdout.toString().matchAll(jobidRegex)].map(match => match[1]); + + // Ensure both job IDs were captured correctly + expect(jobIds.length).toBe(2); + const [job1Id, job2Id] = jobIds; + + // Retrieve job details using the Zowe SDK + const job1: IJob = await GetJobs.getJob(REAL_SESSION, job1Id); + const job2: IJob = await GetJobs.getJob(REAL_SESSION, job2Id); + + expect(job1 && job2).toBeDefined(); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("found"); + + TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(job1, job2); }); }); }); From 123c7f9ad9b32c1deed252f2fe1d4876cd298fe2 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 22 Aug 2024 13:59:21 -0400 Subject: [PATCH 11/65] finishin clizosjobslistspoolfiles Signed-off-by: ATorrise --- .../submit_and_list_dds.sh | 14 ++--- .../submit_and_list_dds_fully_qualified.sh | 14 ++--- ...s.list.spool-files-by-jobid.system.test.ts | 56 +++++++++++++------ 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/spool-files-by-jobid/submit_and_list_dds.sh b/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/spool-files-by-jobid/submit_and_list_dds.sh index e41a62609c..7eb453b4f4 100755 --- a/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/spool-files-by-jobid/submit_and_list_dds.sh +++ b/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/spool-files-by-jobid/submit_and_list_dds.sh @@ -1,5 +1,4 @@ #!/bin/bash -# TODO - delete the job from spool # Submit the job and ensure the RC is 0 JOBID="$(zowe jobs submit ds "$1" --rff jobid --rft string)" CMDRC=$? @@ -9,12 +8,13 @@ then echo "Submit returned a non-zero return code" 1>&2 exit $CMDRC fi -echo $JOBID + +# Echo the JOBID for retrieval in tests +echo "Submitted job ID: $JOBID" + # Loop until the status is output STATUS="" -while [ "$STATUS" != "OUTPUT" ]; do - - # get the status +while [ "$STATUS" != "OUTPUT" ]; do STATUS="$(zowe zos-jobs view job-status-by-jobid $JOBID --rff status --rft string)" RC=$? if [ $RC -gt 0 ] @@ -23,7 +23,7 @@ while [ "$STATUS" != "OUTPUT" ]; do echo "The submit data set command returned a non-zero return code: $RC" 1>&2 exit $RC fi -done +done zowe zos-jobs list spool-files-by-jobid $JOBID -exit $? +exit $? \ No newline at end of file diff --git a/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/spool-files-by-jobid/submit_and_list_dds_fully_qualified.sh b/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/spool-files-by-jobid/submit_and_list_dds_fully_qualified.sh index 5f36f30092..7ef8a4761d 100755 --- a/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/spool-files-by-jobid/submit_and_list_dds_fully_qualified.sh +++ b/packages/cli/__tests__/zosjobs/__system__/list/__scripts__/spool-files-by-jobid/submit_and_list_dds_fully_qualified.sh @@ -6,7 +6,6 @@ PORT=$3 USER=$4 PASS=$5 -# TODO - delete the job from spool # Submit the job and ensure the RC is 0 JOBID="$(zowe jobs submit ds "$JCL" --host $HOST --port $PORT --user $USER --password $PASS --ru=false --rff jobid --rft string)" CMDRC=$? @@ -16,12 +15,13 @@ then echo "Submit returned a non-zero return code" 1>&2 exit $CMDRC fi -echo $JOBID + +# Echo the JOBID for retrieval in tests +echo "Submitted job ID: $JOBID" + # Loop until the status is output STATUS="" -while [ "$STATUS" != "OUTPUT" ]; do - - # get the status +while [ "$STATUS" != "OUTPUT" ]; do STATUS="$(zowe zos-jobs view job-status-by-jobid $JOBID --host $HOST --port $PORT --user $USER --password $PASS --ru=false --rff status --rft string)" RC=$? if [ $RC -gt 0 ] @@ -30,7 +30,7 @@ while [ "$STATUS" != "OUTPUT" ]; do echo "The submit data set command returned a non-zero return code: $RC" 1>&2 exit $RC fi -done +done zowe zos-jobs list spool-files-by-jobid $JOBID --host $HOST --port $PORT --user $USER --password $PASS --ru=false -exit $? +exit $? \ No newline at end of file diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts index b90a2aeb63..71a247964e 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts @@ -9,19 +9,18 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { AbstractSession, TextUtils } from "@zowe/imperative"; +import { IJob, GetJobs, SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; import * as fs from "fs"; -import { Session, TextUtils } from "@zowe/imperative"; -import { IJob, SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; -import { TEST_RESOURCES_DIR } from "../../../../../../packages/zosjobs/__tests__/__src__/ZosJobsTestConstants"; import { join } from "path"; +import { TEST_RESOURCES_DIR } from "@zowe/zos-jobs-for-zowe-sdk/__tests__/__src__/ZosJobsTestConstants"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; let IEFBR14_JOB: string; -let REAL_SESSION: Session; +let REAL_SESSION: AbstractSession; let ACCOUNT: string; let JOB_NAME: string; let NON_HELD_JOBCLASS: string; @@ -31,7 +30,6 @@ const LONG_TIMEOUT = 100000; const trimMessage = (message: string) => { // don't use more than one space or tab when checking error details - // this allows us to expect things like "reason: 6" regardless of how prettyjson aligns the text return message.replace(/( {2,})|\t/g, " "); }; @@ -41,12 +39,11 @@ describe("zos-jobs list spool-files-by-jobid command", () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_list_spool_files_by_jobid_command", tempProfileTypes: ["zosmf"] - }); + }, REAL_SESSION = await TestEnvironment.createSession()); + IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 6; JOB_NAME = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + "SF"; @@ -82,19 +79,29 @@ describe("zos-jobs list spool-files-by-jobid command", () => { }); describe("response", () => { - it("should display the ddnames for a job", () => { + it("should display the ddnames for a job", async () => { const response = runCliScript(__dirname + "/__scripts__/spool-files-by-jobid/submit_and_list_dds.sh", TEST_ENVIRONMENT, [IEFBR14_JOB]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); - // TODO: Hopefully these DDs are deterministic on all of our test systems. - // TODO: Once available, we can submit from a local file via command - // TODO: with certain DDs (wanted this test to be entirely script driven - // TODO: to capture a "real world" scenario) + // Extract the JOBID using regex + const jobidRegex = /Submitted job ID: (JOB\d+)/; + const match = response.stdout.toString().match(jobidRegex); + const jobId = match ? match[1] : null; + + // Ensure the JOBID was captured correctly + expect(jobId).not.toBeNull(); + + // Retrieve job details using the Zowe SDK + const job: IJob = await GetJobs.getJob(REAL_SESSION, jobId); + + // Validate DDs and output expect(response.stdout.toString()).toContain("JESMSGLG"); expect(response.stdout.toString()).toContain("JESJCL"); expect(response.stdout.toString()).toContain("JESYSMSG"); + + TEST_ENVIRONMENT.resources.jobs.push(job); }); it("should display the the procnames and ddnames for a job", async () => { @@ -116,6 +123,8 @@ describe("zos-jobs list spool-files-by-jobid command", () => { expect(response.stdout.toString()).toContain("SYSTSPRT"); expect(response.stdout.toString()).toContain("TSOSTEP1"); expect(response.stdout.toString()).toContain("TSOSTEP2"); + + TEST_ENVIRONMENT.resources.jobs.push(job); }, LONG_TIMEOUT); describe("without profiles", () => { @@ -127,7 +136,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_spool_files_by_jobid_without_profiles" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); @@ -156,9 +165,24 @@ describe("zos-jobs list spool-files-by-jobid command", () => { ]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); + + // Extract the JOBID using regex + const jobidRegex = /Submitted job ID: (JOB\d+)/; + const match = response.stdout.toString().match(jobidRegex); + const jobId = match ? match[1] : null; + + // Ensure the JOBID was captured correctly + expect(jobId).not.toBeNull(); + + // Retrieve job details using the Zowe SDK + const job: IJob = await GetJobs.getJob(REAL_SESSION, jobId); + + // Validate DDs and output expect(response.stdout.toString()).toContain("JESMSGLG"); expect(response.stdout.toString()).toContain("JESJCL"); expect(response.stdout.toString()).toContain("JESYSMSG"); + + TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(job); }, LONG_TIMEOUT); }); }); From d7b2840ea0757c43f7db239ced7fa93f74ebebc1 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 22 Aug 2024 16:31:21 -0400 Subject: [PATCH 12/65] fixing submit with a different, less intensive cleanup approach Signed-off-by: ATorrise --- .../search/cli.zos-jobs.search.job.test.ts | 2 +- ...li.zos-jobs.submit.data-set.system.test.ts | 30 +++++++++++++------ .../__system__/CancelJobs.system.test.ts | 4 +-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index bed23278ce..1349121946 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -51,7 +51,7 @@ describe("zos-jobs search job command", () => { afterAll(async () => { // Retrieve jobs by prefix - const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, IEFBR14_JOB); + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); testEnvironment.resources.jobs = jobs; await TestEnvironment.cleanUp(testEnvironment); diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts index 6449eb7b64..386b756ef3 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts @@ -9,43 +9,51 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; -import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { List } from "../../../../../../zosfiles/src/methods/list"; -import { Session } from "@zowe/imperative"; +import { AbstractSession } from "@zowe/imperative"; +import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk/lib/GetJobs"; process.env.FORCE_COLOR = "0"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; +let REAL_SESSION: AbstractSession; +let JOB_NAME: string; let account: string; let jclMember: string; let psJclDataSet: string; -let REAL_SESSION: Session; describe("zos-jobs submit data-set command", () => { // Create the unique test environment beforeAll(async () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_submit_command", tempProfileTypes: ["zosmf"] - }); + }, REAL_SESSION = await TestEnvironment.createSession()); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = TEST_ENVIRONMENT.systemTestProperties.tso.account; jclMember = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; psJclDataSet = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14PSDataSet; }); afterAll(async () => { + // Retrieve jobs by prefix + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); + TEST_ENVIRONMENT.resources.jobs = jobs; + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); - describe("Live system tests", () => { it("should submit a job in an existing valid data set from a PDS member", async () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_data_set.sh", TEST_ENVIRONMENT, [jclMember]); + + const jobidRegex = /jobname: (\w+)/; + const match = response.stdout.toString().match(jobidRegex); + JOB_NAME = match ? match[1] : null; + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("jobname"); @@ -134,13 +142,17 @@ describe("zos-jobs submit data-set command", () => { beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_submit_data_set_without_profiles" - }); + }, REAL_SESSION = await TestEnvironment.createSession()); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); afterAll(async () => { - await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); + // Retrieve jobs by prefix + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); + TEST_ENVIRONMENT.resources.jobs = jobs; + + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); it("should submit a job in an existing valid data set from a PDS member", async () => { diff --git a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts index 62b320bb4b..e2736e4dd8 100644 --- a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts @@ -9,13 +9,13 @@ * */ -import { ImperativeError, Session, RestClientError } from "@zowe/imperative"; +import { ImperativeError, RestClientError, AbstractSession } from "@zowe/imperative"; import { CancelJobs, SubmitJobs, IJob } from "../../src"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { JobTestsUtils } from "./JobTestsUtils"; import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; -let REAL_SESSION: Session; +let REAL_SESSION: AbstractSession; let sleepJCL: string; let systemProps: ITestPropertiesSchema; From e1f2ca215fe92e7a121846eb785ac9e82349dfc6 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Fri, 23 Aug 2024 10:17:27 -0400 Subject: [PATCH 13/65] realizing need to keep createZosmfSession for uss files.. Signed-off-by: ATorrise --- ...li.zos-jobs.submit.data-set.system.test.ts | 1 + ...li.zos-jobs.submit.uss-file.system.test.ts | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts index 386b756ef3..057aefaaec 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts @@ -50,6 +50,7 @@ describe("zos-jobs submit data-set command", () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_data_set.sh", TEST_ENVIRONMENT, [jclMember]); + // 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/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts index c527d941c0..5791c788b5 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts @@ -13,16 +13,20 @@ import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Session } from "@zowe/imperative"; +import * as path from "path"; // Import path module for path handling +import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; process.env.FORCE_COLOR = "0"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; +let REAL_SESSION: Session; +let JOB_NAME: string; let account: string; let jclMember: string; let ussFile: string; -let REAL_SESSION: Session; + describe("zos-jobs submit uss-file command", () => { // Create the unique test environment beforeAll(async () => { @@ -34,9 +38,18 @@ describe("zos-jobs submit uss-file command", () => { REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = TEST_ENVIRONMENT.systemTestProperties.tso.account; ussFile = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14USSFile; + + // Convert the USS file path to the correct format for Unix if needed + ussFile = path.posix.resolve(ussFile); }); afterAll(async () => { + // Retrieve jobs by prefix and clean them up + if (JOB_NAME) { + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); + TEST_ENVIRONMENT.resources.jobs = jobs; + } + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); @@ -44,6 +57,12 @@ describe("zos-jobs submit uss-file command", () => { it("should submit a job in an existing valid uss file", async () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_uss_file.sh", TEST_ENVIRONMENT, [ussFile]); + + // Set jobname for cleanup of all jobs + const jobidRegex = /jobname: (\w+)/; + const match = response.stdout.toString().match(jobidRegex); + JOB_NAME = match ? match[1] : null; + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("jobname"); @@ -116,6 +135,12 @@ describe("zos-jobs submit uss-file command", () => { }); afterAll(async () => { + // Retrieve jobs by prefix and clean them up + if (JOB_NAME) { + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); + TEST_ENVIRONMENT_NO_PROF.resources.jobs = jobs; + } + await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); @@ -137,6 +162,12 @@ describe("zos-jobs submit uss-file command", () => { SYSTEM_PROPS.zosmf.user, SYSTEM_PROPS.zosmf.password, ]); + + // Set jobname for cleanup of all jobs + const jobidRegex = /jobname: (\w+)/; + const match = response.stdout.toString().match(jobidRegex); + JOB_NAME = match ? match[1] : null; + expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("jobname"); From 4ccaad56ac4427b840f4b3d846642b26fc1b7ab2 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Fri, 23 Aug 2024 10:50:11 -0400 Subject: [PATCH 14/65] finishing cliZosjobsSubmit Signed-off-by: ATorrise --- ....zos-jobs.submit.local-file.system.test.ts | 44 +++++++++++++++---- .../cli.zos-jobs.submit.stdin.system.test.ts | 38 +++++++++++++--- 2 files changed, 68 insertions(+), 14 deletions(-) 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; }); }); }); From c5995ddf8326fd6f2c230256835e48a49700693f Mon Sep 17 00:00:00 2001 From: ATorrise Date: Fri, 23 Aug 2024 12:00:28 -0400 Subject: [PATCH 15/65] fixing error in variable name across files and finishing view spool tests for cliZosJobs Signed-off-by: ATorrise --- ...li.zos-jobs.submit.data-set.system.test.ts | 4 +- ....zos-jobs.submit.local-file.system.test.ts | 7 ++-- .../cli.zos-jobs.submit.stdin.system.test.ts | 9 ++--- ...li.zos-jobs.submit.uss-file.system.test.ts | 7 ++-- ...jobs.view.all-spool-content.system.test.ts | 37 +++++++++++++------ ...bs.view.job-status-by-jobid.system.test.ts | 32 ++++++++++++++-- ...-jobs.view.spool-file-by-id.system.test.ts | 30 ++++++++++++--- 7 files changed, 91 insertions(+), 35 deletions(-) diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts index 057aefaaec..1802033b30 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts @@ -21,6 +21,7 @@ process.env.FORCE_COLOR = "0"; let TEST_ENVIRONMENT: ITestEnvironment; let REAL_SESSION: AbstractSession; let JOB_NAME: string; +const jobNameRegex = /jobname: (\w+)/; let account: string; let jclMember: string; @@ -51,8 +52,7 @@ describe("zos-jobs submit data-set command", () => { TEST_ENVIRONMENT, [jclMember]); // Set jobname for cleanup of all jobs - const jobidRegex = /jobname: (\w+)/; - const match = response.stdout.toString().match(jobidRegex); + const match = response.stdout.toString().match(jobNameRegex); JOB_NAME = match ? match[1] : null; expect(response.stderr.toString()).toBe(""); 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 ad2d28d772..ad22c489e2 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 @@ -25,6 +25,7 @@ let systemProps: ITestPropertiesSchema; let account: string; let jcl: string; let JOB_NAME: string; +const jobNameRegex = /jobname: (\w+)/; describe("zos-jobs submit local-file command", () => { // Create the unique test environment @@ -71,8 +72,7 @@ describe("zos-jobs submit local-file command", () => { expect(response.stdout.toString()).toContain("jobid"); // Set jobname for cleanup of all jobs - const jobidRegex = /jobname: (\w+)/; - const match = response.stdout.toString().match(jobidRegex); + const match = response.stdout.toString().match(jobNameRegex); JOB_NAME = match ? match[1] : null; }); @@ -166,8 +166,7 @@ describe("zos-jobs submit local-file command", () => { expect(response.stdout.toString()).toContain("jobid"); // Set jobname for cleanup of all jobs - const jobidRegex = /jobname: (\w+)/; - const match = response.stdout.toString().match(jobidRegex); + const match = response.stdout.toString().match(jobNameRegex); 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 a15e16bf82..7121c66068 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 @@ -25,7 +25,8 @@ let systemProps: ITestPropertiesSchema; let account: string; let jcl: string; let JOB_NAME: string; - +const jobNameRegex = /jobname: (\w+)/; +s describe("zos-jobs submit stdin command", () => { beforeAll(async () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ @@ -70,8 +71,7 @@ describe("zos-jobs submit stdin command", () => { expect(response.stdout.toString()).toContain("jobid"); // Set jobname for cleanup of all jobs - const jobidRegex = /jobname: (\w+)/; - const match = response.stdout.toString().match(jobidRegex); + const match = response.stdout.toString().match(jobNameRegex); JOB_NAME = match ? match[1] : null; }); @@ -161,8 +161,7 @@ describe("zos-jobs submit stdin command", () => { expect(response.stdout.toString()).toContain("jobid"); // Set jobname for cleanup of all jobs - const jobidRegex = /jobname: (\w+)/; - const match = response.stdout.toString().match(jobidRegex); + const match = response.stdout.toString().match(jobNameRegex); JOB_NAME = match ? match[1] : null; }); }); diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts index 5791c788b5..32cb467b4b 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts @@ -22,6 +22,7 @@ process.env.FORCE_COLOR = "0"; let TEST_ENVIRONMENT: ITestEnvironment; let REAL_SESSION: Session; let JOB_NAME: string; +const jobNameRegex = /jobname: (\w+)/; let account: string; let jclMember: string; @@ -59,8 +60,7 @@ describe("zos-jobs submit uss-file command", () => { TEST_ENVIRONMENT, [ussFile]); // Set jobname for cleanup of all jobs - const jobidRegex = /jobname: (\w+)/; - const match = response.stdout.toString().match(jobidRegex); + const match = response.stdout.toString().match(jobNameRegex); JOB_NAME = match ? match[1] : null; expect(response.stderr.toString()).toBe(""); @@ -164,8 +164,7 @@ describe("zos-jobs submit uss-file command", () => { ]); // Set jobname for cleanup of all jobs - const jobidRegex = /jobname: (\w+)/; - const match = response.stdout.toString().match(jobidRegex); + const match = response.stdout.toString().match(jobNameRegex); JOB_NAME = match ? match[1] : null; expect(response.stderr.toString()).toBe(""); diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts index ebd08c8d5d..a3a95fea86 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts @@ -1,18 +1,8 @@ -/* -* This program and the accompanying materials are made available under the terms of the -* Eclipse Public License v2.0 which accompanies this distribution, and is available at -* https://www.eclipse.org/legal/epl-v20.html -* -* SPDX-License-Identifier: EPL-2.0 -* -* Copyright Contributors to the Zowe Project. -* -*/ - import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Session } from "@zowe/imperative"; +import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; @@ -22,6 +12,9 @@ let ACCOUNT: string; let JOB_NAME: string; let NON_HELD_JOBCLASS: string; +// Regex to match any job name that starts with "IEFBR14" +const jobNameRegex = /IEFBR14\w*/; + describe("zos-jobs view all-spool-content command", () => { // Create the unique test environment beforeAll(async () => { @@ -41,6 +34,12 @@ describe("zos-jobs view all-spool-content 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.resources.jobs.push(...jobs); + } + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); @@ -53,6 +52,10 @@ describe("zos-jobs view all-spool-content command", () => { expect(response.stdout.toString()).not.toContain("!!!SPOOL FILE"); expect(response.stdout.toString()).toContain("Spool file: JESMSGLG"); expect(response.stdout.toString()).toContain("PGM=IEFBR14"); + + // Set jobname for cleanup of all jobs + const match = response.stdout.toString().match(jobNameRegex); + JOB_NAME = match ? match[0] : null; }); describe("without profiles", () => { @@ -70,6 +73,12 @@ describe("zos-jobs view all-spool-content 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); }); @@ -96,6 +105,10 @@ describe("zos-jobs view all-spool-content command", () => { expect(response.stdout.toString()).not.toContain("!!!SPOOL FILE"); expect(response.stdout.toString()).toContain("Spool file: JESMSGLG"); expect(response.stdout.toString()).toContain("PGM=IEFBR14"); + + // Set jobname for cleanup of all jobs + const match = response.stdout.toString().match(jobNameRegex); + JOB_NAME = match ? match[0] : null; }); }); }); @@ -110,4 +123,4 @@ describe("zos-jobs view all-spool-content command", () => { expect(response.stderr.toString()).toContain("Zero jobs were returned"); }); }); -}); +}); \ No newline at end of file diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts index 4c614e5f83..8f6946bdc9 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts @@ -12,16 +12,22 @@ import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { ICommandResponse } from "@zowe/imperative"; +import { ICommandResponse, Session } from "@zowe/imperative"; +import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; +let REAL_SESSION: Session; // Pulled from test properties file let account: string; let systemProps: ITestPropertiesSchema; let jclMember: string; let psJclDataSet: string; +let JOB_NAME: string; + +// Regex to match any job name that starts with "IEFBR14" +const jobNameRegex = /IEFBR14\w*/; describe("zos-jobs view job-status-by-jobid command", () => { // Create the unique test environment @@ -31,6 +37,8 @@ describe("zos-jobs view job-status-by-jobid command", () => { testName: "zos_jobs_view_job_status_by_jobid_command" }); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + systemProps = TEST_ENVIRONMENT.systemTestProperties; account = systemProps.tso.account; @@ -39,6 +47,11 @@ describe("zos-jobs view job-status-by-jobid command", () => { }); afterAll(async () => { + if (JOB_NAME) { + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); + TEST_ENVIRONMENT.resources.jobs.push(...jobs); + } + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); @@ -52,6 +65,10 @@ describe("zos-jobs view job-status-by-jobid command", () => { expect(response.stdout.toString()).toContain("jobid:"); expect(response.stdout.toString()).toContain("status:"); expect(response.stdout.toString()).toContain("retcode:"); + + // Set jobname for cleanup of all jobs + const match = response.stdout.toString().match(jobNameRegex); + JOB_NAME = match ? match[0] : null; }); it("should be able to submit the job then view the job and the details should match", () => { @@ -69,7 +86,7 @@ describe("zos-jobs view job-status-by-jobid command", () => { "/__scripts__/job-status-by-jobid/view_rfj.sh", TEST_ENVIRONMENT, [submitJson.data.jobid]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); - const viewJson: ICommandResponse = JSON.parse(response.stdout.toString()); + const viewJson: ICommandResponse = JSON.parse(viewResponse.stdout.toString()); expect(viewJson.success).toBe(true); expect(viewJson.data.jobid).toBe(submitJson.data.jobid); expect(viewJson.data.jobname).toBe(submitJson.data.jobname); @@ -93,11 +110,16 @@ describe("zos-jobs view job-status-by-jobid command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_view_job_status_by_jobid_command_without_profiles" }); - + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); afterAll(async () => { + 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); }); @@ -125,6 +147,10 @@ describe("zos-jobs view job-status-by-jobid command", () => { expect(response.stdout.toString()).toContain("jobid:"); expect(response.stdout.toString()).toContain("status:"); expect(response.stdout.toString()).toContain("retcode:"); + + // Set jobname for cleanup of all jobs + const match = response.stdout.toString().match(jobNameRegex); + JOB_NAME = match ? match[0] : null; }); }); }); diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts index b50c4bec4b..e71259fa42 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts @@ -14,18 +14,21 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Session, TextUtils } from "@zowe/imperative"; import * as fs from "fs"; -import { IJob, SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; +import { IJob, SubmitJobs, GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; import { TEST_RESOURCES_DIR } from "../../../../../../packages/zosjobs/__tests__/__src__/ZosJobsTestConstants"; import { join } from "path"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; -let IEFBR14_JOB: string; let REAL_SESSION: Session; +let IEFBR14_JOB: string; let ACCOUNT: string; let JOB_NAME: string; let NON_HELD_JOBCLASS: string; +// Regex to match any job name that starts with "IEFBR14" +const jobNameRegex = /IEFBR14\w*/; + describe("zos-jobs view spool-file-by-id command", () => { // Create the unique test environment beforeAll(async () => { @@ -34,10 +37,9 @@ describe("zos-jobs view spool-file-by-id command", () => { tempProfileTypes: ["zosmf"] }); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 6; JOB_NAME = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + "SF"; @@ -45,6 +47,11 @@ describe("zos-jobs view spool-file-by-id command", () => { }); afterAll(async () => { + if (JOB_NAME) { + const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); + TEST_ENVIRONMENT.resources.jobs.push(...jobs); + } + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); @@ -56,13 +63,17 @@ describe("zos-jobs view spool-file-by-id command", () => { expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("!!!SPOOL FILE"); expect(response.stdout.toString()).toContain("PGM=IEFBR14"); + + // Set jobname for cleanup of all jobs + const match = response.stdout.toString().match(jobNameRegex); + JOB_NAME = match ? match[0] : null; }); it("should be able to view the contents of the requested DD", async () => { // Construct the JCL const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/multiple_procs.jcl")).toString(); const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: JOB_NAME, ACCOUNT, JOBCLASS: NON_HELD_JOBCLASS}); + { JOBNAME: JOB_NAME, ACCOUNT, JOBCLASS: NON_HELD_JOBCLASS }); // Submit the job const job: IJob = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); @@ -92,6 +103,11 @@ describe("zos-jobs view spool-file-by-id command", () => { }); afterAll(async () => { + 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); }); @@ -117,6 +133,10 @@ describe("zos-jobs view spool-file-by-id command", () => { expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("!!!SPOOL FILE"); expect(response.stdout.toString()).toContain("PGM=IEFBR14"); + + // Set jobname for cleanup of all jobs + const match = response.stdout.toString().match(jobNameRegex); + JOB_NAME = match ? match[0] : null; }); }); }); From a0fa936adfdd7a225643a9d8fb34bde390c2d508 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Mon, 26 Aug 2024 10:34:03 -0400 Subject: [PATCH 16/65] unable to modify file like others Signed-off-by: ATorrise --- .../dtu/cli.dir.upload.dtu.system.test.ts | 106 ++++++++---------- 1 file changed, 49 insertions(+), 57 deletions(-) diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts index 7f666208d2..1ccaed57ca 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts @@ -16,7 +16,7 @@ import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName, getTag } from "../../../../../../../__tests__/__src__/TestUtils"; -import { Get, ZosFilesConstants, ZosFilesUtils } from "@zowe/zos-files-for-zowe-sdk"; +import { Get, ZosFilesConstants, ZosFilesUtils, Delete } from "@zowe/zos-files-for-zowe-sdk"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; let REAL_SESSION: Session; @@ -34,7 +34,6 @@ let dsname: string; describe("Upload directory to USS", () => { beforeAll(async () => { - TEST_ENVIRONMENT = await TestEnvironment.setUp({ tempProfileTypes: ["zosmf"], testName: "zos_files_upload_directory_to_uss_with_profile" @@ -53,37 +52,44 @@ describe("Upload directory to USS", () => { }); afterAll(async () => { + // Clean up the USS directory + try { + const ussEndpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; + await ZosmfRestClient.deleteExpectString(REAL_SESSION, ussEndpoint, [{"X-IBM-Option": "recursive"}]); + } catch (err) { + Imperative.console.info(`Error cleaning up USS directory: ${err}`); + } + + // Clean up the datasets + try { + await Delete.dataSet(REAL_SESSION, dsname); + } catch (err) { + Imperative.console.info(`Error cleaning up dataset: ${err}`); + } + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); describe("without profiles", () => { let defaultSys: ITestPropertiesSchema; - // Create the unique test environment beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "upload_dir_to_uss" }); defaultSys = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; - Imperative.console.info("Using ussDir:" + ussname); }); - afterEach(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - + afterAll(async () => { try { - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); + const ussEndpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; + await ZosmfRestClient.deleteExpectString(REAL_SESSION, ussEndpoint, [{"X-IBM-Option": "recursive"}]); } catch (err) { - error = err; + Imperative.console.info(`Error cleaning up USS directory: ${inspect(err)}`); } - }); - afterAll(async () => { await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); @@ -93,7 +99,7 @@ describe("Upload directory to USS", () => { const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; - // if API Mediation layer is being used (basePath has a value) then + // If API Mediation layer is being used (basePath has a value) then // set an ENVIRONMENT variable to be used by zowe. if (defaultSys.zosmf.basePath != null) { TEST_ENVIRONMENT_NO_PROF.env[ZOWE_OPT_BASE_PATH] = defaultSys.zosmf.basePath; @@ -117,15 +123,11 @@ describe("Upload directory to USS", () => { describe("Success scenarios", () => { afterEach(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - try { - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); + const ussEndpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; + await ZosmfRestClient.deleteExpectString(REAL_SESSION, ussEndpoint, [{"X-IBM-Option": "recursive"}]); } catch (err) { - error = err; + Imperative.console.info(`Error cleaning up USS directory: ${inspect(err)}`); } }); @@ -227,13 +229,7 @@ describe("Upload directory to USS", () => { ussname ]); - - // const downloadResponse = await Download.ussFile(REAL_SESSION, path.posix.join(ussname, "bin_file.pax"), { file: localFileLocation }); - // expect(downloadResponse.success).toBe(true); - // // fs.readFileSync(localFileLocation).toString(); returns an empty buffer ???? Getting the file directly seems to work consistently - // const downloadedFileContents = fs.readFileSync(localFileLocation).toString(); - - const downloadedFileContents = (await Get.USSFile(REAL_SESSION, path.posix.join(ussname, "bin_file.pax"), {binary: false})).toString(); + const downloadedFileContents = (await Get.USSFile(REAL_SESSION, path.posix.join(ussname, "bin_file.pax"), { binary: false })).toString(); expect(downloadedFileContents).toContain("00000000125"); expect(downloadedFileContents).toContain("13424013123"); expect(response.stderr.toString()).not.toContain("Rest API failure with HTTP(S) status 500"); @@ -310,14 +306,13 @@ describe("Upload directory to USS", () => { expect(err).toBeDefined(); } - let tag = await getTag(REAL_SESSION,ussname + "/I%20have%20a%20space.txt"); + let tag = await getTag(REAL_SESSION, ussname + "/I%20have%20a%20space.txt"); expect(tag).toMatch("t IBM-1140"); - tag = await getTag(REAL_SESSION,ussname + "/dir_with%20spaces/file%20withSpaceinName.txt"); + tag = await getTag(REAL_SESSION, ussname + "/dir_with%20spaces/file%20withSpaceinName.txt"); expect(tag).toMatch("t IBM-1140"); }); - it("should upload files in binary or text as indicated", async () => { const localDirName = path.join(__dirname, "__data__", "command_upload_dtu_dir/dir_with_mixed_files"); @@ -328,7 +323,7 @@ describe("Upload directory to USS", () => { expect(ZosFilesUtils.normalizeNewline(remoteTextFileBuffer)).toEqual(ZosFilesUtils.normalizeNewline(localTextFileBuffer)); - const remoteBinaryFileBuffer = await Get.USSFile(REAL_SESSION, ussname + "/bar.binary", {binary: true}); + const remoteBinaryFileBuffer = await Get.USSFile(REAL_SESSION, ussname + "/bar.binary", { binary: true }); const localBinaryFileBuffer = fs.readFileSync(path.join(localDirName, "bar.binary")); expect(remoteBinaryFileBuffer).toEqual(localBinaryFileBuffer); }); @@ -338,13 +333,13 @@ describe("Upload directory to USS", () => { testSuccessfulUpload(localDirName); - let tag = await getTag(REAL_SESSION,ussname + "/baz.asciitext"); + let tag = await getTag(REAL_SESSION, ussname + "/baz.asciitext"); expect(tag).toMatch("t ISO8859-1"); - tag = await getTag(REAL_SESSION,ussname + "/foo.text"); + tag = await getTag(REAL_SESSION, ussname + "/foo.text"); expect(tag).toMatch("t IBM-1047"); - tag = await getTag(REAL_SESSION,ussname + "/bar.binary"); + tag = await getTag(REAL_SESSION, ussname + "/bar.binary"); expect(tag).toMatch("b binary"); }); @@ -353,10 +348,10 @@ describe("Upload directory to USS", () => { testSuccessfulUpload(localDirName, ["--include-hidden"]); - let tag = await getTag(REAL_SESSION,ussname + "/.project"); + let tag = await getTag(REAL_SESSION, ussname + "/.project"); expect(tag).toMatch("t IBM-1047"); - tag = await getTag(REAL_SESSION,ussname + "/.hidden"); + tag = await getTag(REAL_SESSION, ussname + "/.hidden"); expect(tag).toMatch("b binary"); }); @@ -399,31 +394,31 @@ describe("Upload directory to USS", () => { testSuccessfulUpload(localDirName, ["--recursive --binary"]); - let tag = await getTag(REAL_SESSION,ussname + "/piccpy.png"); + let tag = await getTag(REAL_SESSION, ussname + "/piccpy.png"); expect(tag).toMatch("b binary"); - tag = await getTag(REAL_SESSION,ussname + "/picCopyMe.png"); + tag = await getTag(REAL_SESSION, ussname + "/picCopyMe.png"); expect(tag).toMatch("b binary"); - tag = await getTag(REAL_SESSION,ussname + "/picCopyMeToo.png"); + tag = await getTag(REAL_SESSION, ussname + "/picCopyMeToo.png"); expect(tag).toMatch("b binary"); - tag = await getTag(REAL_SESSION,ussname + "/picCopy.png"); + tag = await getTag(REAL_SESSION, ussname + "/picCopy.png"); expect(tag).toMatch("b binary"); - tag = await getTag(REAL_SESSION,ussname + "/picCopyNoTagPlease.png"); + tag = await getTag(REAL_SESSION, ussname + "/picCopyNoTagPlease.png"); expect(tag).toMatch("b binary"); - tag = await getTag(REAL_SESSION,ussname + "/copyMe.txt"); + tag = await getTag(REAL_SESSION, ussname + "/copyMe.txt"); expect(tag).toMatch("t IBM-1047"); - tag = await getTag(REAL_SESSION,ussname + "/copyMeToo.txt"); + tag = await getTag(REAL_SESSION, ussname + "/copyMeToo.txt"); expect(tag).toMatch("t IBM-1047"); - tag = await getTag(REAL_SESSION,ussname + "/copyAndMeToo.txt"); + tag = await getTag(REAL_SESSION, ussname + "/copyAndMeToo.txt"); expect(tag).toMatch("t IBM-1140"); - tag = await getTag(REAL_SESSION,ussname + "/copyButDontTagMe.text"); + tag = await getTag(REAL_SESSION, ussname + "/copyButDontTagMe.text"); expect(tag).toMatch("b binary"); let error: Error; @@ -458,8 +453,6 @@ describe("Upload directory to USS", () => { error = err; } expect(error).toBeDefined(); - - }); it("should accept zosattributes path as an argument to a nested attributes file (the attribute file should not be uploaded)", async () => { @@ -468,20 +461,19 @@ describe("Upload directory to USS", () => { "command_upload_dtu_dir/dir_with_nested_attributefile/nest_attribute_folder/.attributes"); testSuccessfulUpload(localDirName, ["--r --attributes", path.relative(TEST_ENVIRONMENT.workingDir, attributesPath)]); - let tag = await getTag(REAL_SESSION,ussname + "/baz.asciitext"); + let tag = await getTag(REAL_SESSION, ussname + "/baz.asciitext"); expect(tag).toMatch("t ISO8859-1"); - tag = await getTag(REAL_SESSION,ussname + "/foo.text"); + tag = await getTag(REAL_SESSION, ussname + "/foo.text"); expect(tag).toMatch("t IBM-1047"); - tag = await getTag(REAL_SESSION,ussname + "/bar.binary"); + tag = await getTag(REAL_SESSION, ussname + "/bar.binary"); expect(tag).toMatch("b binary"); - tag = await getTag(REAL_SESSION,ussname + "/nest_attribute_folder/baz.asciitext"); + tag = await getTag(REAL_SESSION, ussname + "/nest_attribute_folder/baz.asciitext"); expect(tag).toMatch("t ISO8859-1"); - tag = await getTag(REAL_SESSION,ussname + "/nest_attribute_folder/foo.text"); + tag = await getTag(REAL_SESSION, ussname + "/nest_attribute_folder/foo.text"); expect(tag).toMatch("t IBM-1047"); - tag = await getTag(REAL_SESSION,ussname + "/nest_attribute_folder/bar.binary"); + tag = await getTag(REAL_SESSION, ussname + "/nest_attribute_folder/bar.binary"); expect(tag).toMatch("b binary"); - let error: Error; try { await Get.USSFile(REAL_SESSION, ussname + "/dir_with_nested_attributefile/nest_attribute_folder/.attributes"); @@ -507,4 +499,4 @@ function testSuccessfulUpload(localDirName: string, additionalParameters?: strin const response = runCliScript(shellScript, TEST_ENVIRONMENT, parms); expect(response.stderr.toString()).toBe(""); expect(response.stdout.toString()).toContain("Directory uploaded successfully."); -} +} \ No newline at end of file From f746a0b4577a8313ac3628a8ad7e86b6945f6526 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Mon, 26 Aug 2024 10:44:07 -0400 Subject: [PATCH 17/65] deletes remaining ds from mf Signed-off-by: ATorrise --- .../fs/cli.files.mount.fs.system.test.ts | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts index 705c181e88..e1c3fa8302 100644 --- a/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts @@ -1,3 +1,4 @@ + /* * This program and the accompanying materials are made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, and is available at @@ -9,7 +10,7 @@ * */ -import { Session } from "@zowe/imperative"; +import { Imperative, Session } from "@zowe/imperative"; import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; @@ -40,12 +41,15 @@ describe("Mount and unmount file system", () => { REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); fsname = getUniqueDatasetName(defaultSystem.zosmf.user); + TEST_ENVIRONMENT.resources.datasets.push(fsname); // Track the dataset for cleanup const dirname = getUniqueDatasetName(defaultSystem.zosmf.user).split(".")[1]; mountPoint = "//tmp/" + dirname; + TEST_ENVIRONMENT.resources.files.push(mountPoint); // Track the USS directory for cleanup + const sshCommand = "mkdir " + mountPoint; - const response = runCliScript(__dirname + "/__scripts__/command/command_setup.sh", + runCliScript(__dirname + "/__scripts__/command/command_setup.sh", TEST_ENVIRONMENT, [sshCommand, fsname, defaultSystem.ssh.host, defaultSystem.ssh.port, @@ -54,14 +58,19 @@ describe("Mount and unmount file system", () => { }); afterAll(async () => { - const sshCommand = "rmdir " + mountPoint; - const response = runCliScript(__dirname + "/__scripts__/command/command_teardown.sh", - TEST_ENVIRONMENT, [sshCommand, fsname, - defaultSystem.ssh.host, - defaultSystem.ssh.port, - defaultSystem.ssh.user, - defaultSystem.ssh.password]); - + try { + const sshCommand = "rmdir " + mountPoint; + runCliScript(__dirname + "/__scripts__/command/command_teardown.sh", + TEST_ENVIRONMENT, [sshCommand, fsname, + defaultSystem.ssh.host, + defaultSystem.ssh.port, + defaultSystem.ssh.user, + defaultSystem.ssh.password]); + } catch (err) { + Imperative.console.info(`Error cleaning up USS directory: ${err}`); + } + + // Clean up any resources tracked by the test environment await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); From f334c7600f603d8c83846d75e010272da539bf6c Mon Sep 17 00:00:00 2001 From: Amber Torrise <112635587+ATorrise@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:04:57 -0400 Subject: [PATCH 18/65] Update cli.zos-jobs.submit.stdin.system.test.ts to remove semicolon Signed-off-by: Amber Torrise <112635587+ATorrise@users.noreply.github.com> --- .../submit/stdin/cli.zos-jobs.submit.stdin.system.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7121c66068..f9f483f48e 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 @@ -25,7 +25,7 @@ let systemProps: ITestPropertiesSchema; let account: string; let jcl: string; let JOB_NAME: string; -const jobNameRegex = /jobname: (\w+)/; +const jobNameRegex = /jobname: (\w+)/ s describe("zos-jobs submit stdin command", () => { beforeAll(async () => { From e11726f0f151cde078dbd7091f1df4cca0ffdd4c Mon Sep 17 00:00:00 2001 From: Amber Torrise <112635587+ATorrise@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:08:15 -0400 Subject: [PATCH 19/65] Update cli.zos-jobs.submit.stdin.system.test.ts removing accidental line Signed-off-by: Amber Torrise <112635587+ATorrise@users.noreply.github.com> --- .../submit/stdin/cli.zos-jobs.submit.stdin.system.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f9f483f48e..2f96e00daf 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 @@ -26,7 +26,7 @@ let account: string; let jcl: string; let JOB_NAME: string; const jobNameRegex = /jobname: (\w+)/ -s + describe("zos-jobs submit stdin command", () => { beforeAll(async () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ From 70cb5221816afb99244ba248123522d025a976f4 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Mon, 26 Aug 2024 11:14:02 -0400 Subject: [PATCH 20/65] whoops Signed-off-by: ATorrise --- ...cli.zos-jobs.view.all-spool-content.system.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts index a3a95fea86..2ae6ef3c1c 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts @@ -1,3 +1,14 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; From 0b475ac9c2cf8250b3a59016f97a35bdc5ba1181 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Tue, 27 Aug 2024 07:59:30 -0400 Subject: [PATCH 21/65] changelog Signed-off-by: ATorrise --- __tests__/__packages__/cli-test-utils/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/__tests__/__packages__/cli-test-utils/CHANGELOG.md b/__tests__/__packages__/cli-test-utils/CHANGELOG.md index 552e7898f5..8d00681eca 100644 --- a/__tests__/__packages__/cli-test-utils/CHANGELOG.md +++ b/__tests__/__packages__/cli-test-utils/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the Zowe CLI test utils package will be documented in this file. +## Recent Changes + +Updating `TestEnvironment`, `ITestEnvironment`, and `TestUtils` to simplify and automate the cleanup of test resources, such as datasets, USS files, jobs, and local files created during system tests. + ## `8.0.0-next.202408131445` - Update: See `7.28.3` for details From 3853c8ac92a626a63084a9a74075122438d1dd9f Mon Sep 17 00:00:00 2001 From: ATorrise Date: Tue, 27 Aug 2024 08:22:44 -0400 Subject: [PATCH 22/65] linting Signed-off-by: ATorrise --- __tests__/__packages__/cli-test-utils/src/TestUtils.ts | 4 ++-- .../cli-test-utils/src/environment/TestEnvironment.ts | 7 ++++--- .../__system__/search/cli.zos-jobs.search.job.test.ts | 2 +- .../stdin/cli.zos-jobs.submit.stdin.system.test.ts | 2 +- .../__system__/methods/upload/Upload.system.test.ts | 9 +++++---- .../__tests__/__system__/CancelJobs.system.test.ts | 2 +- .../zosjobs/__tests__/__system__/GetJobs.system.test.ts | 6 +++--- .../__tests__/__system__/SearchJobs.system.test.ts | 2 +- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts index 014b1db6b7..af68335902 100644 --- a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts +++ b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts @@ -14,7 +14,7 @@ import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process"; import { ITestEnvironment } from "./environment/doc/response/ITestEnvironment"; import { AbstractSession, CommandProfiles, ICommandDefinition, IHandlerParameters, IO } from "@zowe/imperative"; import { DeleteJobs, ICommonJobParms, IDeleteJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; -import { Delete } from "@zowe/zos-files-for-zowe-sdk" +import { Delete } from "@zowe/zos-files-for-zowe-sdk"; import { posix } from "path"; /** @@ -40,7 +40,7 @@ export function deleteLocalFile(filePath: string): void { * @param {string} fileName - The name of the USS file */ export function deleteFiles(session: AbstractSession, fileName: string): void { - Delete.ussFile(session, fileName) + Delete.ussFile(session, fileName); } /** diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index 2297fa64f6..1f474055c3 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -13,7 +13,8 @@ import * as fs from "fs"; import * as nodePath from "path"; import * as yaml from "js-yaml"; import { v4 as uuidv4 } from "uuid"; -import { AbstractSession, ImperativeError, ImperativeExpect, IO, Logger, LoggingConfigurer, ProfileInfo, TextUtils } from "@zowe/imperative"; +import { AbstractSession, Imperative, ImperativeError, + ImperativeExpect, IO, Logger, LoggingConfigurer, ProfileInfo, TextUtils } from "@zowe/imperative"; import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; @@ -71,7 +72,7 @@ export class TestEnvironment { jobs: [], // Array of IJob objects jobData: [], // Array of objects with jobid and jobname datasets: [], - ...(session && { session }) // Only include session if it is passed in + ...session && { session } // Only include session if it is passed in } }; @@ -143,7 +144,7 @@ export class TestEnvironment { if (jobData.jobname && jobData.jobid) { deleteJobCommon(session, jobData); } else { - console.error('Error: Missing jobname or jobid for jobData:', jobData); + Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); } } for (const dataset of testEnvironment.resources.datasets) { diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index 1349121946..622ac5d731 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -41,7 +41,7 @@ describe("zos-jobs search job command", () => { ACCOUNT = defaultSystem.tso.account; // TODO: fix this test to run with any job name - JOB_NAME = "IEFBR14T"//REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase(); + JOB_NAME = "IEFBR14T"; //REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() NON_HELD_JOBCLASS = defaultSystem.zosjobs.jobclass; SEARCH_STRING = "PGM=IEFBR14"; REGEX_STRING = "IEFBR14|RC=0000"; 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 2f96e00daf..ad249947ad 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 @@ -25,7 +25,7 @@ let systemProps: ITestPropertiesSchema; let account: string; let jcl: string; let JOB_NAME: string; -const jobNameRegex = /jobname: (\w+)/ +const jobNameRegex = /jobname: (\w+)/; describe("zos-jobs submit stdin command", () => { beforeAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index 3e2241ccad..a9d83b5f00 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -12,7 +12,6 @@ import { Create, CreateDataSetTypeEnum, Delete, IUploadOptions, IZosFilesResponse, Upload, ZosFilesMessages, Download, Get, ZosFilesConstants, IUploadMap, Utilities } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; -import { inspect } from "util"; import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName, stripNewLines, delay } from "../../../../../../__tests__/__src__/TestUtils"; @@ -72,7 +71,9 @@ describe("All Upload Tests", () => { // longline/longline.txt const longlineFilePath = `${localDir}/longline/longline.txt`; - fs.writeFileSync(longlineFilePath, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); + fs.writeFileSync(longlineFilePath, + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrs"+ + "tuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); testEnvironment.resources.localFiles.push(longlineFilePath); // space dir/file4.txt @@ -96,7 +97,7 @@ describe("All Upload Tests", () => { // main.exe is too complex to build from scratch } catch (err) { - console.error("Error setting up test files and directories:", err); + Imperative.console.info("Error setting up test files and directories:", err); } }); @@ -111,7 +112,7 @@ describe("All Upload Tests", () => { fs.rmdirSync(dir, { recursive: true }); } } catch (err) { - console.error(`Error deleting directory: ${dir}`, err); + Imperative.console.info(`Error deleting directory: ${dir}`, err); } }); }); diff --git a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts index e2736e4dd8..7003a6977c 100644 --- a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts @@ -188,7 +188,7 @@ describe("CancelJobs System tests - encoded", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs_encoded" - }, REAL_SESSION = await TestEnvironment.createSession()); + }, REAL_SESSION = await TestEnvironment.createSession()); systemProps = testEnvironment.systemTestProperties; const ACCOUNT = systemProps.tso.account; diff --git a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts index b31d81a580..8ad1aa3c58 100644 --- a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts @@ -238,7 +238,7 @@ describe("Get Jobs System Tests", () => { }, LONG_TIMEOUT); }); }); - /**********************************************/ + /**********************************************/ // API methods "getJobs..." system tests describe("Get Jobs APIs", () => { @@ -443,7 +443,7 @@ describe("Get Jobs System Tests", () => { }); }); - /**********************************************/ + /**********************************************/ // API methods "getStatus..." system tests describe("Get Status APIs", () => { @@ -1330,7 +1330,7 @@ describe("Get Jobs System Tests", () => { const jobRender = iefbr14JclTemplate; const renderedJcl = TextUtils.renderWithMustache(jobRender, {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - + // Submit the job const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); diff --git a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts index dff4d2c272..7a6f21eff2 100644 --- a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts @@ -80,7 +80,7 @@ describe("Search Jobs - System Tests", () => { "//" + MONITOR_JOB_NAME + " JOB '" + ACCOUNT + "',CLASS=" + JOBCLASS + "\n" + "//IEFBR14 EXEC PGM=IEFBR14"; // GetJobs }); -s + afterAll(async () => { await TestEnvironment.cleanUp(testEnvironment); }); From c7de80c39a72f39774b5e6c3cc03e6e897114826 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 28 Aug 2024 11:30:38 -0400 Subject: [PATCH 23/65] no circ dependency error? Signed-off-by: ATorrise --- .../cli-test-utils/src/TestUtils.ts | 4 +- .../src/environment/doc/index.ts | 1 + .../doc/response/ITestEnvironment.ts | 17 +++--- .../doc/response/ITestEnvironmentResources.ts | 56 +++++++++++++++++++ 4 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 __tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironmentResources.ts diff --git a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts index af68335902..196040433a 100644 --- a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts +++ b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts @@ -12,7 +12,7 @@ import * as fs from "fs"; import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process"; import { ITestEnvironment } from "./environment/doc/response/ITestEnvironment"; -import { AbstractSession, CommandProfiles, ICommandDefinition, IHandlerParameters, IO } from "@zowe/imperative"; +import { AbstractSession, ICommandDefinition, IHandlerParameters, IO } from "@zowe/imperative"; import { DeleteJobs, ICommonJobParms, IDeleteJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; import { posix } from "path"; @@ -192,8 +192,6 @@ export function mockHandlerParameters(params: PartialHandlerParameters): IHandle ...params.arguments || {} }, positionals: params.positionals || [], - // eslint-disable-next-line deprecation/deprecation - profiles: params.profiles || new CommandProfiles(new Map()), definition: params.definition, fullDefinition: params.definition, stdin: process.stdin, diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts index 3e9ef33593..af50e13a56 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts @@ -11,3 +11,4 @@ export * from "./parms/ISetupEnvironmentParms"; export * from "./response/ITestEnvironment"; +export * from "./response/ITestEnvironmentResources"; diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts index 9d2e305c06..59b00e6ed6 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts @@ -9,8 +9,7 @@ * */ -import { AbstractSession } from "@zowe/imperative"; -import { ICommonJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; +import { ITestEnvironmentResources } from "./ITestEnvironmentResources"; /** * The test environment for your test. @@ -18,14 +17,12 @@ import { ICommonJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; * @interface ITestEnvironment */ export interface ITestEnvironment { - resources: { - localFiles: string[]; - files: string[]; - jobs: IJob[]; - jobData: ICommonJobParms[]; // Contains jobname and jobid - datasets: string[]; - session?: AbstractSession; - }; + /** + * A collection of resources used within the test environment that need to be cleaned up once test finishes. + * @type {ITestEnvironmentResources} + * @memberof ITestEnvironment + */ + resources: ITestEnvironmentResources; /** * The working directory for your test environment. It is a unique (uuid) area where your tests can create * their home folders (for imperative, etc.) and you can use the area as scratch for any files, etc. that diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironmentResources.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironmentResources.ts new file mode 100644 index 0000000000..8d343a9431 --- /dev/null +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironmentResources.ts @@ -0,0 +1,56 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { AbstractSession } from "@zowe/imperative"; +import { ICommonJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; + +/** + * Represents the resources used within the test environment. + * @export + * @interface ITestEnvironmentResources + */ +export interface ITestEnvironmentResources { + /** + * Array of local file paths used within the test environment. + * @type {string[]} + */ + localFiles: string[]; + + /** + * Array of mainframe uss files used within the test environment. + * @type {string[]} + */ + files: string[]; + + /** + * Array of job objects representing jobs submitted to the mainframe during the test. + * @type {IJob[]} + */ + jobs: IJob[]; + + /** + * Array of job data containing jobname and jobid, used to track jobs within the test environment. + * @type {ICommonJobParms[]} + */ + jobData: ICommonJobParms[]; // Contains jobname and jobid + + /** + * Array of dataset names used within the test environment. + * @type {string[]} + */ + datasets: string[]; + + /** + * The session used for interacting with z/OS systems during the test, if applicable. + * @type {AbstractSession} + */ + session?: AbstractSession; +} From 54baa2d40958bdfb3b89de0feac8a011d61fd067 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 28 Aug 2024 11:32:45 -0400 Subject: [PATCH 24/65] updating changelog Signed-off-by: ATorrise --- __tests__/__packages__/cli-test-utils/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/__packages__/cli-test-utils/CHANGELOG.md b/__tests__/__packages__/cli-test-utils/CHANGELOG.md index cb77eb35d0..7e1d501b71 100644 --- a/__tests__/__packages__/cli-test-utils/CHANGELOG.md +++ b/__tests__/__packages__/cli-test-utils/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to the Zowe CLI test utils package will be documented in thi ## Recent Changes -Updating `TestEnvironment`, `ITestEnvironment`, and `TestUtils` to simplify and automate the cleanup of test resources, such as datasets, USS files, jobs, and local files created during system tests. +- Updated `TestEnvironment`, `ITestEnvironment`, and `TestUtils` to simplify and automate the cleanup of test resources, such as datasets, USS files, jobs, and local files created during system tests. ## `8.0.0-next.202408271330` From ebe3570f9c2e4b410828066e2da5e57fab283cc9 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 28 Aug 2024 14:21:07 -0400 Subject: [PATCH 25/65] moving things around with andrew's help Signed-off-by: ATorrise --- .../cli-test-utils/src/TestUtils.ts | 59 +----------------- .../src/environment/TestEnvironment.ts | 48 +------------- __tests__/__src__/TestUtils.ts | 62 ++++++++++++++++++- .../__src__/environment/TestEnvironment.ts | 46 +++++++++++++- 4 files changed, 107 insertions(+), 108 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts index 196040433a..6952abcc7c 100644 --- a/__tests__/__packages__/cli-test-utils/src/TestUtils.ts +++ b/__tests__/__packages__/cli-test-utils/src/TestUtils.ts @@ -12,64 +12,7 @@ import * as fs from "fs"; import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process"; import { ITestEnvironment } from "./environment/doc/response/ITestEnvironment"; -import { AbstractSession, ICommandDefinition, IHandlerParameters, IO } from "@zowe/imperative"; -import { DeleteJobs, ICommonJobParms, IDeleteJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; -import { Delete } from "@zowe/zos-files-for-zowe-sdk"; -import { posix } from "path"; - -/** - * Delete a local testing file after use - * @param {string} filePath - File path of temporary file - */ -export function deleteLocalFile(filePath: string): void { - try { - fs.unlinkSync(filePath); - } catch { - // If fs.unlinkSync fails, try to delete it with IO.deleteFile - try { - IO.deleteFile(posix.basename(filePath)); - } catch { - throw new Error(`Error deleting local file: ${filePath}`); - } - } -} - -/** - * Delete a uss file from the mainframe - * @param {AbstractSession} session - z/OSMF connection info - * @param {string} fileName - The name of the USS file - */ -export function deleteFiles(session: AbstractSession, fileName: string): void { - Delete.ussFile(session, fileName); -} - -/** - * Delete a dataset from the mainframe - * @param {AbstractSession} session - z/OSMF connection info - * @param {string} datasetName - The name of the dataset - */ -export function deleteDataset(session: AbstractSession, dataSetName: string): void { - Delete.dataSet(session, dataSetName); -} - -/** - * Delete a job from the mainframe using Zowe SDKs - IJob - * @param {AbstractSession} session - z/OSMF connection info - * @param {IJob} job - the job that you want to delete - */ -export function deleteJob(session: AbstractSession, job: IJob): void { - DeleteJobs.deleteJobForJob(session, job); -} - -/** - * Delete a job from the mainframe using Zowe SDKs - jobid, jobname - * @param {AbstractSession} session - z/OSMF connection info - * @param {params} ICommonJobParms - constains jobname and jobid for job to delete - */ -export function deleteJobCommon(session: AbstractSession, params: ICommonJobParms): void { - DeleteJobs.deleteJobCommon(session, params as IDeleteJobParms); -} - +import { ICommandDefinition, IHandlerParameters } from "@zowe/imperative"; /** * Execute a CLI script diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index 1f474055c3..a6cf631f58 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -13,13 +13,13 @@ import * as fs from "fs"; import * as nodePath from "path"; import * as yaml from "js-yaml"; import { v4 as uuidv4 } from "uuid"; -import { AbstractSession, Imperative, ImperativeError, - ImperativeExpect, IO, Logger, LoggingConfigurer, ProfileInfo, TextUtils } from "@zowe/imperative"; +import { AbstractSession, ImperativeError, ImperativeExpect, + IO, Logger, LoggingConfigurer, ProfileInfo, TextUtils } from "@zowe/imperative"; import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; import { PROJECT_ROOT_DIR, TEST_RESOURCE_DIR, TEST_RESULT_DATA_DIR, TEST_USING_WORKSPACE } from "../TestConstants"; -import { runCliScript, deleteFiles, deleteJob, deleteDataset, deleteLocalFile, deleteJobCommon } from "../TestUtils"; +import { runCliScript } from "../TestUtils"; /** * Use the utility methods here to setup the test environment for running APIs @@ -110,48 +110,6 @@ export class TestEnvironment { return ProfileInfo.createSession(zosmfMergedArgs.knownArgs); } - /** - * Clean up your test environment. - * Deletes any temporary profiles that have been created - * @params {ITestEnvironment} testEnvironment - the test environment returned by createTestEnv - * - * @returns {Promise} - promise fulfilled when cleanup is complete - * @throws errors if profiles fail to delete - * @memberof TestEnvironment - */ - public static async cleanUp(testEnvironment: ITestEnvironment) { - if (testEnvironment.tempProfiles != null) { - await TempTestProfiles.deleteProfiles(testEnvironment); - } - if (testEnvironment.pluginInstalled) { - const pluginDir = testEnvironment.workingDir + "/plugins"; - require("rimraf").sync(pluginDir); - } - - // Clean up resources - for (const file of testEnvironment.resources.localFiles) { - deleteLocalFile(file); - } - // Check if session exists; if not, create one - const session = testEnvironment.resources.session || await TestEnvironment.createSession(); - for (const file of testEnvironment.resources.files) { - deleteFiles(session, file); - } - for (const job of testEnvironment.resources.jobs) { - deleteJob(session, job); - } - for (const jobData of testEnvironment.resources.jobData) { - if (jobData.jobname && jobData.jobid) { - deleteJobCommon(session, jobData); - } else { - Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); - } - } - for (const dataset of testEnvironment.resources.datasets) { - deleteDataset(session, dataset); - } - } - /** * Creates a unique test data directory for a test to work with in isolation. * @static diff --git a/__tests__/__src__/TestUtils.ts b/__tests__/__src__/TestUtils.ts index 759a3ac256..0f92e53850 100644 --- a/__tests__/__src__/TestUtils.ts +++ b/__tests__/__src__/TestUtils.ts @@ -10,9 +10,65 @@ */ import { randomBytes } from "crypto"; -import { ZosFilesConstants } from "../../packages/zosfiles/src"; -import { Imperative, Headers, AbstractSession } from "@zowe/imperative"; +import * as fs from "fs"; +import { Imperative, Headers, AbstractSession, IO } from "@zowe/imperative"; import { ZosmfRestClient } from "../../packages/core/src"; +import { ZosFilesConstants, Delete } from "../../packages/zosfiles/src"; +import { DeleteJobs, ICommonJobParms, IDeleteJobParms, IJob } from "../../packages/zosjobs/src"; +import { posix } from "path"; + +/** + * Delete a local testing file after use + * @param {string} filePath - File path of temporary file + */ +export function deleteLocalFile(filePath: string): void { + try { + fs.unlinkSync(filePath); + } catch { + // If fs.unlinkSync fails, try to delete it with IO.deleteFile + try { + IO.deleteFile(posix.basename(filePath)); + } catch { + throw new Error(`Error deleting local file: ${filePath}`); + } + } +} + +/** + * Delete a uss file from the mainframe + * @param {AbstractSession} session - z/OSMF connection info + * @param {string} fileName - The name of the USS file + */ +export function deleteFiles(session: AbstractSession, fileName: string): void { + Delete.ussFile(session, fileName); +} + +/** + * Delete a dataset from the mainframe + * @param {AbstractSession} session - z/OSMF connection info + * @param {string} datasetName - The name of the dataset + */ +export function deleteDataset(session: AbstractSession, dataSetName: string): void { + Delete.dataSet(session, dataSetName); +} + +/** + * Delete a job from the mainframe using Zowe SDKs - IJob + * @param {AbstractSession} session - z/OSMF connection info + * @param {IJob} job - the job that you want to delete + */ +export function deleteJob(session: AbstractSession, job: IJob): void { + DeleteJobs.deleteJobForJob(session, job); +} + +/** + * Delete a job from the mainframe using Zowe SDKs - jobid, jobname + * @param {AbstractSession} session - z/OSMF connection info + * @param {params} ICommonJobParms - constains jobname and jobid for job to delete + */ +export function deleteJobCommon(session: AbstractSession, params: ICommonJobParms): void { + DeleteJobs.deleteJobCommon(session, params as IDeleteJobParms); +} /** * This function strips any new lines out of the string passed. @@ -113,4 +169,4 @@ export const delTime = 500; */ export function inspect(obj: any) : string { return JSON.stringify(Object.keys(obj).reduce((newObj, key) => ({...newObj, [key]: obj[key]}), {})); -} +} \ No newline at end of file diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index ad81b91189..dbbad511d9 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -11,11 +11,12 @@ import * as nodePath from "path"; -import { AbstractSession, Session } from "@zowe/imperative"; +import { AbstractSession, Imperative, Session } from "@zowe/imperative"; import { ITestPropertiesSchema } from "../properties/ITestPropertiesSchema"; -import { ISetupEnvironmentParms, ITestEnvironment, TestEnvironment as BaseTestEnvironment } from "../../__packages__/cli-test-utils"; +import { ISetupEnvironmentParms, ITestEnvironment, TestEnvironment as BaseTestEnvironment, TempTestProfiles } from "../../__packages__/cli-test-utils"; import { SshSession } from "../../../packages/zosuss/src/SshSession"; +import { deleteFiles, deleteJob, deleteDataset, deleteLocalFile, deleteJobCommon } from "../TestUtils"; /** * Use the utility methods here to setup the test environment for running APIs @@ -49,6 +50,47 @@ export class TestEnvironment extends BaseTestEnvironment { // Return the test environment including working directory that the tests should be using return result; } + /** + * Clean up your test environment. + * Deletes any temporary profiles that have been created + * @params {ITestEnvironment} testEnvironment - the test environment returned by createTestEnv + * + * @returns {Promise} - promise fulfilled when cleanup is complete + * @throws errors if profiles fail to delete + * @memberof TestEnvironment + */ + public static async cleanUp(testEnvironment: ITestEnvironment) { + if (testEnvironment.tempProfiles != null) { + await TempTestProfiles.deleteProfiles(testEnvironment); + } + if (testEnvironment.pluginInstalled) { + const pluginDir = testEnvironment.workingDir + "/plugins"; + require("rimraf").sync(pluginDir); + } + + // Clean up resources + for (const file of testEnvironment.resources.localFiles) { + deleteLocalFile(file); + } + // Check if session exists; if not, create one + const session = testEnvironment.resources.session || await TestEnvironment.createSession(); + for (const file of testEnvironment.resources.files) { + deleteFiles(session, file); + } + for (const job of testEnvironment.resources.jobs) { + deleteJob(session, job); + } + for (const jobData of testEnvironment.resources.jobData) { + if (jobData.jobname && jobData.jobid) { + deleteJobCommon(session, jobData); + } else { + Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); + } + } + for (const dataset of testEnvironment.resources.datasets) { + deleteDataset(session, dataset); + } + } /** * Create a ZOSMF session from properties present in your test environment From 663340f1c36c65179d3a40fc1d5a236b09188393 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 28 Aug 2024 14:59:27 -0400 Subject: [PATCH 26/65] moving around things in testEnv and ITestEnv Signed-off-by: ATorrise --- .../src/environment/TestEnvironment.ts | 10 +------ .../src/environment/doc/index.ts | 3 +-- .../doc/response/ITestEnvironment.ts | 8 ------ .../__src__/environment/ITestEnvironment.ts | 27 +++++++++++++++++++ .../environment}/ITestEnvironmentResources.ts | 2 +- .../__src__/environment/TestEnvironment.ts | 15 ++++++++--- 6 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 __tests__/__src__/environment/ITestEnvironment.ts rename __tests__/{__packages__/cli-test-utils/src/environment/doc/response => __src__/environment}/ITestEnvironmentResources.ts (95%) diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index a6cf631f58..ae230b31c3 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -65,15 +65,7 @@ export class TestEnvironment { const result: ITestEnvironment = { workingDir: testDirectory, systemTestProperties: systemProps, - env, - resources: { - localFiles: [], - files: [], - jobs: [], // Array of IJob objects - jobData: [], // Array of objects with jobid and jobname - datasets: [], - ...session && { session } // Only include session if it is passed in - } + env }; if (params.installPlugin) { diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts index af50e13a56..804ada7677 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts @@ -10,5 +10,4 @@ */ export * from "./parms/ISetupEnvironmentParms"; -export * from "./response/ITestEnvironment"; -export * from "./response/ITestEnvironmentResources"; +export * from "./response/ITestEnvironment"; \ No newline at end of file diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts index 59b00e6ed6..2859aea890 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts @@ -9,20 +9,12 @@ * */ -import { ITestEnvironmentResources } from "./ITestEnvironmentResources"; - /** * The test environment for your test. * @export * @interface ITestEnvironment */ export interface ITestEnvironment { - /** - * A collection of resources used within the test environment that need to be cleaned up once test finishes. - * @type {ITestEnvironmentResources} - * @memberof ITestEnvironment - */ - resources: ITestEnvironmentResources; /** * The working directory for your test environment. It is a unique (uuid) area where your tests can create * their home folders (for imperative, etc.) and you can use the area as scratch for any files, etc. that diff --git a/__tests__/__src__/environment/ITestEnvironment.ts b/__tests__/__src__/environment/ITestEnvironment.ts new file mode 100644 index 0000000000..7424d5b4ac --- /dev/null +++ b/__tests__/__src__/environment/ITestEnvironment.ts @@ -0,0 +1,27 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { ITestEnvironment as IBaseTestEnvironment } from "../../__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment"; +import { ITestEnvironmentResources } from "./ITestEnvironmentResources"; + +/** + * The test environment for your test. + * @export + * @interface ITestEnvironment + */ +export interface ITestEnvironment extends IBaseTestEnvironment{ + /** + * A collection of resources used within the test environment that need to be cleaned up once test finishes. + * @type {ITestEnvironmentResources} + * @memberof ITestEnvironment + */ + resources?: ITestEnvironmentResources; +} \ No newline at end of file diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironmentResources.ts b/__tests__/__src__/environment/ITestEnvironmentResources.ts similarity index 95% rename from __tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironmentResources.ts rename to __tests__/__src__/environment/ITestEnvironmentResources.ts index 8d343a9431..35f7685ffe 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironmentResources.ts +++ b/__tests__/__src__/environment/ITestEnvironmentResources.ts @@ -10,7 +10,7 @@ */ import { AbstractSession } from "@zowe/imperative"; -import { ICommonJobParms, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; +import { ICommonJobParms, IJob } from "../../../packages/zosjobs"; /** * Represents the resources used within the test environment. diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index dbbad511d9..5d2bd19c7b 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -14,7 +14,8 @@ import * as nodePath from "path"; import { AbstractSession, Imperative, Session } from "@zowe/imperative"; import { ITestPropertiesSchema } from "../properties/ITestPropertiesSchema"; -import { ISetupEnvironmentParms, ITestEnvironment, TestEnvironment as BaseTestEnvironment, TempTestProfiles } from "../../__packages__/cli-test-utils"; +import { ISetupEnvironmentParms, TestEnvironment as BaseTestEnvironment, TempTestProfiles } from "../../__packages__/cli-test-utils"; +import { ITestEnvironment } from "./ITestEnvironment"; import { SshSession } from "../../../packages/zosuss/src/SshSession"; import { deleteFiles, deleteJob, deleteDataset, deleteLocalFile, deleteJobCommon } from "../TestUtils"; @@ -36,8 +37,16 @@ export class TestEnvironment extends BaseTestEnvironment { * @returns {Promise} * @memberof TestEnvironment */ - public static async setUp(params: ISetupEnvironmentParms): Promise> { - const result = await super.setUp(params); + public static async setUp(params: ISetupEnvironmentParms, session?: AbstractSession): Promise> { + const result : ITestEnvironment = await super.setUp(params, session); + result.resources = { + localFiles: [], + files: [], + jobs: [], // Array of IJob objects + jobData: [], // Array of objects with jobid and jobname + datasets: [], + ...session && { session } // Only include session if it is passed in + } // Ensure correct path separator for windows or linux like systems. const separator = process.platform === "win32" ? ";" : ":"; From 9d59e1a993f61dc4c943e57a643fe8ffbdc0d5e8 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 29 Aug 2024 11:41:35 -0400 Subject: [PATCH 27/65] about to make a really big change Signed-off-by: ATorrise --- .../src/environment/doc/response/ITestEnvironment.ts | 6 +++--- __tests__/__src__/environment/ITestEnvironment.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts index 2859aea890..202e12231b 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts @@ -14,7 +14,7 @@ * @export * @interface ITestEnvironment */ -export interface ITestEnvironment { +export interface ITestEnvironment { /** * The working directory for your test environment. It is a unique (uuid) area where your tests can create * their home folders (for imperative, etc.) and you can use the area as scratch for any files, etc. that @@ -29,10 +29,10 @@ export interface ITestEnvironment { * in the case that no system test properties were configured or could be loaded. * * Not present if skipProperties is specified on ISetupEnvironmentParms - * @type {TestPropertiesSchema} + * @type {ITestPropertiesSchema} * @memberof ITestEnvironment */ - systemTestProperties: TestPropertiesSchema; + systemTestProperties: ITestPropertiesSchema; /** * Set of environmental variables (such as profile/logging home directory) diff --git a/__tests__/__src__/environment/ITestEnvironment.ts b/__tests__/__src__/environment/ITestEnvironment.ts index 7424d5b4ac..e43351d413 100644 --- a/__tests__/__src__/environment/ITestEnvironment.ts +++ b/__tests__/__src__/environment/ITestEnvironment.ts @@ -17,7 +17,7 @@ import { ITestEnvironmentResources } from "./ITestEnvironmentResources"; * @export * @interface ITestEnvironment */ -export interface ITestEnvironment extends IBaseTestEnvironment{ +export interface ITestEnvironment extends IBaseTestEnvironment{ /** * A collection of resources used within the test environment that need to be cleaned up once test finishes. * @type {ITestEnvironmentResources} From fe2c72b8c563fd59a639774da011d0c01b1da9aa Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 29 Aug 2024 11:49:51 -0400 Subject: [PATCH 28/65] restoring clitestutils cleanup() Signed-off-by: ATorrise --- .../src/environment/TestEnvironment.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index ae230b31c3..a6fd5cb944 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -102,6 +102,25 @@ export class TestEnvironment { return ProfileInfo.createSession(zosmfMergedArgs.knownArgs); } + /** + * Clean up your test environment. + * Deletes any temporary profiles that have been created + * @params {ITestEnvironment} testEnvironment - the test environment returned by createTestEnv + * + * @returns {Promise} - promise fulfilled when cleanup is complete + * @throws errors if profiles fail to delete + * @memberof TestEnvironment + */ + public static async cleanUp(testEnvironment: ITestEnvironment) { + if (testEnvironment.tempProfiles != null) { + await TempTestProfiles.deleteProfiles(testEnvironment); + } + if (testEnvironment.pluginInstalled) { + const pluginDir = testEnvironment.workingDir + "/plugins"; + require("rimraf").sync(pluginDir); + } + } + /** * Creates a unique test data directory for a test to work with in isolation. * @static From 21bf9aaef74b6990178fda480151b884c16bc1af Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 29 Aug 2024 14:20:20 -0400 Subject: [PATCH 29/65] fixing other testEnv Signed-off-by: ATorrise --- .../__src__/environment/TestEnvironment.ts | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index 5d2bd19c7b..eee1877d1a 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -15,9 +15,9 @@ import { AbstractSession, Imperative, Session } from "@zowe/imperative"; import { ITestPropertiesSchema } from "../properties/ITestPropertiesSchema"; import { ISetupEnvironmentParms, TestEnvironment as BaseTestEnvironment, TempTestProfiles } from "../../__packages__/cli-test-utils"; -import { ITestEnvironment } from "./ITestEnvironment"; +import { ITestEnvironment } from "./ITestEnvironment"; +import { deleteLocalFile, deleteFiles, deleteJob, deleteJobCommon, deleteDataset } from "../TestUtils"; import { SshSession } from "../../../packages/zosuss/src/SshSession"; -import { deleteFiles, deleteJob, deleteDataset, deleteLocalFile, deleteJobCommon } from "../TestUtils"; /** * Use the utility methods here to setup the test environment for running APIs @@ -37,16 +37,8 @@ export class TestEnvironment extends BaseTestEnvironment { * @returns {Promise} * @memberof TestEnvironment */ - public static async setUp(params: ISetupEnvironmentParms, session?: AbstractSession): Promise> { - const result : ITestEnvironment = await super.setUp(params, session); - result.resources = { - localFiles: [], - files: [], - jobs: [], // Array of IJob objects - jobData: [], // Array of objects with jobid and jobname - datasets: [], - ...session && { session } // Only include session if it is passed in - } + public static async setUp(params: ISetupEnvironmentParms): Promise> { + const result = await super.setUp(params); // Ensure correct path separator for windows or linux like systems. const separator = process.platform === "win32" ? ";" : ":"; @@ -59,6 +51,7 @@ export class TestEnvironment extends BaseTestEnvironment { // Return the test environment including working directory that the tests should be using return result; } + /** * Clean up your test environment. * Deletes any temporary profiles that have been created @@ -68,7 +61,7 @@ export class TestEnvironment extends BaseTestEnvironment { * @throws errors if profiles fail to delete * @memberof TestEnvironment */ - public static async cleanUp(testEnvironment: ITestEnvironment) { + public static async cleanUp(testEnvironment: ITestEnvironment) { if (testEnvironment.tempProfiles != null) { await TempTestProfiles.deleteProfiles(testEnvironment); } @@ -151,4 +144,4 @@ export class TestEnvironment extends BaseTestEnvironment { handshakeTimeout: defaultSystem.ssh.handshakeTimeout }); } -} +} \ No newline at end of file From a9d28652f53e097eabc620e7371476552a483621 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 29 Aug 2024 15:16:22 -0400 Subject: [PATCH 30/65] updating imports Signed-off-by: ATorrise --- __tests__/__src__/TestUtils.ts | 55 +++++++++++++++++++ .../compare/ds/Compare.ds.system.test.ts | 8 +-- .../copy/ds/cli.files.copy.ds.system.test.ts | 3 +- .../dsclp/cli.files.copy.dsclp.system.test.ts | 4 +- ...files.create.dataset.binary.system.test.ts | 3 +- .../cli.files.create.dataset.c.system.test.ts | 3 +- ...iles.create.dataset.classic.system.test.ts | 3 +- .../ds/cli.files.create.ds.system.test.ts | 3 +- ...li.files.create.dataset.pds.system.test.ts | 3 +- ...cli.files.create.dataset.ps.system.test.ts | 3 +- .../cli.files.create.uss.dir.system.test.ts | 3 +- .../cli.files.create.uss.file.system.test.ts | 3 +- ...i.files.create.dataset.vsam.system.test.ts | 3 +- .../zfs/cli.files.create.zfs.system.test.ts | 3 +- .../ds/cli.files.delete.ds.system.test.ts | 3 +- .../mds/cli.files.delete.mds.system.test.ts | 3 +- .../cli.files.delete.directory.system.test.ts | 3 +- .../uss/cli.files.delete.file.system.test.ts | 3 +- .../vsam/cli.files.delete.vsam.system.test.ts | 4 +- .../zfs/cli.files.delete.zfs.system.test.ts | 4 +- .../am/cli.files.download.am.system.test.ts | 4 +- .../ds/cli.files.download.ds.system.test.ts | 4 +- .../dsm/cli.files.download.dsm.system.test.ts | 4 +- .../uss/cli.files.download.uss.system.test.ts | 4 +- .../cli.files.download.ussdir.system.test.ts | 4 +- .../__system__/edit/ds/Edit.ds.system.test.ts | 4 +- .../edit/uss/Edit.uss.system.test.ts | 8 +-- .../ds/cli.files.HMigrate.ds.system.test.ts | 3 +- .../ds/cli.files.HRecall.ds.system.test.ts | 3 +- .../cli.files.invoke.amsFile.system.test.ts | 4 +- ....files.invoke.amsStatements.system.test.ts | 4 +- .../list/am/cli.files.list.am.system.test.ts | 4 +- .../list/ds/cli.files.list.ds.system.test.ts | 4 +- .../list/fs/cli.files.list.fs.system.test.ts | 4 +- .../uss/cli.files.list.uss.system.test.ts | 3 +- .../fs/cli.files.mount.fs.system.test.ts | 4 +- .../ds/cli.files.rename.ds.system.test.ts | 3 +- .../dsm/cli.files.rename.dsm.system.test.ts | 4 +- .../ds/cli.files.search.ds.system.test.ts | 4 +- .../dtp/cli.files.upload.dtp.system.test.ts | 4 +- .../dtu/cli.dir.upload.dtu.system.test.ts | 4 +- .../ftds/cli.files.upload.ftds.system.test.ts | 4 +- .../ftu/cli.files.upload.ftu.system.test.ts | 3 +- .../stds/cli.files.upload.stds.system.test.ts | 4 +- .../__system__/view/ds/View.ds.system.test.ts | 8 +-- .../view/uss/View.uss.system.test.ts | 9 ++- .../cli.zos-jobs.cancel.job.system.test.ts | 11 ++-- .../cli.zos-jobs.delete.job.system.test.ts | 3 +- ...li.zos-jobs.delete.old-jobs.system.test.ts | 3 +- ...li.zos-jobs.download.output.system.test.ts | 10 +++- .../cli.zos-jobs.list.jobs.system.test.ts | 10 +++- ...s.list.spool-files-by-jobid.system.test.ts | 12 ++-- .../cli.zos-jobs.modify.job.system.test.ts | 3 +- .../search/cli.zos-jobs.search.job.test.ts | 8 ++- ...li.zos-jobs.submit.data-set.system.test.ts | 11 ++-- ....zos-jobs.submit.local-file.system.test.ts | 6 +- .../cli.zos-jobs.submit.stdin.system.test.ts | 3 +- ...li.zos-jobs.submit.uss-file.system.test.ts | 4 +- ...jobs.view.all-spool-content.system.test.ts | 3 +- ...bs.view.job-status-by-jobid.system.test.ts | 3 +- ...-jobs.view.spool-file-by-id.system.test.ts | 2 +- 61 files changed, 211 insertions(+), 113 deletions(-) diff --git a/__tests__/__src__/TestUtils.ts b/__tests__/__src__/TestUtils.ts index 0f92e53850..63facd0262 100644 --- a/__tests__/__src__/TestUtils.ts +++ b/__tests__/__src__/TestUtils.ts @@ -16,6 +16,8 @@ import { ZosmfRestClient } from "../../packages/core/src"; import { ZosFilesConstants, Delete } from "../../packages/zosfiles/src"; import { DeleteJobs, ICommonJobParms, IDeleteJobParms, IJob } from "../../packages/zosjobs/src"; import { posix } from "path"; +import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process"; +import { ITestEnvironment } from "./environment/ITestEnvironment"; /** * Delete a local testing file after use @@ -169,4 +171,57 @@ export const delTime = 500; */ export function inspect(obj: any) : string { return JSON.stringify(Object.keys(obj).reduce((newObj, key) => ({...newObj, [key]: obj[key]}), {})); +} + +/** + * Execute a CLI script + * @export + * @param scriptPath - the path to the script + * @param testEnvironment - the test environment with env + * @param [args=[]] - set of script args (optional) + * @returns node.js details about the results of + * executing the script, including exit code and output + */ +export function runCliScript(scriptPath: string, testEnvironment: ITestEnvironment, args: any[] = []): SpawnSyncReturns { + if (fs.existsSync(scriptPath)) { + + // We force the color off to prevent any oddities in the snapshots or expected values + // Color can vary OS/terminal + const childEnv = JSON.parse(JSON.stringify(process.env)); + childEnv.FORCE_COLOR = "0"; + for (const key of Object.keys(testEnvironment.env)) { + // copy the values from the env + childEnv[key] = testEnvironment.env[key]; + } + + if (process.platform === "win32") { + // Execute the command synchronously + const response = spawnSync("sh", [scriptPath].concat(args), { + cwd: testEnvironment.workingDir, + encoding: "buffer", + env: childEnv + }); + if ((response.error as ExecFileException)?.code === "ENOENT") { + throw new Error(`"sh" is missing from your PATH. Check that Git Bash is installed with the option to ` + + `"Use Git and Unix Tools from Windows Command Prompt".`); + } + return response; + } + + // Check to see if the file is executable + try { + fs.accessSync(scriptPath, fs.constants.X_OK); + } catch { + fs.chmodSync(scriptPath, "755"); + } + return spawnSync(scriptPath, args, { + cwd: testEnvironment.workingDir, + env: childEnv, + encoding: "buffer" + }); + + } else { + throw new Error(`The script file ${scriptPath} doesn't exist`); + + } } \ No newline at end of file diff --git a/packages/cli/__tests__/zosfiles/__system__/compare/ds/Compare.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/compare/ds/Compare.ds.system.test.ts index 5b0060e0cc..98ae988a27 100644 --- a/packages/cli/__tests__/zosfiles/__system__/compare/ds/Compare.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/compare/ds/Compare.ds.system.test.ts @@ -12,10 +12,10 @@ import { Session } from "@zowe/imperative"; import { Create, Delete, CreateDataSetTypeEnum, Upload } from "@zowe/cli"; import * as path from "path"; -import {ITestEnvironment, runCliScript} from "@zowe/cli-test-utils"; -import {TestEnvironment} from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; -import {ITestPropertiesSchema} from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName} from "../../../../../../../__tests__/__src__/TestUtils"; +import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/copy/ds/cli.files.copy.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/copy/ds/cli.files.copy.ds.system.test.ts index 35a866c9c0..f3e9ec56ef 100644 --- a/packages/cli/__tests__/zosfiles/__system__/copy/ds/cli.files.copy.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/copy/ds/cli.files.copy.ds.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create, CreateDataSetTypeEnum, Upload, Get } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; diff --git a/packages/cli/__tests__/zosfiles/__system__/copy/dsclp/cli.files.copy.dsclp.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/copy/dsclp/cli.files.copy.dsclp.system.test.ts index 8e4b753aec..575e4e5273 100644 --- a/packages/cli/__tests__/zosfiles/__system__/copy/dsclp/cli.files.copy.dsclp.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/copy/dsclp/cli.files.copy.dsclp.system.test.ts @@ -10,10 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; -import { getRandomBytes } from "../../../../../../../__tests__/__src__/TestUtils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create, ICreateDataSetOptions, CreateDataSetTypeEnum, Upload, Get } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts index 0c525a387c..0d6b1cc05c 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts index c0293ac07f..142d7bf1a1 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts index 25f97d3c21..651e09d1b7 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts index 51df7e2d96..455993d86f 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts index e550311677..a89fc7d9f1 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { stripNewLines, delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts index 71d3b1fd80..f22c0827d1 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { stripNewLines, delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/ussDir/cli.files.create.uss.dir.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/ussDir/cli.files.create.uss.dir.system.test.ts index c0a4a6c66d..07d6c5f48c 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/ussDir/cli.files.create.uss.dir.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/ussDir/cli.files.create.uss.dir.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/ussFile/cli.files.create.uss.file.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/ussFile/cli.files.create.uss.file.system.test.ts index b8a656f828..048a78c796 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/ussFile/cli.files.create.uss.file.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/ussFile/cli.files.create.uss.file.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/vsam/cli.files.create.dataset.vsam.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/vsam/cli.files.create.dataset.vsam.system.test.ts index 688e3bb6bf..543bc5e7b6 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/vsam/cli.files.create.dataset.vsam.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/vsam/cli.files.create.dataset.vsam.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, IDeleteVsamOptions } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/zfs/cli.files.create.zfs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/zfs/cli.files.create.zfs.system.test.ts index ee69a0155f..d089b9b793 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/zfs/cli.files.create.zfs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/zfs/cli.files.create.zfs.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/ds/cli.files.delete.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/ds/cli.files.delete.ds.system.test.ts index 969016086a..cc7e89bdcf 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/ds/cli.files.delete.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/ds/cli.files.delete.ds.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/mds/cli.files.delete.mds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/mds/cli.files.delete.mds.system.test.ts index 74661c9039..f45694a04b 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/mds/cli.files.delete.mds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/mds/cli.files.delete.mds.system.test.ts @@ -9,9 +9,10 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { join } from "path"; import { Session, Imperative } from "@zowe/imperative"; import { inspect } from "util"; diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.directory.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.directory.system.test.ts index 3b57f25dbe..8f785e240e 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.directory.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.directory.system.test.ts @@ -12,9 +12,10 @@ import { Imperative, Session } from "@zowe/imperative"; import { Create } from "@zowe/zos-files-for-zowe-sdk"; import { inspect } from "util"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.file.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.file.system.test.ts index c921bd5e0d..7e9b628b97 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.file.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.file.system.test.ts @@ -12,9 +12,10 @@ import { Imperative, Session } from "@zowe/imperative"; import { Create } from "@zowe/zos-files-for-zowe-sdk"; import { inspect } from "util"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/vsam/cli.files.delete.vsam.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/vsam/cli.files.delete.vsam.system.test.ts index e65d1024c5..da31972173 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/vsam/cli.files.delete.vsam.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/vsam/cli.files.delete.vsam.system.test.ts @@ -10,10 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, stripNewLines, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/zfs/cli.files.delete.zfs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/zfs/cli.files.delete.zfs.system.test.ts index 08f9250bb7..4fddb0d5f1 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/zfs/cli.files.delete.zfs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/zfs/cli.files.delete.zfs.system.test.ts @@ -10,10 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, stripNewLines, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/download/am/cli.files.download.am.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/am/cli.files.download.am.system.test.ts index b7a71e0c8f..c64ce2c2ca 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/am/cli.files.download.am.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/am/cli.files.download.am.system.test.ts @@ -11,10 +11,10 @@ import { Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/download/ds/cli.files.download.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/ds/cli.files.download.ds.system.test.ts index aa8d5a65b5..9c127e871c 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/ds/cli.files.download.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/ds/cli.files.download.ds.system.test.ts @@ -11,10 +11,10 @@ import { IO, Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getRandomBytes, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/download/dsm/cli.files.download.dsm.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/dsm/cli.files.download.dsm.system.test.ts index ca1d9b381d..34188022e2 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/dsm/cli.files.download.dsm.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/dsm/cli.files.download.dsm.system.test.ts @@ -11,10 +11,10 @@ import { Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts index f5152a178e..46990e42f4 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts @@ -11,10 +11,10 @@ import { Imperative, Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/download/ussdir/cli.files.download.ussdir.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/ussdir/cli.files.download.ussdir.system.test.ts index 17ceb6a81e..65493e5499 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/ussdir/cli.files.download.ussdir.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/ussdir/cli.files.download.ussdir.system.test.ts @@ -12,10 +12,10 @@ import { Imperative, Session } from "@zowe/imperative"; import * as path from "path"; import * as fs from "fs"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/edit/ds/Edit.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/edit/ds/Edit.ds.system.test.ts index d73276c77b..a3c4e2c866 100644 --- a/packages/cli/__tests__/zosfiles/__system__/edit/ds/Edit.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/edit/ds/Edit.ds.system.test.ts @@ -11,10 +11,10 @@ import { Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/edit/uss/Edit.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/edit/uss/Edit.uss.system.test.ts index 1f998b430a..2b5e446e45 100644 --- a/packages/cli/__tests__/zosfiles/__system__/edit/uss/Edit.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/edit/uss/Edit.uss.system.test.ts @@ -12,10 +12,10 @@ import { Session } from "@zowe/imperative"; import * as path from "path"; -import {ITestEnvironment, runCliScript} from "@zowe/cli-test-utils"; -import {TestEnvironment} from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; -import {ITestPropertiesSchema} from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName} from "../../../../../../../__tests__/__src__/TestUtils"; +import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, Delete } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/hMigrate/ds/cli.files.HMigrate.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/hMigrate/ds/cli.files.HMigrate.ds.system.test.ts index 05ca6ce91f..af21677069 100644 --- a/packages/cli/__tests__/zosfiles/__system__/hMigrate/ds/cli.files.HMigrate.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/hMigrate/ds/cli.files.HMigrate.ds.system.test.ts @@ -9,9 +9,10 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { join } from "path"; import { Session, Imperative } from "@zowe/imperative"; import { List, Delete, Create, CreateDataSetTypeEnum, IListOptions, IMigrateOptions } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/hRecall/ds/cli.files.HRecall.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/hRecall/ds/cli.files.HRecall.ds.system.test.ts index 216a3091f9..4249ce7d85 100644 --- a/packages/cli/__tests__/zosfiles/__system__/hRecall/ds/cli.files.HRecall.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/hRecall/ds/cli.files.HRecall.ds.system.test.ts @@ -9,9 +9,10 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { join } from "path"; import { Session, Imperative } from "@zowe/imperative"; import { List, Delete, Create, CreateDataSetTypeEnum, IListOptions, IRecallOptions, HMigrate } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts index 6e73a2a6f7..8e07150396 100644 --- a/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts @@ -11,10 +11,10 @@ import * as fs from "fs"; import { Session, TextUtils } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript, stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; import { ZosFilesMessages } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/invoke/amsStatements/cli.files.invoke.amsStatements.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/invoke/amsStatements/cli.files.invoke.amsStatements.system.test.ts index edab1ab4cc..0a098d5c8d 100644 --- a/packages/cli/__tests__/zosfiles/__system__/invoke/amsStatements/cli.files.invoke.amsStatements.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/invoke/amsStatements/cli.files.invoke.amsStatements.system.test.ts @@ -10,10 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript, stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; import { ZosFilesMessages } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/list/am/cli.files.list.am.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/list/am/cli.files.list.am.system.test.ts index 7e9637b099..825ae517d0 100644 --- a/packages/cli/__tests__/zosfiles/__system__/list/am/cli.files.list.am.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/list/am/cli.files.list.am.system.test.ts @@ -11,10 +11,10 @@ import { Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Upload, Delete } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/list/ds/cli.files.list.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/list/ds/cli.files.list.ds.system.test.ts index e8b463e90a..7b32a86d6e 100644 --- a/packages/cli/__tests__/zosfiles/__system__/list/ds/cli.files.list.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/list/ds/cli.files.list.ds.system.test.ts @@ -11,10 +11,10 @@ import { Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/list/fs/cli.files.list.fs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/list/fs/cli.files.list.fs.system.test.ts index ea5a4d9812..8a1e5e80b5 100644 --- a/packages/cli/__tests__/zosfiles/__system__/list/fs/cli.files.list.fs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/list/fs/cli.files.list.fs.system.test.ts @@ -11,10 +11,10 @@ import { Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/list/uss/cli.files.list.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/list/uss/cli.files.list.uss.system.test.ts index 5233d00855..354b444f6d 100644 --- a/packages/cli/__tests__/zosfiles/__system__/list/uss/cli.files.list.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/list/uss/cli.files.list.uss.system.test.ts @@ -12,9 +12,10 @@ import { Imperative, Session } from "@zowe/imperative"; import * as path from "path"; import { inspect } from "util"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts index e1c3fa8302..a1ce86758b 100644 --- a/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts @@ -11,10 +11,10 @@ */ import { Imperative, Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts index 01b5c75224..bae07ee910 100644 --- a/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts @@ -10,9 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { delay } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create, CreateDataSetTypeEnum, Upload, Get } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; diff --git a/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts index ac4184fca8..96c6633578 100644 --- a/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts @@ -10,10 +10,10 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { delay } from "../../../../../../../__tests__/__src__/TestUtils"; +import { delay, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create, CreateDataSetTypeEnum, Upload, Get } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; diff --git a/packages/cli/__tests__/zosfiles/__system__/search/ds/cli.files.search.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/search/ds/cli.files.search.ds.system.test.ts index cb5ee16471..7896cb2759 100644 --- a/packages/cli/__tests__/zosfiles/__system__/search/ds/cli.files.search.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/search/ds/cli.files.search.ds.system.test.ts @@ -11,10 +11,10 @@ import { Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtp/cli.files.upload.dtp.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtp/cli.files.upload.dtp.system.test.ts index a67d0d5602..a5e273a8c1 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtp/cli.files.upload.dtp.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtp/cli.files.upload.dtp.system.test.ts @@ -11,10 +11,10 @@ import { Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, ZosFilesMessages } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts index 1ccaed57ca..1772167d28 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts @@ -12,10 +12,10 @@ import { Imperative, Session } from "@zowe/imperative"; import * as path from "path"; import * as fs from "fs"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, getTag } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Get, ZosFilesConstants, ZosFilesUtils, Delete } from "@zowe/zos-files-for-zowe-sdk"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts index 61b73755a1..0dfd942920 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts @@ -11,10 +11,10 @@ import { IO, Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getRandomBytes, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, ICreateDataSetOptions, Delete, Get } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts index 426e14fd0c..1e56a21194 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts @@ -11,9 +11,10 @@ import { Imperative, IO, Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Get, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts index fca9f1821f..ee05186200 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts @@ -11,10 +11,10 @@ import { IO, Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getRandomBytes, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Get } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/view/ds/View.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/view/ds/View.ds.system.test.ts index 94d832ccd8..be05415a62 100644 --- a/packages/cli/__tests__/zosfiles/__system__/view/ds/View.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/view/ds/View.ds.system.test.ts @@ -12,10 +12,10 @@ import { Session } from "@zowe/imperative"; import { Create, Delete, CreateDataSetTypeEnum } from "@zowe/cli"; import * as path from "path"; -import {ITestEnvironment, runCliScript} from "@zowe/cli-test-utils"; -import {TestEnvironment} from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; -import {ITestPropertiesSchema} from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName} from "../../../../../../../__tests__/__src__/TestUtils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts index c36f5ab897..9d1bb668bb 100644 --- a/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts @@ -13,11 +13,10 @@ import { Imperative, Session } from "@zowe/imperative"; import * as path from "path"; import { ZosFilesConstants, ZosmfRestClient, ZosmfHeaders, Upload } from "@zowe/cli"; -import {ITestEnvironment, runCliScript} from "@zowe/cli-test-utils"; -import {TestEnvironment} from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; -import { getRandomBytes } from "../../../../../../../__tests__/__src__/TestUtils"; -import {ITestPropertiesSchema} from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName} from "../../../../../../../__tests__/__src__/TestUtils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index 6fc43e4e07..af10ae3903 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -9,7 +9,9 @@ * */ -import { ITestEnvironment, runCliScript, TestEnvironment } from "@zowe/cli-test-utils"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { JobTestsUtils } from "../../../../../zosjobs/__tests__/__system__/JobTestsUtils"; import { AbstractSession, IO } from "@zowe/imperative"; @@ -27,8 +29,8 @@ describe("zos-jobs cancel job command", () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_cancel_job_command", tempProfileTypes: ["zosmf"] - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); const systemProps = TEST_ENVIRONMENT.systemTestProperties; const jcl = JobTestsUtils.getSleepJCL(systemProps.zosmf.user, systemProps.tso.account, systemProps.zosjobs.jobclass); const bufferJCL: Buffer = Buffer.from(jcl); @@ -117,7 +119,8 @@ describe("zos-jobs cancel job command", () => { beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_cancel_job_without_profiles" - }, REAL_SESSION = await TestEnvironment.createSession()); + }); + REAL_SESSION = await TestEnvironment.createSession(); DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.job.system.test.ts index 9d8d74af0d..bc780029f3 100644 --- a/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.job.system.test.ts @@ -9,8 +9,9 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.old-jobs.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.old-jobs.system.test.ts index 3b3d493ef2..1cdaa7c03a 100644 --- a/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.old-jobs.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.old-jobs.system.test.ts @@ -9,8 +9,9 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts index 96c393dd2a..a8faeed623 100644 --- a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts @@ -9,7 +9,9 @@ * */ -import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { AbstractSession } from "@zowe/imperative"; import * as fs from "fs"; @@ -26,7 +28,8 @@ describe("zos-jobs download output command", () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_download_output_command", tempProfileTypes: ["zosmf"] - }, REAL_SESSION = await TestEnvironment.createSession()); + }); + REAL_SESSION = await TestEnvironment.createSession(); IEFBR14_JCL = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; }); @@ -80,7 +83,8 @@ describe("zos-jobs download output command", () => { beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_download_output_without_profiles" - }, REAL_SESSION = await TestEnvironment.createSession()); + }); + REAL_SESSION = await TestEnvironment.createSession(); DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts index 069b568d1b..6b3929993e 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts @@ -9,7 +9,9 @@ * */ -import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { AbstractSession } from "@zowe/imperative"; import { IJob, GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; @@ -38,7 +40,8 @@ describe("zos-jobs list jobs command", () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_list_jobs_command", tempProfileTypes: ["zosmf"] - }, REAL_SESSION = await TestEnvironment.createSession()); + }); + REAL_SESSION = await TestEnvironment.createSession(); const systemProps = TEST_ENVIRONMENT.systemTestProperties; IEFBR14_JOB = systemProps.zosjobs.iefbr14Member; @@ -113,7 +116,8 @@ describe("zos-jobs list jobs command", () => { beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_job_without_profiles" - }, REAL_SESSION = await TestEnvironment.createSession()); + }); + REAL_SESSION = await TestEnvironment.createSession(); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts index 71a247964e..5038e14a79 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts @@ -9,7 +9,9 @@ * */ -import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { AbstractSession, TextUtils } from "@zowe/imperative"; import { IJob, GetJobs, SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; @@ -39,8 +41,8 @@ describe("zos-jobs list spool-files-by-jobid command", () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_list_spool_files_by_jobid_command", tempProfileTypes: ["zosmf"] - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; @@ -136,8 +138,8 @@ describe("zos-jobs list spool-files-by-jobid command", () => { beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_spool_files_by_jobid_without_profiles" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/modify/cli.zos-jobs.modify.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/modify/cli.zos-jobs.modify.job.system.test.ts index 6905d5fd60..8554416ca7 100644 --- a/packages/cli/__tests__/zosjobs/__system__/modify/cli.zos-jobs.modify.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/modify/cli.zos-jobs.modify.job.system.test.ts @@ -9,8 +9,9 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index 622ac5d731..a49dcbdf73 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -9,7 +9,9 @@ * */ -import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { AbstractSession } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; @@ -32,8 +34,8 @@ describe("zos-jobs search job command", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_jobs_search_job_command", tempProfileTypes: ["zosmf"] - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); // Use testEnvironment for accessing properties defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts index 1802033b30..2cd4e28186 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts @@ -9,7 +9,9 @@ * */ -import { ITestEnvironment, TestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { List } from "../../../../../../zosfiles/src/methods/list"; import { AbstractSession } from "@zowe/imperative"; @@ -32,8 +34,8 @@ describe("zos-jobs submit data-set command", () => { TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_submit_command", tempProfileTypes: ["zosmf"] - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); account = TEST_ENVIRONMENT.systemTestProperties.tso.account; jclMember = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; psJclDataSet = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14PSDataSet; @@ -143,7 +145,8 @@ describe("zos-jobs submit data-set command", () => { beforeAll(async () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_submit_data_set_without_profiles" - }, REAL_SESSION = await TestEnvironment.createSession()); + }); + REAL_SESSION = await TestEnvironment.createSession(); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); 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 ad22c489e2..9b8f65671a 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 @@ -9,8 +9,9 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { IO, Session } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; @@ -34,9 +35,8 @@ describe("zos-jobs submit local-file command", () => { testName: "zos_jobs_submit_local_file_command", tempProfileTypes: ["zosmf"] }); - + REAL_SESSION = await TestEnvironment.createSession(); systemProps = TEST_ENVIRONMENT.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = systemProps.tso.account; // JCL to submit 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 ad249947ad..af0ec7c560 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 @@ -9,8 +9,9 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { IO, Session } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts index 32cb467b4b..203a72869c 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts @@ -9,8 +9,9 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Session } from "@zowe/imperative"; import * as path from "path"; // Import path module for path handling @@ -35,7 +36,6 @@ describe("zos-jobs submit uss-file command", () => { testName: "zos_jobs_submit_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = TEST_ENVIRONMENT.systemTestProperties.tso.account; ussFile = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14USSFile; diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts index 2ae6ef3c1c..5716beb40b 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts @@ -9,8 +9,9 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Session } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts index 8f6946bdc9..fc21f68ab7 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts @@ -9,8 +9,9 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { ICommandResponse, Session } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts index e71259fa42..77590c1dfe 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts @@ -9,7 +9,7 @@ * */ -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Session, TextUtils } from "@zowe/imperative"; From 52361c227887fd04d8ac37026b47a6504e2072a0 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 29 Aug 2024 15:26:28 -0400 Subject: [PATCH 31/65] fixing imports Signed-off-by: ATorrise --- .../__system__/methods/get/Get.system.test.ts | 11 ++++--- .../methods/invoke/Invoke.system.test.ts | 11 ++++--- .../methods/upload/Upload.system.test.ts | 32 +++++++++---------- .../utilities/Utilities.system.test.ts | 7 ++-- .../__system__/CancelJobs.system.test.ts | 13 ++++---- .../__system__/DownloadJobs.system.test.ts | 11 ++++--- .../__system__/ModifyJobs.system.test.ts | 11 ++++--- .../__system__/MonitorJobs.system.test.ts | 11 ++++--- .../__system__/SearchJobs.system.test.ts | 6 ++-- .../__system__/SubmitJobs.system.test.ts | 7 ++-- 10 files changed, 65 insertions(+), 55 deletions(-) diff --git a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts index 4e9a86a553..5146d601ba 100644 --- a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts @@ -11,7 +11,8 @@ import { Create, CreateDataSetTypeEnum, Delete, Get, IGetOptions, List, ZosFilesConstants } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getRandomBytes, getUniqueDatasetName, stripNewLines } from "../../../../../../__tests__/__src__/TestUtils"; import { ZosmfRestClient, ZosmfHeaders } from "@zowe/core-for-zowe-sdk"; @@ -28,8 +29,8 @@ describe("Get", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_view" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`); Imperative.console.info("Using dsname:" + dsname); @@ -363,8 +364,8 @@ describe("Get - encoded", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_view" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`, true); Imperative.console.info("Using dsname:" + dsname); diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts index db73254af7..4d9f22469a 100644 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts @@ -13,7 +13,8 @@ import * as fs from "fs"; import { Imperative, IO, Session, TextUtils } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { ZosFilesMessages } from "../../../../src/constants/ZosFiles.messages"; import { Invoke } from "../../../../src/methods/invoke/Invoke"; @@ -32,8 +33,8 @@ describe("Invoke AMS", () => { testEnvironment = await TestEnvironment.setUp({ tempProfileTypes: ["zosmf"], testName: "zos_create_VSAM_dataset" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); systemProps = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); @@ -208,8 +209,8 @@ describe("Invoke AMS - encoded", () => { testEnvironment = await TestEnvironment.setUp({ tempProfileTypes: ["zosmf"], testName: "zos_create_VSAM_dataset" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); systemProps = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.ENCO#ED.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index a9d83b5f00..5da0de0057 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -12,9 +12,9 @@ import { Create, CreateDataSetTypeEnum, Delete, IUploadOptions, IZosFilesResponse, Upload, ZosFilesMessages, Download, Get, ZosFilesConstants, IUploadMap, Utilities } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, stripNewLines, delay } from "../../../../../../__tests__/__src__/TestUtils"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import * as fs from "fs"; @@ -36,8 +36,8 @@ describe("All Upload Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); Imperative.console.info("Using dsname:" + dsname); @@ -676,8 +676,8 @@ describe("All Upload Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); Imperative.console.info("Using dsname:" + dsname); @@ -776,8 +776,8 @@ describe("All Upload Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_uss" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); ussname = dsname.replace(/\./g, ""); @@ -934,8 +934,8 @@ describe("All Upload Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_uss" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); ussname = dsname.replace(/\./g, ""); @@ -1011,8 +1011,8 @@ describe("All Upload Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_dir_to_uss" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); ussname = dsname.replace(/\./g, ""); @@ -1239,8 +1239,8 @@ describe("All Upload Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_dir_to_uss" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); @@ -1376,8 +1376,8 @@ describe("All Upload Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_dir_to_uss" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); ussname = dsname.replace(/\./g, ""); diff --git a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts index b5440681b8..20a2a129e2 100644 --- a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts @@ -10,7 +10,8 @@ */ import { posix } from "path"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { AbstractSession, Imperative, IO } from "@zowe/imperative"; import { Utilities, Tag, Upload, Create, Download } from "../../../../src"; @@ -27,8 +28,8 @@ describe("USS Utilities", () => { testEnvironment = await TestEnvironment.setUp({ tempProfileTypes: ["zosmf"], testName: "zos_files_utilities" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); const defaultSystem = testEnvironment.systemTestProperties; let dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); dsname = dsname.replace(/\./g, ""); diff --git a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts index 7003a6977c..5c497b4623 100644 --- a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts @@ -11,9 +11,10 @@ import { ImperativeError, RestClientError, AbstractSession } from "@zowe/imperative"; import { CancelJobs, SubmitJobs, IJob } from "../../src"; -import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { JobTestsUtils } from "./JobTestsUtils"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; let REAL_SESSION: AbstractSession; let sleepJCL: string; @@ -27,9 +28,9 @@ describe("CancelJobs System tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs" - }, REAL_SESSION = await TestEnvironment.createSession()); + }); + REAL_SESSION = await TestEnvironment.createSession(); systemProps = testEnvironment.systemTestProperties; - const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer @@ -188,9 +189,9 @@ describe("CancelJobs System tests - encoded", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs_encoded" - }, REAL_SESSION = await TestEnvironment.createSession()); + }); + REAL_SESSION = await TestEnvironment.createSession(); systemProps = testEnvironment.systemTestProperties; - const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer diff --git a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts index 7a1e029bfe..69ab8b7f19 100644 --- a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts @@ -11,7 +11,8 @@ import { DeleteJobs, DownloadJobs, GetJobs, IJobFile, SubmitJobs } from "../../src"; import { ImperativeError, IO, Session, TextUtils } from "@zowe/imperative"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Get } from "@zowe/zos-files-for-zowe-sdk"; import { MonitorJobs } from "../../src/MonitorJobs"; @@ -42,8 +43,8 @@ describe("Download Jobs - System tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; @@ -355,8 +356,8 @@ describe("Download Jobs - System tests - Encoded", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs_encoded" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts index d4a828525f..b78e547a47 100644 --- a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts @@ -11,7 +11,8 @@ import { ImperativeError, Session } from "@zowe/imperative"; import { IJob, SubmitJobs, ModifyJobs, CancelJobs } from "../../src"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { JobTestsUtils } from "./JobTestsUtils"; @@ -30,8 +31,8 @@ describe("Modify Jobs - System Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobclass = testEnvironment.systemTestProperties.zosjobs.jobclass; @@ -106,8 +107,8 @@ describe("Modify Jobs - System Tests - Encoded", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs_encoded" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobclass = testEnvironment.systemTestProperties.zosjobs.jobclass; diff --git a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts index 882ae4296b..4ab66d7dc4 100644 --- a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts @@ -15,7 +15,8 @@ import { ImperativeError, Session, TextUtils } from "@zowe/imperative"; import * as fs from "fs"; import { join } from "path"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; // long running test timeout @@ -71,8 +72,8 @@ describe("System Tests - Monitor Jobs", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_monitor_jobs" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 6; @@ -687,8 +688,8 @@ describe("System Tests - Monitor Jobs", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_monitor_jobs_encoded" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 5; diff --git a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts index 7a6f21eff2..38048883c4 100644 --- a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts @@ -11,7 +11,8 @@ import { ImperativeError, Session } from "@zowe/imperative"; import { DeleteJobs, GetJobs, IJob, SearchJobs } from "../../src"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; /**********************************************************************************/ @@ -56,7 +57,8 @@ describe("Search Jobs - System Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_search_jobs" - }, REAL_SESSION = await TestEnvironment.createSession()); + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; INVALID_SESSION = new Session({ diff --git a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts index c7024a6a7d..ae48ed3611 100644 --- a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts @@ -11,7 +11,8 @@ import { ImperativeError, Session } from "@zowe/imperative"; import { GetJobs, IJob, ISpoolFile, SubmitJobs } from "../../src"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { existsSync } from "fs"; import { ZosJobsMessages } from "../../src/JobsMessages"; @@ -37,8 +38,8 @@ describe("Submit Jobs - System Tests", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_submit_jobs" - }, REAL_SESSION = await TestEnvironment.createSession()); - + }); + REAL_SESSION = await TestEnvironment.createSession(); systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobDataSet = testEnvironment.systemTestProperties.zosjobs.iefbr14PSDataSet; From 309be62a1a095df266f3ef81df1e92bf63735f21 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 29 Aug 2024 15:50:31 -0400 Subject: [PATCH 32/65] hopefully not breaking Signed-off-by: ATorrise --- .../__src__/environment/TestEnvironment.ts | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index eee1877d1a..64caa02575 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -74,23 +74,25 @@ export class TestEnvironment extends BaseTestEnvironment { for (const file of testEnvironment.resources.localFiles) { deleteLocalFile(file); } - // Check if session exists; if not, create one - const session = testEnvironment.resources.session || await TestEnvironment.createSession(); - for (const file of testEnvironment.resources.files) { - deleteFiles(session, file); - } - for (const job of testEnvironment.resources.jobs) { - deleteJob(session, job); - } - for (const jobData of testEnvironment.resources.jobData) { - if (jobData.jobname && jobData.jobid) { - deleteJobCommon(session, jobData); - } else { - Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); + // Check if session exists before deleting resources + const session = testEnvironment.resources.session; + if (session) { + for (const file of testEnvironment.resources.files) { + deleteFiles(session, file); + } + for (const job of testEnvironment.resources.jobs) { + deleteJob(session, job); + } + for (const jobData of testEnvironment.resources.jobData) { + if (jobData.jobname && jobData.jobid) { + deleteJobCommon(session, jobData); + } else { + Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); + } + } + for (const dataset of testEnvironment.resources.datasets) { + deleteDataset(session, dataset); } - } - for (const dataset of testEnvironment.resources.datasets) { - deleteDataset(session, dataset); } } From 585bb7539deba898cbddb5c970eb2f43ad2cb76e Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 29 Aug 2024 16:12:23 -0400 Subject: [PATCH 33/65] accidentally left 1 thing out of if statement Signed-off-by: ATorrise --- __tests__/__src__/environment/TestEnvironment.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index 64caa02575..c41476b3cb 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -70,13 +70,12 @@ export class TestEnvironment extends BaseTestEnvironment { require("rimraf").sync(pluginDir); } - // Clean up resources - for (const file of testEnvironment.resources.localFiles) { - deleteLocalFile(file); - } // Check if session exists before deleting resources const session = testEnvironment.resources.session; if (session) { + for (const file of testEnvironment.resources.localFiles) { + deleteLocalFile(file); + } for (const file of testEnvironment.resources.files) { deleteFiles(session, file); } From a83444addaf1ec60a4fbab41dc9ca313326fb466 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 29 Aug 2024 16:28:53 -0400 Subject: [PATCH 34/65] whoops Signed-off-by: ATorrise --- __tests__/__src__/environment/TestEnvironment.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index c41476b3cb..39069d9c50 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -71,8 +71,8 @@ export class TestEnvironment extends BaseTestEnvironment { } // Check if session exists before deleting resources - const session = testEnvironment.resources.session; - if (session) { + if (testEnvironment?.resources?.session) { + const session = testEnvironment.resources.session; for (const file of testEnvironment.resources.localFiles) { deleteLocalFile(file); } From bc1ffa240f1a7842e3a20f22623c2c06939b05fc Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 29 Aug 2024 18:40:59 -0400 Subject: [PATCH 35/65] making a wait util method and implementing it everywhere Signed-off-by: ATorrise --- __tests__/__src__/TestUtils.ts | 28 ++++-- ...rkflows.list.active.details.system.test.ts | 11 ++- ...files.create.dataset.binary.system.test.ts | 6 +- .../cli.files.create.dataset.c.system.test.ts | 6 +- ...iles.create.dataset.classic.system.test.ts | 6 +- .../ds/cli.files.create.ds.system.test.ts | 4 +- ...li.files.create.dataset.pds.system.test.ts | 6 +- ...cli.files.create.dataset.ps.system.test.ts | 6 +- .../ds/cli.files.rename.ds.system.test.ts | 12 ++- .../dsm/cli.files.rename.dsm.system.test.ts | 7 +- .../dtu/cli.dir.upload.dtu.system.test.ts | 6 +- .../search/cli.zos-jobs.search.job.test.ts | 17 ++-- .../methods/download/Download.system.test.ts | 89 +++++++++---------- .../methods/list/List.system.test.ts | 49 +++++----- .../methods/upload/Upload.system.test.ts | 39 ++++---- .../methods/search/Search.unit.test.ts | 10 +-- .../__system__/GetJobs.system.test.ts | 60 +++++-------- 17 files changed, 174 insertions(+), 188 deletions(-) diff --git a/__tests__/__src__/TestUtils.ts b/__tests__/__src__/TestUtils.ts index 63facd0262..157ae9d5e1 100644 --- a/__tests__/__src__/TestUtils.ts +++ b/__tests__/__src__/TestUtils.ts @@ -18,6 +18,7 @@ import { DeleteJobs, ICommonJobParms, IDeleteJobParms, IJob } from "../../packag import { posix } from "path"; import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process"; import { ITestEnvironment } from "./environment/ITestEnvironment"; +import { promisify } from "util"; /** * Delete a local testing file after use @@ -36,6 +37,21 @@ export function deleteLocalFile(filePath: string): void { } } +/** + * Delete local directories after use + * @param {string[]} directories - Array of directories to delete + */ +export function deleteLocalDirectories(directories: string[]): void { + directories.forEach((dir) => { + try { + if (fs.existsSync(dir)) { + fs.rmdirSync(dir, { recursive: true }); + } + } catch (err) { + throw new Error(`Error deleting directory: ${dir}`); + } + }); +} /** * Delete a uss file from the mainframe * @param {AbstractSession} session - z/OSMF connection info @@ -158,11 +174,13 @@ export async function getTag(session: AbstractSession, ussPath: string) { return response.stdout[0]; } -export function delay(ms: number) { - return new Promise((resolve) => setTimeout(resolve, ms) ); -} - -export const delTime = 500; +/** + * Pauses execution for a given number of milliseconds. + * @param {number} ms - Number of milliseconds to wait + * @returns {Promise} - Resolves after the specified time has passed + */ +export const wait = promisify(setTimeout); +export const waitTime = 2000; //wait 2 seconds /** * Use instead of `util.inspect` to get consistently formatted output that can be used in snapshots. diff --git a/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts b/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts index 7f8a9e6b2f..ce32b77968 100644 --- a/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts @@ -11,10 +11,10 @@ import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, delay } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, wait, waitTime, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { CreateWorkflow, DeleteWorkflow } from "@zowe/zos-workflows-for-zowe-sdk"; import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; @@ -29,7 +29,6 @@ let system: string; let owner: string; let wfName: string; const workflow = join(__dirname, "../../../../../../workflows/__tests__/__system__/testfiles/demo.xml"); -const delayTime = 2000; describe("List active workflow details cli system tests", () => { beforeAll(async () => { @@ -45,7 +44,7 @@ describe("List active workflow details cli system tests", () => { fakeDefFile = definitionFile + "fakefile"; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); afterAll(async () => { @@ -58,14 +57,14 @@ describe("List active workflow details cli system tests", () => { // Upload files only for successful scenarios try { await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; } // Create a workflow instance in zOS/MF to list const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds wfKey = response.workflowKey; }); afterAll(async () => { diff --git a/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts index 0d6b1cc05c..37d09672da 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts @@ -14,7 +14,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environm import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; -import { delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; +import { wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; @@ -68,7 +68,7 @@ describe("Create Binary Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); @@ -103,7 +103,7 @@ describe("Create Binary Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); diff --git a/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts index 142d7bf1a1..ecacfa6b9d 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts @@ -14,7 +14,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environm import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; -import { delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; +import { wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; @@ -68,7 +68,7 @@ describe("Create C Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); @@ -104,7 +104,7 @@ describe("Create C Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); diff --git a/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts index 651e09d1b7..9e1588f7ea 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts @@ -14,7 +14,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environm import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; -import { delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; +import { wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; @@ -68,7 +68,7 @@ describe("Create Classic Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); @@ -104,7 +104,7 @@ describe("Create Classic Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); diff --git a/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts index 455993d86f..31e31f0be2 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts @@ -14,7 +14,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environm import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; -import { delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; +import { wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; @@ -61,7 +61,7 @@ describe("Create Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); diff --git a/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts index a89fc7d9f1..9d504684a1 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts @@ -14,7 +14,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environm import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; -import { stripNewLines, delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; +import { stripNewLines, wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; @@ -69,7 +69,7 @@ describe("Create Partitioned Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); @@ -105,7 +105,7 @@ describe("Create Partitioned Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); diff --git a/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts index f22c0827d1..6dacff6d66 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts @@ -14,7 +14,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environm import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; -import { stripNewLines, delay, delTime } from "../../../../../../../__tests__/__src__/TestUtils"; +import { stripNewLines, wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; @@ -69,7 +69,7 @@ describe("Create Physical Sequential Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); @@ -105,7 +105,7 @@ describe("Create Physical Sequential Data Set", () => { afterEach(async () => { // use DELETE APIs if (dsnameSuffix !== "") { - await delay(delTime); + await wait(waitTime); //wait 2 seconds const response = await Delete.dataSet(REAL_SESSION, dsname + "." + dsnameSuffix); } }); diff --git a/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts index bae07ee910..77078145fa 100644 --- a/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts @@ -13,8 +13,7 @@ import { Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; -import { delay } from "../../../../../../../__tests__/__src__/TestUtils"; +import { wait, waitTime, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create, CreateDataSetTypeEnum, Upload, Get } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; @@ -25,7 +24,6 @@ let beforeDataSetName: string; let afterDataSetName: string; let user: string; const memberName = "mem"; -const delayTime = 2000; describe("Rename data set", () => { beforeAll(async () => { @@ -68,7 +66,7 @@ describe("Rename data set", () => { TEST_ENVIRONMENT, [beforeDataSetName, afterDataSetName] ); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds contents = await Get.dataSet(REAL_SESSION, afterDataSetName); } catch(err) { error = err; @@ -90,7 +88,7 @@ describe("Rename data set", () => { TEST_ENVIRONMENT, [beforeDataSetName, afterDataSetName, "--responseTimeout 5"] ); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds contents = await Get.dataSet(REAL_SESSION, afterDataSetName); } catch(err) { error = err; @@ -118,7 +116,7 @@ describe("Rename data set", () => { TEST_ENVIRONMENT, [beforeDataSetName, afterDataSetName] ); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds contents = await Get.dataSet(REAL_SESSION, `${afterDataSetName}(${memberName})`); } catch(err) { error = err; @@ -140,7 +138,7 @@ describe("Rename data set", () => { TEST_ENVIRONMENT, [beforeDataSetName, afterDataSetName, "--responseTimeout 5"] ); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds contents = await Get.dataSet(REAL_SESSION, `${afterDataSetName}(${memberName})`); } catch(err) { error = err; diff --git a/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts index 96c6633578..7111eac25b 100644 --- a/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts @@ -13,7 +13,7 @@ import { Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { delay, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { wait, waitTime, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create, CreateDataSetTypeEnum, Upload, Get } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; @@ -24,7 +24,6 @@ let dataSetName: string; let user: string; const beforeMemberName = "mem1"; const afterMemberName = "mem2"; -const delayTime = 2000; describe("Rename data set member", () => { beforeAll(async () => { @@ -61,7 +60,7 @@ describe("Rename data set member", () => { TEST_ENVIRONMENT, [dataSetName, beforeMemberName, afterMemberName] ); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds contents = await Get.dataSet(REAL_SESSION, `${dataSetName}(${afterMemberName})`); } catch(err) { error = err; @@ -83,7 +82,7 @@ describe("Rename data set member", () => { TEST_ENVIRONMENT, [dataSetName, beforeMemberName, afterMemberName, "--responseTimeout 5"] ); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds contents = await Get.dataSet(REAL_SESSION, `${dataSetName}(${afterMemberName})`); } catch(err) { error = err; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts index 1772167d28..9cd717e9d8 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts @@ -15,7 +15,7 @@ import * as fs from "fs"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getTag, getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Get, ZosFilesConstants, ZosFilesUtils, Delete } from "@zowe/zos-files-for-zowe-sdk"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; @@ -87,7 +87,7 @@ describe("Upload directory to USS", () => { const ussEndpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; await ZosmfRestClient.deleteExpectString(REAL_SESSION, ussEndpoint, [{"X-IBM-Option": "recursive"}]); } catch (err) { - Imperative.console.info(`Error cleaning up USS directory: ${inspect(err)}`); + Imperative.console.info(`Error cleaning up USS directory: ${err}`); } await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); @@ -127,7 +127,7 @@ describe("Upload directory to USS", () => { const ussEndpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; await ZosmfRestClient.deleteExpectString(REAL_SESSION, ussEndpoint, [{"X-IBM-Option": "recursive"}]); } catch (err) { - Imperative.console.info(`Error cleaning up USS directory: ${inspect(err)}`); + Imperative.console.info(`Error cleaning up USS directory: ${err}`); } }); diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index a49dcbdf73..acd5bc684c 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -13,8 +13,10 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; import { AbstractSession } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; +import { promisify } from 'util'; // Test Environment populated in the beforeAll(); let testEnvironment: ITestEnvironment; @@ -74,8 +76,7 @@ describe("zos-jobs search job command", () => { const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", testEnvironment, [JOB_NAME, argString]); - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); @@ -88,8 +89,7 @@ describe("zos-jobs search job command", () => { const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", testEnvironment, [JOB_NAME, argString]); - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); @@ -103,8 +103,7 @@ describe("zos-jobs search job command", () => { const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", testEnvironment, [JOB_NAME, argString]); - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds expect(response.stderr.toString()).toContain("The search spool job command returned a non-zero rc: 1"); expect(response.status).toBe(1); @@ -115,8 +114,7 @@ describe("zos-jobs search job command", () => { const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", testEnvironment, [JOB_NAME, ""]); - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds expect(response.stderr.toString()).toContain("You must specify either the `--search-string` or `--search-regex` option"); expect(response.status).toBe(1); @@ -127,8 +125,7 @@ describe("zos-jobs search job command", () => { const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", testEnvironment, [JOB_NAME, argString]); - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds expect(response.stderr.toString()).toContain("You must specify either the `--search-string` or `--search-regex` option"); expect(response.status).toBe(1); diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index 2009a9b432..1fe87e55d8 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -32,7 +32,7 @@ import { inspect } from "util"; import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, stripNewLines, delay } from "../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, stripNewLines, wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import * as fs from "fs"; import { posix } from "path"; @@ -41,7 +41,6 @@ import { PassThrough } from "stream"; import { text } from "stream/consumers"; const rimraf = require("rimraf").sync; -const delayTime = 2000; const testData = "abcdefghijklmnopqrstuvwxyz"; let REAL_SESSION: Session; @@ -86,7 +85,7 @@ describe("Download Data Set", () => { try { response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; } @@ -98,7 +97,7 @@ describe("Download Data Set", () => { try { response = await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; } @@ -118,7 +117,7 @@ describe("Download Data Set", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.dataSet(REAL_SESSION, dsname); @@ -147,7 +146,7 @@ describe("Download Data Set", () => { let response: IZosFilesResponse; await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.dataSet(REAL_SESSION, dsname, {responseTimeout: 5}); @@ -177,7 +176,7 @@ describe("Download Data Set", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.dataSet(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); @@ -266,7 +265,7 @@ describe("Download Data Set", () => { let response: IZosFilesResponse; await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds const options: IDownloadOptions = { returnEtag: true @@ -306,7 +305,7 @@ describe("Download Data Set", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.dataSet(REAL_SESSION, dsname, options); @@ -337,7 +336,7 @@ describe("Download Data Set", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.dataSet(REAL_SESSION, dsname, { stream: responseStream }); @@ -366,7 +365,7 @@ describe("Download Data Set", () => { try { response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; } @@ -378,7 +377,7 @@ describe("Download Data Set", () => { try { response = await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; } @@ -394,7 +393,7 @@ describe("Download Data Set", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.allMembers(REAL_SESSION, dsname); @@ -424,7 +423,7 @@ describe("Download Data Set", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.allMembers(REAL_SESSION, dsname, {responseTimeout: 5}); @@ -454,7 +453,7 @@ describe("Download Data Set", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.allMembers(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); @@ -491,7 +490,7 @@ describe("Download Data Set", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds const options: IDownloadOptions = { binary: true @@ -521,7 +520,7 @@ describe("Download Data Set", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds const options: IDownloadOptions = { record: true @@ -551,7 +550,7 @@ describe("Download Data Set", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds const options: IDownloadOptions = { extension: "dat" @@ -584,7 +583,7 @@ describe("Download Data Set", () => { try { response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; } @@ -596,7 +595,7 @@ describe("Download Data Set", () => { try { response = await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -766,7 +765,7 @@ describe("Download Data Set", () => { try { response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; } @@ -778,7 +777,7 @@ describe("Download Data Set", () => { try { response = await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; } @@ -1007,7 +1006,7 @@ describe("Download Data Set", () => { try { await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { Imperative.console.error(err); } @@ -1022,7 +1021,7 @@ describe("Download Data Set", () => { let response: IZosFilesResponse; await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.ussFile(REAL_SESSION, ussname); @@ -1043,7 +1042,7 @@ describe("Download Data Set", () => { let response: IZosFilesResponse; await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.ussFile(REAL_SESSION, ussname, {responseTimeout: 5}); @@ -1064,7 +1063,7 @@ describe("Download Data Set", () => { let response: IZosFilesResponse; await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds const options: IDownloadOptions = { returnEtag: true @@ -1096,7 +1095,7 @@ describe("Download Data Set", () => { const data = Buffer.from(buffer); await Upload.bufferToUssFile(REAL_SESSION, ussname, data); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds const options: IDownloadOptions = { returnEtag: true @@ -1122,7 +1121,7 @@ describe("Download Data Set", () => { }; await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData), { binary: true }); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.ussFile(REAL_SESSION, ussname, options); @@ -1145,7 +1144,7 @@ describe("Download Data Set", () => { await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData), { binary: true }); await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "ISO8859-1"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.ussFile(REAL_SESSION, ussname, options); @@ -1169,7 +1168,7 @@ describe("Download Data Set", () => { const data: string = "Hello, world¤"; await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "IBM-1147"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.ussFile(REAL_SESSION, ussname, options); @@ -1193,7 +1192,7 @@ describe("Download Data Set", () => { const options: IDownloadOptions = {file: `test1.txt`}; await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.ussFile(REAL_SESSION, ussname, options); @@ -1217,7 +1216,7 @@ describe("Download Data Set", () => { const responseStream = new PassThrough(); await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.ussFile(REAL_SESSION, ussname, { stream: responseStream }); @@ -1544,7 +1543,7 @@ describe("Download Data Set - encoded", () => { let error; try { await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { // Do nothing, sometimes the files are not created. error = err; @@ -1556,7 +1555,7 @@ describe("Download Data Set - encoded", () => { let error; try { await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { // Do nothing, sometimes the files are not created. error = err; @@ -1576,7 +1575,7 @@ describe("Download Data Set - encoded", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.dataSet(REAL_SESSION, dsname); @@ -1606,7 +1605,7 @@ describe("Download Data Set - encoded", () => { let error; try { await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { // Do nothing, sometimes the files are not created. error = err; @@ -1618,7 +1617,7 @@ describe("Download Data Set - encoded", () => { let error; try { await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { // Do nothing, sometimes the files are not created. error = err; @@ -1636,7 +1635,7 @@ describe("Download Data Set - encoded", () => { // upload data to the newly created data set await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.allMembers(REAL_SESSION, dsname); @@ -1668,7 +1667,7 @@ describe("Download Data Set - encoded", () => { let error; try { await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { // Do nothing, sometimes the files are not created. error = err; @@ -1681,7 +1680,7 @@ describe("Download Data Set - encoded", () => { try { await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { // Do nothing, sometimes the files are not created. error = err; @@ -1734,7 +1733,7 @@ describe("Download Data Set - encoded", () => { let error; try { await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { // Do nothing, sometimes the files are not created. error = err; @@ -1746,7 +1745,7 @@ describe("Download Data Set - encoded", () => { let error; try { await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { // Do nothing, sometimes the files are not created. error = err; @@ -1794,7 +1793,7 @@ describe("Download Data Set - encoded", () => { try { await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { Imperative.console.error(err); } @@ -1809,7 +1808,7 @@ describe("Download Data Set - encoded", () => { let response: IZosFilesResponse; await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.ussFile(REAL_SESSION, ussname); @@ -1833,7 +1832,7 @@ describe("Download Data Set - encoded", () => { const options: IDownloadOptions = {file: `test1.txt`}; await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds try { response = await Download.ussFile(REAL_SESSION, ussname, options); diff --git a/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts index c359540c15..9f6f1753d1 100644 --- a/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts @@ -15,7 +15,7 @@ import { format, inspect } from "util"; import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, delay } from "../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -23,7 +23,6 @@ let defaultSystem: ITestPropertiesSchema; let dsname: string; let path: string; let filename: string; -const delayTime = 2000; describe("List command group", () => { @@ -54,14 +53,14 @@ describe("List command group", () => { beforeEach(async () => { await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname, { volser: defaultSystem.datasets.vol }); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testString), `${dsname}(${testString})`); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); afterEach(async () => { await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); it("should list all members of a data set", async () => { @@ -132,7 +131,7 @@ describe("List command group", () => { try { await Delete.dataSet(REAL_SESSION, `${dsname}(${testString})`); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds response = await List.allMembers(REAL_SESSION, dsname); } catch (err) { error = err; @@ -182,12 +181,12 @@ describe("List command group", () => { beforeEach(async () => { await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname, { volser: defaultSystem.datasets.vol }); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); afterEach(async () => { await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); it("should list a data set", async () => { @@ -299,9 +298,9 @@ describe("List command group", () => { let response; try { response = await Create.uss(REAL_SESSION, path, "directory"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds response = await Create.uss(REAL_SESSION, `${path}/${filename}`, "file"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -594,17 +593,17 @@ describe("List command group", () => { beforeEach(async () => { await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname, { volser: defaultSystem.datasets.vol }); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname + ".LIKE", { volser: defaultSystem.datasets.vol }); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); afterEach(async () => { await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds await Delete.dataSet(REAL_SESSION, dsname + ".LIKE"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); it("should find data sets that match a pattern", async () => { @@ -691,14 +690,14 @@ describe("List command group - encoded", () => { beforeEach(async () => { await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname, { volser: defaultSystem.datasets.vol }); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testString), `${dsname}(${testString})`); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); afterEach(async () => { await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); it("should list all members of a data set", async () => { @@ -750,12 +749,12 @@ describe("List command group - encoded", () => { beforeEach(async () => { await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname, { volser: defaultSystem.datasets.vol }); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); afterEach(async () => { await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); it("should list a data set", async () => { @@ -833,9 +832,9 @@ describe("List command group - encoded", () => { beforeAll(async () => { try { await Create.uss(REAL_SESSION, path, "directory"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds await Create.uss(REAL_SESSION, `${path}/${filename}`, "file"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { Imperative.console.info("Error: " + inspect(err)); } @@ -931,17 +930,17 @@ describe("List command group - encoded", () => { beforeEach(async () => { await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname, { volser: defaultSystem.datasets.vol }); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname + ".LIKE", { volser: defaultSystem.datasets.vol }); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); afterEach(async () => { await Delete.dataSet(REAL_SESSION, dsname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds await Delete.dataSet(REAL_SESSION, dsname + ".LIKE"); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds }); it("should find data sets that match a pattern", async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index 5da0de0057..c2d2b46b50 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -17,13 +17,14 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import * as fs from "fs"; +import { getUniqueDatasetName, deleteLocalDirectories, inspect, + stripNewLines, wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; let defaultSystem: ITestPropertiesSchema; let dsname: string; let ussname: string; -const delayTime = 2000; const inputfile = __dirname + "/testfiles/upload.txt"; const testdata = "abcdefghijklmnopqrstuvwxyz"; const uploadOptions: IUploadOptions = {} as any; @@ -104,17 +105,9 @@ describe("All Upload Tests", () => { afterAll(async () => { await TestEnvironment.cleanUp(testEnvironment); - // Delete directories + // Delete directories using the utility function const dirsToDelete = [localDir, localDirWithSpaces]; - dirsToDelete.forEach((dir) => { - try { - if (fs.existsSync(dir)) { - fs.rmdirSync(dir, { recursive: true }); - } - } catch (err) { - Imperative.console.info(`Error deleting directory: ${dir}`, err); - } - }); + deleteLocalDirectories(dirsToDelete); }); describe("Upload Data Set", () => { @@ -1037,7 +1030,7 @@ describe("All Upload Tests", () => { const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); try { await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { error = err; } @@ -1049,7 +1042,7 @@ describe("All Upload Tests", () => { let isDirectoryExist: boolean; try { uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds Imperative.console.info(`THIS IS USS ${ussname}/testfiles`); isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); } catch (err) { @@ -1072,7 +1065,7 @@ describe("All Upload Tests", () => { try { tempUssname = ussname + " space dir"; uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDirWithSpaces, tempUssname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds Imperative.console.info(`THIS IS USS ${tempUssname}`); isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, tempUssname); } catch (err) { @@ -1093,7 +1086,7 @@ describe("All Upload Tests", () => { let isDirectoryExist: any; try { uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false}); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); } catch (err) { error = err; @@ -1114,7 +1107,7 @@ describe("All Upload Tests", () => { let getResponse; try { uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname, {binary: true}); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: true}); } catch (err) { @@ -1139,7 +1132,7 @@ describe("All Upload Tests", () => { let longResponse: string = ""; try { uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: true}); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: true}); for (let i = 0; i < magicNum; i++) { @@ -1170,7 +1163,7 @@ describe("All Upload Tests", () => { const fileMap: IUploadMap = {binary: true, fileNames: ["file3.txt", "longline.txt"]}; try { uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false, filesMap: fileMap}); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); // file3.txt should be binary as it is mentioned in filesMap getResponseFile3 = await Get.USSFile(REAL_SESSION, `${ussname}/file3.txt`, {binary: true}); @@ -1208,7 +1201,7 @@ describe("All Upload Tests", () => { const filesMap: IUploadMap = {binary: false, fileNames: ["file3.txt", "longline.txt"]}; try { uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: true, filesMap}); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); // file3.txt should be ASCII as it is mentioned in filesMap getResponseFile3 = await Get.USSFile(REAL_SESSION, `${ussname}/file3.txt`, {binary: false}); @@ -1400,7 +1393,7 @@ describe("All Upload Tests", () => { const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); try { await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds } catch (err) { // Do nothing } @@ -1412,7 +1405,7 @@ describe("All Upload Tests", () => { let isDirectoryExist: boolean; try { uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds Imperative.console.info(`THIS IS USS ${ussname}/testfiles`); isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); } catch (err) { @@ -1435,7 +1428,7 @@ describe("All Upload Tests", () => { try { tempUssname = ussname + " space dir"; uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDirWithSpaces, tempUssname); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds Imperative.console.info(`THIS IS USS ${tempUssname}`); isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, tempUssname); } catch (err) { @@ -1456,7 +1449,7 @@ describe("All Upload Tests", () => { let isDirectoryExist: any; try { uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false}); - await delay(delayTime); + await wait(waitTime); //wait 2 seconds isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); } catch (err) { error = err; diff --git a/packages/zosfiles/__tests__/__unit__/methods/search/Search.unit.test.ts b/packages/zosfiles/__tests__/__unit__/methods/search/Search.unit.test.ts index 62c1aea359..045e661ab7 100644 --- a/packages/zosfiles/__tests__/__unit__/methods/search/Search.unit.test.ts +++ b/packages/zosfiles/__tests__/__unit__/methods/search/Search.unit.test.ts @@ -11,6 +11,7 @@ import { ImperativeError, Session, TaskStage } from "@zowe/imperative"; import { Get, ISearchItem, ISearchOptions, IZosFilesResponse, List, Search } from "../../../../src"; +import { wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; describe("Search", () => { @@ -118,7 +119,6 @@ describe("Search", () => { const listDataSetsMatchingPatternSpy = jest.spyOn(List, "dataSetsMatchingPattern"); const listAllMembersSpy = jest.spyOn(List, "allMembers"); - function delay(ms: number) { jest.advanceTimersByTime(ms); } function regenerateMockImplementations() { searchOnMainframeSpy.mockImplementation(async (session, searchOptions, searchItems: ISearchItem[]) => { if ((Search as any).timerExpired != true) { @@ -575,7 +575,7 @@ describe("Search", () => { it("Should handle timing out 1", async () => { searchLocalSpy.mockImplementation(async (session, searchOptions, searchItems: ISearchItem[]) => { - delay(1100); + await wait(waitTime); //wait 2 seconds if ((Search as any).timerExpired != true) { const searchItemArray: ISearchItem[] = []; for (const searchItem of searchItems) { @@ -622,7 +622,7 @@ describe("Search", () => { it("Should handle timing out 2", async () => { searchOnMainframeSpy.mockImplementation(async (session, searchOptions, searchItems: ISearchItem[]) => { - delay(1100); + await wait(waitTime); //wait 2 seconds if ((Search as any).timerExpired != true) { return { responses: searchItems, @@ -666,7 +666,7 @@ describe("Search", () => { it("Should handle timing out 3", async () => { listAllMembersSpy.mockImplementation(async (session, dsn, options) => { - delay(1100); + await wait(waitTime); //wait 2 seconds return { success: true, commandResponse: "", @@ -703,7 +703,7 @@ describe("Search", () => { it("Should handle timing out 4", async () => { listDataSetsMatchingPatternSpy.mockImplementation(async (session, patterns, options) => { - delay(1100); + await wait(waitTime); //wait 2 seconds return { success: true, commandResponse: "", diff --git a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts index 8ad1aa3c58..a9735761f8 100644 --- a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts @@ -13,12 +13,13 @@ import { JOB_STATUS } from "./../../src/types/JobStatus"; import { AbstractSession, ImperativeError, Session, TextUtils } from "@zowe/imperative"; import * as fs from "fs"; import { join } from "path"; -import { ITestEnvironment, TestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; +import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { TEST_RESOURCES_DIR } from "../__src__/ZosJobsTestConstants"; import { GetJobs, DeleteJobs, IJob, JOB_STATUS_ORDER, SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; +import { wait, waitTime } from "../../../../__tests__/__src__/TestUtils"; -/**********************************************************************************/ let ACCOUNT: string; let JOBCLASS: string; @@ -59,11 +60,10 @@ const LONG_TIMEOUT = 200000; describe("Get Jobs System Tests", () => { describe("Non-Encoded System Tests", () => { beforeAll(async () => { - REAL_SESSION = await TestEnvironment.createSession(); - testEnvironment = await TestEnvironment.setUp({ testName: "get_jobs_system_test" - }, REAL_SESSION); + }); + REAL_SESSION = await TestEnvironment.createSession(); defaultSystem = testEnvironment.systemTestProperties; @@ -159,8 +159,7 @@ describe("Get Jobs System Tests", () => { testEnvironment.resources.jobs.push(job); } - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Obtain the three jobs submitted const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, MONITOR_JOB_NAME + "*"); @@ -217,8 +216,7 @@ describe("Get Jobs System Tests", () => { testEnvironment.resources.jobs.push(job); } - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Obtain the three jobs submitted const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, TEST_JOB_NAME + "*"); @@ -281,8 +279,7 @@ describe("Get Jobs System Tests", () => { jobs.push(job); testEnvironment.resources.jobs.push(job); } - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Obtain all jobs for the user const allJobs: IJob[] = await GetJobs.getJobs(REAL_SESSION); @@ -316,8 +313,7 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Search all jobs returned for each of the submitted jobs const foundJob = await GetJobs.getJob(REAL_SESSION, job.jobid); @@ -343,8 +339,7 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Search all jobs returned for each of the submitted jobs const foundJobs = await GetJobs.getJobsCommon(REAL_SESSION, {jobid: job.jobid}); @@ -421,8 +416,7 @@ describe("Get Jobs System Tests", () => { testEnvironment.resources.jobs.push(job); } - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Obtain all jobs for ***REMOVED*** const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, REAL_SESSION.ISession.user); @@ -719,8 +713,7 @@ describe("Get Jobs System Tests", () => { await DeleteJobs.deleteJobForJob(REAL_SESSION, job); - // Add a delay to ensure job deletion is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(3000); //Wait for 3 seconds let error; try { @@ -853,8 +846,7 @@ describe("Get Jobs System Tests", () => { await DeleteJobs.deleteJobForJob(REAL_SESSION, job); - // Add a delay to ensure job deletion is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(3000); //Wait for 3 seconds let error; try { @@ -990,8 +982,7 @@ describe("Get Jobs System Tests", () => { await DeleteJobs.deleteJobForJob(REAL_SESSION, job); - // Add a delay to ensure job deletion is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(3000); //Wait for 3 seconds let error; try { @@ -1022,12 +1013,11 @@ describe("Get Jobs System Tests", () => { describe("Encoded System Tests", () => { beforeAll(async () => { - const REAL_SESSION = await TestEnvironment.createSession(); testEnvironment = await TestEnvironment.setUp({ testName: "zos_get_jobs_encoded" - }, REAL_SESSION); - defaultSystem = testEnvironment.systemTestProperties; + }); + REAL_SESSION = await TestEnvironment.createSession(); INVALID_SESSION = new Session({ user: "fakeuser", @@ -1083,8 +1073,7 @@ describe("Get Jobs System Tests", () => { testEnvironment.resources.jobs.push(job); } - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Obtain all jobs for the user const allJobs: IJob[] = await GetJobs.getJobs(REAL_SESSION); @@ -1118,8 +1107,7 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Search all jobs returned for each of the submitted jobs const foundJob = await GetJobs.getJob(REAL_SESSION, job.jobid); @@ -1145,8 +1133,7 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Search all jobs returned for each of the submitted jobs const foundJobs = await GetJobs.getJobsCommon(REAL_SESSION, {jobid: job.jobid}); @@ -1185,8 +1172,7 @@ describe("Get Jobs System Tests", () => { testEnvironment.resources.jobs.push(job); } - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Obtain the three jobs submitted const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, MONITOR_JOB_NAME + "*"); @@ -1243,8 +1229,7 @@ describe("Get Jobs System Tests", () => { testEnvironment.resources.jobs.push(job); } - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Obtain the three jobs submitted const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, TEST_JOB_NAME + "*"); @@ -1297,8 +1282,7 @@ describe("Get Jobs System Tests", () => { testEnvironment.resources.jobs.push(job); } - // Add a delay to ensure job is recognized - await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds + await wait(waitTime); // Waits for 2 seconds // Obtain all jobs for ***REMOVED*** const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, REAL_SESSION.ISession.user); From 8ccb8f4b44a91d47f469a651ad7a83c1c683242b Mon Sep 17 00:00:00 2001 From: ATorrise Date: Fri, 30 Aug 2024 09:59:58 -0400 Subject: [PATCH 36/65] addressing one of fernandos comments Signed-off-by: ATorrise --- .../__tests__/__system__/SubmitJobs.system.test.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts index ae48ed3611..78463754e0 100644 --- a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts @@ -212,13 +212,8 @@ describe("Submit Jobs - System Tests", () => { it("should return the job info of a submitted JCL string", async () => { const jobOrSpoolFiles = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", { jclSource: "stdin" }); - // Check if the returned value is an array of spool files or a single job object - if (Array.isArray(jobOrSpoolFiles)) { - throw new Error("Expected a single job object, but received spool files."); - } - // Now `jobOrSpoolFiles` is guaranteed to be of type `IJob` - const job: IJob = jobOrSpoolFiles; + const job: IJob = jobOrSpoolFiles as IJob; // Ensure jobid and jobname are defined before proceeding expect(job.jobid).toBeDefined(); @@ -275,13 +270,8 @@ describe("Submit Jobs - System Tests", () => { directory: "./" }); - // Check if the returned value is an array of spool files or a single job object - if (Array.isArray(jobOrSpoolFiles)) { - throw new Error("Expected a single job object, but received spool files."); - } - // Now `jobOrSpoolFiles` is guaranteed to be of type `IJob` - const job: IJob = jobOrSpoolFiles; + const job: IJob = jobOrSpoolFiles as IJob; // Ensure jobid and jobname and file are defined before proceeding expect(job.jobid).toBeDefined(); From 842ee6b998601b28b78c72162478ae4339533135 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Fri, 30 Aug 2024 10:20:28 -0400 Subject: [PATCH 37/65] timeout corrections Signed-off-by: ATorrise --- .../__system__/search/cli.zos-jobs.search.job.test.ts | 1 - .../zosjobs/__tests__/__system__/SubmitJobs.system.test.ts | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index acd5bc684c..c6aadab59e 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -16,7 +16,6 @@ import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/prope import { wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; import { AbstractSession } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; -import { promisify } from 'util'; // Test Environment populated in the beforeAll(); let testEnvironment: ITestEnvironment; diff --git a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts index 78463754e0..a9e071d285 100644 --- a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts @@ -14,9 +14,9 @@ import { GetJobs, IJob, ISpoolFile, SubmitJobs } from "../../src"; import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { wait } from "../../../../__tests__/__src__/TestUtils"; import { existsSync } from "fs"; import { ZosJobsMessages } from "../../src/JobsMessages"; -import { promisify } from 'util'; let testEnvironment: ITestEnvironment; let systemProps: ITestPropertiesSchema; @@ -28,11 +28,8 @@ let iefbr14JCL: string; const badJCL = "thIsIs BaDJCL!"; const badDataSet = "DOES.NOT.EXIST(FAKE)"; const badUSSFile = "/tmp/does/not/exist/fake.txt"; - const LONG_TIMEOUT = 100000; // 100 second timeout - jobs could take a while to complete due to system load -const wait = promisify(setTimeout); - describe("Submit Jobs - System Tests", () => { beforeAll(async () => { From 9e8f22ec5635bbca5e6df3c33aeb4b28b118c328 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Fri, 30 Aug 2024 10:59:44 -0400 Subject: [PATCH 38/65] removing change to a unit test Signed-off-by: ATorrise --- .../__unit__/methods/search/Search.unit.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/zosfiles/__tests__/__unit__/methods/search/Search.unit.test.ts b/packages/zosfiles/__tests__/__unit__/methods/search/Search.unit.test.ts index 045e661ab7..7b1f6a7c99 100644 --- a/packages/zosfiles/__tests__/__unit__/methods/search/Search.unit.test.ts +++ b/packages/zosfiles/__tests__/__unit__/methods/search/Search.unit.test.ts @@ -11,7 +11,6 @@ import { ImperativeError, Session, TaskStage } from "@zowe/imperative"; import { Get, ISearchItem, ISearchOptions, IZosFilesResponse, List, Search } from "../../../../src"; -import { wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; describe("Search", () => { @@ -119,6 +118,7 @@ describe("Search", () => { const listDataSetsMatchingPatternSpy = jest.spyOn(List, "dataSetsMatchingPattern"); const listAllMembersSpy = jest.spyOn(List, "allMembers"); + function delay(ms: number) { jest.advanceTimersByTime(ms); } function regenerateMockImplementations() { searchOnMainframeSpy.mockImplementation(async (session, searchOptions, searchItems: ISearchItem[]) => { if ((Search as any).timerExpired != true) { @@ -575,7 +575,7 @@ describe("Search", () => { it("Should handle timing out 1", async () => { searchLocalSpy.mockImplementation(async (session, searchOptions, searchItems: ISearchItem[]) => { - await wait(waitTime); //wait 2 seconds + delay(1100); if ((Search as any).timerExpired != true) { const searchItemArray: ISearchItem[] = []; for (const searchItem of searchItems) { @@ -622,7 +622,7 @@ describe("Search", () => { it("Should handle timing out 2", async () => { searchOnMainframeSpy.mockImplementation(async (session, searchOptions, searchItems: ISearchItem[]) => { - await wait(waitTime); //wait 2 seconds + delay(1100); if ((Search as any).timerExpired != true) { return { responses: searchItems, @@ -666,7 +666,7 @@ describe("Search", () => { it("Should handle timing out 3", async () => { listAllMembersSpy.mockImplementation(async (session, dsn, options) => { - await wait(waitTime); //wait 2 seconds + delay(1100); return { success: true, commandResponse: "", @@ -703,7 +703,7 @@ describe("Search", () => { it("Should handle timing out 4", async () => { listDataSetsMatchingPatternSpy.mockImplementation(async (session, patterns, options) => { - await wait(waitTime); //wait 2 seconds + delay(1100); return { success: true, commandResponse: "", @@ -1224,4 +1224,4 @@ describe("Search", () => { expect(response).toEqual({responses: [], failures: []}); }); }); -}); +}); \ No newline at end of file From 1c7a5b2a94bfb65d53691d6b827a8f6bc93f39c2 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Fri, 30 Aug 2024 11:17:09 -0400 Subject: [PATCH 39/65] changing system test to work with 'any' job name Signed-off-by: ATorrise --- .../search/cli.zos-jobs.search.job.test.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index c6aadab59e..188120f9af 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -43,11 +43,14 @@ describe("zos-jobs search job command", () => { IEFBR14_JOB = defaultSystem.zosjobs.iefbr14Member; ACCOUNT = defaultSystem.tso.account; - // TODO: fix this test to run with any job name - JOB_NAME = "IEFBR14T"; //REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + + const JOB_LENGTH = 5; // 5 letters from the user's id + const userIdPart = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase(); + JOB_NAME = `IEF${userIdPart}`; + NON_HELD_JOBCLASS = defaultSystem.zosjobs.jobclass; - SEARCH_STRING = "PGM=IEFBR14"; - REGEX_STRING = "IEFBR14|RC=0000"; + SEARCH_STRING = `PGM=${JOB_NAME}`; + REGEX_STRING = `${JOB_NAME}|RC=0000`; BAD_SEARCH_STRING = "bluhbluh"; }); @@ -79,7 +82,7 @@ describe("zos-jobs search job command", () => { expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); - expect(response.stdout.toString()).toContain("IEFBR14"); + expect(response.stdout.toString()).toContain(`${JOB_NAME}`); expect(response.stdout.toString()).toContain("RC=0000"); }); From 83faac94fe03cf619a7c53aa67b9e2db4b0d0cb3 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 4 Sep 2024 09:44:26 -0400 Subject: [PATCH 40/65] wiping testEnvironment.resources in cleanup Signed-off-by: ATorrise --- __tests__/__src__/environment/TestEnvironment.ts | 8 ++++++++ .../__tests__/__system__/DownloadJobs.system.test.ts | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index 39069d9c50..50c1cc6d4b 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -93,6 +93,14 @@ export class TestEnvironment extends BaseTestEnvironment { deleteDataset(session, dataset); } } + testEnvironment.resources = { + localFiles: [], + files: [], + jobs: [], + jobData: [], + datasets: [], + session: testEnvironment.resources.session //probably need to retain the session + }; } /** diff --git a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts index 69ab8b7f19..d7d457f27a 100644 --- a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts @@ -9,7 +9,7 @@ * */ -import { DeleteJobs, DownloadJobs, GetJobs, IJobFile, SubmitJobs } from "../../src"; +import { DeleteJobs, DownloadJobs, GetJobs, ICommonJobParms, IJobFile, SubmitJobs } from "../../src"; import { ImperativeError, IO, Session, TextUtils } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; @@ -78,7 +78,7 @@ describe("Download Jobs - System tests", () => { }); afterAll(async () => { - await DeleteJobs.deleteJob(REAL_SESSION, jobname, jobid); + testEnvironment.resources.jobData.push({ jobname: jobname, jobid: jobid } as ICommonJobParms); await TestEnvironment.cleanUp(testEnvironment); }); From 6c7064b6ca965f78cd0ab891bd06ce6b38761a7a Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 4 Sep 2024 10:51:15 -0400 Subject: [PATCH 41/65] changing the way the test works but need testing mini to be active and not IPLed to test Signed-off-by: ATorrise --- .../dtu/cli.dir.upload.dtu.system.test.ts | 41 ++----------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts index 9cd717e9d8..22deca6c0a 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts @@ -6,7 +6,6 @@ * SPDX-License-Identifier: EPL-2.0 * * Copyright Contributors to the Zowe Project. -* */ import { Imperative, Session } from "@zowe/imperative"; @@ -16,8 +15,7 @@ import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getTag, getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; -import { Get, ZosFilesConstants, ZosFilesUtils, Delete } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; +import { Get, ZosFilesUtils } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); @@ -44,6 +42,8 @@ describe("Upload directory to USS", () => { dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILES.UPLOAD`); dsname = dsname.replace(/\./g, ""); ussname = `${defaultSystem.unix.testdir}/${dsname}`; + TEST_ENVIRONMENT.resources.datasets.push(dsname); + TEST_ENVIRONMENT.resources.files.push(ussname); Imperative.console.info("Using ussDir:" + ussname); binaryFile = "bin_file.pax"; binaryFiles = "bin_file.pax,subdir_bin_file1.pax,subdir_bin_file2.pax.Z"; @@ -52,21 +52,6 @@ describe("Upload directory to USS", () => { }); afterAll(async () => { - // Clean up the USS directory - try { - const ussEndpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - await ZosmfRestClient.deleteExpectString(REAL_SESSION, ussEndpoint, [{"X-IBM-Option": "recursive"}]); - } catch (err) { - Imperative.console.info(`Error cleaning up USS directory: ${err}`); - } - - // Clean up the datasets - try { - await Delete.dataSet(REAL_SESSION, dsname); - } catch (err) { - Imperative.console.info(`Error cleaning up dataset: ${err}`); - } - await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); @@ -80,16 +65,10 @@ describe("Upload directory to USS", () => { defaultSys = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; Imperative.console.info("Using ussDir:" + ussname); + TEST_ENVIRONMENT_NO_PROF.resources.files.push(ussname); }); afterAll(async () => { - try { - const ussEndpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - await ZosmfRestClient.deleteExpectString(REAL_SESSION, ussEndpoint, [{"X-IBM-Option": "recursive"}]); - } catch (err) { - Imperative.console.info(`Error cleaning up USS directory: ${err}`); - } - await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); @@ -122,15 +101,6 @@ describe("Upload directory to USS", () => { describe("Success scenarios", () => { - afterEach(async () => { - try { - const ussEndpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - await ZosmfRestClient.deleteExpectString(REAL_SESSION, ussEndpoint, [{"X-IBM-Option": "recursive"}]); - } catch (err) { - Imperative.console.info(`Error cleaning up USS directory: ${err}`); - } - }); - it("should upload local directory to USS directory", async () => { const localDirName = path.join(__dirname, "__data__", "command_upload_dtu_dir/command_upload_dtu_subdir_ascii"); const shellScript = path.join(__dirname, "__scripts__", "command", "command_upload_dtu.sh"); @@ -384,9 +354,6 @@ describe("Upload directory to USS", () => { error = err; } expect(error).toBeDefined(); - - const ussResponse = await Get.USSFile(REAL_SESSION, ussname + "/uploaded_dir/uploaded_file"); - expect(ussResponse).toBeInstanceOf(Buffer); }); it("wild cards should work with * and mixed casing on tagging and ignore", async () => { From cefbff19d4ba943a0c20e423f021dd1b53d39354 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 4 Sep 2024 12:53:52 -0400 Subject: [PATCH 42/65] hopefully good to merge now Signed-off-by: ATorrise --- .../__src__/environment/TestEnvironment.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index 50c1cc6d4b..fcc16b049b 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -92,15 +92,18 @@ export class TestEnvironment extends BaseTestEnvironment { for (const dataset of testEnvironment.resources.datasets) { deleteDataset(session, dataset); } + testEnvironment.resources = { + localFiles: [], + files: [], + jobs: [], + jobData: [], + datasets: [], + session: null // initializing session as null + }; + + // Retaining session if exists + testEnvironment.resources.session = testEnvironment.resources.session || testEnvironment?.resources?.session || null; } - testEnvironment.resources = { - localFiles: [], - files: [], - jobs: [], - jobData: [], - datasets: [], - session: testEnvironment.resources.session //probably need to retain the session - }; } /** From 201ecc185d4bd31e0477231ea562e6cac4cf63c9 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 4 Sep 2024 16:00:17 -0400 Subject: [PATCH 43/65] fixin - initializing resources Signed-off-by: ATorrise --- .../__src__/environment/TestEnvironment.ts | 16 +++++++++------ .../dtu/cli.dir.upload.dtu.system.test.ts | 4 ++-- .../__system__/ModifyJobs.system.test.ts | 20 ++++++++----------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index fcc16b049b..e44b5d2b85 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -38,7 +38,7 @@ export class TestEnvironment extends BaseTestEnvironment { * @memberof TestEnvironment */ public static async setUp(params: ISetupEnvironmentParms): Promise> { - const result = await super.setUp(params); + const result: ITestEnvironment = await super.setUp(params); // Ensure correct path separator for windows or linux like systems. const separator = process.platform === "win32" ? ";" : ":"; @@ -47,7 +47,14 @@ export class TestEnvironment extends BaseTestEnvironment { nodePath.resolve(__dirname, "../../__resources__/application_instances"), process.env.PATH ].join(separator); - + result.resources = { + localFiles: [], + files: [], + jobs: [], + jobData: [], + datasets: [], + session: result.resources?.session || null + }; // Return the test environment including working directory that the tests should be using return result; } @@ -98,11 +105,8 @@ export class TestEnvironment extends BaseTestEnvironment { jobs: [], jobData: [], datasets: [], - session: null // initializing session as null + session: testEnvironment.resources.session }; - - // Retaining session if exists - testEnvironment.resources.session = testEnvironment.resources.session || testEnvironment?.resources?.session || null; } } diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts index 22deca6c0a..55ca43dfa9 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts @@ -6,6 +6,7 @@ * SPDX-License-Identifier: EPL-2.0 * * Copyright Contributors to the Zowe Project. +* */ import { Imperative, Session } from "@zowe/imperative"; @@ -18,7 +19,6 @@ import { getTag, getUniqueDatasetName, runCliScript } from "../../../../../../.. import { Get, ZosFilesUtils } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; -// Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; let TEST_ENVIRONMENT_NO_PROF: ITestEnvironment; let defaultSystem: ITestPropertiesSchema; @@ -36,9 +36,9 @@ describe("Upload directory to USS", () => { tempProfileTypes: ["zosmf"], testName: "zos_files_upload_directory_to_uss_with_profile" }); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); defaultSystem = TEST_ENVIRONMENT.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILES.UPLOAD`); dsname = dsname.replace(/\./g, ""); ussname = `${defaultSystem.unix.testdir}/${dsname}`; diff --git a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts index b78e547a47..f71760fe3b 100644 --- a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts @@ -10,7 +10,7 @@ */ import { ImperativeError, Session } from "@zowe/imperative"; -import { IJob, SubmitJobs, ModifyJobs, CancelJobs } from "../../src"; +import { IJob, SubmitJobs, ModifyJobs } from "../../src"; import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; @@ -43,7 +43,8 @@ describe("Modify Jobs - System Tests", () => { }); afterAll(async () => { - await CancelJobs.cancelJob(REAL_SESSION, iefbr14Job.jobname, iefbr14Job.jobid); + // Add the job to resources for automatic cleanup + testEnvironment.resources.jobData.push({jobname: iefbr14Job.jobname, jobid: iefbr14Job.jobid}); await TestEnvironment.cleanUp(testEnvironment); }); @@ -56,7 +57,6 @@ describe("Modify Jobs - System Tests", () => { ); expect(job.jobid).toMatch(iefbr14Job.jobid); expect(job.message).toContain("Request was successful"); - testEnvironment.resources.jobs.push(job); }); it("should return a success message once hold has been added to job", async () => { @@ -67,7 +67,6 @@ describe("Modify Jobs - System Tests", () => { ); expect(job.jobid).toMatch(iefbr14Job.jobid); expect(job.message).toContain("Request was successful"); - testEnvironment.resources.jobs.push(job); }); it("should return a success message once job has been released", async () => { @@ -78,12 +77,10 @@ describe("Modify Jobs - System Tests", () => { ); expect(job.jobid).toMatch(iefbr14Job.jobid); expect(job.message).toContain("Request was successful"); - testEnvironment.resources.jobs.push(job); }); }); describe("Negative tests", () => { - it("should surface an error from z/OSMF when calling an unknown jobid", async () => { let err: any; try { @@ -111,15 +108,17 @@ describe("Modify Jobs - System Tests - Encoded", () => { REAL_SESSION = await TestEnvironment.createSession(); systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; - jobclass = testEnvironment.systemTestProperties.zosjobs.jobclass; - modifiedJobClass = testEnvironment.systemTestProperties.zosjobs.modifiedJobclass; + jobclass = systemProps.zosjobs.jobclass; + modifiedJobClass = systemProps.zosjobs.modifiedJobclass; + const maxStepNum = 6; const sleepJCL = JobTestsUtils.getSleepJCL(REAL_SESSION.ISession.user, account, systemProps.zosjobs.jobclass, maxStepNum, true); sleepJCLJob = await SubmitJobs.submitJcl(REAL_SESSION, sleepJCL); }); afterAll(async () => { - await CancelJobs.cancelJob(REAL_SESSION, iefbr14Job.jobname, iefbr14Job.jobid); + // Add the sleep job to resources for automatic cleanup + testEnvironment.resources.jobData.push({jobname: sleepJCLJob.jobname, jobid: sleepJCLJob.jobid}); await TestEnvironment.cleanUp(testEnvironment); }); @@ -132,7 +131,6 @@ describe("Modify Jobs - System Tests - Encoded", () => { ); expect(job.jobid).toMatch(sleepJCLJob.jobid); expect(job.message).toContain("Request was successful"); - testEnvironment.resources.jobs.push(job); }); it("should return a success message once hold has been added to job", async () => { @@ -143,7 +141,6 @@ describe("Modify Jobs - System Tests - Encoded", () => { ); expect(job.jobid).toMatch(sleepJCLJob.jobid); expect(job.message).toContain("Request was successful"); - testEnvironment.resources.jobs.push(job); }); it("should return a success message once job has been released", async () => { @@ -154,7 +151,6 @@ describe("Modify Jobs - System Tests - Encoded", () => { ); expect(job.jobid).toMatch(sleepJCLJob.jobid); expect(job.message).toContain("Request was successful"); - testEnvironment.resources.jobs.push(job); }); }); }); \ No newline at end of file From 4a37668ed0212fc6c47191f71737f7bb769c786a Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 19 Sep 2024 12:44:51 -0400 Subject: [PATCH 44/65] addressing timothy's requests Signed-off-by: ATorrise --- .../src/environment/TestEnvironment.ts | 23 ++--- __tests__/__src__/TestUtils.ts | 86 ++++--------------- .../__src__/environment/TestEnvironment.ts | 41 +-------- 3 files changed, 33 insertions(+), 117 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index a6fd5cb944..fae3cbf13f 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -14,7 +14,7 @@ import * as nodePath from "path"; import * as yaml from "js-yaml"; import { v4 as uuidv4 } from "uuid"; import { AbstractSession, ImperativeError, ImperativeExpect, - IO, Logger, LoggingConfigurer, ProfileInfo, TextUtils } from "@zowe/imperative"; + IO, Logger, LoggingConfigurer, ProfileInfo, Session, TextUtils } from "@zowe/imperative"; import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; @@ -90,16 +90,17 @@ export class TestEnvironment { * @throws Will throw an error if reading profiles or creating the session fails * @memberof TestEnvironment */ - public static async createSession(): Promise { - // Load connection info from default z/OSMF profile - const profInfo = new ProfileInfo("zowe"); - await profInfo.readProfilesFromDisk(); - const zosmfProfAttrs = profInfo.getDefaultProfile("zosmf"); - if (!zosmfProfAttrs) { - throw new Error("Default z/OSMF profile not found."); - } - const zosmfMergedArgs = profInfo.mergeArgsForProfile(zosmfProfAttrs, { getSecureVals: true }); - return ProfileInfo.createSession(zosmfMergedArgs.knownArgs); + public static async createSession(testEnvironment: any): Promise { + const SYSTEM_PROPS = testEnvironment.systemTestProperties.zosmf; + return new Session({ + user: SYSTEM_PROPS.user, + password: SYSTEM_PROPS.password, + hostname: SYSTEM_PROPS.host, + port: SYSTEM_PROPS.port, + type: "basic", + rejectUnauthorized: SYSTEM_PROPS.rejectUnauthorized, + basePath: SYSTEM_PROPS.basePath + }); } /** diff --git a/__tests__/__src__/TestUtils.ts b/__tests__/__src__/TestUtils.ts index 157ae9d5e1..56724eebbf 100644 --- a/__tests__/__src__/TestUtils.ts +++ b/__tests__/__src__/TestUtils.ts @@ -52,40 +52,45 @@ export function deleteLocalDirectories(directories: string[]): void { } }); } + /** - * Delete a uss file from the mainframe - * @param {AbstractSession} session - z/OSMF connection info - * @param {string} fileName - The name of the USS file + * Deletes a USS file from the mainframe + * @param {AbstractSession} session - The session object + * @param {string} fileName - The name of the file to delete + * @returns {Promise} A promise that resolves when the file is deleted */ -export function deleteFiles(session: AbstractSession, fileName: string): void { - Delete.ussFile(session, fileName); +export async function deleteFiles(session: AbstractSession, fileName: string): Promise { + await Delete.ussFile(session, fileName); } /** - * Delete a dataset from the mainframe - * @param {AbstractSession} session - z/OSMF connection info - * @param {string} datasetName - The name of the dataset + * Deletes a data set from the mainframe + * @param {AbstractSession} session - The session object + * @param {string} dataSetName - The name of the data set to delete. + * @returns {Promise} A promise that resolves when the data set is deleted */ -export function deleteDataset(session: AbstractSession, dataSetName: string): void { - Delete.dataSet(session, dataSetName); +export async function deleteDataset(session: AbstractSession, dataSetName: string): Promise { + await Delete.dataSet(session, dataSetName); } /** * Delete a job from the mainframe using Zowe SDKs - IJob * @param {AbstractSession} session - z/OSMF connection info * @param {IJob} job - the job that you want to delete + * @returns {Promise} A promise that resolves when the job is deleted. */ -export function deleteJob(session: AbstractSession, job: IJob): void { - DeleteJobs.deleteJobForJob(session, job); +export async function deleteJob(session: AbstractSession, job: IJob): Promise { + await DeleteJobs.deleteJobForJob(session, job); } /** * Delete a job from the mainframe using Zowe SDKs - jobid, jobname * @param {AbstractSession} session - z/OSMF connection info * @param {params} ICommonJobParms - constains jobname and jobid for job to delete + * @returns {Promise} A promise that resolves when the job is deleted. */ -export function deleteJobCommon(session: AbstractSession, params: ICommonJobParms): void { - DeleteJobs.deleteJobCommon(session, params as IDeleteJobParms); +export async function deleteJobCommon(session: AbstractSession, params: ICommonJobParms): Promise { + await DeleteJobs.deleteJobCommon(session, params as IDeleteJobParms); } /** @@ -189,57 +194,4 @@ export const waitTime = 2000; //wait 2 seconds */ export function inspect(obj: any) : string { return JSON.stringify(Object.keys(obj).reduce((newObj, key) => ({...newObj, [key]: obj[key]}), {})); -} - -/** - * Execute a CLI script - * @export - * @param scriptPath - the path to the script - * @param testEnvironment - the test environment with env - * @param [args=[]] - set of script args (optional) - * @returns node.js details about the results of - * executing the script, including exit code and output - */ -export function runCliScript(scriptPath: string, testEnvironment: ITestEnvironment, args: any[] = []): SpawnSyncReturns { - if (fs.existsSync(scriptPath)) { - - // We force the color off to prevent any oddities in the snapshots or expected values - // Color can vary OS/terminal - const childEnv = JSON.parse(JSON.stringify(process.env)); - childEnv.FORCE_COLOR = "0"; - for (const key of Object.keys(testEnvironment.env)) { - // copy the values from the env - childEnv[key] = testEnvironment.env[key]; - } - - if (process.platform === "win32") { - // Execute the command synchronously - const response = spawnSync("sh", [scriptPath].concat(args), { - cwd: testEnvironment.workingDir, - encoding: "buffer", - env: childEnv - }); - if ((response.error as ExecFileException)?.code === "ENOENT") { - throw new Error(`"sh" is missing from your PATH. Check that Git Bash is installed with the option to ` + - `"Use Git and Unix Tools from Windows Command Prompt".`); - } - return response; - } - - // Check to see if the file is executable - try { - fs.accessSync(scriptPath, fs.constants.X_OK); - } catch { - fs.chmodSync(scriptPath, "755"); - } - return spawnSync(scriptPath, args, { - cwd: testEnvironment.workingDir, - env: childEnv, - encoding: "buffer" - }); - - } else { - throw new Error(`The script file ${scriptPath} doesn't exist`); - - } } \ No newline at end of file diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index e44b5d2b85..614b058e91 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -69,45 +69,8 @@ export class TestEnvironment extends BaseTestEnvironment { * @memberof TestEnvironment */ public static async cleanUp(testEnvironment: ITestEnvironment) { - if (testEnvironment.tempProfiles != null) { - await TempTestProfiles.deleteProfiles(testEnvironment); - } - if (testEnvironment.pluginInstalled) { - const pluginDir = testEnvironment.workingDir + "/plugins"; - require("rimraf").sync(pluginDir); - } - - // Check if session exists before deleting resources - if (testEnvironment?.resources?.session) { - const session = testEnvironment.resources.session; - for (const file of testEnvironment.resources.localFiles) { - deleteLocalFile(file); - } - for (const file of testEnvironment.resources.files) { - deleteFiles(session, file); - } - for (const job of testEnvironment.resources.jobs) { - deleteJob(session, job); - } - for (const jobData of testEnvironment.resources.jobData) { - if (jobData.jobname && jobData.jobid) { - deleteJobCommon(session, jobData); - } else { - Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); - } - } - for (const dataset of testEnvironment.resources.datasets) { - deleteDataset(session, dataset); - } - testEnvironment.resources = { - localFiles: [], - files: [], - jobs: [], - jobData: [], - datasets: [], - session: testEnvironment.resources.session - }; - } + // Invoke the superclass's cleanup method + await super.cleanUp(testEnvironment); } /** From 2d1c9be60df1749c5c54c1cea5007f3765d28124 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 19 Sep 2024 14:57:50 -0400 Subject: [PATCH 45/65] fixing runCliScrip import and TestEnvironment.cleanup Signed-off-by: ATorrise --- .../src/environment/TestEnvironment.ts | 2 +- .../doc/response/ITestEnvironment.ts | 8 ++-- .../__src__/environment/TestEnvironment.ts | 38 +++++++++++++++++-- ...rkflows.list.active.details.system.test.ts | 3 +- .../compare/ds/Compare.ds.system.test.ts | 3 +- .../copy/ds/cli.files.copy.ds.system.test.ts | 2 +- .../dsclp/cli.files.copy.dsclp.system.test.ts | 3 +- ...files.create.dataset.binary.system.test.ts | 2 +- .../cli.files.create.dataset.c.system.test.ts | 2 +- ...iles.create.dataset.classic.system.test.ts | 2 +- .../ds/cli.files.create.ds.system.test.ts | 2 +- ...li.files.create.dataset.pds.system.test.ts | 2 +- ...cli.files.create.dataset.ps.system.test.ts | 2 +- .../cli.files.create.uss.dir.system.test.ts | 2 +- .../cli.files.create.uss.file.system.test.ts | 2 +- ...i.files.create.dataset.vsam.system.test.ts | 2 +- .../zfs/cli.files.create.zfs.system.test.ts | 2 +- .../ds/cli.files.delete.ds.system.test.ts | 2 +- .../mds/cli.files.delete.mds.system.test.ts | 2 +- .../cli.files.delete.directory.system.test.ts | 2 +- .../uss/cli.files.delete.file.system.test.ts | 2 +- .../vsam/cli.files.delete.vsam.system.test.ts | 3 +- .../zfs/cli.files.delete.zfs.system.test.ts | 4 +- .../am/cli.files.download.am.system.test.ts | 3 +- .../ds/cli.files.download.ds.system.test.ts | 3 +- .../dsm/cli.files.download.dsm.system.test.ts | 3 +- .../uss/cli.files.download.uss.system.test.ts | 3 +- .../cli.files.download.ussdir.system.test.ts | 3 +- .../__system__/edit/ds/Edit.ds.system.test.ts | 3 +- .../edit/uss/Edit.uss.system.test.ts | 3 +- .../ds/cli.files.HMigrate.ds.system.test.ts | 2 +- .../ds/cli.files.HRecall.ds.system.test.ts | 2 +- .../cli.files.invoke.amsFile.system.test.ts | 3 +- ....files.invoke.amsStatements.system.test.ts | 3 +- .../list/am/cli.files.list.am.system.test.ts | 3 +- .../list/ds/cli.files.list.ds.system.test.ts | 3 +- .../list/fs/cli.files.list.fs.system.test.ts | 3 +- .../uss/cli.files.list.uss.system.test.ts | 2 +- .../fs/cli.files.mount.fs.system.test.ts | 3 +- .../ds/cli.files.rename.ds.system.test.ts | 3 +- .../dsm/cli.files.rename.dsm.system.test.ts | 3 +- .../ds/cli.files.search.ds.system.test.ts | 3 +- .../dtp/cli.files.upload.dtp.system.test.ts | 3 +- .../dtu/cli.dir.upload.dtu.system.test.ts | 3 +- .../ftds/cli.files.upload.ftds.system.test.ts | 3 +- .../ftu/cli.files.upload.ftu.system.test.ts | 2 +- .../stds/cli.files.upload.stds.system.test.ts | 3 +- .../__system__/view/ds/View.ds.system.test.ts | 3 +- .../view/uss/View.uss.system.test.ts | 3 +- .../cli.zos-jobs.cancel.job.system.test.ts | 2 +- .../cli.zos-jobs.delete.job.system.test.ts | 2 +- ...li.zos-jobs.delete.old-jobs.system.test.ts | 2 +- ...li.zos-jobs.download.output.system.test.ts | 2 +- .../cli.zos-jobs.list.jobs.system.test.ts | 2 +- ...s.list.spool-files-by-jobid.system.test.ts | 2 +- .../cli.zos-jobs.modify.job.system.test.ts | 2 +- .../search/cli.zos-jobs.search.job.test.ts | 2 +- ...jobs.view.all-spool-content.system.test.ts | 2 +- ...bs.view.job-status-by-jobid.system.test.ts | 2 +- 59 files changed, 124 insertions(+), 64 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index fae3cbf13f..c82eb1af5d 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -14,7 +14,7 @@ import * as nodePath from "path"; import * as yaml from "js-yaml"; import { v4 as uuidv4 } from "uuid"; import { AbstractSession, ImperativeError, ImperativeExpect, - IO, Logger, LoggingConfigurer, ProfileInfo, Session, TextUtils } from "@zowe/imperative"; + IO, Logger, LoggingConfigurer, Session, TextUtils } from "@zowe/imperative"; import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts index 202e12231b..e707069e8d 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts @@ -14,7 +14,7 @@ * @export * @interface ITestEnvironment */ -export interface ITestEnvironment { +export interface ITestEnvironment { /** * The working directory for your test environment. It is a unique (uuid) area where your tests can create * their home folders (for imperative, etc.) and you can use the area as scratch for any files, etc. that @@ -29,10 +29,10 @@ export interface ITestEnvironment { * in the case that no system test properties were configured or could be loaded. * * Not present if skipProperties is specified on ISetupEnvironmentParms - * @type {ITestPropertiesSchema} + * @type {TestPropertiesSchema} * @memberof ITestEnvironment */ - systemTestProperties: ITestPropertiesSchema; + systemTestProperties: TestPropertiesSchema; /** * Set of environmental variables (such as profile/logging home directory) @@ -55,4 +55,4 @@ export interface ITestEnvironment { * Was the plugin installed in the working directory */ pluginInstalled?: boolean; -} +} \ No newline at end of file diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index 614b058e91..6112887e36 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -14,10 +14,10 @@ import * as nodePath from "path"; import { AbstractSession, Imperative, Session } from "@zowe/imperative"; import { ITestPropertiesSchema } from "../properties/ITestPropertiesSchema"; -import { ISetupEnvironmentParms, TestEnvironment as BaseTestEnvironment, TempTestProfiles } from "../../__packages__/cli-test-utils"; +import { ISetupEnvironmentParms, TestEnvironment as BaseTestEnvironment } from "../../__packages__/cli-test-utils"; import { ITestEnvironment } from "./ITestEnvironment"; -import { deleteLocalFile, deleteFiles, deleteJob, deleteJobCommon, deleteDataset } from "../TestUtils"; import { SshSession } from "../../../packages/zosuss/src/SshSession"; +import { deleteLocalFile, deleteFiles, deleteJob, deleteJobCommon, deleteDataset } from "../TestUtils"; /** * Use the utility methods here to setup the test environment for running APIs @@ -69,8 +69,40 @@ export class TestEnvironment extends BaseTestEnvironment { * @memberof TestEnvironment */ public static async cleanUp(testEnvironment: ITestEnvironment) { - // Invoke the superclass's cleanup method + // Delete profiles and plugindir await super.cleanUp(testEnvironment); + + // Deleting resources (if they exist) + if (testEnvironment?.resources?.session) { + const session = testEnvironment.resources.session; + for (const file of testEnvironment.resources.localFiles) { + deleteLocalFile(file); + } + for (const file of testEnvironment.resources.files) { + deleteFiles(session, file); + } + for (const job of testEnvironment.resources.jobs) { + deleteJob(session, job); + } + for (const jobData of testEnvironment.resources.jobData) { + if (jobData.jobname && jobData.jobid) { + deleteJobCommon(session, jobData); + } else { + Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); + } + } + for (const dataset of testEnvironment.resources.datasets) { + deleteDataset(session, dataset); + } + testEnvironment.resources = { + localFiles: [], + files: [], + jobs: [], + jobData: [], + datasets: [], + session: testEnvironment.resources.session + }; + } } /** diff --git a/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts b/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts index ce32b77968..312134ab74 100644 --- a/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts @@ -14,10 +14,11 @@ import { Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, wait, waitTime, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { CreateWorkflow, DeleteWorkflow } from "@zowe/zos-workflows-for-zowe-sdk"; import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/compare/ds/Compare.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/compare/ds/Compare.ds.system.test.ts index 98ae988a27..03394dea43 100644 --- a/packages/cli/__tests__/zosfiles/__system__/compare/ds/Compare.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/compare/ds/Compare.ds.system.test.ts @@ -15,7 +15,8 @@ import * as path from "path"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/copy/ds/cli.files.copy.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/copy/ds/cli.files.copy.ds.system.test.ts index f3e9ec56ef..402ae9571c 100644 --- a/packages/cli/__tests__/zosfiles/__system__/copy/ds/cli.files.copy.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/copy/ds/cli.files.copy.ds.system.test.ts @@ -13,9 +13,9 @@ import { Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create, CreateDataSetTypeEnum, Upload, Get } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/copy/dsclp/cli.files.copy.dsclp.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/copy/dsclp/cli.files.copy.dsclp.system.test.ts index 575e4e5273..07967beefc 100644 --- a/packages/cli/__tests__/zosfiles/__system__/copy/dsclp/cli.files.copy.dsclp.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/copy/dsclp/cli.files.copy.dsclp.system.test.ts @@ -13,9 +13,10 @@ import { Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create, ICreateDataSetOptions, CreateDataSetTypeEnum, Upload, Get } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; +import { runCliScript } from "@zowe/cli-test-utils"; +import { getRandomBytes } from "../../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts index 37d09672da..14fa3b10e6 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/binaryPds/cli.files.create.dataset.binary.system.test.ts @@ -13,9 +13,9 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts index ecacfa6b9d..051aee635c 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/cPds/cli.files.create.dataset.c.system.test.ts @@ -13,9 +13,9 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts index 9e1588f7ea..8834fd3be8 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/classicPds/cli.files.create.dataset.classic.system.test.ts @@ -13,9 +13,9 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts index 31e31f0be2..5f532ced13 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/ds/cli.files.create.ds.system.test.ts @@ -13,9 +13,9 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts index 9d504684a1..3ceea68fd3 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/pds/cli.files.create.dataset.pds.system.test.ts @@ -13,9 +13,9 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { stripNewLines, wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts index 6dacff6d66..03292e6a16 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/ps/cli.files.create.dataset.ps.system.test.ts @@ -13,9 +13,9 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { stripNewLines, wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/ussDir/cli.files.create.uss.dir.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/ussDir/cli.files.create.uss.dir.system.test.ts index 07d6c5f48c..52aa7d6789 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/ussDir/cli.files.create.uss.dir.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/ussDir/cli.files.create.uss.dir.system.test.ts @@ -13,8 +13,8 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/ussFile/cli.files.create.uss.file.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/ussFile/cli.files.create.uss.file.system.test.ts index 048a78c796..a20b58bac1 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/ussFile/cli.files.create.uss.file.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/ussFile/cli.files.create.uss.file.system.test.ts @@ -13,8 +13,8 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/vsam/cli.files.create.dataset.vsam.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/vsam/cli.files.create.dataset.vsam.system.test.ts index 543bc5e7b6..f4780a1079 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/vsam/cli.files.create.dataset.vsam.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/vsam/cli.files.create.dataset.vsam.system.test.ts @@ -13,9 +13,9 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, IDeleteVsamOptions } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/create/zfs/cli.files.create.zfs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/create/zfs/cli.files.create.zfs.system.test.ts index d089b9b793..33095b9af8 100644 --- a/packages/cli/__tests__/zosfiles/__system__/create/zfs/cli.files.create.zfs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/create/zfs/cli.files.create.zfs.system.test.ts @@ -13,9 +13,9 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/ds/cli.files.delete.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/ds/cli.files.delete.ds.system.test.ts index cc7e89bdcf..19a5dd259b 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/ds/cli.files.delete.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/ds/cli.files.delete.ds.system.test.ts @@ -13,7 +13,7 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/mds/cli.files.delete.mds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/mds/cli.files.delete.mds.system.test.ts index f45694a04b..319c2eaa85 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/mds/cli.files.delete.mds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/mds/cli.files.delete.mds.system.test.ts @@ -12,7 +12,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; import { join } from "path"; import { Session, Imperative } from "@zowe/imperative"; import { inspect } from "util"; diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.directory.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.directory.system.test.ts index 8f785e240e..e002720dad 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.directory.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.directory.system.test.ts @@ -15,7 +15,7 @@ import { inspect } from "util"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.file.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.file.system.test.ts index 7e9b628b97..7b01434797 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.file.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/uss/cli.files.delete.file.system.test.ts @@ -15,7 +15,7 @@ import { inspect } from "util"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/vsam/cli.files.delete.vsam.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/vsam/cli.files.delete.vsam.system.test.ts index da31972173..b8207771b7 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/vsam/cli.files.delete.vsam.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/vsam/cli.files.delete.vsam.system.test.ts @@ -13,7 +13,8 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, stripNewLines, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/delete/zfs/cli.files.delete.zfs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/delete/zfs/cli.files.delete.zfs.system.test.ts index 4fddb0d5f1..a8df1eed3e 100644 --- a/packages/cli/__tests__/zosfiles/__system__/delete/zfs/cli.files.delete.zfs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/delete/zfs/cli.files.delete.zfs.system.test.ts @@ -13,7 +13,9 @@ import { Session } from "@zowe/imperative"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, stripNewLines, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; + const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/download/am/cli.files.download.am.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/am/cli.files.download.am.system.test.ts index c64ce2c2ca..6ea4e5eccb 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/am/cli.files.download.am.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/am/cli.files.download.am.system.test.ts @@ -14,8 +14,9 @@ import * as path from "path"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/download/ds/cli.files.download.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/ds/cli.files.download.ds.system.test.ts index 9c127e871c..ee9152a0f9 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/ds/cli.files.download.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/ds/cli.files.download.ds.system.test.ts @@ -14,8 +14,9 @@ import * as path from "path"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { getRandomBytes, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/download/dsm/cli.files.download.dsm.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/dsm/cli.files.download.dsm.system.test.ts index 34188022e2..9c6f1b1963 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/dsm/cli.files.download.dsm.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/dsm/cli.files.download.dsm.system.test.ts @@ -14,8 +14,9 @@ import * as path from "path"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts index 46990e42f4..4b266bc962 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts @@ -14,9 +14,10 @@ import * as path from "path"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/download/ussdir/cli.files.download.ussdir.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/ussdir/cli.files.download.ussdir.system.test.ts index 65493e5499..10ae9227dd 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/ussdir/cli.files.download.ussdir.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/ussdir/cli.files.download.ussdir.system.test.ts @@ -15,8 +15,9 @@ import * as fs from "fs"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/edit/ds/Edit.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/edit/ds/Edit.ds.system.test.ts index a3c4e2c866..6fd09a4870 100644 --- a/packages/cli/__tests__/zosfiles/__system__/edit/ds/Edit.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/edit/ds/Edit.ds.system.test.ts @@ -14,8 +14,9 @@ import * as path from "path"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/edit/uss/Edit.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/edit/uss/Edit.uss.system.test.ts index 2b5e446e45..4669ecf402 100644 --- a/packages/cli/__tests__/zosfiles/__system__/edit/uss/Edit.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/edit/uss/Edit.uss.system.test.ts @@ -15,8 +15,9 @@ import * as path from "path"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/hMigrate/ds/cli.files.HMigrate.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/hMigrate/ds/cli.files.HMigrate.ds.system.test.ts index af21677069..ad7d12503f 100644 --- a/packages/cli/__tests__/zosfiles/__system__/hMigrate/ds/cli.files.HMigrate.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/hMigrate/ds/cli.files.HMigrate.ds.system.test.ts @@ -12,7 +12,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; import { join } from "path"; import { Session, Imperative } from "@zowe/imperative"; import { List, Delete, Create, CreateDataSetTypeEnum, IListOptions, IMigrateOptions } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/hRecall/ds/cli.files.HRecall.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/hRecall/ds/cli.files.HRecall.ds.system.test.ts index 4249ce7d85..d3ce7cfc06 100644 --- a/packages/cli/__tests__/zosfiles/__system__/hRecall/ds/cli.files.HRecall.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/hRecall/ds/cli.files.HRecall.ds.system.test.ts @@ -12,7 +12,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript} from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; import { join } from "path"; import { Session, Imperative } from "@zowe/imperative"; import { List, Delete, Create, CreateDataSetTypeEnum, IListOptions, IRecallOptions, HMigrate } from "@zowe/zos-files-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts index 8e07150396..2db9b03e64 100644 --- a/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts @@ -14,8 +14,9 @@ import { Session, TextUtils } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript, stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; import { ZosFilesMessages } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/invoke/amsStatements/cli.files.invoke.amsStatements.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/invoke/amsStatements/cli.files.invoke.amsStatements.system.test.ts index 0a098d5c8d..3ff350298f 100644 --- a/packages/cli/__tests__/zosfiles/__system__/invoke/amsStatements/cli.files.invoke.amsStatements.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/invoke/amsStatements/cli.files.invoke.amsStatements.system.test.ts @@ -13,8 +13,9 @@ import { Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript, stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; +import { stripNewLines } from "../../../../../../../__tests__/__src__/TestUtils"; import { ZosFilesMessages } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/list/am/cli.files.list.am.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/list/am/cli.files.list.am.system.test.ts index 825ae517d0..a0f5cb4496 100644 --- a/packages/cli/__tests__/zosfiles/__system__/list/am/cli.files.list.am.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/list/am/cli.files.list.am.system.test.ts @@ -14,8 +14,9 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Upload, Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/list/ds/cli.files.list.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/list/ds/cli.files.list.ds.system.test.ts index 7b32a86d6e..b3755750a5 100644 --- a/packages/cli/__tests__/zosfiles/__system__/list/ds/cli.files.list.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/list/ds/cli.files.list.ds.system.test.ts @@ -14,8 +14,9 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/list/fs/cli.files.list.fs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/list/fs/cli.files.list.fs.system.test.ts index 8a1e5e80b5..37bac544c6 100644 --- a/packages/cli/__tests__/zosfiles/__system__/list/fs/cli.files.list.fs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/list/fs/cli.files.list.fs.system.test.ts @@ -14,7 +14,8 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/list/uss/cli.files.list.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/list/uss/cli.files.list.uss.system.test.ts index 354b444f6d..0220397b41 100644 --- a/packages/cli/__tests__/zosfiles/__system__/list/uss/cli.files.list.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/list/uss/cli.files.list.uss.system.test.ts @@ -15,7 +15,7 @@ import { inspect } from "util"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; import { Delete, Create } from "@zowe/zos-files-for-zowe-sdk"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts index a1ce86758b..93f74afb60 100644 --- a/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts @@ -14,7 +14,8 @@ import { Imperative, Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; diff --git a/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts index 77078145fa..f6b764eae2 100644 --- a/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/rename/ds/cli.files.rename.ds.system.test.ts @@ -13,9 +13,10 @@ import { Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { wait, waitTime, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create, CreateDataSetTypeEnum, Upload, Get } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts index 7111eac25b..2996df596e 100644 --- a/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/rename/dsm/cli.files.rename.dsm.system.test.ts @@ -13,9 +13,10 @@ import { Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { wait, waitTime, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { Delete, Create, CreateDataSetTypeEnum, Upload, Get } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/search/ds/cli.files.search.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/search/ds/cli.files.search.ds.system.test.ts index 7896cb2759..4254ed3098 100644 --- a/packages/cli/__tests__/zosfiles/__system__/search/ds/cli.files.search.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/search/ds/cli.files.search.ds.system.test.ts @@ -14,8 +14,9 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtp/cli.files.upload.dtp.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtp/cli.files.upload.dtp.system.test.ts index a5e273a8c1..9c98337b4e 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtp/cli.files.upload.dtp.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtp/cli.files.upload.dtp.system.test.ts @@ -14,8 +14,9 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, ZosFilesMessages } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts index 55ca43dfa9..d17029e146 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts @@ -15,8 +15,9 @@ import * as fs from "fs"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getTag, getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getTag, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Get, ZosFilesUtils } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts index 0dfd942920..2e05585dea 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts @@ -14,8 +14,9 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, ICreateDataSetOptions, Delete, Get } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts index 1e56a21194..e6ad2f98fd 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts @@ -14,7 +14,7 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; import { Get, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts index ee05186200..d0d5787cf7 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts @@ -14,8 +14,9 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Get } from "@zowe/zos-files-for-zowe-sdk"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/view/ds/View.ds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/view/ds/View.ds.system.test.ts index be05415a62..190b96f248 100644 --- a/packages/cli/__tests__/zosfiles/__system__/view/ds/View.ds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/view/ds/View.ds.system.test.ts @@ -15,7 +15,8 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; diff --git a/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts index 9d1bb668bb..a35e0b5ce3 100644 --- a/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts @@ -16,7 +16,8 @@ import { ZosFilesConstants, ZosmfRestClient, ZosmfHeaders, Upload } from "@zowe/ import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, runCliScript } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index af10ae3903..6e2ee76b16 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { JobTestsUtils } from "../../../../../zosjobs/__tests__/__system__/JobTestsUtils"; import { AbstractSession, IO } from "@zowe/imperative"; diff --git a/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.job.system.test.ts index bc780029f3..e34559b5fe 100644 --- a/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.job.system.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; // Test Environment populated in the beforeAll(); diff --git a/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.old-jobs.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.old-jobs.system.test.ts index 1cdaa7c03a..be09c0dfaf 100644 --- a/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.old-jobs.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/delete/cli.zos-jobs.delete.old-jobs.system.test.ts @@ -11,8 +11,8 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { runCliScript } from "@zowe/cli-test-utils"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts index a8faeed623..084287dd36 100644 --- a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { AbstractSession } from "@zowe/imperative"; import * as fs from "fs"; diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts index 6b3929993e..b7c0a10a5b 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { AbstractSession } from "@zowe/imperative"; import { IJob, GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts index 5038e14a79..b47c7ff48f 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { AbstractSession, TextUtils } from "@zowe/imperative"; import { IJob, GetJobs, SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosjobs/__system__/modify/cli.zos-jobs.modify.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/modify/cli.zos-jobs.modify.job.system.test.ts index 8554416ca7..62262941d4 100644 --- a/packages/cli/__tests__/zosjobs/__system__/modify/cli.zos-jobs.modify.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/modify/cli.zos-jobs.modify.job.system.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; let TEST_ENVIRONMENT: ITestEnvironment; diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index 188120f9af..057df02d08 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; import { AbstractSession } from "@zowe/imperative"; diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts index 5716beb40b..b815ad48ec 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Session } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts index fc21f68ab7..8b773e777c 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { ICommandResponse, Session } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; From d89d3b1973d94c0e7934544370eae9c2c3e53b85 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 19 Sep 2024 15:47:42 -0400 Subject: [PATCH 46/65] createSession() to createZosmfSession() Signed-off-by: ATorrise --- .../src/environment/TestEnvironment.ts | 19 ------------------- .../cli.zos-jobs.cancel.job.system.test.ts | 4 ++-- ...li.zos-jobs.download.output.system.test.ts | 4 ++-- .../cli.zos-jobs.list.jobs.system.test.ts | 4 ++-- ...s.list.spool-files-by-jobid.system.test.ts | 4 ++-- .../search/cli.zos-jobs.search.job.test.ts | 2 +- ...li.zos-jobs.submit.data-set.system.test.ts | 6 +++--- ....zos-jobs.submit.local-file.system.test.ts | 4 ++-- .../cli.zos-jobs.submit.stdin.system.test.ts | 2 +- ...li.zos-jobs.submit.uss-file.system.test.ts | 2 +- .../__system__/methods/get/Get.system.test.ts | 4 ++-- .../methods/invoke/Invoke.system.test.ts | 4 ++-- .../methods/upload/Upload.system.test.ts | 14 +++++++------- .../utilities/Utilities.system.test.ts | 2 +- .../__system__/CancelJobs.system.test.ts | 4 ++-- .../__system__/DownloadJobs.system.test.ts | 4 ++-- .../__system__/GetJobs.system.test.ts | 4 ++-- .../__system__/ModifyJobs.system.test.ts | 4 ++-- .../__system__/MonitorJobs.system.test.ts | 4 ++-- .../__system__/SearchJobs.system.test.ts | 2 +- .../__system__/SubmitJobs.system.test.ts | 2 +- 21 files changed, 40 insertions(+), 59 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index c82eb1af5d..ae2697b704 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -84,25 +84,6 @@ export class TestEnvironment { return result; } - /** - * Create a session using the default z/OSMF profile (if a session has not been added to test) - * @returns {Promise} - A promise that resolves to the created session object - * @throws Will throw an error if reading profiles or creating the session fails - * @memberof TestEnvironment - */ - public static async createSession(testEnvironment: any): Promise { - const SYSTEM_PROPS = testEnvironment.systemTestProperties.zosmf; - return new Session({ - user: SYSTEM_PROPS.user, - password: SYSTEM_PROPS.password, - hostname: SYSTEM_PROPS.host, - port: SYSTEM_PROPS.port, - type: "basic", - rejectUnauthorized: SYSTEM_PROPS.rejectUnauthorized, - basePath: SYSTEM_PROPS.basePath - }); - } - /** * Clean up your test environment. * Deletes any temporary profiles that have been created diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index 6e2ee76b16..5a05112fa8 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -30,7 +30,7 @@ describe("zos-jobs cancel job command", () => { testName: "zos_jobs_cancel_job_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); const systemProps = TEST_ENVIRONMENT.systemTestProperties; const jcl = JobTestsUtils.getSleepJCL(systemProps.zosmf.user, systemProps.tso.account, systemProps.zosjobs.jobclass); const bufferJCL: Buffer = Buffer.from(jcl); @@ -120,7 +120,7 @@ describe("zos-jobs cancel job command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_cancel_job_without_profiles" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts index 084287dd36..cd1a4a816a 100644 --- a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts @@ -29,7 +29,7 @@ describe("zos-jobs download output command", () => { testName: "zos_jobs_download_output_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); IEFBR14_JCL = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; }); @@ -84,7 +84,7 @@ describe("zos-jobs download output command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_download_output_without_profiles" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts index b7c0a10a5b..664f925d1d 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts @@ -41,7 +41,7 @@ describe("zos-jobs list jobs command", () => { testName: "zos_jobs_list_jobs_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); const systemProps = TEST_ENVIRONMENT.systemTestProperties; IEFBR14_JOB = systemProps.zosjobs.iefbr14Member; @@ -117,7 +117,7 @@ describe("zos-jobs list jobs command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_job_without_profiles" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts index b47c7ff48f..cca0184188 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts @@ -42,7 +42,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { testName: "zos_jobs_list_spool_files_by_jobid_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; @@ -139,7 +139,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_spool_files_by_jobid_without_profiles" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index 057df02d08..687c3dd887 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -36,7 +36,7 @@ describe("zos-jobs search job command", () => { testName: "zos_jobs_search_job_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); // Use testEnvironment for accessing properties defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts index 2cd4e28186..6a2b724c00 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { List } from "../../../../../../zosfiles/src/methods/list"; import { AbstractSession } from "@zowe/imperative"; @@ -35,7 +35,7 @@ describe("zos-jobs submit data-set command", () => { testName: "zos_jobs_submit_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); account = TEST_ENVIRONMENT.systemTestProperties.tso.account; jclMember = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; psJclDataSet = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14PSDataSet; @@ -146,7 +146,7 @@ describe("zos-jobs submit data-set command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_submit_data_set_without_profiles" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); 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 9b8f65671a..f4c00f40f7 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 @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { IO, Session } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; @@ -35,7 +35,7 @@ describe("zos-jobs submit local-file command", () => { testName: "zos_jobs_submit_local_file_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); systemProps = TEST_ENVIRONMENT.systemTestProperties; account = systemProps.tso.account; 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 af0ec7c560..636c5d30f0 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 @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { IO, Session } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts index 203a72869c..e326ec14d9 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts @@ -11,7 +11,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; -import { runCliScript } from "../../../../../../../__tests__/__src__/TestUtils" +import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Session } from "@zowe/imperative"; import * as path from "path"; // Import path module for path handling diff --git a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts index 5146d601ba..700bb97dda 100644 --- a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts @@ -30,7 +30,7 @@ describe("Get", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_view" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`); Imperative.console.info("Using dsname:" + dsname); @@ -365,7 +365,7 @@ describe("Get - encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_view" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`, true); Imperative.console.info("Using dsname:" + dsname); diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts index 4d9f22469a..2ccbe3281a 100644 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts @@ -34,7 +34,7 @@ describe("Invoke AMS", () => { tempProfileTypes: ["zosmf"], testName: "zos_create_VSAM_dataset" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); systemProps = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); @@ -210,7 +210,7 @@ describe("Invoke AMS - encoded", () => { tempProfileTypes: ["zosmf"], testName: "zos_create_VSAM_dataset" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); systemProps = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.ENCO#ED.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index c2d2b46b50..26d613d0aa 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -38,7 +38,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); Imperative.console.info("Using dsname:" + dsname); @@ -670,7 +670,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); Imperative.console.info("Using dsname:" + dsname); @@ -770,7 +770,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_uss" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); ussname = dsname.replace(/\./g, ""); @@ -928,7 +928,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_uss" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); ussname = dsname.replace(/\./g, ""); @@ -1005,7 +1005,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_dir_to_uss" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); ussname = dsname.replace(/\./g, ""); @@ -1233,7 +1233,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_dir_to_uss" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); @@ -1370,7 +1370,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_dir_to_uss" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); ussname = dsname.replace(/\./g, ""); diff --git a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts index 20a2a129e2..9337616f52 100644 --- a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts @@ -29,7 +29,7 @@ describe("USS Utilities", () => { tempProfileTypes: ["zosmf"], testName: "zos_files_utilities" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); const defaultSystem = testEnvironment.systemTestProperties; let dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); dsname = dsname.replace(/\./g, ""); diff --git a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts index 5c497b4623..70f0b31b81 100644 --- a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts @@ -29,7 +29,7 @@ describe("CancelJobs System tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); systemProps = testEnvironment.systemTestProperties; const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer @@ -190,7 +190,7 @@ describe("CancelJobs System tests - encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); systemProps = testEnvironment.systemTestProperties; const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer diff --git a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts index d7d457f27a..861c87fbfc 100644 --- a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts @@ -44,7 +44,7 @@ describe("Download Jobs - System tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; @@ -357,7 +357,7 @@ describe("Download Jobs - System tests - Encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts index a9735761f8..be3826fabf 100644 --- a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts @@ -63,7 +63,7 @@ describe("Get Jobs System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "get_jobs_system_test" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; @@ -1017,7 +1017,7 @@ describe("Get Jobs System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_get_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); INVALID_SESSION = new Session({ user: "fakeuser", diff --git a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts index f71760fe3b..2ff3af69a9 100644 --- a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts @@ -32,7 +32,7 @@ describe("Modify Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobclass = testEnvironment.systemTestProperties.zosjobs.jobclass; @@ -105,7 +105,7 @@ describe("Modify Jobs - System Tests - Encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobclass = systemProps.zosjobs.jobclass; diff --git a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts index 4ab66d7dc4..5f73fa41e6 100644 --- a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts @@ -73,7 +73,7 @@ describe("System Tests - Monitor Jobs", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_monitor_jobs" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 6; @@ -689,7 +689,7 @@ describe("System Tests - Monitor Jobs", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_monitor_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 5; diff --git a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts index 38048883c4..55bf677232 100644 --- a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts @@ -58,7 +58,7 @@ describe("Search Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_search_jobs" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); defaultSystem = testEnvironment.systemTestProperties; INVALID_SESSION = new Session({ diff --git a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts index a9e071d285..f202f8ae4f 100644 --- a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts @@ -36,7 +36,7 @@ describe("Submit Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_submit_jobs" }); - REAL_SESSION = await TestEnvironment.createSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(); systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobDataSet = testEnvironment.systemTestProperties.zosjobs.iefbr14PSDataSet; From ae20141f2b466de3cebf8aa50d157cdf1b8a152d Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 19 Sep 2024 16:44:42 -0400 Subject: [PATCH 47/65] createsession to createzosmfsession Signed-off-by: ATorrise --- .../src/environment/TestEnvironment.ts | 2 +- .../ftds/cli.files.upload.ftds.system.test.ts | 2 +- .../stds/cli.files.upload.stds.system.test.ts | 2 +- .../__system__/view/uss/View.uss.system.test.ts | 2 +- .../cancel/cli.zos-jobs.cancel.job.system.test.ts | 4 ++-- .../cli.zos-jobs.download.output.system.test.ts | 4 ++-- .../list/cli.zos-jobs.list.jobs.system.test.ts | 4 ++-- ...s-jobs.list.spool-files-by-jobid.system.test.ts | 4 ++-- .../search/cli.zos-jobs.search.job.test.ts | 2 +- .../cli.zos-jobs.submit.data-set.system.test.ts | 4 ++-- .../cli.zos-jobs.submit.local-file.system.test.ts | 2 +- .../__system__/methods/get/Get.system.test.ts | 4 ++-- .../methods/invoke/Invoke.system.test.ts | 4 ++-- .../methods/upload/Upload.system.test.ts | 14 +++++++------- .../methods/utilities/Utilities.system.test.ts | 2 +- .../__tests__/__system__/CancelJobs.system.test.ts | 4 ++-- .../__system__/DownloadJobs.system.test.ts | 4 ++-- .../__tests__/__system__/GetJobs.system.test.ts | 4 ++-- .../__tests__/__system__/ModifyJobs.system.test.ts | 4 ++-- .../__system__/MonitorJobs.system.test.ts | 4 ++-- .../__tests__/__system__/SearchJobs.system.test.ts | 2 +- .../__tests__/__system__/SubmitJobs.system.test.ts | 2 +- 22 files changed, 40 insertions(+), 40 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index ae2697b704..0fedf65017 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -14,7 +14,7 @@ import * as nodePath from "path"; import * as yaml from "js-yaml"; import { v4 as uuidv4 } from "uuid"; import { AbstractSession, ImperativeError, ImperativeExpect, - IO, Logger, LoggingConfigurer, Session, TextUtils } from "@zowe/imperative"; + IO, Logger, LoggingConfigurer, TextUtils } from "@zowe/imperative"; import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts index 2e05585dea..2bdc381e95 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/ftds/cli.files.upload.ftds.system.test.ts @@ -14,7 +14,7 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getRandomBytes, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, ICreateDataSetOptions, Delete, Get } from "@zowe/zos-files-for-zowe-sdk"; import { runCliScript } from "@zowe/cli-test-utils"; diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts index d0d5787cf7..a723db9453 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/stds/cli.files.upload.stds.system.test.ts @@ -14,7 +14,7 @@ import * as path from "path"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getRandomBytes, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Create, CreateDataSetTypeEnum, Delete, Get } from "@zowe/zos-files-for-zowe-sdk"; import { runCliScript } from "@zowe/cli-test-utils"; diff --git a/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts index a35e0b5ce3..d01eb1ac7c 100644 --- a/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts @@ -16,7 +16,7 @@ import { ZosFilesConstants, ZosmfRestClient, ZosmfHeaders, Upload } from "@zowe/ import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { getRandomBytes, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index 5a05112fa8..5f5f089f05 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -30,7 +30,7 @@ describe("zos-jobs cancel job command", () => { testName: "zos_jobs_cancel_job_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); const systemProps = TEST_ENVIRONMENT.systemTestProperties; const jcl = JobTestsUtils.getSleepJCL(systemProps.zosmf.user, systemProps.tso.account, systemProps.zosjobs.jobclass); const bufferJCL: Buffer = Buffer.from(jcl); @@ -120,7 +120,7 @@ describe("zos-jobs cancel job command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_cancel_job_without_profiles" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts index cd1a4a816a..f3f0188ff4 100644 --- a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts @@ -29,7 +29,7 @@ describe("zos-jobs download output command", () => { testName: "zos_jobs_download_output_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); IEFBR14_JCL = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; }); @@ -84,7 +84,7 @@ describe("zos-jobs download output command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_download_output_without_profiles" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts index 664f925d1d..c99e18c1cb 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts @@ -41,7 +41,7 @@ describe("zos-jobs list jobs command", () => { testName: "zos_jobs_list_jobs_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); const systemProps = TEST_ENVIRONMENT.systemTestProperties; IEFBR14_JOB = systemProps.zosjobs.iefbr14Member; @@ -117,7 +117,7 @@ describe("zos-jobs list jobs command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_job_without_profiles" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts index cca0184188..b945bc1a3f 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts @@ -42,7 +42,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { testName: "zos_jobs_list_spool_files_by_jobid_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; @@ -139,7 +139,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_spool_files_by_jobid_without_profiles" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index 687c3dd887..97968fa168 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -36,7 +36,7 @@ describe("zos-jobs search job command", () => { testName: "zos_jobs_search_job_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); // Use testEnvironment for accessing properties defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts index 6a2b724c00..a92cc11fbf 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts @@ -35,7 +35,7 @@ describe("zos-jobs submit data-set command", () => { testName: "zos_jobs_submit_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = TEST_ENVIRONMENT.systemTestProperties.tso.account; jclMember = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; psJclDataSet = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14PSDataSet; @@ -146,7 +146,7 @@ describe("zos-jobs submit data-set command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_submit_data_set_without_profiles" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); 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 f4c00f40f7..92550f6ad0 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 @@ -35,7 +35,7 @@ describe("zos-jobs submit local-file command", () => { testName: "zos_jobs_submit_local_file_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); systemProps = TEST_ENVIRONMENT.systemTestProperties; account = systemProps.tso.account; diff --git a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts index 700bb97dda..9804bde779 100644 --- a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts @@ -30,7 +30,7 @@ describe("Get", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_view" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`); Imperative.console.info("Using dsname:" + dsname); @@ -365,7 +365,7 @@ describe("Get - encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_view" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`, true); Imperative.console.info("Using dsname:" + dsname); diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts index 2ccbe3281a..045568fd94 100644 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts @@ -34,7 +34,7 @@ describe("Invoke AMS", () => { tempProfileTypes: ["zosmf"], testName: "zos_create_VSAM_dataset" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); @@ -210,7 +210,7 @@ describe("Invoke AMS - encoded", () => { tempProfileTypes: ["zosmf"], testName: "zos_create_VSAM_dataset" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.ENCO#ED.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index 26d613d0aa..c2e435b66d 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -38,7 +38,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); Imperative.console.info("Using dsname:" + dsname); @@ -670,7 +670,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); Imperative.console.info("Using dsname:" + dsname); @@ -770,7 +770,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_uss" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); ussname = dsname.replace(/\./g, ""); @@ -928,7 +928,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_uss" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); ussname = dsname.replace(/\./g, ""); @@ -1005,7 +1005,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_dir_to_uss" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); ussname = dsname.replace(/\./g, ""); @@ -1233,7 +1233,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_dir_to_uss" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); @@ -1370,7 +1370,7 @@ describe("All Upload Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload_dir_to_uss" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); ussname = dsname.replace(/\./g, ""); diff --git a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts index 9337616f52..5203c6329d 100644 --- a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts @@ -29,7 +29,7 @@ describe("USS Utilities", () => { tempProfileTypes: ["zosmf"], testName: "zos_files_utilities" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); const defaultSystem = testEnvironment.systemTestProperties; let dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); dsname = dsname.replace(/\./g, ""); diff --git a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts index 70f0b31b81..38e94a4e12 100644 --- a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts @@ -29,7 +29,7 @@ describe("CancelJobs System tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer @@ -190,7 +190,7 @@ describe("CancelJobs System tests - encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer diff --git a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts index 861c87fbfc..3328b92644 100644 --- a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts @@ -44,7 +44,7 @@ describe("Download Jobs - System tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; @@ -357,7 +357,7 @@ describe("Download Jobs - System tests - Encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts index be3826fabf..5f5fb90a4d 100644 --- a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts @@ -63,7 +63,7 @@ describe("Get Jobs System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "get_jobs_system_test" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; @@ -1017,7 +1017,7 @@ describe("Get Jobs System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_get_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); INVALID_SESSION = new Session({ user: "fakeuser", diff --git a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts index 2ff3af69a9..6e352e63fb 100644 --- a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts @@ -32,7 +32,7 @@ describe("Modify Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobclass = testEnvironment.systemTestProperties.zosjobs.jobclass; @@ -105,7 +105,7 @@ describe("Modify Jobs - System Tests - Encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobclass = systemProps.zosjobs.jobclass; diff --git a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts index 5f73fa41e6..5eca46bcf6 100644 --- a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts @@ -73,7 +73,7 @@ describe("System Tests - Monitor Jobs", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_monitor_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 6; @@ -689,7 +689,7 @@ describe("System Tests - Monitor Jobs", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_monitor_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 5; diff --git a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts index 55bf677232..e0bf9ddf9c 100644 --- a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts @@ -58,7 +58,7 @@ describe("Search Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_search_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); defaultSystem = testEnvironment.systemTestProperties; INVALID_SESSION = new Session({ diff --git a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts index f202f8ae4f..1b3953fa74 100644 --- a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts @@ -36,7 +36,7 @@ describe("Submit Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_submit_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(); + REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobDataSet = testEnvironment.systemTestProperties.zosjobs.iefbr14PSDataSet; From 54e8d99426b4da967ec0d901dadaab986feb315c Mon Sep 17 00:00:00 2001 From: ATorrise Date: Fri, 20 Sep 2024 08:43:13 -0400 Subject: [PATCH 48/65] adding import back into test Signed-off-by: ATorrise --- .../view/cli.zos-jobs.view.spool-file-by-id.system.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts index 77590c1dfe..ffb16f7259 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts @@ -17,6 +17,7 @@ import * as fs from "fs"; import { IJob, SubmitJobs, GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; import { TEST_RESOURCES_DIR } from "../../../../../../packages/zosjobs/__tests__/__src__/ZosJobsTestConstants"; import { join } from "path"; +import { runCliScript } from "@zowe/cli-test-utils"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; From 9de05a22fa6e78c334b3cac2943b64aad5d085c1 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Fri, 20 Sep 2024 17:03:46 -0400 Subject: [PATCH 49/65] getting things deleted Signed-off-by: ATorrise --- __tests__/__src__/TestUtils.ts | 2 +- .../__src__/environment/TestEnvironment.ts | 43 +++++++++++-------- .../dtu/cli.dir.upload.dtu.system.test.ts | 2 + .../cli.zos-jobs.cancel.job.system.test.ts | 3 +- ...li.zos-jobs.download.output.system.test.ts | 3 +- .../cli.zos-jobs.list.jobs.system.test.ts | 4 +- ...s.list.spool-files-by-jobid.system.test.ts | 2 + ....zos-jobs.submit.local-file.system.test.ts | 2 + .../cli.zos-jobs.submit.stdin.system.test.ts | 2 + ...jobs.view.all-spool-content.system.test.ts | 1 + ...bs.view.job-status-by-jobid.system.test.ts | 2 + ...-jobs.view.spool-file-by-id.system.test.ts | 1 + .../methods/copy/Copy.system.test.ts | 7 ++- .../methods/create/Create.system.test.ts | 34 +++++++++++++-- .../delete/DeleteDataset.system.test.ts | 8 +++- .../delete/DeleteUSSFile.system.test.ts | 20 ++++++++- .../methods/delete/DeleteZfs.system.test.ts | 4 +- .../methods/download/Download.system.test.ts | 10 ++++- .../__system__/methods/get/Get.system.test.ts | 4 ++ .../methods/hDelete/HDelete.system.test.ts | 4 +- .../methods/hMigrate/HMigrate.system.test.ts | 4 +- .../methods/hRecall/HRecall.system.test.ts | 4 +- .../__system__/methods/invoke/DeleteVSAM.ams | 1 - .../methods/invoke/Invoke.system.test.ts | 4 ++ .../methods/list/List.system.test.ts | 4 +- .../methods/mount/Mount.system.test.ts | 6 ++- .../methods/rename/Rename.system.test.ts | 6 ++- .../methods/search/Search.system.test.ts | 3 +- .../methods/upload/Upload.system.test.ts | 14 ++++++ .../utilities/Utilities.system.test.ts | 4 ++ .../__system__/CancelJobs.system.test.ts | 4 +- .../__system__/DeleteJobs.system.test.ts | 3 +- .../__system__/DownloadJobs.system.test.ts | 3 ++ .../__system__/GetJobs.system.test.ts | 3 ++ .../__system__/ModifyJobs.system.test.ts | 4 ++ .../__system__/MonitorJobs.system.test.ts | 4 ++ .../__system__/SearchJobs.system.test.ts | 1 + .../__system__/SubmitJobs.system.test.ts | 2 + 38 files changed, 190 insertions(+), 42 deletions(-) delete mode 100644 packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams diff --git a/__tests__/__src__/TestUtils.ts b/__tests__/__src__/TestUtils.ts index 56724eebbf..6f09a64877 100644 --- a/__tests__/__src__/TestUtils.ts +++ b/__tests__/__src__/TestUtils.ts @@ -60,7 +60,7 @@ export function deleteLocalDirectories(directories: string[]): void { * @returns {Promise} A promise that resolves when the file is deleted */ export async function deleteFiles(session: AbstractSession, fileName: string): Promise { - await Delete.ussFile(session, fileName); + await Delete.ussFile(session, fileName, true); //recursive = true } /** diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index 6112887e36..4f69543550 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -11,7 +11,7 @@ import * as nodePath from "path"; -import { AbstractSession, Imperative, Session } from "@zowe/imperative"; +import { AbstractSession, Imperative, ImperativeError, Session } from "@zowe/imperative"; import { ITestPropertiesSchema } from "../properties/ITestPropertiesSchema"; import { ISetupEnvironmentParms, TestEnvironment as BaseTestEnvironment } from "../../__packages__/cli-test-utils"; @@ -75,25 +75,32 @@ export class TestEnvironment extends BaseTestEnvironment { // Deleting resources (if they exist) if (testEnvironment?.resources?.session) { const session = testEnvironment.resources.session; - for (const file of testEnvironment.resources.localFiles) { - deleteLocalFile(file); - } - for (const file of testEnvironment.resources.files) { - deleteFiles(session, file); - } - for (const job of testEnvironment.resources.jobs) { - deleteJob(session, job); - } - for (const jobData of testEnvironment.resources.jobData) { - if (jobData.jobname && jobData.jobid) { - deleteJobCommon(session, jobData); - } else { - Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); + try{ + for (const file of testEnvironment.resources.localFiles) { + deleteLocalFile(file); + } + for (const file of testEnvironment.resources.files) { + deleteFiles(session, file); + } + for (const job of testEnvironment.resources.jobs) { + deleteJob(session, job); + } + for (const jobData of testEnvironment.resources.jobData) { + if (jobData.jobname && jobData.jobid) { + deleteJobCommon(session, jobData); + } else { + Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); + } + } + for (const dataset of testEnvironment.resources.datasets) { + deleteDataset(session, dataset); + } + }catch (error){ + if (error.mDetails?.httpStatus !== 404) { + throw error; } } - for (const dataset of testEnvironment.resources.datasets) { - deleteDataset(session, dataset); - } + testEnvironment.resources = { localFiles: [], files: [], diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts index d17029e146..81a19d8ec4 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts @@ -43,6 +43,7 @@ describe("Upload directory to USS", () => { dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILES.UPLOAD`); dsname = dsname.replace(/\./g, ""); ussname = `${defaultSystem.unix.testdir}/${dsname}`; + TEST_ENVIRONMENT.resources.session = REAL_SESSION; TEST_ENVIRONMENT.resources.datasets.push(dsname); TEST_ENVIRONMENT.resources.files.push(ussname); Imperative.console.info("Using ussDir:" + ussname); @@ -66,6 +67,7 @@ describe("Upload directory to USS", () => { defaultSys = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; Imperative.console.info("Using ussDir:" + ussname); + TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; TEST_ENVIRONMENT_NO_PROF.resources.files.push(ussname); }); diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index 5f5f089f05..a535f1b716 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -31,6 +31,7 @@ describe("zos-jobs cancel job command", () => { tempProfileTypes: ["zosmf"] }); REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + TEST_ENVIRONMENT.resources.session = REAL_SESSION; const systemProps = TEST_ENVIRONMENT.systemTestProperties; const jcl = JobTestsUtils.getSleepJCL(systemProps.zosmf.user, systemProps.tso.account, systemProps.zosjobs.jobclass); const bufferJCL: Buffer = Buffer.from(jcl); @@ -121,7 +122,7 @@ describe("zos-jobs cancel job command", () => { testName: "zos_jobs_cancel_job_without_profiles" }); REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); - + TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts index f3f0188ff4..03e4dfa4b1 100644 --- a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts @@ -31,6 +31,7 @@ describe("zos-jobs download output command", () => { }); REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + TEST_ENVIRONMENT.resources.session = REAL_SESSION; IEFBR14_JCL = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; }); @@ -85,7 +86,7 @@ describe("zos-jobs download output command", () => { testName: "zos_jobs_download_output_without_profiles" }); REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); - + TEST_ENVIRONMENT.resources.session = REAL_SESSION; DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts index c99e18c1cb..8c8f6d4584 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts @@ -42,7 +42,7 @@ describe("zos-jobs list jobs command", () => { tempProfileTypes: ["zosmf"] }); REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - + TEST_ENVIRONMENT.resources.session = REAL_SESSION; const systemProps = TEST_ENVIRONMENT.systemTestProperties; IEFBR14_JOB = systemProps.zosjobs.iefbr14Member; @@ -118,7 +118,7 @@ describe("zos-jobs list jobs command", () => { testName: "zos_jobs_list_job_without_profiles" }); REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); - + TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts index b945bc1a3f..3a038d26a9 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts @@ -43,6 +43,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { tempProfileTypes: ["zosmf"] }); REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + TEST_ENVIRONMENT.resources.session = REAL_SESSION; IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; @@ -140,6 +141,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { testName: "zos_jobs_list_spool_files_by_jobid_without_profiles" }); REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); + TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); 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 92550f6ad0..19bdf1bd5f 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 @@ -39,6 +39,8 @@ describe("zos-jobs submit local-file command", () => { systemProps = TEST_ENVIRONMENT.systemTestProperties; account = systemProps.tso.account; + TEST_ENVIRONMENT.resources.session = REAL_SESSION; + // JCL to submit jcl = (await Get.dataSet(REAL_SESSION, systemProps.zosjobs.iefbr14Member)).toString(); 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 636c5d30f0..c5385ac3b8 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 @@ -40,6 +40,8 @@ describe("zos-jobs submit stdin command", () => { REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = systemProps.tso.account; + TEST_ENVIRONMENT.resources.session = REAL_SESSION; + // JCL to submit jcl = (await Get.dataSet(REAL_SESSION, systemProps.zosjobs.iefbr14Member)).toString(); diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts index b815ad48ec..ac12fb6d9a 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts @@ -38,6 +38,7 @@ describe("zos-jobs view all-spool-content command", () => { IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + TEST_ENVIRONMENT.resources.session = REAL_SESSION; ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 6; diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts index 8b773e777c..1003645f6d 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts @@ -39,6 +39,7 @@ describe("zos-jobs view job-status-by-jobid command", () => { }); REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + TEST_ENVIRONMENT.resources.session = REAL_SESSION; systemProps = TEST_ENVIRONMENT.systemTestProperties; @@ -112,6 +113,7 @@ describe("zos-jobs view job-status-by-jobid command", () => { testName: "zos_jobs_view_job_status_by_jobid_command_without_profiles" }); REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + TEST_ENVIRONMENT.resources.session = REAL_SESSION; DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts index ffb16f7259..e77d9b0988 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts @@ -39,6 +39,7 @@ describe("zos-jobs view spool-file-by-id command", () => { }); REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + TEST_ENVIRONMENT.resources.session = REAL_SESSION; IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; ACCOUNT = defaultSystem.tso.account; diff --git a/packages/zosfiles/__tests__/__system__/methods/copy/Copy.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/copy/Copy.system.test.ts index 540acc395c..a9df2f890b 100644 --- a/packages/zosfiles/__tests__/__system__/methods/copy/Copy.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/copy/Copy.system.test.ts @@ -13,11 +13,11 @@ import { Create, Upload, Delete, CreateDataSetTypeEnum, Copy, ZosFilesMessages, ICrossLparCopyDatasetOptions, IGetOptions, IZosFilesResponse } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { join } from "path"; import { readFileSync } from "fs"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let REAL_TARGET_SESSION: Session; @@ -41,6 +41,9 @@ describe("Copy", () => { REAL_TARGET_SESSION = REAL_SESSION; fromDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.DATA.ORIGINAL`; toDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.DATA.COPY`; + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(fromDataSetName, toDataSetName); }); afterAll(async () => { @@ -1022,6 +1025,8 @@ describe("Copy - Encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); fromDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.DATA.ENCO#ED.ORIGINAL`; toDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.ENCO#ED.DATA.COPY`; + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(fromDataSetName, toDataSetName); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts index 105fe7be10..fec0e8ccc8 100644 --- a/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts @@ -12,13 +12,13 @@ import { Imperative, Session } from "@zowe/imperative"; import { inspect } from "util"; import { Create, CreateDataSetTypeEnum, ICreateDataSetOptions, ICreateVsamOptions } from "../../../../src/methods/create"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Delete } from "../../../../src/methods/delete"; import { ZosFilesMessages } from "../../../../src"; import { getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; import { ICreateZfsOptions } from "../../../../src/methods/create/doc/ICreateZfsOptions"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let testEnvironment: ITestEnvironment; @@ -51,6 +51,8 @@ describe("Create data set", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.DATA.SET`; + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { @@ -168,6 +170,9 @@ describe("Create data set - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.ENCO#ED.DATA.SET`; + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { @@ -251,7 +256,8 @@ describe("Allocate Like", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsnameLike = `${dsname}.LIKE`; - + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(dsnameLike); await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_CLASSIC, dsname, options); }); @@ -313,7 +319,8 @@ describe("Allocate Like - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsnameLike = `${dsname}.ENCO#ED.LIKE`; - + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(dsnameLike); await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_CLASSIC, dsname, options); }); @@ -368,6 +375,9 @@ describe("Create VSAM", () => { volume = defaultSystem.datasets.vol; dsname = getUniqueDatasetName(defaultSystem.zosmf.user); + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { @@ -449,6 +459,9 @@ describe("Create VSAM - encoded", () => { volume = defaultSystem.datasets.vol; dsname = getUniqueDatasetName(defaultSystem.zosmf.user, true); + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { @@ -509,6 +522,9 @@ describe("Create z/OS file system", () => { fsname = getUniqueDatasetName(defaultSystem.zosmf.user); volume = defaultSystem.datasets.vol; + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(fsname); }); afterAll(async () => { @@ -601,6 +617,9 @@ describe("Create z/OS file system - encoded", () => { fsname = getUniqueDatasetName(defaultSystem.zosmf.user, true); volume = defaultSystem.datasets.vol; + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(fsname); }); afterAll(async () => { @@ -669,6 +688,9 @@ describe("Create uss file", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); basePath = defaultSystem.unix.testdir; // `${defaultSystem.zosmf.basePath.trim()}`; filename = `${basePath}/test.txt`.replace(/\./g, ""); + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -745,6 +767,8 @@ describe("Create uss file - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); basePath = defaultSystem.unix.testdir; // `${defaultSystem.zosmf.basePath.trim()}`; filename = `${basePath}/enco#edtest.txt`.replace(/\./g, ""); + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -800,6 +824,8 @@ describe("Create uss directory", () => { // dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.DATA.SET`; basePath = defaultSystem.unix.testdir; // `${defaultSystem.zosmf.basePath.trim()}`; filename = `${basePath}/testDir`.replace(/\./g, ""); + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -875,6 +901,8 @@ describe("Create uss directory - encoded", () => { // dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.DATA.SET`; basePath = defaultSystem.unix.testdir; // `${defaultSystem.zosmf.basePath.trim()}`; filename = `${basePath}/testEnco#edDir`.replace(/\./g, ""); + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.files.push(filename); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteDataset.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteDataset.system.test.ts index e0a6c1c6bb..f573e495f8 100644 --- a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteDataset.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteDataset.system.test.ts @@ -12,9 +12,9 @@ import { Create, CreateDataSetTypeEnum, Delete, ZosFilesMessages } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -30,7 +30,10 @@ describe("Delete Dataset", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.DATA.SET.DELETE`; + testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { @@ -137,6 +140,9 @@ describe("Delete Dataset - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.ENCO#ED.DATA.SET.DELETE`; + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts index 264d6c7f9e..0b316215d6 100644 --- a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts @@ -12,9 +12,9 @@ import { Create, Delete, ZosFilesMessages } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -32,6 +32,9 @@ describe("Delete a USS File", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); ussname = `${defaultSystem.zosmf.user.trim()}`; + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.files.push(ussname); }); afterAll(async () => { @@ -154,6 +157,9 @@ describe("Delete a USS File - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); ussname = `${defaultSystem.zosmf.user.trim() + ".Enco#ed"}`; + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.files.push(ussname); }); afterAll(async () => { @@ -220,6 +226,9 @@ describe("Delete USS Directory", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); filename = `${defaultSystem.unix.testdir}/${ussname}.aTestUssFolderDelete`.replace(/\./g, ""); + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -319,6 +328,9 @@ describe("Delete USS Directory - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); filename = `${defaultSystem.unix.testdir}/${ussname}.Enco#ed.aTestUssFolderDelete`.replace(/\./g, ""); + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -367,6 +379,9 @@ describe("Delete USS Directory with children", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); filename = `${defaultSystem.unix.testdir}/${ussname}.aTestUssFileDelete`.replace(/\./g, ""); + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -475,6 +490,9 @@ describe("Delete USS Directory with children - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); filename = `${defaultSystem.unix.testdir}/${ussname}.Enco#ed.aTestUssFileDelete`.replace(/\./g, ""); + + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.files.push(filename); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteZfs.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteZfs.system.test.ts index 983827a193..6b0044d183 100644 --- a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteZfs.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteZfs.system.test.ts @@ -12,11 +12,11 @@ import { Create, Delete, ZosFilesMessages } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; import { ICreateZfsOptions } from "../../../../src/methods/create/doc/ICreateZfsOptions"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -43,6 +43,8 @@ describe("Delete a z/OS File System", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); fsname = getUniqueDatasetName(defaultSystem.zosmf.user); createOptions.volumes = [defaultSystem.datasets.vol]; + testEnvironment.resources.session = REAL_SESSION; + testEnvironment.resources.datasets.push(fsname); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index 1fe87e55d8..bcdb01bc25 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -29,7 +29,7 @@ import { } from "../../../../src"; import { Imperative, IO, Session } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName, stripNewLines, wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; @@ -61,6 +61,7 @@ describe("Download Data Set", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); Imperative.console.info("Using dsname:" + dsname); @@ -69,6 +70,9 @@ describe("Download Data Set", () => { ussname = `${defaultSystem.unix.testdir}/${dsname}`; ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; localDirname = `${testEnvironment.workingDir}/ussDir`; + + testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.files.push(ussname, ussDirname); }); afterAll(async () => { @@ -1522,6 +1526,7 @@ describe("Download Data Set - encoded", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); Imperative.console.info("Using dsname:" + dsname); @@ -1530,6 +1535,9 @@ describe("Download Data Set - encoded", () => { ussname = `${defaultSystem.unix.testdir}/ENCO#ED${dsname}`; ussDirname = `${defaultSystem.unix.testdir}/ENCO#EDzos_file_download`; localDirname = `${testEnvironment.workingDir}/ENCO#EDussDir`; + + testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.files.push(ussname, ussDirname); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts index 9804bde779..b27274bcef 100644 --- a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts @@ -31,6 +31,8 @@ describe("Get", () => { testName: "zos_file_view" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`); Imperative.console.info("Using dsname:" + dsname); @@ -366,6 +368,8 @@ describe("Get - encoded", () => { testName: "zos_file_view" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`, true); Imperative.console.info("Using dsname:" + dsname); diff --git a/packages/zosfiles/__tests__/__system__/methods/hDelete/HDelete.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/hDelete/HDelete.system.test.ts index 4e1596f66a..20b971f090 100644 --- a/packages/zosfiles/__tests__/__system__/methods/hDelete/HDelete.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/hDelete/HDelete.system.test.ts @@ -12,9 +12,9 @@ import { Create, Delete, CreateDataSetTypeEnum, HDelete, HMigrate, IDeleteOptions, ZosFilesMessages } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -29,6 +29,8 @@ describe("Delete Migrated Dataset", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + dataSet1 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.SDATA.DEL`; dataSet2 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.PDATA.DEL`; dataSet3 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.FAIL.DEL`; diff --git a/packages/zosfiles/__tests__/__system__/methods/hMigrate/HMigrate.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/hMigrate/HMigrate.system.test.ts index 208dbd40e6..dd50e26233 100644 --- a/packages/zosfiles/__tests__/__system__/methods/hMigrate/HMigrate.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/hMigrate/HMigrate.system.test.ts @@ -12,9 +12,9 @@ import { Create, Delete, CreateDataSetTypeEnum, HMigrate, IListOptions, IMigrateOptions, List, ZosFilesMessages } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -31,6 +31,8 @@ describe("Migrate Dataset", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + dataSet1 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.SDATA.MIGR`; dataSet2 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.PDATA.MIGR`; dataSet3 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.FAIL.MIGR`; diff --git a/packages/zosfiles/__tests__/__system__/methods/hRecall/HRecall.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/hRecall/HRecall.system.test.ts index 8e76a56ae3..ec1964fa39 100644 --- a/packages/zosfiles/__tests__/__system__/methods/hRecall/HRecall.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/hRecall/HRecall.system.test.ts @@ -12,9 +12,9 @@ import { Create, Delete, CreateDataSetTypeEnum, HMigrate, HRecall, IListOptions, IRecallOptions, List, ZosFilesMessages } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -31,6 +31,8 @@ describe("Recall Dataset", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + dataSet1 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.SDATA.REC`; dataSet2 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.PDATA.REC`; dataSet3 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.FAIL.REC`; diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams b/packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams deleted file mode 100644 index 7cc9b7f813..0000000000 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams +++ /dev/null @@ -1 +0,0 @@ -DELETE {{DSN}} CLUSTER \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts index 045568fd94..3efa954d9a 100644 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts @@ -35,6 +35,8 @@ describe("Invoke AMS", () => { testName: "zos_create_VSAM_dataset" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + systemProps = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); @@ -211,6 +213,8 @@ describe("Invoke AMS - encoded", () => { testName: "zos_create_VSAM_dataset" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + systemProps = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.ENCO#ED.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); diff --git a/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts index 9f6f1753d1..a386bcf547 100644 --- a/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts @@ -12,10 +12,10 @@ import { Create, CreateDataSetTypeEnum, Delete, IListOptions, IZosFilesResponse, List, Upload, ZosFilesMessages } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { format, inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName, wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -33,6 +33,7 @@ describe("List command group", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.LIST`); Imperative.console.info("Using dsname:" + dsname); @@ -670,6 +671,7 @@ describe("List command group - encoded", () => { }); defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.LIST`, true); Imperative.console.info("Using dsname:" + dsname); diff --git a/packages/zosfiles/__tests__/__system__/methods/mount/Mount.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/mount/Mount.system.test.ts index a60253f675..b92b6d9b36 100644 --- a/packages/zosfiles/__tests__/__system__/methods/mount/Mount.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/mount/Mount.system.test.ts @@ -14,7 +14,6 @@ import { inspect } from "util"; import { Create } from "../../../../src/methods/create"; import { Mount, IMountFsOptions } from "../../../../src/methods/mount"; import { Unmount } from "../../../../src/methods/unmount"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Delete } from "../../../../src/methods/delete"; @@ -22,6 +21,7 @@ import { List, ZosFilesMessages } from "../../../../src"; import { getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; import { ICreateZfsOptions } from "../../../../src/methods/create/doc/ICreateZfsOptions"; import { SshSession, Shell } from "@zowe/zos-uss-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let testEnvironment: ITestEnvironment; @@ -59,6 +59,8 @@ describe("Mount and unmount a file system", () => { volume = defaultSystem.datasets.vol; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + fsname = getUniqueDatasetName(defaultSystem.zosmf.user); const dirname = getUniqueDatasetName(defaultSystem.zosmf.user).split(".")[1]; mountPoint = "/tmp/" + dirname; @@ -261,6 +263,8 @@ describe("Mount and unmount a file system - encoded", () => { volume = defaultSystem.datasets.vol; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + fsname = getUniqueDatasetName(defaultSystem.zosmf.user, true); const dirname = getUniqueDatasetName(defaultSystem.zosmf.user, true).split(".")[1]; mountPoint = "/tmp/" + dirname; diff --git a/packages/zosfiles/__tests__/__system__/methods/rename/Rename.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/rename/Rename.system.test.ts index 3bdf6fcea7..237d75a0c8 100644 --- a/packages/zosfiles/__tests__/__system__/methods/rename/Rename.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/rename/Rename.system.test.ts @@ -12,10 +12,10 @@ import { Create, CreateDataSetTypeEnum, Delete, List, Rename, Upload, ZosFilesMessages } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { inspect } from "util"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { join } from "path"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -33,6 +33,8 @@ describe("Rename", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + beforeDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.BEFORE.SET`; afterDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.AFTER.SET`; }); @@ -426,6 +428,8 @@ describe("Rename - encoded", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + beforeDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.ENCO#ED.BEFORE.SET`; afterDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.ENCO#ED.AFTER.SET`; }); diff --git a/packages/zosfiles/__tests__/__system__/methods/search/Search.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/search/Search.system.test.ts index 34ba130ba8..df78a236b3 100644 --- a/packages/zosfiles/__tests__/__system__/methods/search/Search.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/search/Search.system.test.ts @@ -10,11 +10,11 @@ */ import { Session } from "@zowe/imperative"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; import { Create, Upload, Delete, Search, CreateDataSetTypeEnum, ISearchOptions, IZosFilesResponse } from "../../../../src"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -34,6 +34,7 @@ describe("Search", () => { }); defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; // We can't test color related stuff in GitHub Actions or Jenkins oldForceColor = process.env.FORCE_COLOR; diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index c2e435b66d..026463006a 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -39,6 +39,8 @@ describe("All Upload Tests", () => { testName: "zos_file_upload" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); Imperative.console.info("Using dsname:" + dsname); @@ -671,6 +673,8 @@ describe("All Upload Tests", () => { testName: "zos_file_upload" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); Imperative.console.info("Using dsname:" + dsname); @@ -771,6 +775,8 @@ describe("All Upload Tests", () => { testName: "zos_file_upload_uss" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); ussname = dsname.replace(/\./g, ""); @@ -929,6 +935,8 @@ describe("All Upload Tests", () => { testName: "zos_file_upload_uss" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); ussname = dsname.replace(/\./g, ""); @@ -1006,6 +1014,8 @@ describe("All Upload Tests", () => { testName: "zos_file_upload_dir_to_uss" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); ussname = dsname.replace(/\./g, ""); @@ -1234,6 +1244,8 @@ describe("All Upload Tests", () => { testName: "zos_file_upload_dir_to_uss" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); @@ -1371,6 +1383,8 @@ describe("All Upload Tests", () => { testName: "zos_file_upload_dir_to_uss" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); ussname = dsname.replace(/\./g, ""); diff --git a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts index 5203c6329d..476425e85d 100644 --- a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts @@ -30,11 +30,15 @@ describe("USS Utilities", () => { testName: "zos_files_utilities" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + const defaultSystem = testEnvironment.systemTestProperties; let dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); dsname = dsname.replace(/\./g, ""); ussname = `${defaultSystem.unix.testdir}/${dsname}`; Imperative.console.info("Using ussDir:" + ussname); + + testEnvironment.resources.files.push(ussname); }); afterAll(async () => { diff --git a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts index 38e94a4e12..9a74f14daa 100644 --- a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts @@ -33,7 +33,7 @@ describe("CancelJobs System tests", () => { systemProps = testEnvironment.systemTestProperties; const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer - + testEnvironment.resources.session = REAL_SESSION; sleepJCL = JobTestsUtils.getSleepJCL(REAL_SESSION.ISession.user, ACCOUNT, systemProps.zosjobs.jobclass, maxStepNum); }); @@ -194,7 +194,7 @@ describe("CancelJobs System tests - encoded", () => { systemProps = testEnvironment.systemTestProperties; const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer - + testEnvironment.resources.session = REAL_SESSION; sleepJCL = JobTestsUtils.getSleepJCL(REAL_SESSION.ISession.user, ACCOUNT, systemProps.zosjobs.jobclass, maxStepNum, true); }); diff --git a/packages/zosjobs/__tests__/__system__/DeleteJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/DeleteJobs.system.test.ts index a12dc6957c..b0ba31d305 100644 --- a/packages/zosjobs/__tests__/__system__/DeleteJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/DeleteJobs.system.test.ts @@ -12,11 +12,11 @@ import { ImperativeError, Session } from "@zowe/imperative"; import { DeleteJobs, IJobFeedback, SubmitJobs } from "../../src"; import { IJob } from "../../src/doc/response/IJob"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Get } from "@zowe/zos-files-for-zowe-sdk"; import { JobTestsUtils } from "./JobTestsUtils"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let iefbr14JCL: string; @@ -34,6 +34,7 @@ describe("DeleteJobs System tests", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; const ACCOUNT = defaultSystem.tso.account; diff --git a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts index 3328b92644..db14f6f548 100644 --- a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts @@ -45,6 +45,8 @@ describe("Download Jobs - System tests", () => { testName: "zos_download_jobs" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; @@ -358,6 +360,7 @@ describe("Download Jobs - System tests - Encoded", () => { testName: "zos_download_jobs_encoded" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts index 5f5fb90a4d..c7d689a72b 100644 --- a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts @@ -64,6 +64,7 @@ describe("Get Jobs System Tests", () => { testName: "get_jobs_system_test" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; defaultSystem = testEnvironment.systemTestProperties; @@ -1018,6 +1019,8 @@ describe("Get Jobs System Tests", () => { testName: "zos_get_jobs_encoded" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + INVALID_SESSION = new Session({ user: "fakeuser", diff --git a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts index 6e352e63fb..00e1dcbc9c 100644 --- a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts @@ -33,6 +33,8 @@ describe("Modify Jobs - System Tests", () => { testName: "zos_modify_jobs" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobclass = testEnvironment.systemTestProperties.zosjobs.jobclass; @@ -106,6 +108,8 @@ describe("Modify Jobs - System Tests - Encoded", () => { testName: "zos_modify_jobs_encoded" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobclass = systemProps.zosjobs.jobclass; diff --git a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts index 5eca46bcf6..052b214930 100644 --- a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts @@ -74,6 +74,8 @@ describe("System Tests - Monitor Jobs", () => { testName: "zos_monitor_jobs" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 6; @@ -690,6 +692,8 @@ describe("System Tests - Monitor Jobs", () => { testName: "zos_monitor_jobs_encoded" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 5; diff --git a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts index e0bf9ddf9c..a7f7e60e6e 100644 --- a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts @@ -59,6 +59,7 @@ describe("Search Jobs - System Tests", () => { testName: "zos_search_jobs" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; defaultSystem = testEnvironment.systemTestProperties; INVALID_SESSION = new Session({ diff --git a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts index 1b3953fa74..b9c77df57b 100644 --- a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts @@ -37,6 +37,8 @@ describe("Submit Jobs - System Tests", () => { testName: "zos_submit_jobs" }); REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + systemProps = testEnvironment.systemTestProperties; account = systemProps.tso.account; jobDataSet = testEnvironment.systemTestProperties.zosjobs.iefbr14PSDataSet; From 3b008cb3b5d016559f2cdc70f0b5de438a58867a Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:22:37 -0400 Subject: [PATCH 50/65] review: update a few files based on comments :yum: Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../download/cli.zos-jobs.download.output.system.test.ts | 2 +- .../zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams diff --git a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts index 03e4dfa4b1..78f8dec5ee 100644 --- a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts @@ -86,7 +86,7 @@ describe("zos-jobs download output command", () => { testName: "zos_jobs_download_output_without_profiles" }); REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); - TEST_ENVIRONMENT.resources.session = REAL_SESSION; + TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams b/packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams new file mode 100644 index 0000000000..7cc9b7f813 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams @@ -0,0 +1 @@ +DELETE {{DSN}} CLUSTER \ No newline at end of file From 4a967097975c6f563f5eba299f70430c5ceac4d7 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:11:45 -0400 Subject: [PATCH 51/65] chore: address Zos limitation on dataset name length Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- __tests__/__src__/TestUtils.ts | 4 ++-- .../__system__/methods/invoke/Invoke.system.test.ts | 6 ++++++ .../__tests__/__system__/methods/list/List.system.test.ts | 6 +++--- .../zosjobs/__tests__/__system__/SearchJobs.system.test.ts | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/__tests__/__src__/TestUtils.ts b/__tests__/__src__/TestUtils.ts index 6f09a64877..9ffd278f44 100644 --- a/__tests__/__src__/TestUtils.ts +++ b/__tests__/__src__/TestUtils.ts @@ -111,14 +111,14 @@ export function stripNewLines(str: string): string { * @param {string} hlq User specified high level qualify * @returns {string} A generated data set name */ -export function getUniqueDatasetName(hlq: string, encoded = false): string { +export function getUniqueDatasetName(hlq: string, encoded = false, maxNodes = 2): string { let generatedName: string = ""; const randomNumber = Math.random(); const timestampInMsNum = Date.now(); let timestampInMs = Math.floor(randomNumber * timestampInMsNum).toString(); let tempStr: string; const MAX_NODE_LENGTH = 7; - let MAX_NODES = 2; + let MAX_NODES = maxNodes; let currNodes = 0; if (encoded) {MAX_NODES = 1;} diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts index 3efa954d9a..cd9767b888 100644 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts @@ -222,6 +222,12 @@ describe("Invoke AMS - encoded", () => { afterAll(async () => { await TestEnvironment.cleanUp(testEnvironment); + try { + fs.unlinkSync(__dirname + "/DefineVSAM.ams.temp"); + fs.unlinkSync(__dirname + "/DeleteVSAM.ams.temp"); + } catch (err) { + // do nothing + } }); function createTestAMSStatementFileFromTemplate(templateFile: string) { diff --git a/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts index a386bcf547..4cf39470de 100644 --- a/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts @@ -35,7 +35,7 @@ describe("List command group", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.LIST`); + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.LIST`, false, 1); Imperative.console.info("Using dsname:" + dsname); const user = `${defaultSystem.zosmf.user.trim()}`.replace(/\./g, ""); @@ -655,8 +655,8 @@ describe("List command group", () => { caughtError = error; } - expect(response).toBeDefined(); expect(caughtError).not.toBeDefined(); + expect(response).toBeDefined(); expect(response.commandResponse).toContain("There are no data sets that match"); }); }); @@ -993,8 +993,8 @@ describe("List command group - encoded", () => { caughtError = error; } - expect(response).toBeDefined(); expect(caughtError).not.toBeDefined(); + expect(response).toBeDefined(); expect(response.commandResponse).toContain("There are no data sets that match"); }); }); diff --git a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts index a7f7e60e6e..3438f7d222 100644 --- a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts @@ -110,7 +110,7 @@ describe("Search Jobs - System Tests", () => { it("should detect and surface an error for an invalid user", async () => { let err; try { - await SearchJobs.searchJobs(INVALID_SESSION,{jobName: "IBMUSER"}); + await SearchJobs.searchJobs(INVALID_SESSION,{jobName: "IBMUSER", searchString: "dummy"}); } catch (e) { err = e; } From 04b92c88288b9fc934355457338a9c3bd3d97e4e Mon Sep 17 00:00:00 2001 From: ATorrise Date: Mon, 30 Sep 2024 14:21:32 -0400 Subject: [PATCH 52/65] midway through editing file to utilize testResources Signed-off-by: ATorrise --- .../methods/download/Download.system.test.ts | 2284 ++++++++--------- 1 file changed, 1089 insertions(+), 1195 deletions(-) diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index bcdb01bc25..03888edf0e 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -52,971 +52,863 @@ let ussDirname: string; let localDirname: string; let file: string; -describe("Download Data Set", () => { +describe("Unencoded", () => { + describe("Download Data Sets", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); - Imperative.console.info("Using dsname:" + dsname); - - // using unique DS function to generate unique USS file name - ussname = `${defaultSystem.unix.testdir}/${dsname}`; - ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; - localDirname = `${testEnvironment.workingDir}/ussDir`; - - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(ussname, ussDirname); - }); - - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - - describe("Success Scenarios", () => { - - describe("Physical sequential data set", () => { - - beforeEach(async () => { - let error; - let response; - - try { - response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - }); - - afterEach(async () => { - let error; - let response; - - try { - response = await Delete.dataSet(REAL_SESSION, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - - // delete the top-level folder and the folders and file below - // variable 'file' should be set in the test - if (file != null) { - const folders = file.split("/"); - rimraf(folders[0]); - rimraf(file); - } - }); - - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set with response timeout", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname, {responseTimeout: 5}); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set and create folders and file in original letter case", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - - // Check if folders and file are created in original uppercase - file.split("/").reduce((path, pathSegment) => { - const pathExists = fs.readdirSync(path).indexOf(pathSegment) !== -1; - expect(pathExists).toBeTruthy(); - return [path, pathSegment].join("/"); - }, "."); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set in binary mode", async () => { - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = { - binary: true - }; - - try { - response = await Download.dataSet(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file for clean up in AfterEach - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - }); - - it("should download a data set in record mode", async () => { - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = { - record: true - }; - - try { - response = await Download.dataSet(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file for clean up in AfterEach - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - }); - - - it("should download a data set and return Etag", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); //wait 2 seconds - - const options: IDownloadOptions = { - returnEtag: true - }; - - try { - response = await Download.dataSet(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - expect(response.apiResponse.etag).toBeDefined(); - // convert the data set name to use as a path/file for clean up in AfterEach - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set that has been populated by upload and use file extension specified", async () => { - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = { - extension: "dat" - }; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".dat"; - file = file.toLowerCase(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set to a stream", async () => { - let error; - let response: IZosFilesResponse; - const responseStream = new PassThrough(); - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname, { stream: responseStream }); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(await text(responseStream)); - expect(fileContents).toEqual(testData); - }); - }); - - describe("Partitioned data set - all members", () => { - - beforeEach(async () => { - let error; - let response; - - try { - response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - }); - - afterEach(async () => { - let error; - let response; - - try { - response = await Delete.dataSet(REAL_SESSION, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - - // delete the top-level folder and the folders and file below - const folders = file.split("/"); - rimraf(folders[0]); - }); - - it("should download a data set member", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.allMembers(REAL_SESSION, dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/"); - file = file.toLowerCase(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set member with response timeout", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.allMembers(REAL_SESSION, dsname, {responseTimeout: 5}); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/"); - file = file.toLowerCase(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set and create folders and file in original letter case", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.allMembers(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + "/MEMBER.txt"; - - // Check if folders and file are created in original uppercase - file.split("/").reduce((path, pathSegment) => { - const pathExists = fs.readdirSync(path).indexOf(pathSegment) !== -1; - expect(pathExists).toBeTruthy(); - return [path, pathSegment].join("/"); - }, "."); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(file).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set in binary mode", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); //wait 2 seconds - - const options: IDownloadOptions = { - binary: true - }; - - try { - response = await Download.allMembers(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file for clean up in AfterEach - const regex = /\./gi; - file = dsname.replace(regex, "/") + "/member.txt"; - }); - - it("should download a data set in record mode", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); //wait 2 seconds - - const options: IDownloadOptions = { - record: true - }; - - try { - response = await Download.allMembers(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file for clean up in AfterEach - const regex = /\./gi; - file = dsname.replace(regex, "/") + "/member.txt"; - }); - - it("should download a data set and use file extension specified", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); //wait 2 seconds - - const options: IDownloadOptions = { - extension: "dat" - }; - - try { - response = await Download.allMembers(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file for clean up in AfterEach - const regex = /\./gi; - file = dsname.replace(regex, "/") + "/member.dat"; - }); - }); - - describe("Data sets matching - all data sets - PO", () => { - - beforeEach(async () => { - let error; - let response; - - try { - response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - }); - - afterEach(async () => { - let error; - let response; - - try { - response = await Delete.dataSet(REAL_SESSION, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - - // delete the top-level folder and the folders and file below - try { - const folders = file.split("/"); - rimraf(folders[0]); - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - }); - - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.toLowerCase().replace(regex, "/"); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set in binary mode", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - - const options: IDownloadOptions = { - binary: true, - extension: ".txt", - directory: "testDir" - }; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - // convert the data set name to use as a path/file for clean up in AfterEach - const regex = /\./gi; - file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; - }); - - it("should download a data set in record mode", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - - const options: IDownloadOptions = { - record: true, - extension: ".txt", - directory: "testDir" - }; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - // convert the data set name to use as a path/file for clean up in AfterEach - const regex = /\./gi; - file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; - }); - - it("should download a data set with a different extension", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extension: "jcl"}); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.toLowerCase().replace(regex, "/"); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.jcl`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set with an extension map", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - const ending = dsname.split(".").pop().toLowerCase(); - const extMap: any = {}; - extMap[ending] = "jcl"; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extensionMap: extMap}); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.toLowerCase().replace(regex, "/"); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.jcl`).toString()); - expect(fileContents).toEqual(testData); - }); - }); - - describe("Data sets matching - all data sets - PS", () => { - - beforeEach(async () => { - let error; - let response; - - try { - response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - }); - - afterEach(async () => { - let error; - let response; - - try { - response = await Delete.dataSet(REAL_SESSION, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - - // delete the top-level folder and the folders and file below - const folders = file.split("/"); - rimraf(folders[0]); - rimraf(file); - }); - - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.toLowerCase() + ".txt"; - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set in binary mode", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - - const options: IDownloadOptions = { - binary: true, - extension: ".txt", - directory: "testDir" - }; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - file = "testdir/" + dsname.toLowerCase() + ".txt"; - }); - - it("should download a data set in record mode", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - - const options: IDownloadOptions = { - record: true, - extension: ".txt", - directory: "testDir" - }; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - file = "testdir/" + dsname.toLowerCase() + ".txt"; - }); - - it("should download a data set with a different extension", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extension: "jcl"}); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - file = dsname.toLowerCase() + ".jcl"; - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download" }); + defaultSystem = testEnvironment.systemTestProperties; - it("should download a data set with an extension map", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - const ending = dsname.split(".").pop().toLowerCase(); - const extMap: any = {}; - extMap[ending] = "jcl"; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extensionMap: extMap}); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); + Imperative.console.info("Using dsname:" + dsname); - file = dsname.toLowerCase() + ".jcl"; - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); + testEnvironment.resources.datasets.push(dsname); }); - }); - describe("Failure Scenarios", () => { - afterAll(() => { - // delete the top-level folder and the folders and file below - const folders = dsname.split("."); - rimraf(folders[0].toLowerCase()); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); }); - describe("Physical sequential data set", () => { - - it("should display proper error message when missing session", async () => { - let response: IZosFilesResponse; - let error; + describe("Success Scenarios", () => { - try { - response = await Download.dataSet(undefined, dsname); - } catch (err) { - error = err; - } + describe("Physical sequential data set", () => { + + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; + + // Upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + try { + response = await Download.dataSet(REAL_SESSION, dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + + it("should download a data set with response timeout", async () => { + let error; + let response: IZosFilesResponse; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + try { + response = await Download.dataSet(REAL_SESSION, dsname, { responseTimeout: 5 }); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set and create folders and file in original letter case", async () => { + let error; + let response: IZosFilesResponse; + + // Upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + try { + response = await Download.dataSet(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + + // Check if folders and file are created in original uppercase + file.split("/").reduce((path, pathSegment) => { + const pathExists = fs.readdirSync(path).indexOf(pathSegment) !== -1; + expect(pathExists).toBeTruthy(); + return [path, pathSegment].join("/"); + }, "."); + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { + binary: true + }; + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + }); + it("should download a data set in record mode", async () => { + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { + record: true + }; + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file for cleanup + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + }); + + + + it("should download a data set and return Etag", async () => { + let error; + let response: IZosFilesResponse; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + const options: IDownloadOptions = { + returnEtag: true + }; + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + expect(response.apiResponse.etag).toBeDefined(); + + // Convert the data set name to use as a path/file for cleanup + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + it("should download a data set that has been populated by upload and use file extension specified", async () => { + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { + extension: "dat" + }; + + // Upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".dat"; + file = file.toLowerCase(); + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set to a stream", async () => { + let error; + let response: IZosFilesResponse; + const responseStream = new PassThrough(); + + // Upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + try { + response = await Download.dataSet(REAL_SESSION, dsname, { stream: responseStream }); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(await text(responseStream)); + expect(fileContents).toEqual(testData); + }); + }); + + describe("Partitioned data set - all members", () => { + + beforeEach(async () => { + try { + let response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + // Adding the dataset to resources for tracking and cleanup + testEnvironment.resources.datasets.push(dsname); + } catch (err) { + console.error("Setup error:", err); + } + }); + + afterEach(async () => { + // Trusting TestEnvironment.cleanUp() to handle all resource cleanups + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should download a data set member", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); //wait 2 seconds - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Required object must be defined"); + try { + response = await Download.allMembers(REAL_SESSION, dsname); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("Data set downloaded successfully"); + + // Path file construction and assertion + const regex = /\./gi; + const file = dsname.replace(regex, "/") + "/member.txt"; + testEnvironment.resources.localFiles.push(file); // Add file to resources for cleanup + + // Comparing the downloaded contents + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set and create folders and file in original letter case", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("Data set downloaded successfully"); + + const regex = /\./gi; + const file = dsname.replace(regex, "/") + "/MEMBER.txt"; + testEnvironment.resources.localFiles.push(file); + + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname, { binary: true }); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("Data set downloaded successfully"); + + const regex = /\./gi; + const file = dsname.replace(regex, "/") + "/member.txt"; + testEnvironment.resources.localFiles.push(file); + }); + + it("should download a data set in record mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname, { record: true }); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("Data set downloaded successfully"); + + const regex = /\./gi; + the file = dsname.replace(regex, "/") + "/member.txt"; + testEnvironment.resources.localFiles.push(file); + }); + + it("should download a data set and use file extension specified", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname, { extension: "dat" }); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("Data set downloaded successfully"); + + const regex = /\./gi; + const file = dsname.replace(regex, "/") + "/member.dat"; + testEnvironment.resources.localFiles.push(file); + }); + }); + + describe("Data sets matching - all data sets - PO", () => { + + beforeEach(async () => { + try { + let response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + testEnvironment.resources.datasets.push(dsname); // Tracking created dataset for cleanup + } catch (err) { + console.error("Setup error:", err); + } + }); + + afterEach(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should download a data set", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase().replace(regex, "/"); + testEnvironment.resources.localFiles.push(file + "/member.txt"); + + const fileContents = stripNewLines(fs.readFileSync(file + "/member.txt").toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + const options: IDownloadOptions = { + binary: true, + extension: ".txt", + directory: "testDir" + }; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; + testEnvironment.resources.localFiles.push(file); + }); + + it("should download a data set in record mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + const options: IDownloadOptions = { + record: true, + extension: ".txt", + directory: "testDir" + }; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; + testEnvironment.resources.localFiles.push(file); + }); + + it("should download a data set with a different extension", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extension: "jcl"}); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase().replace(regex, "/"); + testEnvironment.resources.localFiles.push(file + "/member.jcl"); + + const fileContents = stripNewLines(fs.readFileSync(file + "/member.jcl").toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set with an extension map", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + const ending = dsname.split(".").pop().toLowerCase(); + const extMap: any = {}; + extMap[ending] = "jcl"; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extensionMap: extMap}); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase().replace(regex, "/"); + testEnvironment.resources.localFiles.push(file + "/member.jcl"); + + const fileContents = stripNewLines(fs.readFileSync(file + "/member.jcl").toString()); + expect(fileContents).toEqual(testData); + }); + }); + + describe("Data sets matching - all data sets - PS", () => { + + beforeEach(async () => { + try { + let response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + testEnvironment.resources.datasets.push(dsname); // Tracking created dataset for cleanup + } catch (err) { + console.error("Setup error:", err); + } + }); + + afterEach(async () => { + // Utilizing TestEnvironment.cleanUp() for comprehensive cleanup + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should download a data set", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase() + ".txt"; + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + const options: IDownloadOptions = { + binary: true, + extension: ".txt", + directory: "testDir" + }; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = "testDir/" + dsname.toLowerCase() + ".txt"; + }); + + it("should download a data set in record mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + const options: IDownloadOptions = { + record: true, + extension: ".txt", + directory: "testDir" + }; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = "testDir/" + dsname.toLowerCase() + ".txt"; + }); + + it("should download a data set with a different extension", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extension: "jcl"}); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase() + ".jcl"; + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set with an extension map", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + const ending = dsname.split(".").pop().toLowerCase(); + const extMap: any = {}; + extMap[ending] = "jcl"; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extensionMap: extMap}); + console.info("Response:", response); + } catch (err) { + error = err; + console.error("Error:", error); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase() + ".jcl"; + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); + }); }); - it("should display proper message when downloading a data set that does not exist", async () => { - let response: IZosFilesResponse; - let error; - - try { - response = await Download.dataSet(REAL_SESSION, dsname); - } catch (err) { - error = err; - } + }); - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("Data set not found."); + describe("Failure Scenarios", () => { + afterAll(async () => { + // Utilizing TestEnvironment.cleanUp() for comprehensive cleanup + await TestEnvironment.cleanUp(testEnvironment); + }); + + describe("Physical sequential data set", () => { + + it("should display proper error message when missing session", async () => { + let response; + let error; + + try { + response = await Download.dataSet(undefined, dsname); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Required object must be defined"); + }); + + it("should display proper message when downloading a data set that does not exist", async () => { + let response; + let error; + + try { + response = await Download.dataSet(REAL_SESSION, dsname); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("Data set not found."); + }); + }); + + describe("Partitioned data set - all members", () => { + it("should display proper error message when missing session", async () => { + let response; + let error; + + try { + response = await Download.allMembers(undefined, dsname); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("Expect Error: Required object must be defined"); + }); + + it("should display a relevant message when downloading data set members and the data set does not exist", async () => { + let response; + let error; + + try { + response = await Download.allMembers(REAL_SESSION, dsname + ".d"); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("Data set not cataloged"); + }); }); }); + }); - describe("Partitioned data set - all members", () => { - it("should display proper error message when missing session", async () => { - let response: IZosFilesResponse; - let error; + /////STOPPED + describe("Download USS File", () => { + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download_uss" + }); + defaultSystem = testEnvironment.systemTestProperties; - try { - response = await Download.allMembers(undefined, dsname); - } catch (err) { - error = err; - } + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("Expect Error: Required object must be defined"); - }); + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD.USS`); + Imperative.console.info("Using dsname:" + dsname); - it("should display a relevant message when downloading data set members and the data set does not exist", async () => { - let response: IZosFilesResponse; - let error; + testEnvironment.resources.datasets.push(dsname); - try { - response = await Download.allMembers(REAL_SESSION, dsname + ".d"); - } catch (err) { - error = err; - } + // using unique DS function to generate unique USS file name + ussname = `${defaultSystem.unix.testdir}/${dsname}`; + ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; + localDirname = `${testEnvironment.workingDir}/ussDir`; - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("Data set not cataloged"); - }); + testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.files.push(ussname, ussDirname); }); - }); - describe("Download USS File", () => { afterAll(async () => { - // Delete created uss file - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - await wait(waitTime); //wait 2 seconds - } catch (err) { - Imperative.console.error(err); - } - - // Delete created local file - IO.deleteFile(`./${posix.basename(ussname)}`); + await TestEnvironment.cleanUp(testEnvironment); }); describe("Successful scenarios", () => { @@ -1301,7 +1193,6 @@ describe("Download Data Set", () => { }); }); }); - describe("Download USS Directory", () => { describe("Success Scenarios", () => { const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -1515,286 +1406,289 @@ describe("Download Data Set", () => { }); }); }); -}); - -describe("Download Data Set - encoded", () => { - - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); - Imperative.console.info("Using dsname:" + dsname); - - // using unique DS function to generate unique USS file name - ussname = `${defaultSystem.unix.testdir}/ENCO#ED${dsname}`; - ussDirname = `${defaultSystem.unix.testdir}/ENCO#EDzos_file_download`; - localDirname = `${testEnvironment.workingDir}/ENCO#EDussDir`; - - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(ussname, ussDirname); - }); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); +}) - describe("Success Scenarios", () => { +describe("Encoded", () => { + describe("Download Data Set - encoded", () => { - describe("Physical sequential data set", () => { - beforeEach(async () => { - let error; - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download" }); + defaultSystem = testEnvironment.systemTestProperties; - afterEach(async () => { - let error; - try { - await Delete.dataSet(REAL_SESSION, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - - // delete the top-level folder and the folders and file below - // variable 'file' should be set in the test - const folders = file.split("/"); - rimraf(folders[0]); - rimraf(file); - }); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); + Imperative.console.info("Using dsname:" + dsname); - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); //wait 2 seconds + // using unique DS function to generate unique USS file name + ussname = `${defaultSystem.unix.testdir}/ENCO#ED${dsname}`; + ussDirname = `${defaultSystem.unix.testdir}/ENCO#EDzos_file_download`; + localDirname = `${testEnvironment.workingDir}/ENCO#EDussDir`; - try { - response = await Download.dataSet(REAL_SESSION, dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); + testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.files.push(ussname, ussDirname); }); - describe("Partitioned data set - all members", () => { - beforeEach(async () => { - let error; - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - }); - - afterEach(async () => { - let error; - try { - await Delete.dataSet(REAL_SESSION, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - - // delete the top-level folder and the folders and file below - const folders = file.split("/"); - rimraf(folders[0]); - }); - - it("should download a data set member", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.allMembers(REAL_SESSION, dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/"); - file = file.toLowerCase(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); - expect(fileContents).toEqual(testData); - }); - + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); }); - describe("Data sets matching - all data sets - PO", () => { + describe("Success Scenarios", () => { - beforeEach(async () => { - let error; - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - }); + describe("Physical sequential data set", () => { + beforeEach(async () => { + let error; + try { + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + // Do nothing, sometimes the files are not created. + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + }); + + afterEach(async () => { + let error; + try { + await Delete.dataSet(REAL_SESSION, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + // Do nothing, sometimes the files are not created. + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + // delete the top-level folder and the folders and file below + // variable 'file' should be set in the test + const folders = file.split("/"); + rimraf(folders[0]); + rimraf(file); + }); - afterEach(async () => { - let error; + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; - try { - await Delete.dataSet(REAL_SESSION, dsname); + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - // delete the top-level folder and the folders and file below - try { + try { + response = await Download.dataSet(REAL_SESSION, dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + }); + + describe("Partitioned data set - all members", () => { + beforeEach(async () => { + let error; + try { + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + // Do nothing, sometimes the files are not created. + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + }); + + afterEach(async () => { + let error; + try { + await Delete.dataSet(REAL_SESSION, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + // Do nothing, sometimes the files are not created. + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + // delete the top-level folder and the folders and file below const folders = file.split("/"); rimraf(folders[0]); - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - }); - - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.toLowerCase().replace(regex, "/"); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); - expect(fileContents).toEqual(testData); - }); - - }); - - describe("Data sets matching - all data sets - PS", () => { + }); - beforeEach(async () => { - let error; - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - }); + it("should download a data set member", async () => { + let error; + let response: IZosFilesResponse; - afterEach(async () => { - let error; - try { - await Delete.dataSet(REAL_SESSION, dsname); + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - - // delete the top-level folder and the folders and file below - const folders = file.split("/"); - rimraf(folders[0]); - rimraf(file); - }); - - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + try { + response = await Download.allMembers(REAL_SESSION, dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/"); + file = file.toLowerCase(); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); + expect(fileContents).toEqual(testData); + }); + + }); + + describe("Data sets matching - all data sets - PO", () => { + + beforeEach(async () => { + let error; + try { + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + // Do nothing, sometimes the files are not created. + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + }); + + afterEach(async () => { + let error; + + try { + await Delete.dataSet(REAL_SESSION, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + // Do nothing, sometimes the files are not created. + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + // delete the top-level folder and the folders and file below + try { + const folders = file.split("/"); + rimraf(folders[0]); + } catch (err) { + // Do nothing, sometimes the files are not created. + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + }); + + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.toLowerCase().replace(regex, "/"); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); + expect(fileContents).toEqual(testData); + }); + + }); + + describe("Data sets matching - all data sets - PS", () => { + + beforeEach(async () => { + let error; + try { + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + // Do nothing, sometimes the files are not created. + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + }); + + afterEach(async () => { + let error; + try { + await Delete.dataSet(REAL_SESSION, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + // Do nothing, sometimes the files are not created. + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + // delete the top-level folder and the folders and file below + const folders = file.split("/"); + rimraf(folders[0]); + rimraf(file); + }); + + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + file = dsname.toLowerCase() + ".txt"; + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); - file = dsname.toLowerCase() + ".txt"; - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); }); - }); }); - describe("Download USS File", () => { + describe("Download USS File - encoded", () => { afterAll(async () => { // Delete created uss file const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); @@ -1862,7 +1756,7 @@ describe("Download Data Set - encoded", () => { }); - describe("Download USS Directory", () => { + describe("Download USS Directory - encoded", () => { describe("Success Scenarios", () => { const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const anotherTestFileContents = testFileContents.toLowerCase(); @@ -2030,4 +1924,4 @@ describe("Download Data Set - encoded", () => { }); }); -}); \ No newline at end of file +}) \ No newline at end of file From 5f1d974b94a7b188551c35c1c06ccb43b7d43442 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Tue, 1 Oct 2024 14:28:22 -0400 Subject: [PATCH 53/65] midway changes.. tests failing Signed-off-by: ATorrise --- .../methods/download/Download.system.test.ts | 3013 ++++++++--------- 1 file changed, 1455 insertions(+), 1558 deletions(-) diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index 03888edf0e..64e9050b51 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -19,7 +19,6 @@ import { IZosFilesResponse, Tag, Utilities, - ZosFilesConstants, ZosFilesMessages, ICreateZfsOptions, IMountFsOptions, @@ -27,20 +26,17 @@ import { Unmount, IUSSListOptions } from "../../../../src"; -import { Imperative, IO, Session } from "@zowe/imperative"; -import { inspect } from "util"; +import { IO, Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName, stripNewLines, wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import * as fs from "fs"; import { posix } from "path"; import { Shell } from "@zowe/zos-uss-for-zowe-sdk"; import { PassThrough } from "stream"; import { text } from "stream/consumers"; -const rimraf = require("rimraf").sync; const testData = "abcdefghijklmnopqrstuvwxyz"; let REAL_SESSION: Session; @@ -52,1876 +48,1777 @@ let ussDirname: string; let localDirname: string; let file: string; -describe("Unencoded", () => { - describe("Download Data Sets", () => { +describe("All Download System Tests", () => { + describe("Unencoded", () => { + describe("Download Data Sets", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download" - }); - defaultSystem = testEnvironment.systemTestProperties; + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download" + }); + defaultSystem = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); - Imperative.console.info("Using dsname:" + dsname); + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); + }); - testEnvironment.resources.datasets.push(dsname); - }); + afterAll(async () => { + testEnvironment.resources.datasets.push(dsname); + await TestEnvironment.cleanUp(testEnvironment); + }); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); + describe("Success Scenarios", () => { + + describe("Physical sequential data set", () => { + + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; + + // Upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + try { + response = await Download.dataSet(REAL_SESSION, dsname); + await wait(waitTime); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + + it("should download a data set with response timeout", async () => { + let error; + let response: IZosFilesResponse; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + try { + response = await Download.dataSet(REAL_SESSION, dsname, { responseTimeout: 5 }); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set and create folders and file in original letter case", async () => { + let error; + let response: IZosFilesResponse; + + // Upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + try { + response = await Download.dataSet(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + + // Check if folders and file are created in original uppercase + file.split("/").reduce((path, pathSegment) => { + const pathExists = fs.readdirSync(path).indexOf(pathSegment) !== -1; + expect(pathExists).toBeTruthy(); + return [path, pathSegment].join("/"); + }, "."); + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { + binary: true + }; + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + }); + it("should download a data set in record mode", async () => { + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { + record: true + }; + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file for cleanup + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + }); + + it("should download a data set and return Etag", async () => { + let error; + let response: IZosFilesResponse; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + const options: IDownloadOptions = { + returnEtag: true + }; + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + } catch (err) { + error = err; + } + + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + expect(response.apiResponse.etag).toBeDefined(); + + // Convert the data set name to use as a path/file for cleanup + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + it("should download a data set that has been populated by upload and use file extension specified", async () => { + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { + extension: "dat" + }; + + // Upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".dat"; + file = file.toLowerCase(); + + // Add the file to localFiles resources for cleanup + testEnvironment.resources.localFiles.push(file); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set to a stream", async () => { + let error; + let response: IZosFilesResponse; + const responseStream = new PassThrough(); + + // Upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); // Wait 2 seconds + + try { + response = await Download.dataSet(REAL_SESSION, dsname, { stream: responseStream }); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) + ); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(await text(responseStream)); + expect(fileContents).toEqual(testData); + }); + }); - describe("Success Scenarios", () => { + describe("Partitioned data set - all members", () => { + + beforeEach(async () => { + let error; + try { + const response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + // Adding the dataset to resources for tracking and cleanup + testEnvironment.resources.datasets.push(dsname); + } catch (err) { + error = err; } + }); + + afterEach(async () => { + // Trusting TestEnvironment.cleanUp() to handle all resource cleanups + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should download a data set member", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); //wait 2 seconds - describe("Physical sequential data set", () => { + try { + response = await Download.allMembers(REAL_SESSION, dsname); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("Data set downloaded successfully"); + + // Path file construction and assertion + const regex = /\./gi; + const file = dsname.replace(regex, "/") + "/member.txt"; + testEnvironment.resources.localFiles.push(file); // Add file to resources for cleanup + + // Comparing the downloaded contents + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set and create folders and file in original letter case", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("Data set downloaded successfully"); + + const regex = /\./gi; + const file = dsname.replace(regex, "/") + "/MEMBER.txt"; + testEnvironment.resources.localFiles.push(file); + + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname, { binary: true }); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("Data set downloaded successfully"); + + const regex = /\./gi; + const file = dsname.replace(regex, "/") + "/member.txt"; + testEnvironment.resources.localFiles.push(file); + }); + + it("should download a data set in record mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname, { record: true }); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("Data set downloaded successfully"); + + const regex = /\./gi; + file = dsname.replace(regex, "/") + "/member.txt"; + testEnvironment.resources.localFiles.push(file); + }); + + it("should download a data set and use file extension specified", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname, { extension: "dat" }); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("Data set downloaded successfully"); + + const regex = /\./gi; + const file = dsname.replace(regex, "/") + "/member.dat"; + testEnvironment.resources.localFiles.push(file); + }); + }); - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; + describe("Data sets matching - all data sets - PO", () => { + + beforeEach(async () => { + let error; + try { + const response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + testEnvironment.resources.datasets.push(dsname); // Tracking created dataset for cleanup + } catch (err) { + error = err; + } + }); + + afterEach(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should download a data set", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase().replace(regex, "/"); + testEnvironment.resources.localFiles.push(file + "/member.txt"); + + const fileContents = stripNewLines(fs.readFileSync(file + "/member.txt").toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + const options: IDownloadOptions = { + binary: true, + extension: ".txt", + directory: "testDir" + }; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; + testEnvironment.resources.localFiles.push(file); + }); + + it("should download a data set in record mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + const options: IDownloadOptions = { + record: true, + extension: ".txt", + directory: "testDir" + }; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; + testEnvironment.resources.localFiles.push(file); + }); + + it("should download a data set with a different extension", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extension: "jcl"}); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase().replace(regex, "/"); + testEnvironment.resources.localFiles.push(file + "/member.jcl"); + + const fileContents = stripNewLines(fs.readFileSync(file + "/member.jcl").toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set with an extension map", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + const ending = dsname.split(".").pop().toLowerCase(); + const extMap: any = {}; + extMap[ending] = "jcl"; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extensionMap: extMap}); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase().replace(regex, "/"); + testEnvironment.resources.localFiles.push(file + "/member.jcl"); + + const fileContents = stripNewLines(fs.readFileSync(file + "/member.jcl").toString()); + expect(fileContents).toEqual(testData); + }); + }); - // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); // Wait 2 seconds + describe("Data sets matching - all data sets - PS", () => { + + beforeEach(async () => { + let error; + try { + const response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + testEnvironment.resources.datasets.push(dsname); // Tracking created dataset for cleanup + } catch (err) { + error = err; + } + }); + + afterEach(async () => { + // Utilizing TestEnvironment.cleanUp() for comprehensive cleanup + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should download a data set", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase() + ".txt"; + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + const options: IDownloadOptions = { + binary: true, + extension: ".txt", + directory: "testDir" + }; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = "testDir/" + dsname.toLowerCase() + ".txt"; + }); + + it("should download a data set in record mode", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + const options: IDownloadOptions = { + record: true, + extension: ".txt", + directory: "testDir" + }; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = "testDir/" + dsname.toLowerCase() + ".txt"; + }); + + it("should download a data set with a different extension", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extension: "jcl"}); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase() + ".jcl"; + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set with an extension map", async () => { + let error; + let response; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + const ending = dsname.split(".").pop().toLowerCase(); + const extMap: any = {}; + extMap[ending] = "jcl"; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extensionMap: extMap}); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + const regex = /\./gi; + const file = dsname.toLowerCase() + ".jcl"; + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); + }); + }); - try { - response = await Download.dataSet(REAL_SESSION, dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); + }); - // Convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); + describe("Failure Scenarios", () => { + afterAll(async () => { + // Utilizing TestEnvironment.cleanUp() for comprehensive cleanup + await TestEnvironment.cleanUp(testEnvironment); + }); - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); + describe("Physical sequential data set", () => { + + it("should display proper error message when missing session", async () => { + let response; + let error; + + try { + response = await Download.dataSet(undefined, dsname); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Required object must be defined"); + }); + + it("should display proper message when downloading a data set that does not exist", async () => { + let response; + let error; + + try { + response = await Download.dataSet(REAL_SESSION, dsname); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("Data set not found."); + }); + }); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); + describe("Partitioned data set - all members", () => { + it("should display proper error message when missing session", async () => { + let response; + let error; + + try { + response = await Download.allMembers(undefined, dsname); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("Expect Error: Required object must be defined"); + }); + + it("should display a relevant message when downloading data set members and the data set does not exist", async () => { + let response; + let error; + + try { + response = await Download.allMembers(REAL_SESSION, dsname + ".d"); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("Data set not cataloged"); + }); }); + }); + }); + describe("Download USS File", () => { + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download_uss" + }); + defaultSystem = testEnvironment.systemTestProperties; - it("should download a data set with response timeout", async () => { - let error; - let response: IZosFilesResponse; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); // Wait 2 seconds + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD.USS`); - try { - response = await Download.dataSet(REAL_SESSION, dsname, { responseTimeout: 5 }); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); + testEnvironment.resources.datasets.push(dsname); - // Convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); + // using unique DS function to generate unique USS file name + ussname = `${defaultSystem.unix.testdir}/${dsname}`; + ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; + localDirname = `${testEnvironment.workingDir}/ussDir`; - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); + // Track local and USS files for cleanup + testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.files.push(ussname, ussDirname); + }); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - it("should download a data set and create folders and file in original letter case", async () => { + describe("Successful scenarios", () => { + it("should download uss file without any options", async () => { let error; let response: IZosFilesResponse; - // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); // Wait 2 seconds + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(waitTime); //wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); - Imperative.console.info("Response: " + inspect(response)); + response = await Download.ussFile(REAL_SESSION, ussname); } catch (err) { error = err; - Imperative.console.info("Error: " + inspect(error)); } expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - - // Convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - - // Check if folders and file are created in original uppercase - file.split("/").reduce((path, pathSegment) => { - const pathExists = fs.readdirSync(path).indexOf(pathSegment) !== -1; - expect(pathExists).toBeTruthy(); - return [path, pathSegment].join("/"); - }, "."); - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); expect(fileContents).toEqual(testData); }); - it("should download a data set in binary mode", async () => { + it("should download uss file with response timeout", async () => { let error; let response: IZosFilesResponse; - const options: IDownloadOptions = { - binary: true - }; + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(waitTime); //wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); + response = await Download.ussFile(REAL_SESSION, ussname, { responseTimeout: 5 }); } catch (err) { error = err; - Imperative.console.info("Error: " + inspect(error)); } expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - // Convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(testData); }); - it("should download a data set in record mode", async () => { + + it("should download uss file and return Etag", async () => { let error; let response: IZosFilesResponse; + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(waitTime); //wait 2 seconds + const options: IDownloadOptions = { - record: true + returnEtag: true }; try { - response = await Download.dataSet(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); + response = await Download.ussFile(REAL_SESSION, ussname, options); } catch (err) { error = err; - Imperative.console.info("Error: " + inspect(error)); } expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - - // Convert the data set name to use as a path/file for cleanup - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; + expect(response.apiResponse.etag).toBeDefined(); - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(testData); }); - - - it("should download a data set and return Etag", async () => { + // When requesting etag, z/OSMF has a limit on file size when it stops to return etag by default (>8mb) + // We are passing X-IBM-Return-Etag to force z/OSMF to always return etag, but testing here for case where it would be optional + it("should download a 10mb uss file and return Etag", async () => { let error; let response: IZosFilesResponse; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); // Wait 2 seconds + // Create a 10 mb buffer + const bufferSize = 10000000; + const buffer = new ArrayBuffer(bufferSize); + const data = Buffer.from(buffer); + + await Upload.bufferToUssFile(REAL_SESSION, ussname, data); + await wait(waitTime); //wait 2 seconds const options: IDownloadOptions = { returnEtag: true }; try { - response = await Download.dataSet(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); + response = await Download.ussFile(REAL_SESSION, ussname, options); } catch (err) { error = err; - Imperative.console.info("Error: " + inspect(error)); } - expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); expect(response.apiResponse.etag).toBeDefined(); - - // Convert the data set name to use as a path/file for cleanup - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); }); - it("should download a data set that has been populated by upload and use file extension specified", async () => { + + it("should download uss file content in binary", async () => { let error; let response: IZosFilesResponse; const options: IDownloadOptions = { - extension: "dat" + binary: true }; - // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); // Wait 2 seconds + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData), { binary: true }); + await wait(waitTime); //wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname, options); - Imperative.console.info("Response: " + inspect(response)); + response = await Download.ussFile(REAL_SESSION, ussname, options); } catch (err) { error = err; - Imperative.console.info("Error: " + inspect(error)); } + expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - - // Convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".dat"; - file = file.toLowerCase(); - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); expect(fileContents).toEqual(testData); }); - it("should download a data set to a stream", async () => { + it("should download ISO8859-1 uss file in binary mode", async () => { let error; let response: IZosFilesResponse; - const responseStream = new PassThrough(); + const options: IDownloadOptions = {}; - // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); // Wait 2 seconds + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData), { binary: true }); + await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "ISO8859-1"); + await wait(waitTime); //wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname, { stream: responseStream }); - Imperative.console.info("Response: " + inspect(response)); + response = await Download.ussFile(REAL_SESSION, ussname, options); } catch (err) { error = err; - Imperative.console.info("Error: " + inspect(error)); } + expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(await text(responseStream)); + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); expect(fileContents).toEqual(testData); }); - }); - - describe("Partitioned data set - all members", () => { - - beforeEach(async () => { - try { - let response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - // Adding the dataset to resources for tracking and cleanup - testEnvironment.resources.datasets.push(dsname); - } catch (err) { - console.error("Setup error:", err); - } - }); - - afterEach(async () => { - // Trusting TestEnvironment.cleanUp() to handle all resource cleanups - await TestEnvironment.cleanUp(testEnvironment); - }); - it("should download a data set member", async () => { + it("should download IBM-1147 uss file with encoding mode", async () => { let error; let response: IZosFilesResponse; + const options: IDownloadOptions = {}; - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + const data: string = "Hello, world¤"; + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); + await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "IBM-1147"); await wait(waitTime); //wait 2 seconds try { - response = await Download.allMembers(REAL_SESSION, dsname); - console.info("Response:", response); + response = await Download.ussFile(REAL_SESSION, ussname, options); } catch (err) { error = err; - console.error("Error:", error); } + expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("Data set downloaded successfully"); - - // Path file construction and assertion - const regex = /\./gi; - const file = dsname.replace(regex, "/") + "/member.txt"; - testEnvironment.resources.localFiles.push(file); // Add file to resources for cleanup - // Comparing the downloaded contents - const fileContents = stripNewLines(fs.readFileSync(file).toString()); - expect(fileContents).toEqual(testData); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(data.slice(0, -1) + "€"); }); - it("should download a data set and create folders and file in original letter case", async () => { + it("should download uss file content to local file", async () => { let error; - let response; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { file: `test1.txt` }; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(waitTime); //wait 2 seconds try { - response = await Download.allMembers(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); - console.info("Response:", response); + response = await Download.ussFile(REAL_SESSION, ussname, options); } catch (err) { error = err; - console.error("Error:", error); } expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("Data set downloaded successfully"); - - const regex = /\./gi; - const file = dsname.replace(regex, "/") + "/MEMBER.txt"; - testEnvironment.resources.localFiles.push(file); - const fileContents = stripNewLines(fs.readFileSync(file).toString()); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`test1.txt`).toString()); expect(fileContents).toEqual(testData); + + // Delete created local file + IO.deleteFile("test1.txt"); }); - it("should download a data set in binary mode", async () => { + it("should download uss file to a stream", async () => { let error; - let response; + let response: IZosFilesResponse; + const responseStream = new PassThrough(); - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(waitTime); //wait 2 seconds try { - response = await Download.allMembers(REAL_SESSION, dsname, { binary: true }); - console.info("Response:", response); + response = await Download.ussFile(REAL_SESSION, ussname, { stream: responseStream }); } catch (err) { error = err; - console.error("Error:", error); } + expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("Data set downloaded successfully"); - const regex = /\./gi; - const file = dsname.replace(regex, "/") + "/member.txt"; - testEnvironment.resources.localFiles.push(file); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(await text(responseStream)); + expect(fileContents).toEqual(testData); }); + }); - it("should download a data set in record mode", async () => { + describe("Failure scenarios", () => { + it("should display proper error message when missing session", async () => { + let response: IZosFilesResponse; let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); try { - response = await Download.allMembers(REAL_SESSION, dsname, { record: true }); - console.info("Response:", response); + response = await Download.ussFile(undefined, ussname); } catch (err) { error = err; - console.error("Error:", error); } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("Data set downloaded successfully"); - const regex = /\./gi; - the file = dsname.replace(regex, "/") + "/member.txt"; - testEnvironment.resources.localFiles.push(file); + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Required object must be defined"); }); - it("should download a data set and use file extension specified", async () => { + it("should display proper error message when missing uss file name", async () => { + let response: IZosFilesResponse; let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); try { - response = await Download.allMembers(REAL_SESSION, dsname, { extension: "dat" }); - console.info("Response:", response); + response = await Download.ussFile(REAL_SESSION, undefined); } catch (err) { error = err; - console.error("Error:", error); } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("Data set downloaded successfully"); - const regex = /\./gi; - const file = dsname.replace(regex, "/") + "/member.dat"; - testEnvironment.resources.localFiles.push(file); + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Specify the USS file name."); }); - }); - describe("Data sets matching - all data sets - PO", () => { + it("should display proper error message when uss file name is empty string", async () => { + let response: IZosFilesResponse; + let error; - beforeEach(async () => { try { - let response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - testEnvironment.resources.datasets.push(dsname); // Tracking created dataset for cleanup + response = await Download.ussFile(REAL_SESSION, ""); } catch (err) { - console.error("Setup error:", err); + error = err; } - }); - afterEach(async () => { - await TestEnvironment.cleanUp(testEnvironment); + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Specify the USS file name."); }); - it("should download a data set", async () => { + it("should display proper error message when uss file data type is record", async () => { + let response: IZosFilesResponse; let error; - let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + const options: IDownloadOptions = {file: `test1.txt`, record: true}; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); - console.info("Response:", response); + response = await Download.ussFile(REAL_SESSION, ussname, options); } catch (err) { error = err; - console.error("Error:", error); } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = dsname.toLowerCase().replace(regex, "/"); - testEnvironment.resources.localFiles.push(file + "/member.txt"); - const fileContents = stripNewLines(fs.readFileSync(file + "/member.txt").toString()); - expect(fileContents).toEqual(testData); + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Unsupported data type 'record' specified for USS file operation."); }); + }); + }); - it("should download a data set in binary mode", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + describe("Download USS Directory", () => { + describe("Success Scenarios", () => { + const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + const anotherTestFileContents = testFileContents.toLowerCase(); + const binaryFileContents = String.fromCharCode(...Array(256).keys()); + const createZfsOptions: ICreateZfsOptions = { + perms: 755, + cylsPri: 10, + cylsSec: 2, + timeout: 20 + }; + const mountZfsOptions: IMountFsOptions = { + "fs-type": "ZFS", + mode: "rdwr" + }; + let zfsName: string; + + const expectDownloaded = (dirname: string, options: IUSSListOptions = {}) => { + expect(fs.existsSync(`${dirname}/emptyFolder`)).toBe(true); + expect(fs.readdirSync(`${dirname}/emptyFolder`).length).toBe(0); + expect(fs.existsSync(`${dirname}/parentFolder`)).toBe(true); + expect(fs.readFileSync(`${dirname}/testFile.txt`, "utf-8")).toBe(testFileContents); + + // Test depth option + const depth = options.depth || 0; + expect(fs.existsSync(`${dirname}/parentFolder/childFolder`)).toBe(depth !== 1); + if (depth !== 1) { + expect(fs.readFileSync(`${dirname}/parentFolder/childFolder/anotherTestFile.txt`, "utf-8")).toBe(anotherTestFileContents); + } - const options: IDownloadOptions = { - binary: true, - extension: ".txt", - directory: "testDir" - }; + // Test filesys option + const filesys = options.filesys || false; + expect(fs.existsSync(`${dirname}/mountFolder`)).toBe(filesys); + if (filesys) { + expect(fs.readFileSync(`${dirname}/mountFolder/binaryFile.bin`, "utf-8")).toBe(binaryFileContents); + } - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); - console.info("Response:", response); - } catch (err) { - error = err; - console.error("Error:", error); + // Test symlinks option + const symlinks = options.symlinks || false; + expect(fs.existsSync(`${dirname}/testFile.lnk`)).toBe(!symlinks); + if (!symlinks) { + expect(fs.readFileSync(`${dirname}/testFile.lnk`, "utf-8")).toBe(testFileContents); } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + }; - const regex = /\./gi; - const file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; - testEnvironment.resources.localFiles.push(file); - }); + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download_uss_directory" + }); + defaultSystem = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + + ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; + localDirname = `${testEnvironment.workingDir}/ussDir`; + + testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.files.push(ussDirname); + + const emptyFolder = posix.join(ussDirname, "emptyFolder"); + const parentFolder = posix.join(ussDirname, "parentFolder"); + const childFolder = posix.join(parentFolder, "childFolder"); + const testFile = posix.join(ussDirname, "testFile.txt"); + const anotherTestFile = posix.join(childFolder, "anotherTestFile.txt"); + const mountFolder = posix.join(ussDirname, "mountFolder"); + const binaryFile = posix.join(mountFolder, "binaryFile.bin"); + const testSymlink = posix.join(ussDirname, "testFile.lnk"); + + // Create directories + for (const directory of [ussDirname, emptyFolder, parentFolder, childFolder, mountFolder]) { + await Create.uss(REAL_SESSION, directory, "directory"); + } - it("should download a data set in record mode", async () => { - let error; - let response; + // Create and mount file system + zfsName = getUniqueDatasetName(defaultSystem.zosmf.user); + await Create.zfs(REAL_SESSION, zfsName, createZfsOptions); + await Mount.fs(REAL_SESSION, zfsName, mountFolder, mountZfsOptions); + testEnvironment.resources.datasets.push(zfsName); - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + // Upload files + await Upload.bufferToUssFile(REAL_SESSION, testFile, Buffer.from(testFileContents)); + await Upload.bufferToUssFile(REAL_SESSION, anotherTestFile, Buffer.from(anotherTestFileContents)); + await Upload.bufferToUssFile(REAL_SESSION, binaryFile, Buffer.from(binaryFileContents), { binary: true }); + await Utilities.chtag(REAL_SESSION, binaryFile, Tag.BINARY); - const options: IDownloadOptions = { - record: true, - extension: ".txt", - directory: "testDir" - }; + // Create symlink + const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); + await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); - console.info("Response:", response); - } catch (err) { - error = err; - console.error("Error:", error); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + testEnvironment.resources.files.push(testSymlink); + }); - const regex = /\./gi; - const file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; - testEnvironment.resources.localFiles.push(file); + afterEach(() => { + IO.deleteDirTree(localDirname); }); - it("should download a data set with a different extension", async () => { - let error; - let response; + afterAll(async () => { + // Unmount and delete file system + await Unmount.fs(REAL_SESSION, zfsName); + await Delete.zfs(REAL_SESSION, zfsName); - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + // Delete directory recursively + const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); + await Shell.executeSshCwd(SSH_SESSION, `rm testFile.lnk`, ussDirname, jest.fn()); + await Delete.ussFile(REAL_SESSION, ussDirname, true); + + await TestEnvironment.cleanUp(testEnvironment); + }); + it("should download directory recursively", async () => { + let caughtError; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extension: "jcl"}); - console.info("Response:", response); - } catch (err) { - error = err; - console.error("Error:", error); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); + } catch (error) { + caughtError = error; } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = dsname.toLowerCase().replace(regex, "/"); - testEnvironment.resources.localFiles.push(file + "/member.jcl"); - - const fileContents = stripNewLines(fs.readFileSync(file + "/member.jcl").toString()); - expect(fileContents).toEqual(testData); + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname); }); - it("should download a data set with an extension map", async () => { - let error; - let response; + it("should download directory with depth of 1", async () => { + const listOptions: IUSSListOptions = { depth: 1 }; + let caughtError; + try { + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname, listOptions); + }); - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - const ending = dsname.split(".").pop().toLowerCase(); - const extMap: any = {}; - extMap[ending] = "jcl"; + it("should download directory including all filesystems", async () => { + const listOptions: IUSSListOptions = { filesys: true }; + let caughtError; + try { + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname, listOptions); + }); + it("should download directory excluding symlinks", async () => { + const listOptions: IUSSListOptions = { symlinks: true }; + let caughtError; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extensionMap: extMap}); - console.info("Response:", response); - } catch (err) { - error = err; - console.error("Error:", error); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); + } catch (error) { + caughtError = error; } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname, listOptions); + }); - const regex = /\./gi; - const file = dsname.toLowerCase().replace(regex, "/"); - testEnvironment.resources.localFiles.push(file + "/member.jcl"); + it("should not download files that already exist", async () => { + let caughtError; + const testFile = posix.join(localDirname, "testFile.txt"); + try { + fs.mkdirSync(localDirname); + fs.writeFileSync(testFile, "test"); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + expect(fs.readFileSync(testFile).toString()).toEqual("test"); + }); - const fileContents = stripNewLines(fs.readFileSync(file + "/member.jcl").toString()); - expect(fileContents).toEqual(testData); + it("should download files that already exist when overwrite is true", async () => { + let caughtError; + const testFile = posix.join(localDirname, "testFile.txt"); + try { + fs.mkdirSync(localDirname); + fs.writeFileSync(testFile, "test"); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname, overwrite: true }); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + expect(fs.readFileSync(testFile).toString()).toEqual(testFileContents); }); }); - describe("Data sets matching - all data sets - PS", () => { - - beforeEach(async () => { + describe("Failure Scenarios", () => { + it("should throw error when session is undefined", async () => { + let caughtError; try { - let response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - testEnvironment.resources.datasets.push(dsname); // Tracking created dataset for cleanup - } catch (err) { - console.error("Setup error:", err); + await Download.ussDir(undefined, ussDirname); + } catch (error) { + caughtError = error; } + expect(caughtError).toBeDefined(); + expect(caughtError.message).toBe("Expect Error: Required object must be defined"); }); - afterEach(async () => { - // Utilizing TestEnvironment.cleanUp() for comprehensive cleanup - await TestEnvironment.cleanUp(testEnvironment); + it("should throw error when USS dir name is undefined", async () => { + let caughtError; + try { + await Download.ussDir(REAL_SESSION, undefined); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeDefined(); + expect(caughtError.message).toBe("Expect Error: Specify the USS directory name."); }); - it("should download a data set", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + it("should throw error when USS dir name is empty string", async () => { + let caughtError; + try { + await Download.ussDir(REAL_SESSION, ""); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeDefined(); + expect(caughtError.message).toBe("Expect Error: Specify the USS directory name."); + }); + it("should fail to download directory that does not exist", async () => { + let caughtError; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); - console.info("Response:", response); - } catch (err) { - error = err; - console.error("Error:", error); + await Download.ussDir(REAL_SESSION, posix.join(ussDirname, "invalidDir"), { directory: testEnvironment.workingDir }); + } catch (error) { + caughtError = error; } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + expect(caughtError).toBeDefined(); + expect(stripNewLines(caughtError.message)).toContain("Path name not found"); + }); + }); + }); + }); - const regex = /\./gi; - const file = dsname.toLowerCase() + ".txt"; - const fileContents = stripNewLines(fs.readFileSync(file).toString()); - expect(fileContents).toEqual(testData); + describe("Encoded", () => { + describe("Download Data Set - encoded", () => { + + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download_encoded" }); + defaultSystem = testEnvironment.systemTestProperties; - it("should download a data set in binary mode", async () => { - let error; - let response; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); - const options: IDownloadOptions = { - binary: true, - extension: ".txt", - directory: "testDir" - }; + // using unique DS function to generate unique USS file name + ussname = `${defaultSystem.unix.testdir}/ENCO#ED${dsname}`; + ussDirname = `${defaultSystem.unix.testdir}/ENCO#EDzos_file_download`; + localDirname = `${testEnvironment.workingDir}/ENCO#EDussDir`; - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); - console.info("Response:", response); - } catch (err) { - error = err; - console.error("Error:", error); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.files.push(ussname, ussDirname); + }); - const regex = /\./gi; - const file = "testDir/" + dsname.toLowerCase() + ".txt"; - }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - it("should download a data set in record mode", async () => { - let error; - let response; + describe("Success Scenarios", () => { + + describe("Physical sequential data set", () => { + beforeEach(async () => { + let error; + try { + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + error = err; + } + testEnvironment.resources.datasets.push(dsname); + }); - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + afterEach(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - const options: IDownloadOptions = { - record: true, - extension: ".txt", - directory: "testDir" - }; + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); - console.info("Response:", response); - } catch (err) { - error = err; - console.error("Error:", error); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(waitTime); //wait 2 seconds - const regex = /\./gi; - const file = "testDir/" + dsname.toLowerCase() + ".txt"; + try { + response = await Download.dataSet(REAL_SESSION, dsname); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); }); - it("should download a data set with a different extension", async () => { - let error; - let response; + describe("Partitioned data set - all members", () => { + beforeEach(async () => { + let error; + try { + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + error = err; + } + testEnvironment.resources.datasets.push(dsname); + }); - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + afterEach(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extension: "jcl"}); - console.info("Response:", response); - } catch (err) { - error = err; - console.error("Error:", error); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = dsname.toLowerCase() + ".jcl"; - const fileContents = stripNewLines(fs.readFileSync(file).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set with an extension map", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - const ending = dsname.split(".").pop().toLowerCase(); - const extMap: any = {}; - extMap[ending] = "jcl"; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extensionMap: extMap}); - console.info("Response:", response); - } catch (err) { - error = err; - console.error("Error:", error); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + it("should download a data set member", async () => { + let error; + let response: IZosFilesResponse; - const regex = /\./gi; - const file = dsname.toLowerCase() + ".jcl"; - const fileContents = stripNewLines(fs.readFileSync(file).toString()); - expect(fileContents).toEqual(testData); - }); - }); - - }); - - describe("Failure Scenarios", () => { - afterAll(async () => { - // Utilizing TestEnvironment.cleanUp() for comprehensive cleanup - await TestEnvironment.cleanUp(testEnvironment); - }); - - describe("Physical sequential data set", () => { - - it("should display proper error message when missing session", async () => { - let response; - let error; - - try { - response = await Download.dataSet(undefined, dsname); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Required object must be defined"); - }); - - it("should display proper message when downloading a data set that does not exist", async () => { - let response; - let error; - - try { - response = await Download.dataSet(REAL_SESSION, dsname); - } catch (err) { - error = err; - } + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(waitTime); //wait 2 seconds - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("Data set not found."); + try { + response = await Download.allMembers(REAL_SESSION, dsname); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/"); + file = file.toLowerCase(); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); + expect(fileContents).toEqual(testData); + }); }); - }); - describe("Partitioned data set - all members", () => { - it("should display proper error message when missing session", async () => { - let response; - let error; - - try { - response = await Download.allMembers(undefined, dsname); - } catch (err) { - error = err; - } + describe("Data sets matching - all data sets - PO", () => { - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("Expect Error: Required object must be defined"); + beforeEach(async () => { + let error; + try { + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + error = err; + } + testEnvironment.resources.datasets.push(dsname); + }); + + afterEach(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.toLowerCase().replace(regex, "/"); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); + expect(fileContents).toEqual(testData); + }); }); - it("should display a relevant message when downloading data set members and the data set does not exist", async () => { - let response; - let error; + describe("Data sets matching - all data sets - PS", () => { - try { - response = await Download.allMembers(REAL_SESSION, dsname + ".d"); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("Data set not cataloged"); + beforeEach(async () => { + let error; + try { + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + await wait(waitTime); //wait 2 seconds + } catch (err) { + error = err; + } + testEnvironment.resources.datasets.push(dsname); + }); + + afterEach(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + file = dsname.toLowerCase() + ".txt"; + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); }); }); }); - }); - - /////STOPPED - describe("Download USS File", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download_uss" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD.USS`); - Imperative.console.info("Using dsname:" + dsname); - - testEnvironment.resources.datasets.push(dsname); - - // using unique DS function to generate unique USS file name - ussname = `${defaultSystem.unix.testdir}/${dsname}`; - ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; - localDirname = `${testEnvironment.workingDir}/ussDir`; - - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(ussname, ussDirname); - }); - - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - - describe("Successful scenarios", () => { - it("should download uss file without any options", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - - }); - - it("should download uss file with response timeout", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, {responseTimeout: 5}); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - - }); - - it("should download uss file and return Etag", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - const options: IDownloadOptions = { - returnEtag: true - }; - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.apiResponse.etag).toBeDefined(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - - }); - - // When requesting etag, z/OSMF has a limit on file size when it stops to return etag by default (>8mb) - // We are passing X-IBM-Return-Etag to force z/OSMF to always return etag, but testing here for case where it would be optional - it("should download a 10mb uss file and return Etag", async () => { - let error; - let response: IZosFilesResponse; - - // Create a 10 mb buffer - const bufferSize = 10000000; - const buffer = new ArrayBuffer(bufferSize); - const data = Buffer.from(buffer); - - await Upload.bufferToUssFile(REAL_SESSION, ussname, data); - await wait(waitTime); //wait 2 seconds - - const options: IDownloadOptions = { - returnEtag: true - }; - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.apiResponse.etag).toBeDefined(); - Imperative.console.info(response.apiResponse.etag); - }); - - it("should download uss file content in binary", async () => { - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = { - binary: true - }; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData), { binary: true }); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download ISO8859-1 uss file in binary mode", async () => { - let error; - let response: IZosFilesResponse; - const options: IDownloadOptions = {}; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData), { binary: true }); - await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "ISO8859-1"); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download IBM-1147 uss file with encoding mode", async () => { - let error; - let response: IZosFilesResponse; - const options: IDownloadOptions = {}; - - const data: string = "Hello, world¤"; - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); - await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "IBM-1147"); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(data.slice(0, -1) + "€"); - }); - - it("should download uss file content to local file", async () => { - - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = {file: `test1.txt`}; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`test1.txt`).toString()); - expect(fileContents).toEqual(testData); - - // Delete created local file - IO.deleteFile("test1.txt"); - }); - - it("should download uss file to a stream", async () => { - let error; - let response: IZosFilesResponse; - const responseStream = new PassThrough(); - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, { stream: responseStream }); - } catch (err) { - error = err; - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(await text(responseStream)); - expect(fileContents).toEqual(testData); - }); - }); - - describe("Failure scenarios", () => { - it("should display proper error message when missing session", async () => { - let response: IZosFilesResponse; - let error; - - try { - response = await Download.ussFile(undefined, ussname); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Required object must be defined"); - }); - - it("should display proper error message when missing uss file name", async () => { - let response: IZosFilesResponse; - let error; - - try { - response = await Download.ussFile(REAL_SESSION, undefined); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Specify the USS file name."); - }); - - it("should display proper error message when uss file name is empty string", async () => { - let response: IZosFilesResponse; - let error; - - try { - response = await Download.ussFile(REAL_SESSION, ""); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Specify the USS file name."); - }); - - it("should display proper error message when uss file data type is record", async () => { - let response: IZosFilesResponse; - let error; - - const options: IDownloadOptions = {file: `test1.txt`, record: true}; - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Unsupported data type 'record' specified for USS file operation."); - }); - }); - }); - describe("Download USS Directory", () => { - describe("Success Scenarios", () => { - const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - const anotherTestFileContents = testFileContents.toLowerCase(); - const binaryFileContents = String.fromCharCode(...Array(256).keys()); - const createZfsOptions: ICreateZfsOptions = { - perms: 755, - cylsPri: 10, - cylsSec: 2, - timeout: 20 - }; - const mountZfsOptions: IMountFsOptions = { - "fs-type": "ZFS", - mode: "rdwr" - }; - let zfsName: string; - - const expectDownloaded = (dirname: string, options: IUSSListOptions = {}) => { - expect(fs.existsSync(`${dirname}/emptyFolder`)).toBe(true); - expect(fs.readdirSync(`${dirname}/emptyFolder`).length).toBe(0); - expect(fs.existsSync(`${dirname}/parentFolder`)).toBe(true); - expect(fs.readFileSync(`${dirname}/testFile.txt`, "utf-8")).toBe(testFileContents); - - // Test depth option - const depth = options.depth || 0; - expect(fs.existsSync(`${dirname}/parentFolder/childFolder`)).toBe(depth !== 1); - if (depth !== 1) { - expect(fs.readFileSync(`${dirname}/parentFolder/childFolder/anotherTestFile.txt`, "utf-8")).toBe(anotherTestFileContents); - } - - // Test filesys option - const filesys = options.filesys || false; - expect(fs.existsSync(`${dirname}/mountFolder`)).toBe(filesys); - if (filesys) { - expect(fs.readFileSync(`${dirname}/mountFolder/binaryFile.bin`, "utf-8")).toBe(binaryFileContents); - } - - // Test symlinks option - const symlinks = options.symlinks || false; - expect(fs.existsSync(`${dirname}/testFile.lnk`)).toBe(!symlinks); - if (!symlinks) { - expect(fs.readFileSync(`${dirname}/testFile.lnk`, "utf-8")).toBe(testFileContents); - } - }; + describe("Download USS File - encoded", () => { beforeAll(async () => { - const emptyFolder = posix.join(ussDirname, "emptyFolder"); - const parentFolder = posix.join(ussDirname, "parentFolder"); - const childFolder = posix.join(parentFolder, "childFolder"); - const testFile = posix.join(ussDirname, "testFile.txt"); - const anotherTestFile = posix.join(childFolder, "anotherTestFile.txt"); - const mountFolder = posix.join(ussDirname, "mountFolder"); - const binaryFile = posix.join(mountFolder, "binaryFile.bin"); - const testSymlink = posix.join(ussDirname, "testFile.lnk"); - - // Create directories - for (const directory of [ussDirname, emptyFolder, parentFolder, childFolder, mountFolder]) { - await Create.uss(REAL_SESSION, directory, "directory"); - } - - // Create and mount file system - zfsName = getUniqueDatasetName(defaultSystem.zosmf.user); - await Create.zfs(REAL_SESSION, zfsName, createZfsOptions); - await Mount.fs(REAL_SESSION, zfsName, mountFolder, mountZfsOptions); - - // Upload files - await Upload.bufferToUssFile(REAL_SESSION, testFile, Buffer.from(testFileContents)); - await Upload.bufferToUssFile(REAL_SESSION, anotherTestFile, Buffer.from(anotherTestFileContents)); - await Upload.bufferToUssFile(REAL_SESSION, binaryFile, Buffer.from(binaryFileContents), { binary: true }); - await Utilities.chtag(REAL_SESSION, binaryFile, Tag.BINARY); - - // Create symlink - const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); - await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); - }); - - afterEach(() => { - IO.deleteDirTree(localDirname); - }); - - afterAll(async () => { - // Unmount and delete file system - await Unmount.fs(REAL_SESSION, zfsName); - await Delete.zfs(REAL_SESSION, zfsName); - - // Delete directory recursively - const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); - await Shell.executeSshCwd(SSH_SESSION, `rm testFile.lnk`, ussDirname, jest.fn()); - await Delete.ussFile(REAL_SESSION, ussDirname, true); - }); - - it("should download directory recursively", async () => { - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname); - }); - - it("should download directory with depth of 1", async () => { - const listOptions: IUSSListOptions = { depth: 1 }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should download directory including all filesystems", async () => { - const listOptions: IUSSListOptions = { filesys: true }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should download directory excluding symlinks", async () => { - const listOptions: IUSSListOptions = { symlinks: true }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should not download files that already exist", async () => { - let caughtError; - const testFile = posix.join(localDirname, "testFile.txt"); - try { - fs.mkdirSync(localDirname); - fs.writeFileSync(testFile, "test"); - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expect(fs.readFileSync(testFile).toString()).toEqual("test"); - }); - - it("should download files that already exist when overwrite is true", async () => { - let caughtError; - const testFile = posix.join(localDirname, "testFile.txt"); - try { - fs.mkdirSync(localDirname); - fs.writeFileSync(testFile, "test"); - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname, overwrite: true }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expect(fs.readFileSync(testFile).toString()).toEqual(testFileContents); - }); - }); + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download_uss_encoded" + }); + defaultSystem = testEnvironment.systemTestProperties; - describe("Failure Scenarios", () => { - it("should throw error when session is undefined", async () => { - let caughtError; - try { - await Download.ussDir(undefined, ussDirname); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeDefined(); - expect(caughtError.message).toBe("Expect Error: Required object must be defined"); - }); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; - it("should throw error when USS dir name is undefined", async () => { - let caughtError; - try { - await Download.ussDir(REAL_SESSION, undefined); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeDefined(); - expect(caughtError.message).toBe("Expect Error: Specify the USS directory name."); - }); - - it("should throw error when USS dir name is empty string", async () => { - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ""); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeDefined(); - expect(caughtError.message).toBe("Expect Error: Specify the USS directory name."); - }); + // using unique DS function to generate unique USS file name + ussname = `${defaultSystem.unix.testdir}/ENCO#ED${getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true)}`; - it("should fail to download directory that does not exist", async () => { - let caughtError; - try { - await Download.ussDir(REAL_SESSION, posix.join(ussDirname, "invalidDir"), { directory: testEnvironment.workingDir }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeDefined(); - expect(stripNewLines(caughtError.message)).toContain("Path name not found"); + // Track the USS file and local files in testEnvironment resources for cleanup + testEnvironment.resources.files.push(ussname); }); - }); - }); - -}) -describe("Encoded", () => { - describe("Download Data Set - encoded", () => { - - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download" + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); - Imperative.console.info("Using dsname:" + dsname); - - // using unique DS function to generate unique USS file name - ussname = `${defaultSystem.unix.testdir}/ENCO#ED${dsname}`; - ussDirname = `${defaultSystem.unix.testdir}/ENCO#EDzos_file_download`; - localDirname = `${testEnvironment.workingDir}/ENCO#EDussDir`; - - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(ussname, ussDirname); - }); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); + describe("Successful scenarios", () => { + it("should download uss file without any options", async () => { + let error; + let response: IZosFilesResponse; - describe("Success Scenarios", () => { + // Upload the USS file + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(waitTime); // wait 2 seconds - describe("Physical sequential data set", () => { - beforeEach(async () => { - let error; try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await wait(waitTime); //wait 2 seconds + // Download the USS file + response = await Download.ussFile(REAL_SESSION, ussname); } catch (err) { - // Do nothing, sometimes the files are not created. error = err; - Imperative.console.info("Error: " + inspect(error)); } - }); + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); - afterEach(async () => { - let error; - try { - await Delete.dataSet(REAL_SESSION, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(testData); - // delete the top-level folder and the folders and file below - // variable 'file' should be set in the test - const folders = file.split("/"); - rimraf(folders[0]); - rimraf(file); + // Track the local file created during the download + testEnvironment.resources.localFiles.push(`./${posix.basename(ussname)}`); }); - it("should download a data set", async () => { + it("should download uss file content to local file", async () => { let error; let response: IZosFilesResponse; - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - await wait(waitTime); //wait 2 seconds + const options: IDownloadOptions = { file: `test1.txt` }; + + // Upload the USS file + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(waitTime); // wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname); - Imperative.console.info("Response: " + inspect(response)); + // Download the USS file to a local file + response = await Download.ussFile(REAL_SESSION, ussname, options); } catch (err) { error = err; - Imperative.console.info("Error: " + inspect(error)); } expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); + // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + const fileContents = stripNewLines(fs.readFileSync(`test1.txt`).toString()); expect(fileContents).toEqual(testData); + + // Track the local file created during the test + testEnvironment.resources.localFiles.push(`test1.txt`); }); }); + }); - describe("Partitioned data set - all members", () => { - beforeEach(async () => { - let error; - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); + describe("Download USS Directory - encoded", () => { + describe("Success Scenarios", () => { + const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + const anotherTestFileContents = testFileContents.toLowerCase(); + const binaryFileContents = String.fromCharCode(...Array(256).keys()); + const createZfsOptions: ICreateZfsOptions = { + perms: 755, + cylsPri: 10, + cylsSec: 2, + timeout: 20 + }; + const mountZfsOptions: IMountFsOptions = { + "fs-type": "ZFS", + mode: "rdwr" + }; + let zfsName: string; + + const expectDownloaded = (dirname: string, options: IUSSListOptions = {}) => { + expect(fs.existsSync(`${dirname}/emptyFolder`)).toBe(true); + expect(fs.readdirSync(`${dirname}/emptyFolder`).length).toBe(0); + expect(fs.existsSync(`${dirname}/parentFolder`)).toBe(true); + expect(fs.readFileSync(`${dirname}/testFile.txt`, "utf-8")).toBe(testFileContents); + + const depth = options.depth || 0; + expect(fs.existsSync(`${dirname}/parentFolder/childFolder`)).toBe(depth !== 1); + if (depth !== 1) { + expect(fs.readFileSync(`${dirname}/parentFolder/childFolder/anotherTestFile.txt`, "utf-8")).toBe(anotherTestFileContents); } - }); - afterEach(async () => { - let error; - try { - await Delete.dataSet(REAL_SESSION, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); + const filesys = options.filesys || false; + expect(fs.existsSync(`${dirname}/mountFolder`)).toBe(filesys); + if (filesys) { + expect(fs.readFileSync(`${dirname}/mountFolder/binaryFile.bin`, "utf-8")).toBe(binaryFileContents); } - // delete the top-level folder and the folders and file below - const folders = file.split("/"); - rimraf(folders[0]); - }); - - it("should download a data set member", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - await wait(waitTime); //wait 2 seconds + const symlinks = options.symlinks || false; + expect(fs.existsSync(`${dirname}/testFile.lnk`)).toBe(!symlinks); + if (!symlinks) { + expect(fs.readFileSync(`${dirname}/testFile.lnk`, "utf-8")).toBe(testFileContents); + } + }; - try { - response = await Download.allMembers(REAL_SESSION, dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); + beforeAll(async () => { + const emptyFolder = posix.join(ussDirname, "emptyFolder"); + const parentFolder = posix.join(ussDirname, "parentFolder"); + const childFolder = posix.join(parentFolder, "childFolder"); + const testFile = posix.join(ussDirname, "testFile.txt"); + const anotherTestFile = posix.join(childFolder, "anotherTestFile.txt"); + const mountFolder = posix.join(ussDirname, "mountFolder"); + const binaryFile = posix.join(mountFolder, "binaryFile.bin"); + const testSymlink = posix.join(ussDirname, "testFile.lnk"); + + testEnvironment = await TestEnvironment.setUp({ + testName: "download_uss_dir_encoded" + }); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + + testEnvironment.resources.files.push(ussDirname, mountFolder, testFile, anotherTestFile, binaryFile, testSymlink); + testEnvironment.resources.localFiles.push(localDirname); + + // Create directories + for (const directory of [ussDirname, emptyFolder, parentFolder, childFolder, mountFolder]) { + await Create.uss(REAL_SESSION, directory, "directory"); } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.replace(regex, "/"); - file = file.toLowerCase(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); - expect(fileContents).toEqual(testData); - }); - }); + // Create and mount file system + zfsName = getUniqueDatasetName(defaultSystem.zosmf.user, true); + await Create.zfs(REAL_SESSION, zfsName, createZfsOptions); + await Mount.fs(REAL_SESSION, zfsName, mountFolder, mountZfsOptions); - describe("Data sets matching - all data sets - PO", () => { + // Upload files + await Upload.bufferToUssFile(REAL_SESSION, testFile, Buffer.from(testFileContents)); + await Upload.bufferToUssFile(REAL_SESSION, anotherTestFile, Buffer.from(anotherTestFileContents)); + await Upload.bufferToUssFile(REAL_SESSION, binaryFile, Buffer.from(binaryFileContents), { binary: true }); + await Utilities.chtag(REAL_SESSION, binaryFile, Tag.BINARY); - beforeEach(async () => { - let error; - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + // Create symlink + const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); + await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); }); - afterEach(async () => { - let error; + afterEach(() => { + IO.deleteDirTree(localDirname); + }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should download directory recursively", async () => { + let caughtError; try { - await Delete.dataSet(REAL_SESSION, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); + } catch (error) { + caughtError = error; } + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname); + }); - // delete the top-level folder and the folders and file below + it("should download directory with depth of 1", async () => { + const listOptions: IUSSListOptions = { depth: 1 }; + let caughtError; try { - const folders = file.split("/"); - rimraf(folders[0]); - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); + } catch (error) { + caughtError = error; } + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname, listOptions); }); - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - + it("should download directory including all filesystems", async () => { + const listOptions: IUSSListOptions = { filesys: true }; + let caughtError; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); + } catch (error) { + caughtError = error; } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname.toLowerCase().replace(regex, "/"); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); - expect(fileContents).toEqual(testData); + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname, listOptions); }); - }); - - describe("Data sets matching - all data sets - PS", () => { - - beforeEach(async () => { - let error; + it("should download directory excluding symlinks", async () => { + const listOptions: IUSSListOptions = { symlinks: true }; + let caughtError; try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); + } catch (error) { + caughtError = error; } + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname, listOptions); }); - afterEach(async () => { - let error; + it("should not download files that already exist", async () => { + let caughtError; + const testFile = posix.join(localDirname, "testFile.txt"); try { - await Delete.dataSet(REAL_SESSION, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing, sometimes the files are not created. - error = err; - Imperative.console.info("Error: " + inspect(error)); + fs.mkdirSync(localDirname); + fs.writeFileSync(testFile, "test"); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); + } catch (error) { + caughtError = error; } - - // delete the top-level folder and the folders and file below - const folders = file.split("/"); - rimraf(folders[0]); - rimraf(file); + expect(caughtError).toBeUndefined(); + expect(fs.readFileSync(testFile).toString()).toEqual("test"); }); - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - + it("should download files that already exist when overwrite is true", async () => { + let caughtError; + const testFile = posix.join(localDirname, "testFile.txt"); try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); + fs.mkdirSync(localDirname); + fs.writeFileSync(testFile, "test"); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname, overwrite: true }); + } catch (error) { + caughtError = error; } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - file = dsname.toLowerCase() + ".txt"; - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); + expect(caughtError).toBeUndefined(); + expect(fs.readFileSync(testFile).toString()).toEqual(testFileContents); }); - }); }); }); - - describe("Download USS File - encoded", () => { - afterAll(async () => { - // Delete created uss file - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); - - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - await wait(waitTime); //wait 2 seconds - } catch (err) { - Imperative.console.error(err); - } - - // Delete created local file - IO.deleteFile(`./${posix.basename(ussname)}`); - }); - - describe("Successful scenarios", () => { - it("should download uss file without any options", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - - }); - - it("should download uss file content to local file", async () => { - - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = {file: `test1.txt`}; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`test1.txt`).toString()); - expect(fileContents).toEqual(testData); - - // Delete created local file - IO.deleteFile("test1.txt"); - }); - - }); - - }); - - describe("Download USS Directory - encoded", () => { - describe("Success Scenarios", () => { - const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - const anotherTestFileContents = testFileContents.toLowerCase(); - const binaryFileContents = String.fromCharCode(...Array(256).keys()); - const createZfsOptions: ICreateZfsOptions = { - perms: 755, - cylsPri: 10, - cylsSec: 2, - timeout: 20 - }; - const mountZfsOptions: IMountFsOptions = { - "fs-type": "ZFS", - mode: "rdwr" - }; - let zfsName: string; - - const expectDownloaded = (dirname: string, options: IUSSListOptions = {}) => { - expect(fs.existsSync(`${dirname}/emptyFolder`)).toBe(true); - expect(fs.readdirSync(`${dirname}/emptyFolder`).length).toBe(0); - expect(fs.existsSync(`${dirname}/parentFolder`)).toBe(true); - expect(fs.readFileSync(`${dirname}/testFile.txt`, "utf-8")).toBe(testFileContents); - - // Test depth option - const depth = options.depth || 0; - expect(fs.existsSync(`${dirname}/parentFolder/childFolder`)).toBe(depth !== 1); - if (depth !== 1) { - expect(fs.readFileSync(`${dirname}/parentFolder/childFolder/anotherTestFile.txt`, "utf-8")).toBe(anotherTestFileContents); - } - - // Test filesys option - const filesys = options.filesys || false; - expect(fs.existsSync(`${dirname}/mountFolder`)).toBe(filesys); - if (filesys) { - expect(fs.readFileSync(`${dirname}/mountFolder/binaryFile.bin`, "utf-8")).toBe(binaryFileContents); - } - - // Test symlinks option - const symlinks = options.symlinks || false; - expect(fs.existsSync(`${dirname}/testFile.lnk`)).toBe(!symlinks); - if (!symlinks) { - expect(fs.readFileSync(`${dirname}/testFile.lnk`, "utf-8")).toBe(testFileContents); - } - }; - - beforeAll(async () => { - const emptyFolder = posix.join(ussDirname, "emptyFolder"); - const parentFolder = posix.join(ussDirname, "parentFolder"); - const childFolder = posix.join(parentFolder, "childFolder"); - const testFile = posix.join(ussDirname, "testFile.txt"); - const anotherTestFile = posix.join(childFolder, "anotherTestFile.txt"); - const mountFolder = posix.join(ussDirname, "mountFolder"); - const binaryFile = posix.join(mountFolder, "binaryFile.bin"); - const testSymlink = posix.join(ussDirname, "testFile.lnk"); - - // Create directories - for (const directory of [ussDirname, emptyFolder, parentFolder, childFolder, mountFolder]) { - await Create.uss(REAL_SESSION, directory, "directory"); - } - - // Create and mount file system - zfsName = getUniqueDatasetName(defaultSystem.zosmf.user, true); - await Create.zfs(REAL_SESSION, zfsName, createZfsOptions); - await Mount.fs(REAL_SESSION, zfsName, mountFolder, mountZfsOptions); - - // Upload files - await Upload.bufferToUssFile(REAL_SESSION, testFile, Buffer.from(testFileContents)); - await Upload.bufferToUssFile(REAL_SESSION, anotherTestFile, Buffer.from(anotherTestFileContents)); - await Upload.bufferToUssFile(REAL_SESSION, binaryFile, Buffer.from(binaryFileContents), { binary: true }); - await Utilities.chtag(REAL_SESSION, binaryFile, Tag.BINARY); - - // Create symlink - const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); - await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); - }); - - afterEach(() => { - IO.deleteDirTree(localDirname); - }); - - afterAll(async () => { - // Unmount and delete file system - await Unmount.fs(REAL_SESSION, zfsName); - await Delete.zfs(REAL_SESSION, zfsName); - - // Delete directory recursively - const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); - await Shell.executeSshCwd(SSH_SESSION, `rm testFile.lnk`, ussDirname, jest.fn()); - await Delete.ussFile(REAL_SESSION, ussDirname, true); - }); - - it("should download directory recursively", async () => { - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname); - }); - - it("should download directory with depth of 1", async () => { - const listOptions: IUSSListOptions = { depth: 1 }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should download directory including all filesystems", async () => { - const listOptions: IUSSListOptions = { filesys: true }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should download directory excluding symlinks", async () => { - const listOptions: IUSSListOptions = { symlinks: true }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should not download files that already exist", async () => { - let caughtError; - const testFile = posix.join(localDirname, "testFile.txt"); - try { - fs.mkdirSync(localDirname); - fs.writeFileSync(testFile, "test"); - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expect(fs.readFileSync(testFile).toString()).toEqual("test"); - }); - - it("should download files that already exist when overwrite is true", async () => { - let caughtError; - const testFile = posix.join(localDirname, "testFile.txt"); - try { - fs.mkdirSync(localDirname); - fs.writeFileSync(testFile, "test"); - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname, overwrite: true }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expect(fs.readFileSync(testFile).toString()).toEqual(testFileContents); - }); - }); - - }); -}) \ No newline at end of file +}); \ No newline at end of file From 6a1dc9f2048d4d4bcf9387426bac0d6b4c11c61e Mon Sep 17 00:00:00 2001 From: ATorrise Date: Wed, 2 Oct 2024 17:16:27 -0400 Subject: [PATCH 54/65] test fixin Signed-off-by: ATorrise --- .../methods/download/Download.system.test.ts | 367 +++++++----------- 1 file changed, 131 insertions(+), 236 deletions(-) diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index 64e9050b51..88549bba3d 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -42,7 +42,11 @@ const testData = "abcdefghijklmnopqrstuvwxyz"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; let defaultSystem: ITestPropertiesSchema; -let dsname: string; +let dsname: string; //uss +let dsname_seq: string; +let dsname_part: string; +let dsname_all_po: string; +let dsname_all_ps: string; let ussname: string; let ussDirname: string; let localDirname: string; @@ -61,29 +65,35 @@ describe("All Download System Tests", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); + dsname_seq = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); + dsname_part = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); + dsname_all_po = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); + dsname_all_ps = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname_seq); + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname_part); + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname_all_po); + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname_all_ps); }); afterAll(async () => { - testEnvironment.resources.datasets.push(dsname); + testEnvironment.resources.datasets.push(dsname_seq, dsname_part, dsname_all_po, dsname_all_ps); await TestEnvironment.cleanUp(testEnvironment); }); describe("Success Scenarios", () => { describe("Physical sequential data set", () => { - - it("should download a data set", async () => { + //this test needs to be first because it requires dir to be created as uppercase (other tests have no requirement) + it("should download a data set and create folders and file in original letter case", async () => { let error; let response: IZosFilesResponse; // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); await wait(waitTime); // Wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname); - await wait(waitTime); + response = await Download.dataSet(REAL_SESSION, dsname_seq, { preserveOriginalLetterCase: true }); } catch (err) { error = err; } @@ -96,8 +106,14 @@ describe("All Download System Tests", () => { // Convert the data set name to use as a path/file const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); + file = dsname_seq.replace(regex, "/") + ".txt"; + + // Check if folders and file are created in original uppercase + file.split("/").reduce((path, pathSegment) => { + const pathExists = fs.readdirSync(path).indexOf(pathSegment) !== -1; + expect(pathExists).toBeTruthy(); + return [path, pathSegment].join("/"); + }, "."); // Add the file to localFiles resources for cleanup testEnvironment.resources.localFiles.push(file); @@ -107,16 +123,17 @@ describe("All Download System Tests", () => { expect(fileContents).toEqual(testData); }); - - it("should download a data set with response timeout", async () => { + it("should download a data set", async () => { let error; let response: IZosFilesResponse; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + // Upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); await wait(waitTime); // Wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname, { responseTimeout: 5 }); + response = await Download.dataSet(REAL_SESSION, dsname_seq); + await wait(waitTime); } catch (err) { error = err; } @@ -129,7 +146,7 @@ describe("All Download System Tests", () => { // Convert the data set name to use as a path/file const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; + file = dsname_seq.replace(regex, "/") + ".txt"; file = file.toLowerCase(); // Add the file to localFiles resources for cleanup @@ -140,16 +157,16 @@ describe("All Download System Tests", () => { expect(fileContents).toEqual(testData); }); - it("should download a data set and create folders and file in original letter case", async () => { + + it("should download a data set with response timeout", async () => { let error; let response: IZosFilesResponse; - // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); await wait(waitTime); // Wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); + response = await Download.dataSet(REAL_SESSION, dsname_seq, { responseTimeout: 5 }); } catch (err) { error = err; } @@ -162,14 +179,8 @@ describe("All Download System Tests", () => { // Convert the data set name to use as a path/file const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; - - // Check if folders and file are created in original uppercase - file.split("/").reduce((path, pathSegment) => { - const pathExists = fs.readdirSync(path).indexOf(pathSegment) !== -1; - expect(pathExists).toBeTruthy(); - return [path, pathSegment].join("/"); - }, "."); + file = dsname_seq.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); // Add the file to localFiles resources for cleanup testEnvironment.resources.localFiles.push(file); @@ -188,7 +199,7 @@ describe("All Download System Tests", () => { }; try { - response = await Download.dataSet(REAL_SESSION, dsname, options); + response = await Download.dataSet(REAL_SESSION, dsname_seq, options); } catch (err) { error = err; } @@ -201,7 +212,7 @@ describe("All Download System Tests", () => { // Convert the data set name to use as a path/file const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; + file = dsname_seq.replace(regex, "/") + ".txt"; // Add the file to localFiles resources for cleanup testEnvironment.resources.localFiles.push(file); @@ -215,7 +226,7 @@ describe("All Download System Tests", () => { }; try { - response = await Download.dataSet(REAL_SESSION, dsname, options); + response = await Download.dataSet(REAL_SESSION, dsname_seq, options); } catch (err) { error = err; } @@ -228,7 +239,7 @@ describe("All Download System Tests", () => { // Convert the data set name to use as a path/file for cleanup const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; + file = dsname_seq.replace(regex, "/") + ".txt"; // Add the file to localFiles resources for cleanup testEnvironment.resources.localFiles.push(file); @@ -238,7 +249,7 @@ describe("All Download System Tests", () => { let error; let response: IZosFilesResponse; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); await wait(waitTime); // Wait 2 seconds const options: IDownloadOptions = { @@ -246,7 +257,7 @@ describe("All Download System Tests", () => { }; try { - response = await Download.dataSet(REAL_SESSION, dsname, options); + response = await Download.dataSet(REAL_SESSION, dsname_seq, options); } catch (err) { error = err; } @@ -261,7 +272,7 @@ describe("All Download System Tests", () => { // Convert the data set name to use as a path/file for cleanup const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; + file = dsname_seq.replace(regex, "/") + ".txt"; file = file.toLowerCase(); // Add the file to localFiles resources for cleanup @@ -280,11 +291,11 @@ describe("All Download System Tests", () => { }; // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); await wait(waitTime); // Wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname, options); + response = await Download.dataSet(REAL_SESSION, dsname_seq, options); } catch (err) { error = err; } @@ -297,7 +308,7 @@ describe("All Download System Tests", () => { // Convert the data set name to use as a path/file const regex = /\./gi; - file = dsname.replace(regex, "/") + ".dat"; + file = dsname_seq.replace(regex, "/") + ".dat"; file = file.toLowerCase(); // Add the file to localFiles resources for cleanup @@ -314,11 +325,11 @@ describe("All Download System Tests", () => { const responseStream = new PassThrough(); // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); await wait(waitTime); // Wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname, { stream: responseStream }); + response = await Download.dataSet(REAL_SESSION, dsname_seq, { stream: responseStream }); } catch (err) { error = err; } @@ -337,31 +348,16 @@ describe("All Download System Tests", () => { describe("Partitioned data set - all members", () => { - beforeEach(async () => { - let error; - try { - const response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - // Adding the dataset to resources for tracking and cleanup - testEnvironment.resources.datasets.push(dsname); - } catch (err) { - error = err; } - }); - - afterEach(async () => { - // Trusting TestEnvironment.cleanUp() to handle all resource cleanups - await TestEnvironment.cleanUp(testEnvironment); - }); - it("should download a data set member", async () => { let error; let response: IZosFilesResponse; // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); await wait(waitTime); //wait 2 seconds try { - response = await Download.allMembers(REAL_SESSION, dsname); + response = await Download.allMembers(REAL_SESSION, dsname_part); } catch (err) { error = err; } @@ -372,7 +368,7 @@ describe("All Download System Tests", () => { // Path file construction and assertion const regex = /\./gi; - const file = dsname.replace(regex, "/") + "/member.txt"; + const file = dsname_part.replace(regex, "/") + "/member.txt"; testEnvironment.resources.localFiles.push(file); // Add file to resources for cleanup // Comparing the downloaded contents @@ -384,11 +380,11 @@ describe("All Download System Tests", () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); await wait(waitTime); try { - response = await Download.allMembers(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); + response = await Download.allMembers(REAL_SESSION, dsname_part, { preserveOriginalLetterCase: true }); } catch (err) { error = err; } @@ -398,7 +394,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("Data set downloaded successfully"); const regex = /\./gi; - const file = dsname.replace(regex, "/") + "/MEMBER.txt"; + const file = dsname_part.replace(regex, "/") + "/MEMBER.txt"; testEnvironment.resources.localFiles.push(file); const fileContents = stripNewLines(fs.readFileSync(file).toString()); @@ -409,11 +405,11 @@ describe("All Download System Tests", () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); await wait(waitTime); try { - response = await Download.allMembers(REAL_SESSION, dsname, { binary: true }); + response = await Download.allMembers(REAL_SESSION, dsname_part, { binary: true }); } catch (err) { error = err; } @@ -423,7 +419,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("Data set downloaded successfully"); const regex = /\./gi; - const file = dsname.replace(regex, "/") + "/member.txt"; + const file = dsname_part.replace(regex, "/") + "/member.txt"; testEnvironment.resources.localFiles.push(file); }); @@ -431,11 +427,11 @@ describe("All Download System Tests", () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); await wait(waitTime); try { - response = await Download.allMembers(REAL_SESSION, dsname, { record: true }); + response = await Download.allMembers(REAL_SESSION, dsname_part, { record: true }); } catch (err) { error = err; } @@ -445,7 +441,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("Data set downloaded successfully"); const regex = /\./gi; - file = dsname.replace(regex, "/") + "/member.txt"; + file = dsname_part.replace(regex, "/") + "/member.txt"; testEnvironment.resources.localFiles.push(file); }); @@ -453,11 +449,11 @@ describe("All Download System Tests", () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); await wait(waitTime); try { - response = await Download.allMembers(REAL_SESSION, dsname, { extension: "dat" }); + response = await Download.allMembers(REAL_SESSION, dsname_part, { extension: "dat" }); } catch (err) { error = err; } @@ -467,35 +463,21 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("Data set downloaded successfully"); const regex = /\./gi; - const file = dsname.replace(regex, "/") + "/member.dat"; + const file = dsname_part.replace(regex, "/") + "/member.dat"; testEnvironment.resources.localFiles.push(file); }); }); describe("Data sets matching - all data sets - PO", () => { - beforeEach(async () => { - let error; - try { - const response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - testEnvironment.resources.datasets.push(dsname); // Tracking created dataset for cleanup - } catch (err) { - error = err; - } - }); - - afterEach(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - it("should download a data set", async () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }]); } catch (err) { error = err; } @@ -505,7 +487,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); const regex = /\./gi; - const file = dsname.toLowerCase().replace(regex, "/"); + const file = dsname_all_po.toLowerCase().replace(regex, "/"); testEnvironment.resources.localFiles.push(file + "/member.txt"); const fileContents = stripNewLines(fs.readFileSync(file + "/member.txt").toString()); @@ -516,7 +498,7 @@ describe("All Download System Tests", () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); const options: IDownloadOptions = { binary: true, @@ -525,7 +507,7 @@ describe("All Download System Tests", () => { }; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }], options); } catch (err) { error = err; } @@ -535,7 +517,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); const regex = /\./gi; - const file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; + const file = "testDir/" + dsname_all_po.replace(regex, "/") + "/member.txt"; testEnvironment.resources.localFiles.push(file); }); @@ -543,7 +525,7 @@ describe("All Download System Tests", () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); const options: IDownloadOptions = { record: true, @@ -552,7 +534,7 @@ describe("All Download System Tests", () => { }; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }], options); } catch (err) { error = err; } @@ -562,7 +544,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); const regex = /\./gi; - const file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; + const file = "testDir/" + dsname_all_po.replace(regex, "/") + "/member.txt"; testEnvironment.resources.localFiles.push(file); }); @@ -570,10 +552,10 @@ describe("All Download System Tests", () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extension: "jcl"}); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }], {extension: "jcl"}); } catch (err) { error = err; } @@ -583,7 +565,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); const regex = /\./gi; - const file = dsname.toLowerCase().replace(regex, "/"); + const file = dsname_all_po.toLowerCase().replace(regex, "/"); testEnvironment.resources.localFiles.push(file + "/member.jcl"); const fileContents = stripNewLines(fs.readFileSync(file + "/member.jcl").toString()); @@ -594,13 +576,13 @@ describe("All Download System Tests", () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); - const ending = dsname.split(".").pop().toLowerCase(); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); + const ending = dsname_all_po.split(".").pop().toLowerCase(); const extMap: any = {}; extMap[ending] = "jcl"; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extensionMap: extMap}); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }], {extensionMap: extMap}); } catch (err) { error = err; } @@ -610,7 +592,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); const regex = /\./gi; - const file = dsname.toLowerCase().replace(regex, "/"); + const file = dsname_all_po.toLowerCase().replace(regex, "/"); testEnvironment.resources.localFiles.push(file + "/member.jcl"); const fileContents = stripNewLines(fs.readFileSync(file + "/member.jcl").toString()); @@ -620,29 +602,14 @@ describe("All Download System Tests", () => { describe("Data sets matching - all data sets - PS", () => { - beforeEach(async () => { - let error; - try { - const response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - testEnvironment.resources.datasets.push(dsname); // Tracking created dataset for cleanup - } catch (err) { - error = err; - } - }); - - afterEach(async () => { - // Utilizing TestEnvironment.cleanUp() for comprehensive cleanup - await TestEnvironment.cleanUp(testEnvironment); - }); - it("should download a data set", async () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }]); } catch (err) { error = err; } @@ -652,7 +619,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); const regex = /\./gi; - const file = dsname.toLowerCase() + ".txt"; + const file = dsname_all_ps.toLowerCase() + ".txt"; const fileContents = stripNewLines(fs.readFileSync(file).toString()); expect(fileContents).toEqual(testData); }); @@ -661,7 +628,7 @@ describe("All Download System Tests", () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); const options: IDownloadOptions = { binary: true, @@ -670,7 +637,7 @@ describe("All Download System Tests", () => { }; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }], options); } catch (err) { error = err; } @@ -680,14 +647,14 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); const regex = /\./gi; - const file = "testDir/" + dsname.toLowerCase() + ".txt"; + const file = "testDir/" + dsname_all_ps.toLowerCase() + ".txt"; }); it("should download a data set in record mode", async () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); const options: IDownloadOptions = { record: true, @@ -696,7 +663,7 @@ describe("All Download System Tests", () => { }; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }], options); } catch (err) { error = err; } @@ -706,17 +673,17 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); const regex = /\./gi; - const file = "testDir/" + dsname.toLowerCase() + ".txt"; + const file = "testDir/" + dsname_all_ps.toLowerCase() + ".txt"; }); it("should download a data set with a different extension", async () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extension: "jcl"}); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }], {extension: "jcl"}); } catch (err) { error = err; } @@ -726,7 +693,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); const regex = /\./gi; - const file = dsname.toLowerCase() + ".jcl"; + const file = dsname_all_ps.toLowerCase() + ".jcl"; const fileContents = stripNewLines(fs.readFileSync(file).toString()); expect(fileContents).toEqual(testData); }); @@ -735,13 +702,13 @@ describe("All Download System Tests", () => { let error; let response; - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); - const ending = dsname.split(".").pop().toLowerCase(); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); + const ending = dsname_all_ps.split(".").pop().toLowerCase(); const extMap: any = {}; extMap[ending] = "jcl"; try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extensionMap: extMap}); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }], {extensionMap: extMap}); } catch (err) { error = err; } @@ -751,7 +718,7 @@ describe("All Download System Tests", () => { expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); const regex = /\./gi; - const file = dsname.toLowerCase() + ".jcl"; + const file = dsname_all_ps.toLowerCase() + ".jcl"; const fileContents = stripNewLines(fs.readFileSync(file).toString()); expect(fileContents).toEqual(testData); }); @@ -760,11 +727,6 @@ describe("All Download System Tests", () => { }); describe("Failure Scenarios", () => { - afterAll(async () => { - // Utilizing TestEnvironment.cleanUp() for comprehensive cleanup - await TestEnvironment.cleanUp(testEnvironment); - }); - describe("Physical sequential data set", () => { it("should display proper error message when missing session", async () => { @@ -772,7 +734,7 @@ describe("All Download System Tests", () => { let error; try { - response = await Download.dataSet(undefined, dsname); + response = await Download.dataSet(undefined, dsname_seq); } catch (err) { error = err; } @@ -785,9 +747,8 @@ describe("All Download System Tests", () => { it("should display proper message when downloading a data set that does not exist", async () => { let response; let error; - try { - response = await Download.dataSet(REAL_SESSION, dsname); + response = await Download.dataSet(REAL_SESSION, dsname_seq+".F"); } catch (err) { error = err; } @@ -804,7 +765,7 @@ describe("All Download System Tests", () => { let error; try { - response = await Download.allMembers(undefined, dsname); + response = await Download.allMembers(undefined, dsname_part); } catch (err) { error = err; } @@ -819,7 +780,7 @@ describe("All Download System Tests", () => { let error; try { - response = await Download.allMembers(REAL_SESSION, dsname + ".d"); + response = await Download.allMembers(REAL_SESSION, dsname_part + ".d"); } catch (err) { error = err; } @@ -844,19 +805,17 @@ describe("All Download System Tests", () => { dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD.USS`); - testEnvironment.resources.datasets.push(dsname); - // using unique DS function to generate unique USS file name ussname = `${defaultSystem.unix.testdir}/${dsname}`; ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; localDirname = `${testEnvironment.workingDir}/ussDir`; + }); + afterAll(async () => { // Track local and USS files for cleanup testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(ussname, ussDirname); - }); + testEnvironment.resources.files.push(dsname, ussname, ussDirname); - afterAll(async () => { await TestEnvironment.cleanUp(testEnvironment); }); @@ -1196,9 +1155,6 @@ describe("All Download System Tests", () => { ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; localDirname = `${testEnvironment.workingDir}/ussDir`; - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(ussDirname); - const emptyFolder = posix.join(ussDirname, "emptyFolder"); const parentFolder = posix.join(ussDirname, "parentFolder"); const childFolder = posix.join(parentFolder, "childFolder"); @@ -1217,7 +1173,6 @@ describe("All Download System Tests", () => { zfsName = getUniqueDatasetName(defaultSystem.zosmf.user); await Create.zfs(REAL_SESSION, zfsName, createZfsOptions); await Mount.fs(REAL_SESSION, zfsName, mountFolder, mountZfsOptions); - testEnvironment.resources.datasets.push(zfsName); // Upload files await Upload.bufferToUssFile(REAL_SESSION, testFile, Buffer.from(testFileContents)); @@ -1244,8 +1199,9 @@ describe("All Download System Tests", () => { // Delete directory recursively const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); await Shell.executeSshCwd(SSH_SESSION, `rm testFile.lnk`, ussDirname, jest.fn()); - await Delete.ussFile(REAL_SESSION, ussDirname, true); - + // await Delete.ussFile(REAL_SESSION, ussDirname, true); + testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.files.push(ussDirname); await TestEnvironment.cleanUp(testEnvironment); }); @@ -1385,49 +1341,40 @@ describe("All Download System Tests", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); + dsname_seq = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); + dsname_part = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); + dsname_all_po = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); + dsname_all_ps = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname_seq); + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname_part); + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname_all_po); + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname_all_ps); // using unique DS function to generate unique USS file name ussname = `${defaultSystem.unix.testdir}/ENCO#ED${dsname}`; ussDirname = `${defaultSystem.unix.testdir}/ENCO#EDzos_file_download`; localDirname = `${testEnvironment.workingDir}/ENCO#EDussDir`; - - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(ussname, ussDirname); }); afterAll(async () => { + testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.datasets.push(ussname, ussDirname); await TestEnvironment.cleanUp(testEnvironment); }); describe("Success Scenarios", () => { describe("Physical sequential data set", () => { - beforeEach(async () => { - let error; - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - testEnvironment.resources.datasets.push(dsname); - }); - - afterEach(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - it("should download a data set", async () => { let error; let response: IZosFilesResponse; // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); await wait(waitTime); //wait 2 seconds try { - response = await Download.dataSet(REAL_SESSION, dsname); + response = await Download.dataSet(REAL_SESSION, dsname_seq); } catch (err) { error = err; } @@ -1448,31 +1395,16 @@ describe("All Download System Tests", () => { }); describe("Partitioned data set - all members", () => { - beforeEach(async () => { - let error; - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - testEnvironment.resources.datasets.push(dsname); - }); - - afterEach(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - it("should download a data set member", async () => { let error; let response: IZosFilesResponse; // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); await wait(waitTime); //wait 2 seconds try { - response = await Download.allMembers(REAL_SESSION, dsname); + response = await Download.allMembers(REAL_SESSION, dsname_part); } catch (err) { error = err; } @@ -1493,31 +1425,15 @@ describe("All Download System Tests", () => { }); describe("Data sets matching - all data sets - PO", () => { - - beforeEach(async () => { - let error; - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - testEnvironment.resources.datasets.push(dsname); - }); - - afterEach(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - it("should download a data set", async () => { let error; let response: IZosFilesResponse; // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }]); } catch (err) { error = err; } @@ -1537,30 +1453,15 @@ describe("All Download System Tests", () => { describe("Data sets matching - all data sets - PS", () => { - beforeEach(async () => { - let error; - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - testEnvironment.resources.datasets.push(dsname); - }); - - afterEach(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - it("should download a data set", async () => { let error; let response: IZosFilesResponse; // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); + response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }]); } catch (err) { error = err; } @@ -1569,7 +1470,7 @@ describe("All Download System Tests", () => { expect(response.success).toBeTruthy(); expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - file = dsname.toLowerCase() + ".txt"; + file = dsname_all_ps.toLowerCase() + ".txt"; // Compare the downloaded contents to those uploaded const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); expect(fileContents).toEqual(testData); @@ -1590,12 +1491,10 @@ describe("All Download System Tests", () => { // using unique DS function to generate unique USS file name ussname = `${defaultSystem.unix.testdir}/ENCO#ED${getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true)}`; - - // Track the USS file and local files in testEnvironment resources for cleanup - testEnvironment.resources.files.push(ussname); }); afterAll(async () => { + testEnvironment.resources.files.push(ussname); await TestEnvironment.cleanUp(testEnvironment); }); @@ -1712,9 +1611,6 @@ describe("All Download System Tests", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(ussDirname, mountFolder, testFile, anotherTestFile, binaryFile, testSymlink); - testEnvironment.resources.localFiles.push(localDirname); - // Create directories for (const directory of [ussDirname, emptyFolder, parentFolder, childFolder, mountFolder]) { await Create.uss(REAL_SESSION, directory, "directory"); @@ -1731,16 +1627,15 @@ describe("All Download System Tests", () => { await Upload.bufferToUssFile(REAL_SESSION, binaryFile, Buffer.from(binaryFileContents), { binary: true }); await Utilities.chtag(REAL_SESSION, binaryFile, Tag.BINARY); + testEnvironment.resources.files.push(testFile, anotherTestFile, binaryFile); + // Create symlink const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); - await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); - }); - - afterEach(() => { - IO.deleteDirTree(localDirname); + await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); testEnvironment.resources.files.push(ussDirname, mountFolder, testFile, anotherTestFile, binaryFile, testSymlink); }); afterAll(async () => { + testEnvironment.resources.localFiles.push(localDirname); await TestEnvironment.cleanUp(testEnvironment); }); From a6281448e126667bc66875b6b056c097b8b4cf19 Mon Sep 17 00:00:00 2001 From: ATorrise Date: Thu, 3 Oct 2024 15:19:44 -0400 Subject: [PATCH 55/65] 1 error left in download test Signed-off-by: ATorrise --- .../methods/download/Download.system.test.ts | 146 ++++++++++-------- 1 file changed, 79 insertions(+), 67 deletions(-) diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index 88549bba3d..c1ce1f7905 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -1099,8 +1099,7 @@ describe("All Download System Tests", () => { }); describe("Download USS Directory", () => { - describe("Success Scenarios", () => { - const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const anotherTestFileContents = testFileContents.toLowerCase(); const binaryFileContents = String.fromCharCode(...Array(256).keys()); const createZfsOptions: ICreateZfsOptions = { @@ -1115,6 +1114,69 @@ describe("All Download System Tests", () => { }; let zfsName: string; + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download_uss_directory" + }); + defaultSystem = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + + ussDirname = `${defaultSystem.unix.testdir}/zos_file_download_unecoded`; + localDirname = `${testEnvironment.workingDir}/ussDir`; + + const emptyFolder = posix.join(ussDirname, "emptyFolder"); + const parentFolder = posix.join(ussDirname, "parentFolder"); + const childFolder = posix.join(parentFolder, "childFolder"); + const testFile = posix.join(ussDirname, "testFile.txt"); + const anotherTestFile = posix.join(childFolder, "anotherTestFile.txt"); + const mountFolder = posix.join(ussDirname, "mountFolder"); + const binaryFile = posix.join(mountFolder, "binaryFile.bin"); + const testSymlink = posix.join(ussDirname, "testFile.lnk"); + + // Create directories + for (const directory of [ussDirname, emptyFolder, parentFolder, childFolder, mountFolder]) { + await Create.uss(REAL_SESSION, directory, "directory"); + } + + // Create and mount file system + zfsName = getUniqueDatasetName(defaultSystem.zosmf.user); + await Create.zfs(REAL_SESSION, zfsName, createZfsOptions); + await Mount.fs(REAL_SESSION, zfsName, mountFolder, mountZfsOptions); + + // Upload files + await Upload.bufferToUssFile(REAL_SESSION, testFile, Buffer.from(testFileContents)); + await Upload.bufferToUssFile(REAL_SESSION, anotherTestFile, Buffer.from(anotherTestFileContents)); + await Upload.bufferToUssFile(REAL_SESSION, binaryFile, Buffer.from(binaryFileContents), { binary: true }); + await Utilities.chtag(REAL_SESSION, binaryFile, Tag.BINARY); + + // Create symlink + const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); + await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); + + testEnvironment.resources.files.push(testSymlink); + }); + + afterEach(() => { + IO.deleteDirTree(localDirname); + }); + + afterAll(async () => { + // Unmount and delete file system + await Unmount.fs(REAL_SESSION, zfsName); + await Delete.zfs(REAL_SESSION, zfsName); + + // Delete directory recursively + const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); + await Shell.executeSshCwd(SSH_SESSION, `rm testFile.lnk`, ussDirname, jest.fn()); + // await Delete.ussFile(REAL_SESSION, ussDirname, true); + testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.files.push(ussDirname); + await TestEnvironment.cleanUp(testEnvironment); + }); + + describe("Success Scenarios", () => { const expectDownloaded = (dirname: string, options: IUSSListOptions = {}) => { expect(fs.existsSync(`${dirname}/emptyFolder`)).toBe(true); expect(fs.readdirSync(`${dirname}/emptyFolder`).length).toBe(0); @@ -1143,68 +1205,6 @@ describe("All Download System Tests", () => { } }; - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download_uss_directory" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; - localDirname = `${testEnvironment.workingDir}/ussDir`; - - const emptyFolder = posix.join(ussDirname, "emptyFolder"); - const parentFolder = posix.join(ussDirname, "parentFolder"); - const childFolder = posix.join(parentFolder, "childFolder"); - const testFile = posix.join(ussDirname, "testFile.txt"); - const anotherTestFile = posix.join(childFolder, "anotherTestFile.txt"); - const mountFolder = posix.join(ussDirname, "mountFolder"); - const binaryFile = posix.join(mountFolder, "binaryFile.bin"); - const testSymlink = posix.join(ussDirname, "testFile.lnk"); - - // Create directories - for (const directory of [ussDirname, emptyFolder, parentFolder, childFolder, mountFolder]) { - await Create.uss(REAL_SESSION, directory, "directory"); - } - - // Create and mount file system - zfsName = getUniqueDatasetName(defaultSystem.zosmf.user); - await Create.zfs(REAL_SESSION, zfsName, createZfsOptions); - await Mount.fs(REAL_SESSION, zfsName, mountFolder, mountZfsOptions); - - // Upload files - await Upload.bufferToUssFile(REAL_SESSION, testFile, Buffer.from(testFileContents)); - await Upload.bufferToUssFile(REAL_SESSION, anotherTestFile, Buffer.from(anotherTestFileContents)); - await Upload.bufferToUssFile(REAL_SESSION, binaryFile, Buffer.from(binaryFileContents), { binary: true }); - await Utilities.chtag(REAL_SESSION, binaryFile, Tag.BINARY); - - // Create symlink - const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); - await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); - - testEnvironment.resources.files.push(testSymlink); - }); - - afterEach(() => { - IO.deleteDirTree(localDirname); - }); - - afterAll(async () => { - // Unmount and delete file system - await Unmount.fs(REAL_SESSION, zfsName); - await Delete.zfs(REAL_SESSION, zfsName); - - // Delete directory recursively - const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); - await Shell.executeSshCwd(SSH_SESSION, `rm testFile.lnk`, ussDirname, jest.fn()); - // await Delete.ussFile(REAL_SESSION, ussDirname, true); - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(ussDirname); - await TestEnvironment.cleanUp(testEnvironment); - }); - it("should download directory recursively", async () => { let caughtError; try { @@ -1386,7 +1386,7 @@ describe("All Download System Tests", () => { // convert the data set name to use as a path/file const regex = /\./gi; - file = dsname.replace(regex, "/") + ".txt"; + file = dsname_seq.replace(regex, "/") + ".txt"; file = file.toLowerCase(); // Compare the downloaded contents to those uploaded const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); @@ -1416,7 +1416,7 @@ describe("All Download System Tests", () => { // convert the data set name to use as a path/file const regex = /\./gi; - file = dsname.replace(regex, "/"); + file = dsname_part.replace(regex, "/"); file = file.toLowerCase(); // Compare the downloaded contents to those uploaded const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); @@ -1444,7 +1444,7 @@ describe("All Download System Tests", () => { // convert the data set name to use as a path/file const regex = /\./gi; - file = dsname.toLowerCase().replace(regex, "/"); + file = dsname_all_po.toLowerCase().replace(regex, "/"); // Compare the downloaded contents to those uploaded const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); expect(fileContents).toEqual(testData); @@ -1596,6 +1596,14 @@ describe("All Download System Tests", () => { }; beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download_uss_dir_encoded" + }); + defaultSystem = testEnvironment.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + + ussDirname = `${defaultSystem.unix.testdir}/ENCO#EDzos_file_download`; const emptyFolder = posix.join(ussDirname, "emptyFolder"); const parentFolder = posix.join(ussDirname, "parentFolder"); const childFolder = posix.join(parentFolder, "childFolder"); @@ -1634,6 +1642,10 @@ describe("All Download System Tests", () => { await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); testEnvironment.resources.files.push(ussDirname, mountFolder, testFile, anotherTestFile, binaryFile, testSymlink); }); + afterEach(() => { + IO.deleteDirTree(localDirname); + }); + afterAll(async () => { testEnvironment.resources.localFiles.push(localDirname); await TestEnvironment.cleanUp(testEnvironment); From 7f503523522694dfacc6b0b3e8cbf11f82415bfd Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Thu, 3 Oct 2024 16:07:34 -0400 Subject: [PATCH 56/65] Fix remaining uss download system tests Co-authored-by: ATorrise Signed-off-by: Timothy Johnson --- __tests__/__src__/environment/TestEnvironment.ts | 10 +++++----- .../methods/download/Download.system.test.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index 4f69543550..dd1dfe4333 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -72,7 +72,7 @@ export class TestEnvironment extends BaseTestEnvironment { // Delete profiles and plugindir await super.cleanUp(testEnvironment); - // Deleting resources (if they exist) + // Deleting resources (if they exist) if (testEnvironment?.resources?.session) { const session = testEnvironment.resources.session; try{ @@ -80,20 +80,20 @@ export class TestEnvironment extends BaseTestEnvironment { deleteLocalFile(file); } for (const file of testEnvironment.resources.files) { - deleteFiles(session, file); + await deleteFiles(session, file); } for (const job of testEnvironment.resources.jobs) { - deleteJob(session, job); + await deleteJob(session, job); } for (const jobData of testEnvironment.resources.jobData) { if (jobData.jobname && jobData.jobid) { - deleteJobCommon(session, jobData); + await deleteJobCommon(session, jobData); } else { Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); } } for (const dataset of testEnvironment.resources.datasets) { - deleteDataset(session, dataset); + await deleteDataset(session, dataset); } }catch (error){ if (error.mDetails?.httpStatus !== 404) { diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index c1ce1f7905..a29c28b8fc 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -814,7 +814,8 @@ describe("All Download System Tests", () => { afterAll(async () => { // Track local and USS files for cleanup testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(dsname, ussname, ussDirname); + testEnvironment.resources.datasets.push(dsname); + testEnvironment.resources.files.push(ussname, ussDirname); await TestEnvironment.cleanUp(testEnvironment); }); @@ -1647,7 +1648,16 @@ describe("All Download System Tests", () => { }); afterAll(async () => { + // Unmount and delete file system + await Unmount.fs(REAL_SESSION, zfsName); + await Delete.zfs(REAL_SESSION, zfsName); + + // Delete directory recursively + const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); + await Shell.executeSshCwd(SSH_SESSION, `rm testFile.lnk`, ussDirname, jest.fn()); + // await Delete.ussFile(REAL_SESSION, ussDirname, true); testEnvironment.resources.localFiles.push(localDirname); + testEnvironment.resources.files.push(ussDirname); await TestEnvironment.cleanUp(testEnvironment); }); From 66f5e11b56edc12d9f23a997447abaf0655ea30b Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Mon, 7 Oct 2024 09:30:46 -0400 Subject: [PATCH 57/65] Clean up resources in download system tests Signed-off-by: Timothy Johnson --- .../methods/download/Download.system.test.ts | 2984 ++++++++--------- 1 file changed, 1384 insertions(+), 1600 deletions(-) diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index a29c28b8fc..e81f88337b 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -19,6 +19,7 @@ import { IZosFilesResponse, Tag, Utilities, + ZosFilesConstants, ZosFilesMessages, ICreateZfsOptions, IMountFsOptions, @@ -26,1107 +27,1334 @@ import { Unmount, IUSSListOptions } from "../../../../src"; -import { IO, Session } from "@zowe/imperative"; +import { Imperative, IO, Session } from "@zowe/imperative"; +import { inspect } from "util"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, stripNewLines, wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; +import { getUniqueDatasetName, stripNewLines, wait } from "../../../../../../__tests__/__src__/TestUtils"; +import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import * as fs from "fs"; import { posix } from "path"; import { Shell } from "@zowe/zos-uss-for-zowe-sdk"; import { PassThrough } from "stream"; import { text } from "stream/consumers"; +const rimraf = require("rimraf").sync; +const delayTime = 2000; const testData = "abcdefghijklmnopqrstuvwxyz"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; let defaultSystem: ITestPropertiesSchema; -let dsname: string; //uss -let dsname_seq: string; -let dsname_part: string; -let dsname_all_po: string; -let dsname_all_ps: string; +let dsname: string; let ussname: string; let ussDirname: string; let localDirname: string; let file: string; -describe("All Download System Tests", () => { - describe("Unencoded", () => { - describe("Download Data Sets", () => { +describe.each([false, true])("Download Data Set - Encoded: %s", (encoded: boolean) => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - dsname_seq = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); - dsname_part = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); - dsname_all_po = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); - dsname_all_ps = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`); - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname_seq); - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname_part); - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname_all_po); - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname_all_ps); + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_download" + }); + defaultSystem = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + testEnvironment.resources.session = REAL_SESSION; + + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, encoded); + testEnvironment.resources.datasets.push(dsname); + Imperative.console.info("Using dsname:" + dsname); + + // using unique DS function to generate unique USS file name + if (encoded) { + ussname = `${defaultSystem.unix.testdir}/ENCO#ED${dsname}`; + ussDirname = `${defaultSystem.unix.testdir}/ENCO#EDzos_file_download`; + localDirname = `${testEnvironment.workingDir}/ENCO#EDussDir`; + } else { + ussname = `${defaultSystem.unix.testdir}/${dsname}`; + ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; + localDirname = `${testEnvironment.workingDir}/ussDir`; + } + testEnvironment.resources.files.push(ussname, ussDirname); + testEnvironment.resources.localFiles.push(localDirname); + }); + + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + + describe("Success Scenarios", () => { + + describe("Physical sequential data set", () => { + + beforeEach(async () => { + let error; + let response; + + try { + response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + await wait(delayTime); + } catch (err) { + error = err; + } }); - afterAll(async () => { - testEnvironment.resources.datasets.push(dsname_seq, dsname_part, dsname_all_po, dsname_all_ps); - await TestEnvironment.cleanUp(testEnvironment); + afterEach(async () => { + let error; + let response; + + try { + response = await Delete.dataSet(REAL_SESSION, dsname); + await wait(delayTime); + } catch (err) { + error = err; + } + + // delete the top-level folder and the folders and file below + // variable 'file' should be set in the test + if (file != null) { + const folders = file.split("/"); + rimraf(folders[0]); + rimraf(file); + } + }); + + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(delayTime); + + try { + response = await Download.dataSet(REAL_SESSION, dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set with response timeout", async () => { + let error; + let response: IZosFilesResponse; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(delayTime); + + try { + response = await Download.dataSet(REAL_SESSION, dsname, {responseTimeout: 5}); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set and create folders and file in original letter case", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(delayTime); + + try { + response = await Download.dataSet(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + + // Check if folders and file are created in original uppercase + file.split("/").reduce((path, pathSegment) => { + const pathExists = fs.readdirSync(path).indexOf(pathSegment) !== -1; + expect(pathExists).toBeTruthy(); + return [path, pathSegment].join("/"); + }, "."); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { + binary: true + }; + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file for clean up in AfterEach + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + }); + + it("should download a data set in record mode", async () => { + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { + record: true + }; + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file for clean up in AfterEach + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; }); - describe("Success Scenarios", () => { - - describe("Physical sequential data set", () => { - //this test needs to be first because it requires dir to be created as uppercase (other tests have no requirement) - it("should download a data set and create folders and file in original letter case", async () => { - let error; - let response: IZosFilesResponse; - - // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); - await wait(waitTime); // Wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname_seq, { preserveOriginalLetterCase: true }); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - - // Convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname_seq.replace(regex, "/") + ".txt"; - - // Check if folders and file are created in original uppercase - file.split("/").reduce((path, pathSegment) => { - const pathExists = fs.readdirSync(path).indexOf(pathSegment) !== -1; - expect(pathExists).toBeTruthy(); - return [path, pathSegment].join("/"); - }, "."); - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); - await wait(waitTime); // Wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname_seq); - await wait(waitTime); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - - // Convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname_seq.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - - - it("should download a data set with response timeout", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); - await wait(waitTime); // Wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname_seq, { responseTimeout: 5 }); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - - // Convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname_seq.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set in binary mode", async () => { - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = { - binary: true - }; - - try { - response = await Download.dataSet(REAL_SESSION, dsname_seq, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - - // Convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname_seq.replace(regex, "/") + ".txt"; - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); - }); - it("should download a data set in record mode", async () => { - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = { - record: true - }; - - try { - response = await Download.dataSet(REAL_SESSION, dsname_seq, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - - // Convert the data set name to use as a path/file for cleanup - const regex = /\./gi; - file = dsname_seq.replace(regex, "/") + ".txt"; - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); - }); - - it("should download a data set and return Etag", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); - await wait(waitTime); // Wait 2 seconds - - const options: IDownloadOptions = { - returnEtag: true - }; - - try { - response = await Download.dataSet(REAL_SESSION, dsname_seq, options); - } catch (err) { - error = err; - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - expect(response.apiResponse.etag).toBeDefined(); - - // Convert the data set name to use as a path/file for cleanup - const regex = /\./gi; - file = dsname_seq.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - it("should download a data set that has been populated by upload and use file extension specified", async () => { - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = { - extension: "dat" - }; - - // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); - await wait(waitTime); // Wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname_seq, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - - // Convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname_seq.replace(regex, "/") + ".dat"; - file = file.toLowerCase(); - - // Add the file to localFiles resources for cleanup - testEnvironment.resources.localFiles.push(file); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set to a stream", async () => { - let error; - let response: IZosFilesResponse; - const responseStream = new PassThrough(); - - // Upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); - await wait(waitTime); // Wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname_seq, { stream: responseStream }); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1) - ); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(await text(responseStream)); - expect(fileContents).toEqual(testData); - }); - }); - - describe("Partitioned data set - all members", () => { - - it("should download a data set member", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.allMembers(REAL_SESSION, dsname_part); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("Data set downloaded successfully"); - - // Path file construction and assertion - const regex = /\./gi; - const file = dsname_part.replace(regex, "/") + "/member.txt"; - testEnvironment.resources.localFiles.push(file); // Add file to resources for cleanup - - // Comparing the downloaded contents - const fileContents = stripNewLines(fs.readFileSync(file).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set and create folders and file in original letter case", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); - await wait(waitTime); - - try { - response = await Download.allMembers(REAL_SESSION, dsname_part, { preserveOriginalLetterCase: true }); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("Data set downloaded successfully"); - - const regex = /\./gi; - const file = dsname_part.replace(regex, "/") + "/MEMBER.txt"; - testEnvironment.resources.localFiles.push(file); - - const fileContents = stripNewLines(fs.readFileSync(file).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set in binary mode", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); - await wait(waitTime); - - try { - response = await Download.allMembers(REAL_SESSION, dsname_part, { binary: true }); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("Data set downloaded successfully"); - - const regex = /\./gi; - const file = dsname_part.replace(regex, "/") + "/member.txt"; - testEnvironment.resources.localFiles.push(file); - }); - - it("should download a data set in record mode", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); - await wait(waitTime); - - try { - response = await Download.allMembers(REAL_SESSION, dsname_part, { record: true }); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("Data set downloaded successfully"); - - const regex = /\./gi; - file = dsname_part.replace(regex, "/") + "/member.txt"; - testEnvironment.resources.localFiles.push(file); - }); - - it("should download a data set and use file extension specified", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); - await wait(waitTime); - - try { - response = await Download.allMembers(REAL_SESSION, dsname_part, { extension: "dat" }); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("Data set downloaded successfully"); - - const regex = /\./gi; - const file = dsname_part.replace(regex, "/") + "/member.dat"; - testEnvironment.resources.localFiles.push(file); - }); - }); - - describe("Data sets matching - all data sets - PO", () => { - - it("should download a data set", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }]); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = dsname_all_po.toLowerCase().replace(regex, "/"); - testEnvironment.resources.localFiles.push(file + "/member.txt"); - - const fileContents = stripNewLines(fs.readFileSync(file + "/member.txt").toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set in binary mode", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); - - const options: IDownloadOptions = { - binary: true, - extension: ".txt", - directory: "testDir" - }; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }], options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = "testDir/" + dsname_all_po.replace(regex, "/") + "/member.txt"; - testEnvironment.resources.localFiles.push(file); - }); - - it("should download a data set in record mode", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); - - const options: IDownloadOptions = { - record: true, - extension: ".txt", - directory: "testDir" - }; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }], options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = "testDir/" + dsname_all_po.replace(regex, "/") + "/member.txt"; - testEnvironment.resources.localFiles.push(file); - }); - - it("should download a data set with a different extension", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }], {extension: "jcl"}); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = dsname_all_po.toLowerCase().replace(regex, "/"); - testEnvironment.resources.localFiles.push(file + "/member.jcl"); - - const fileContents = stripNewLines(fs.readFileSync(file + "/member.jcl").toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set with an extension map", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); - const ending = dsname_all_po.split(".").pop().toLowerCase(); - const extMap: any = {}; - extMap[ending] = "jcl"; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }], {extensionMap: extMap}); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = dsname_all_po.toLowerCase().replace(regex, "/"); - testEnvironment.resources.localFiles.push(file + "/member.jcl"); - - const fileContents = stripNewLines(fs.readFileSync(file + "/member.jcl").toString()); - expect(fileContents).toEqual(testData); - }); - }); - - describe("Data sets matching - all data sets - PS", () => { - - it("should download a data set", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }]); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = dsname_all_ps.toLowerCase() + ".txt"; - const fileContents = stripNewLines(fs.readFileSync(file).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set in binary mode", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); - - const options: IDownloadOptions = { - binary: true, - extension: ".txt", - directory: "testDir" - }; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }], options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = "testDir/" + dsname_all_ps.toLowerCase() + ".txt"; - }); - - it("should download a data set in record mode", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); - - const options: IDownloadOptions = { - record: true, - extension: ".txt", - directory: "testDir" - }; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }], options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = "testDir/" + dsname_all_ps.toLowerCase() + ".txt"; - }); - - it("should download a data set with a different extension", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }], {extension: "jcl"}); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = dsname_all_ps.toLowerCase() + ".jcl"; - const fileContents = stripNewLines(fs.readFileSync(file).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download a data set with an extension map", async () => { - let error; - let response; - - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); - const ending = dsname_all_ps.split(".").pop().toLowerCase(); - const extMap: any = {}; - extMap[ending] = "jcl"; - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }], {extensionMap: extMap}); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - const regex = /\./gi; - const file = dsname_all_ps.toLowerCase() + ".jcl"; - const fileContents = stripNewLines(fs.readFileSync(file).toString()); - expect(fileContents).toEqual(testData); - }); - }); + it("should download a data set and return Etag", async () => { + let error; + let response: IZosFilesResponse; + + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(delayTime); + + const options: IDownloadOptions = { + returnEtag: true + }; + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + expect(response.apiResponse.etag).toBeDefined(); + // convert the data set name to use as a path/file for clean up in AfterEach + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".txt"; + file = file.toLowerCase(); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); }); - describe("Failure Scenarios", () => { - describe("Physical sequential data set", () => { - - it("should display proper error message when missing session", async () => { - let response; - let error; - - try { - response = await Download.dataSet(undefined, dsname_seq); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Required object must be defined"); - }); - - it("should display proper message when downloading a data set that does not exist", async () => { - let response; - let error; - try { - response = await Download.dataSet(REAL_SESSION, dsname_seq+".F"); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("Data set not found."); - }); - }); - - describe("Partitioned data set - all members", () => { - it("should display proper error message when missing session", async () => { - let response; - let error; - - try { - response = await Download.allMembers(undefined, dsname_part); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("Expect Error: Required object must be defined"); - }); - - it("should display a relevant message when downloading data set members and the data set does not exist", async () => { - let response; - let error; - - try { - response = await Download.allMembers(REAL_SESSION, dsname_part + ".d"); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("Data set not cataloged"); - }); - }); + it("should download a data set that has been populated by upload and use file extension specified", async () => { + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { + extension: "dat" + }; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(delayTime); + + try { + response = await Download.dataSet(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + ".dat"; + file = file.toLowerCase(); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set to a stream", async () => { + let error; + let response: IZosFilesResponse; + const responseStream = new PassThrough(); + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + await wait(delayTime); + + try { + response = await Download.dataSet(REAL_SESSION, dsname, { stream: responseStream }); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(await text(responseStream)); + expect(fileContents).toEqual(testData); }); }); - describe("Download USS File", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download_uss" - }); - defaultSystem = testEnvironment.systemTestProperties; + describe("Partitioned data set - all members", () => { - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; + beforeEach(async () => { + let error; + let response; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD.USS`); + try { + response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + await wait(delayTime); + } catch (err) { + error = err; + } + }); + + afterEach(async () => { + let error; + let response; + + try { + response = await Delete.dataSet(REAL_SESSION, dsname); + await wait(delayTime); + } catch (err) { + error = err; + } - // using unique DS function to generate unique USS file name - ussname = `${defaultSystem.unix.testdir}/${dsname}`; - ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; - localDirname = `${testEnvironment.workingDir}/ussDir`; + // delete the top-level folder and the folders and file below + const folders = file.split("/"); + rimraf(folders[0]); }); - afterAll(async () => { - // Track local and USS files for cleanup - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.datasets.push(dsname); - testEnvironment.resources.files.push(ussname, ussDirname); + it("should download a data set member", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(delayTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/"); + file = file.toLowerCase(); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); + expect(fileContents).toEqual(testData); + }); - await TestEnvironment.cleanUp(testEnvironment); + it("should download a data set member with response timeout", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(delayTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname, {responseTimeout: 5}); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/"); + file = file.toLowerCase(); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); + expect(fileContents).toEqual(testData); }); - describe("Successful scenarios", () => { - it("should download uss file without any options", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download uss file with response timeout", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, { responseTimeout: 5 }); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download uss file and return Etag", async () => { - let error; - let response: IZosFilesResponse; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - const options: IDownloadOptions = { - returnEtag: true - }; - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.apiResponse.etag).toBeDefined(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - }); - - // When requesting etag, z/OSMF has a limit on file size when it stops to return etag by default (>8mb) - // We are passing X-IBM-Return-Etag to force z/OSMF to always return etag, but testing here for case where it would be optional - it("should download a 10mb uss file and return Etag", async () => { - let error; - let response: IZosFilesResponse; - - // Create a 10 mb buffer - const bufferSize = 10000000; - const buffer = new ArrayBuffer(bufferSize); - const data = Buffer.from(buffer); - - await Upload.bufferToUssFile(REAL_SESSION, ussname, data); - await wait(waitTime); //wait 2 seconds - - const options: IDownloadOptions = { - returnEtag: true - }; - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.apiResponse.etag).toBeDefined(); - }); - - it("should download uss file content in binary", async () => { - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = { - binary: true - }; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData), { binary: true }); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download ISO8859-1 uss file in binary mode", async () => { - let error; - let response: IZosFilesResponse; - const options: IDownloadOptions = {}; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData), { binary: true }); - await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "ISO8859-1"); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - }); - - it("should download IBM-1147 uss file with encoding mode", async () => { - let error; - let response: IZosFilesResponse; - const options: IDownloadOptions = {}; - - const data: string = "Hello, world¤"; - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); - await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "IBM-1147"); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(data.slice(0, -1) + "€"); - }); - - it("should download uss file content to local file", async () => { - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = { file: `test1.txt` }; - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`test1.txt`).toString()); - expect(fileContents).toEqual(testData); - - // Delete created local file - IO.deleteFile("test1.txt"); - }); - - it("should download uss file to a stream", async () => { - let error; - let response: IZosFilesResponse; - const responseStream = new PassThrough(); - - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.ussFile(REAL_SESSION, ussname, { stream: responseStream }); - } catch (err) { - error = err; - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(await text(responseStream)); - expect(fileContents).toEqual(testData); - }); + it("should download a data set and create folders and file in original letter case", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(delayTime); + + try { + response = await Download.allMembers(REAL_SESSION, dsname, { preserveOriginalLetterCase: true }); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.replace(regex, "/") + "/MEMBER.txt"; + + // Check if folders and file are created in original uppercase + file.split("/").reduce((path, pathSegment) => { + const pathExists = fs.readdirSync(path).indexOf(pathSegment) !== -1; + expect(pathExists).toBeTruthy(); + return [path, pathSegment].join("/"); + }, "."); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(file).toString()); + expect(fileContents).toEqual(testData); }); - describe("Failure scenarios", () => { - it("should display proper error message when missing session", async () => { - let response: IZosFilesResponse; - let error; - - try { - response = await Download.ussFile(undefined, ussname); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Required object must be defined"); - }); - - it("should display proper error message when missing uss file name", async () => { - let response: IZosFilesResponse; - let error; - - try { - response = await Download.ussFile(REAL_SESSION, undefined); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Specify the USS file name."); - }); - - it("should display proper error message when uss file name is empty string", async () => { - let response: IZosFilesResponse; - let error; - - try { - response = await Download.ussFile(REAL_SESSION, ""); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Specify the USS file name."); - }); - - it("should display proper error message when uss file data type is record", async () => { - let response: IZosFilesResponse; - let error; - - const options: IDownloadOptions = {file: `test1.txt`, record: true}; - - try { - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(error.message).toContain("Expect Error: Unsupported data type 'record' specified for USS file operation."); - }); + it("should download a data set in binary mode", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(delayTime); + + const options: IDownloadOptions = { + binary: true + }; + + try { + response = await Download.allMembers(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file for clean up in AfterEach + const regex = /\./gi; + file = dsname.replace(regex, "/") + "/member.txt"; + }); + + it("should download a data set in record mode", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(delayTime); + + const options: IDownloadOptions = { + record: true + }; + + try { + response = await Download.allMembers(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file for clean up in AfterEach + const regex = /\./gi; + file = dsname.replace(regex, "/") + "/member.txt"; + }); + + it("should download a data set and use file extension specified", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + await wait(delayTime); + + const options: IDownloadOptions = { + extension: "dat" + }; + + try { + response = await Download.allMembers(REAL_SESSION, dsname, options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain( + ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); + + // convert the data set name to use as a path/file for clean up in AfterEach + const regex = /\./gi; + file = dsname.replace(regex, "/") + "/member.dat"; }); }); - describe("Download USS Directory", () => { - const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - const anotherTestFileContents = testFileContents.toLowerCase(); - const binaryFileContents = String.fromCharCode(...Array(256).keys()); - const createZfsOptions: ICreateZfsOptions = { - perms: 755, - cylsPri: 10, - cylsSec: 2, - timeout: 20 + describe("Data sets matching - all data sets - PO", () => { + + beforeEach(async () => { + let error; + let response; + + try { + response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + await wait(delayTime); + } catch (err) { + error = err; + } + }); + + afterEach(async () => { + let error; + let response; + + try { + response = await Delete.dataSet(REAL_SESSION, dsname); + await wait(delayTime); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + // delete the top-level folder and the folders and file below + try { + const folders = file.split("/"); + rimraf(folders[0]); + } catch (err) { + // Do nothing, sometimes the files are not created. + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + }); + + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }]); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.toLowerCase().replace(regex, "/"); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + const options: IDownloadOptions = { + binary: true, + extension: ".txt", + directory: "testDir" }; - const mountZfsOptions: IMountFsOptions = { - "fs-type": "ZFS", - mode: "rdwr" + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + // convert the data set name to use as a path/file for clean up in AfterEach + const regex = /\./gi; + file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; + }); + + it("should download a data set in record mode", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + const options: IDownloadOptions = { + record: true, + extension: ".txt", + directory: "testDir" }; - let zfsName: string; - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download_uss_directory" - }); - defaultSystem = testEnvironment.systemTestProperties; + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + // convert the data set name to use as a path/file for clean up in AfterEach + const regex = /\./gi; + file = "testDir/" + dsname.replace(regex, "/") + "/member.txt"; + }); + + it("should download a data set with a different extension", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extension: "jcl"}); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.toLowerCase().replace(regex, "/"); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}/member.jcl`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set with an extension map", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname + "(member)"); + const ending = dsname.split(".").pop().toLowerCase(); + const extMap: any = {}; + extMap[ending] = "jcl"; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PO", vol: "*" }], {extensionMap: extMap}); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.toLowerCase().replace(regex, "/"); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}/member.jcl`).toString()); + expect(fileContents).toEqual(testData); + }); + }); + + describe("Data sets matching - all data sets - PS", () => { + + beforeEach(async () => { + let error; + let response; + + try { + response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + await wait(delayTime); + } catch (err) { + error = err; + } + }); + + afterEach(async () => { + let error; + let response; + + try { + response = await Delete.dataSet(REAL_SESSION, dsname); + await wait(delayTime); + } catch (err) { + error = err; + } + + // delete the top-level folder and the folders and file below + const folders = file.split("/"); + rimraf(folders[0]); + rimraf(file); + }); + + it("should download a data set", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }]); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + // convert the data set name to use as a path/file + const regex = /\./gi; + file = dsname.toLowerCase() + ".txt"; + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set in binary mode", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + const options: IDownloadOptions = { + binary: true, + extension: ".txt", + directory: "testDir" + }; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + file = "testdir/" + dsname.toLowerCase() + ".txt"; + }); + + it("should download a data set in record mode", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + const options: IDownloadOptions = { + record: true, + extension: ".txt", + directory: "testDir" + }; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], options); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + file = "testdir/" + dsname.toLowerCase() + ".txt"; + }); + + it("should download a data set with a different extension", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extension: "jcl"}); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + file = dsname.toLowerCase() + ".jcl"; + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download a data set with an extension map", async () => { + let error; + let response: IZosFilesResponse; + + // upload data to the newly created data set + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname); + const ending = dsname.split(".").pop().toLowerCase(); + const extMap: any = {}; + extMap[ending] = "jcl"; + + try { + response = await Download.allDataSets(REAL_SESSION, [{ dsname, dsorg: "PS", vol: "*" }], {extensionMap: extMap}); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); + + file = dsname.toLowerCase() + ".jcl"; + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); + expect(fileContents).toEqual(testData); + }); + }); + }); + + describe("Failure Scenarios", () => { + afterAll(() => { + // delete the top-level folder and the folders and file below + const folders = dsname.split("."); + rimraf(folders[0].toLowerCase()); + }); + + describe("Physical sequential data set", () => { + + it("should display proper error message when missing session", async () => { + let response: IZosFilesResponse; + let error; + + try { + response = await Download.dataSet(undefined, dsname); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Required object must be defined"); + }); + + it("should display proper message when downloading a data set that does not exist", async () => { + let response: IZosFilesResponse; + let error; + + try { + response = await Download.dataSet(REAL_SESSION, dsname); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("Data set not found."); + }); + }); + + describe("Partitioned data set - all members", () => { + it("should display proper error message when missing session", async () => { + let response: IZosFilesResponse; + let error; + + try { + response = await Download.allMembers(undefined, dsname); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("Expect Error: Required object must be defined"); + }); + + it("should display a relevant message when downloading data set members and the data set does not exist", async () => { + let response: IZosFilesResponse; + let error; + + try { + response = await Download.allMembers(REAL_SESSION, dsname + ".d"); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("Data set not cataloged"); + }); + }); + }); + + describe("Download USS File", () => { + afterAll(async () => { + // Delete created uss file + const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; + + try { + await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); + await wait(delayTime); + } catch (err) { + Imperative.console.error(err); + } + + // Delete created local file + IO.deleteFile(`./${posix.basename(ussname)}`); + }); + + describe("Successful scenarios", () => { + it("should download uss file without any options", async () => { + let error; + let response: IZosFilesResponse; + + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(delayTime); + + try { + response = await Download.ussFile(REAL_SESSION, ussname); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(testData); + + }); + + it("should download uss file with response timeout", async () => { + let error; + let response: IZosFilesResponse; + + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(delayTime); + + try { + response = await Download.ussFile(REAL_SESSION, ussname, {responseTimeout: 5}); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(testData); + + }); + + it("should download uss file and return Etag", async () => { + let error; + let response: IZosFilesResponse; + + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(delayTime); + + const options: IDownloadOptions = { + returnEtag: true + }; + + try { + response = await Download.ussFile(REAL_SESSION, ussname, options); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.apiResponse.etag).toBeDefined(); + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(testData); + + }); + + // When requesting etag, z/OSMF has a limit on file size when it stops to return etag by default (>8mb) + // We are passing X-IBM-Return-Etag to force z/OSMF to always return etag, but testing here for case where it would be optional + it("should download a 10mb uss file and return Etag", async () => { + let error; + let response: IZosFilesResponse; + + // Create a 10 mb buffer + const bufferSize = 10000000; + const buffer = new ArrayBuffer(bufferSize); + const data = Buffer.from(buffer); + + await Upload.bufferToUssFile(REAL_SESSION, ussname, data); + await wait(delayTime); + + const options: IDownloadOptions = { + returnEtag: true + }; + + try { + response = await Download.ussFile(REAL_SESSION, ussname, options); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.apiResponse.etag).toBeDefined(); + Imperative.console.info(response.apiResponse.etag); + }); + + it("should download uss file content in binary", async () => { + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = { + binary: true + }; + + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData), { binary: true }); + await wait(delayTime); + + try { + response = await Download.ussFile(REAL_SESSION, ussname, options); + } catch (err) { + error = err; + } + + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(testData); + }); + + it("should download ISO8859-1 uss file in binary mode", async () => { + let error; + let response: IZosFilesResponse; + const options: IDownloadOptions = {}; + + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData), { binary: true }); + await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "ISO8859-1"); + await wait(delayTime); + + try { + response = await Download.ussFile(REAL_SESSION, ussname, options); + } catch (err) { + error = err; + } + + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(testData); + }); - ussDirname = `${defaultSystem.unix.testdir}/zos_file_download_unecoded`; - localDirname = `${testEnvironment.workingDir}/ussDir`; + it("should download IBM-1147 uss file with encoding mode", async () => { + let error; + let response: IZosFilesResponse; + const options: IDownloadOptions = {}; + const data: string = "Hello, world¤"; + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); + await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "IBM-1147"); + await wait(delayTime); + + try { + response = await Download.ussFile(REAL_SESSION, ussname, options); + } catch (err) { + error = err; + } + + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); + expect(fileContents).toEqual(data.slice(0, -1) + "€"); + }); + + it("should download uss file content to local file", async () => { + + let error; + let response: IZosFilesResponse; + + const options: IDownloadOptions = {file: `test1.txt`}; + + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(delayTime); + + try { + response = await Download.ussFile(REAL_SESSION, ussname, options); + } catch (err) { + error = err; + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(fs.readFileSync(`test1.txt`).toString()); + expect(fileContents).toEqual(testData); + + // Delete created local file + IO.deleteFile("test1.txt"); + }); + + it("should download uss file to a stream", async () => { + let error; + let response: IZosFilesResponse; + const responseStream = new PassThrough(); + + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); + await wait(delayTime); + + try { + response = await Download.ussFile(REAL_SESSION, ussname, { stream: responseStream }); + } catch (err) { + error = err; + } + + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + + // Compare the downloaded contents to those uploaded + const fileContents = stripNewLines(await text(responseStream)); + expect(fileContents).toEqual(testData); + }); + }); + + describe("Failure scenarios", () => { + it("should display proper error message when missing session", async () => { + let response: IZosFilesResponse; + let error; + + try { + response = await Download.ussFile(undefined, ussname); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Required object must be defined"); + }); + + it("should display proper error message when missing uss file name", async () => { + let response: IZosFilesResponse; + let error; + + try { + response = await Download.ussFile(REAL_SESSION, undefined); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Specify the USS file name."); + }); + + it("should display proper error message when uss file name is empty string", async () => { + let response: IZosFilesResponse; + let error; + + try { + response = await Download.ussFile(REAL_SESSION, ""); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Specify the USS file name."); + }); + + it("should display proper error message when uss file data type is record", async () => { + let response: IZosFilesResponse; + let error; + + const options: IDownloadOptions = {file: `test1.txt`, record: true}; + + try { + response = await Download.ussFile(REAL_SESSION, ussname, options); + } catch (err) { + error = err; + } + + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(error.message).toContain("Expect Error: Unsupported data type 'record' specified for USS file operation."); + }); + }); + }); + + describe("Download USS Directory", () => { + describe("Success Scenarios", () => { + const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + const anotherTestFileContents = testFileContents.toLowerCase(); + const binaryFileContents = String.fromCharCode(...Array(256).keys()); + const createZfsOptions: ICreateZfsOptions = { + perms: 755, + cylsPri: 10, + cylsSec: 2, + timeout: 20 + }; + const mountZfsOptions: IMountFsOptions = { + "fs-type": "ZFS", + mode: "rdwr" + }; + let zfsName: string; + + const expectDownloaded = (dirname: string, options: IUSSListOptions = {}) => { + expect(fs.existsSync(`${dirname}/emptyFolder`)).toBe(true); + expect(fs.readdirSync(`${dirname}/emptyFolder`).length).toBe(0); + expect(fs.existsSync(`${dirname}/parentFolder`)).toBe(true); + expect(fs.readFileSync(`${dirname}/testFile.txt`, "utf-8")).toBe(testFileContents); + + // Test depth option + const depth = options.depth || 0; + expect(fs.existsSync(`${dirname}/parentFolder/childFolder`)).toBe(depth !== 1); + if (depth !== 1) { + expect(fs.readFileSync(`${dirname}/parentFolder/childFolder/anotherTestFile.txt`, "utf-8")).toBe(anotherTestFileContents); + } + + // Test filesys option + const filesys = options.filesys || false; + expect(fs.existsSync(`${dirname}/mountFolder`)).toBe(filesys); + if (filesys) { + expect(fs.readFileSync(`${dirname}/mountFolder/binaryFile.bin`, "utf-8")).toBe(binaryFileContents); + } + + // Test symlinks option + const symlinks = options.symlinks || false; + expect(fs.existsSync(`${dirname}/testFile.lnk`)).toBe(!symlinks); + if (!symlinks) { + expect(fs.readFileSync(`${dirname}/testFile.lnk`, "utf-8")).toBe(testFileContents); + } + }; + + beforeAll(async () => { const emptyFolder = posix.join(ussDirname, "emptyFolder"); const parentFolder = posix.join(ussDirname, "parentFolder"); const childFolder = posix.join(parentFolder, "childFolder"); @@ -1142,7 +1370,7 @@ describe("All Download System Tests", () => { } // Create and mount file system - zfsName = getUniqueDatasetName(defaultSystem.zosmf.user); + zfsName = getUniqueDatasetName(defaultSystem.zosmf.user, encoded); await Create.zfs(REAL_SESSION, zfsName, createZfsOptions); await Mount.fs(REAL_SESSION, zfsName, mountFolder, mountZfsOptions); @@ -1155,8 +1383,6 @@ describe("All Download System Tests", () => { // Create symlink const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); - - testEnvironment.resources.files.push(testSymlink); }); afterEach(() => { @@ -1171,571 +1397,129 @@ describe("All Download System Tests", () => { // Delete directory recursively const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); await Shell.executeSshCwd(SSH_SESSION, `rm testFile.lnk`, ussDirname, jest.fn()); - // await Delete.ussFile(REAL_SESSION, ussDirname, true); - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(ussDirname); - await TestEnvironment.cleanUp(testEnvironment); + await Delete.ussFile(REAL_SESSION, ussDirname, true); }); - describe("Success Scenarios", () => { - const expectDownloaded = (dirname: string, options: IUSSListOptions = {}) => { - expect(fs.existsSync(`${dirname}/emptyFolder`)).toBe(true); - expect(fs.readdirSync(`${dirname}/emptyFolder`).length).toBe(0); - expect(fs.existsSync(`${dirname}/parentFolder`)).toBe(true); - expect(fs.readFileSync(`${dirname}/testFile.txt`, "utf-8")).toBe(testFileContents); - - // Test depth option - const depth = options.depth || 0; - expect(fs.existsSync(`${dirname}/parentFolder/childFolder`)).toBe(depth !== 1); - if (depth !== 1) { - expect(fs.readFileSync(`${dirname}/parentFolder/childFolder/anotherTestFile.txt`, "utf-8")).toBe(anotherTestFileContents); - } - - // Test filesys option - const filesys = options.filesys || false; - expect(fs.existsSync(`${dirname}/mountFolder`)).toBe(filesys); - if (filesys) { - expect(fs.readFileSync(`${dirname}/mountFolder/binaryFile.bin`, "utf-8")).toBe(binaryFileContents); - } - - // Test symlinks option - const symlinks = options.symlinks || false; - expect(fs.existsSync(`${dirname}/testFile.lnk`)).toBe(!symlinks); - if (!symlinks) { - expect(fs.readFileSync(`${dirname}/testFile.lnk`, "utf-8")).toBe(testFileContents); - } - }; - - it("should download directory recursively", async () => { - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname); - }); - - it("should download directory with depth of 1", async () => { - const listOptions: IUSSListOptions = { depth: 1 }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should download directory including all filesystems", async () => { - const listOptions: IUSSListOptions = { filesys: true }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should download directory excluding symlinks", async () => { - const listOptions: IUSSListOptions = { symlinks: true }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should not download files that already exist", async () => { - let caughtError; - const testFile = posix.join(localDirname, "testFile.txt"); - try { - fs.mkdirSync(localDirname); - fs.writeFileSync(testFile, "test"); - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expect(fs.readFileSync(testFile).toString()).toEqual("test"); - }); - - it("should download files that already exist when overwrite is true", async () => { - let caughtError; - const testFile = posix.join(localDirname, "testFile.txt"); - try { - fs.mkdirSync(localDirname); - fs.writeFileSync(testFile, "test"); - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname, overwrite: true }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expect(fs.readFileSync(testFile).toString()).toEqual(testFileContents); - }); + it("should download directory recursively", async () => { + let caughtError; + try { + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname); }); - describe("Failure Scenarios", () => { - it("should throw error when session is undefined", async () => { - let caughtError; - try { - await Download.ussDir(undefined, ussDirname); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeDefined(); - expect(caughtError.message).toBe("Expect Error: Required object must be defined"); - }); - - it("should throw error when USS dir name is undefined", async () => { - let caughtError; - try { - await Download.ussDir(REAL_SESSION, undefined); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeDefined(); - expect(caughtError.message).toBe("Expect Error: Specify the USS directory name."); - }); - - it("should throw error when USS dir name is empty string", async () => { - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ""); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeDefined(); - expect(caughtError.message).toBe("Expect Error: Specify the USS directory name."); - }); - - it("should fail to download directory that does not exist", async () => { - let caughtError; - try { - await Download.ussDir(REAL_SESSION, posix.join(ussDirname, "invalidDir"), { directory: testEnvironment.workingDir }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeDefined(); - expect(stripNewLines(caughtError.message)).toContain("Path name not found"); - }); + it("should download directory with depth of 1", async () => { + const listOptions: IUSSListOptions = { depth: 1 }; + let caughtError; + try { + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname, listOptions); }); - }); - }); - describe("Encoded", () => { - describe("Download Data Set - encoded", () => { + it("should download directory including all filesystems", async () => { + const listOptions: IUSSListOptions = { filesys: true }; + let caughtError; + try { + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname, listOptions); + }); - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download_encoded" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - dsname_seq = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); - dsname_part = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); - dsname_all_po = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); - dsname_all_ps = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true); - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname_seq); - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname_part); - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname_all_po); - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname_all_ps); - - // using unique DS function to generate unique USS file name - ussname = `${defaultSystem.unix.testdir}/ENCO#ED${dsname}`; - ussDirname = `${defaultSystem.unix.testdir}/ENCO#EDzos_file_download`; - localDirname = `${testEnvironment.workingDir}/ENCO#EDussDir`; + it("should download directory excluding symlinks", async () => { + const listOptions: IUSSListOptions = { symlinks: true }; + let caughtError; + try { + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + expectDownloaded(localDirname, listOptions); }); - afterAll(async () => { - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.datasets.push(ussname, ussDirname); - await TestEnvironment.cleanUp(testEnvironment); + it("should not download files that already exist", async () => { + let caughtError; + const testFile = posix.join(localDirname, "testFile.txt"); + try { + fs.mkdirSync(localDirname); + fs.writeFileSync(testFile, "test"); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + expect(fs.readFileSync(testFile).toString()).toEqual("test"); }); - describe("Success Scenarios", () => { - - describe("Physical sequential data set", () => { - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_seq); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.dataSet(REAL_SESSION, dsname_seq); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname_seq.replace(regex, "/") + ".txt"; - file = file.toLowerCase(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - }); - - describe("Partitioned data set - all members", () => { - it("should download a data set member", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_part + "(member)"); - await wait(waitTime); //wait 2 seconds - - try { - response = await Download.allMembers(REAL_SESSION, dsname_part); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain( - ZosFilesMessages.datasetDownloadedSuccessfully.message.substring(0, "Data set downloaded successfully".length + 1)); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname_part.replace(regex, "/"); - file = file.toLowerCase(); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); - expect(fileContents).toEqual(testData); - }); - }); - - describe("Data sets matching - all data sets - PO", () => { - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_po + "(member)"); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_po, dsorg: "PO", vol: "*" }]); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - // convert the data set name to use as a path/file - const regex = /\./gi; - file = dsname_all_po.toLowerCase().replace(regex, "/"); - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}/member.txt`).toString()); - expect(fileContents).toEqual(testData); - }); - }); - - describe("Data sets matching - all data sets - PS", () => { - - it("should download a data set", async () => { - let error; - let response: IZosFilesResponse; - - // upload data to the newly created data set - await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(testData), dsname_all_ps); - - try { - response = await Download.allDataSets(REAL_SESSION, [{ dsname: dsname_all_ps, dsorg: "PS", vol: "*" }]); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain("1 data set(s) downloaded successfully"); - - file = dsname_all_ps.toLowerCase() + ".txt"; - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`${file}`).toString()); - expect(fileContents).toEqual(testData); - }); - }); + it("should download files that already exist when overwrite is true", async () => { + let caughtError; + const testFile = posix.join(localDirname, "testFile.txt"); + try { + fs.mkdirSync(localDirname); + fs.writeFileSync(testFile, "test"); + await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname, overwrite: true }); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + expect(fs.readFileSync(testFile).toString()).toEqual(testFileContents); }); }); - describe("Download USS File - encoded", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download_uss_encoded" - }); - defaultSystem = testEnvironment.systemTestProperties; - - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - // using unique DS function to generate unique USS file name - ussname = `${defaultSystem.unix.testdir}/ENCO#ED${getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, true)}`; + describe("Failure Scenarios", () => { + it("should throw error when session is undefined", async () => { + let caughtError; + try { + await Download.ussDir(undefined, ussDirname); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeDefined(); + expect(caughtError.message).toBe("Expect Error: Required object must be defined"); }); - afterAll(async () => { - testEnvironment.resources.files.push(ussname); - await TestEnvironment.cleanUp(testEnvironment); + it("should throw error when USS dir name is undefined", async () => { + let caughtError; + try { + await Download.ussDir(REAL_SESSION, undefined); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeDefined(); + expect(caughtError.message).toBe("Expect Error: Specify the USS directory name."); }); - describe("Successful scenarios", () => { - it("should download uss file without any options", async () => { - let error; - let response: IZosFilesResponse; - - // Upload the USS file - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); // wait 2 seconds - - try { - // Download the USS file - response = await Download.ussFile(REAL_SESSION, ussname); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString()); - expect(fileContents).toEqual(testData); - - // Track the local file created during the download - testEnvironment.resources.localFiles.push(`./${posix.basename(ussname)}`); - }); - - it("should download uss file content to local file", async () => { - let error; - let response: IZosFilesResponse; - - const options: IDownloadOptions = { file: `test1.txt` }; - - // Upload the USS file - await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData)); - await wait(waitTime); // wait 2 seconds - - try { - // Download the USS file to a local file - response = await Download.ussFile(REAL_SESSION, ussname, options); - } catch (err) { - error = err; - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = stripNewLines(fs.readFileSync(`test1.txt`).toString()); - expect(fileContents).toEqual(testData); - - // Track the local file created during the test - testEnvironment.resources.localFiles.push(`test1.txt`); - }); + it("should throw error when USS dir name is empty string", async () => { + let caughtError; + try { + await Download.ussDir(REAL_SESSION, ""); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeDefined(); + expect(caughtError.message).toBe("Expect Error: Specify the USS directory name."); }); - }); - describe("Download USS Directory - encoded", () => { - describe("Success Scenarios", () => { - const testFileContents = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - const anotherTestFileContents = testFileContents.toLowerCase(); - const binaryFileContents = String.fromCharCode(...Array(256).keys()); - const createZfsOptions: ICreateZfsOptions = { - perms: 755, - cylsPri: 10, - cylsSec: 2, - timeout: 20 - }; - const mountZfsOptions: IMountFsOptions = { - "fs-type": "ZFS", - mode: "rdwr" - }; - let zfsName: string; - - const expectDownloaded = (dirname: string, options: IUSSListOptions = {}) => { - expect(fs.existsSync(`${dirname}/emptyFolder`)).toBe(true); - expect(fs.readdirSync(`${dirname}/emptyFolder`).length).toBe(0); - expect(fs.existsSync(`${dirname}/parentFolder`)).toBe(true); - expect(fs.readFileSync(`${dirname}/testFile.txt`, "utf-8")).toBe(testFileContents); - - const depth = options.depth || 0; - expect(fs.existsSync(`${dirname}/parentFolder/childFolder`)).toBe(depth !== 1); - if (depth !== 1) { - expect(fs.readFileSync(`${dirname}/parentFolder/childFolder/anotherTestFile.txt`, "utf-8")).toBe(anotherTestFileContents); - } - - const filesys = options.filesys || false; - expect(fs.existsSync(`${dirname}/mountFolder`)).toBe(filesys); - if (filesys) { - expect(fs.readFileSync(`${dirname}/mountFolder/binaryFile.bin`, "utf-8")).toBe(binaryFileContents); - } - - const symlinks = options.symlinks || false; - expect(fs.existsSync(`${dirname}/testFile.lnk`)).toBe(!symlinks); - if (!symlinks) { - expect(fs.readFileSync(`${dirname}/testFile.lnk`, "utf-8")).toBe(testFileContents); - } - }; - - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_download_uss_dir_encoded" - }); - defaultSystem = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - ussDirname = `${defaultSystem.unix.testdir}/ENCO#EDzos_file_download`; - const emptyFolder = posix.join(ussDirname, "emptyFolder"); - const parentFolder = posix.join(ussDirname, "parentFolder"); - const childFolder = posix.join(parentFolder, "childFolder"); - const testFile = posix.join(ussDirname, "testFile.txt"); - const anotherTestFile = posix.join(childFolder, "anotherTestFile.txt"); - const mountFolder = posix.join(ussDirname, "mountFolder"); - const binaryFile = posix.join(mountFolder, "binaryFile.bin"); - const testSymlink = posix.join(ussDirname, "testFile.lnk"); - - testEnvironment = await TestEnvironment.setUp({ - testName: "download_uss_dir_encoded" - }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - // Create directories - for (const directory of [ussDirname, emptyFolder, parentFolder, childFolder, mountFolder]) { - await Create.uss(REAL_SESSION, directory, "directory"); - } - - // Create and mount file system - zfsName = getUniqueDatasetName(defaultSystem.zosmf.user, true); - await Create.zfs(REAL_SESSION, zfsName, createZfsOptions); - await Mount.fs(REAL_SESSION, zfsName, mountFolder, mountZfsOptions); - - // Upload files - await Upload.bufferToUssFile(REAL_SESSION, testFile, Buffer.from(testFileContents)); - await Upload.bufferToUssFile(REAL_SESSION, anotherTestFile, Buffer.from(anotherTestFileContents)); - await Upload.bufferToUssFile(REAL_SESSION, binaryFile, Buffer.from(binaryFileContents), { binary: true }); - await Utilities.chtag(REAL_SESSION, binaryFile, Tag.BINARY); - - testEnvironment.resources.files.push(testFile, anotherTestFile, binaryFile); - - // Create symlink - const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); - await Shell.executeSshCwd(SSH_SESSION, `ln -s ${posix.basename(testFile)} ${posix.basename(testSymlink)}`, ussDirname, jest.fn()); testEnvironment.resources.files.push(ussDirname, mountFolder, testFile, anotherTestFile, binaryFile, testSymlink); - }); - - afterEach(() => { - IO.deleteDirTree(localDirname); - }); - - afterAll(async () => { - // Unmount and delete file system - await Unmount.fs(REAL_SESSION, zfsName); - await Delete.zfs(REAL_SESSION, zfsName); - - // Delete directory recursively - const SSH_SESSION: any = TestEnvironment.createSshSession(testEnvironment); - await Shell.executeSshCwd(SSH_SESSION, `rm testFile.lnk`, ussDirname, jest.fn()); - // await Delete.ussFile(REAL_SESSION, ussDirname, true); - testEnvironment.resources.localFiles.push(localDirname); - testEnvironment.resources.files.push(ussDirname); - await TestEnvironment.cleanUp(testEnvironment); - }); - - it("should download directory recursively", async () => { - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname); - }); - - it("should download directory with depth of 1", async () => { - const listOptions: IUSSListOptions = { depth: 1 }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should download directory including all filesystems", async () => { - const listOptions: IUSSListOptions = { filesys: true }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should download directory excluding symlinks", async () => { - const listOptions: IUSSListOptions = { symlinks: true }; - let caughtError; - try { - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }, listOptions); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expectDownloaded(localDirname, listOptions); - }); - - it("should not download files that already exist", async () => { - let caughtError; - const testFile = posix.join(localDirname, "testFile.txt"); - try { - fs.mkdirSync(localDirname); - fs.writeFileSync(testFile, "test"); - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expect(fs.readFileSync(testFile).toString()).toEqual("test"); - }); - - it("should download files that already exist when overwrite is true", async () => { - let caughtError; - const testFile = posix.join(localDirname, "testFile.txt"); - try { - fs.mkdirSync(localDirname); - fs.writeFileSync(testFile, "test"); - await Download.ussDir(REAL_SESSION, ussDirname, { directory: localDirname, overwrite: true }); - } catch (error) { - caughtError = error; - } - expect(caughtError).toBeUndefined(); - expect(fs.readFileSync(testFile).toString()).toEqual(testFileContents); - }); + it("should fail to download directory that does not exist", async () => { + let caughtError; + try { + await Download.ussDir(REAL_SESSION, posix.join(ussDirname, "invalidDir"), { directory: testEnvironment.workingDir }); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeDefined(); + expect(stripNewLines(caughtError.message)).toContain("Path name not found"); }); }); }); -}); \ No newline at end of file +}); From 73e9201e329f32769c92bd11ac5b513a3838a698 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Tue, 8 Oct 2024 17:20:34 -0400 Subject: [PATCH 58/65] Clean up remaining resources for zosfiles Signed-off-by: Timothy Johnson --- __tests__/__src__/TestUtils.ts | 14 +- .../__src__/environment/ITestEnvironment.ts | 2 +- .../__src__/environment/TestEnvironment.ts | 42 +- ...rkflows.list.active.details.system.test.ts | 31 +- ....retrieveWorkflowDefinition.system.test.ts | 20 +- ...cli.workflows.create.common.system.test.ts | 34 +- ...cli.workflows.delete.common.system.test.ts | 32 +- ...cli.workflows.delete.common.system.test.ts | 20 +- .../cli.workflows.start.common.system.test.ts | 20 +- .../uss/cli.files.download.uss.system.test.ts | 55 +- .../fs/cli.files.mount.fs.system.test.ts | 25 +- .../dtu/cli.dir.upload.dtu.system.test.ts | 21 +- .../ftu/cli.files.upload.ftu.system.test.ts | 15 +- .../view/uss/View.uss.system.test.ts | 38 +- .../cli.zos-jobs.cancel.job.system.test.ts | 4 +- ...li.zos-jobs.download.output.system.test.ts | 4 +- .../cli.zos-jobs.list.jobs.system.test.ts | 4 +- ...s.list.spool-files-by-jobid.system.test.ts | 4 +- .../search/cli.zos-jobs.search.job.test.ts | 2 +- ...li.zos-jobs.submit.data-set.system.test.ts | 4 +- ....zos-jobs.submit.local-file.system.test.ts | 2 +- .../issue/cli.issue.ssh.system.test.ts | 71 +- .../__system__/Archive.system.test.ts | 4 +- .../__system__/Cancel.system.test.ts | 20 +- .../api/ArchivedDelete.system.test.ts | 20 +- .../__system__/api/Create.system.test.ts | 26 +- .../__system__/api/Definition.system.test.ts | 36 +- .../__system__/api/Delete.system.test.ts | 20 +- .../api/ListArchivedWorkflows.system.test.ts | 20 +- .../api/ListWorkflows.system.test.ts | 20 +- .../__system__/api/Properties.system.test.ts | 44 +- .../__system__/api/Start.system.test.ts | 30 +- .../methods/copy/Copy.system.test.ts | 5 - .../methods/create/Create.system.test.ts | 30 - .../delete/DeleteDataset.system.test.ts | 6 - .../delete/DeleteUSSFile.system.test.ts | 26 +- .../methods/delete/DeleteZfs.system.test.ts | 2 - .../methods/download/Download.system.test.ts | 17 +- .../__system__/methods/get/Get.system.test.ts | 93 +- .../methods/hDelete/HDelete.system.test.ts | 2 - .../methods/hMigrate/HMigrate.system.test.ts | 2 - .../methods/hRecall/HRecall.system.test.ts | 2 - .../methods/invoke/DefineVSAM.ams.temp | 1 + .../methods/invoke/Invoke.system.test.ts | 25 +- .../methods/list/List.system.test.ts | 5 +- .../methods/mount/Mount.system.test.ts | 4 - .../methods/rename/Rename.system.test.ts | 4 - .../methods/search/Search.system.test.ts | 1 - .../methods/upload/Upload.system.test.ts | 2195 ++++++++--------- .../methods/upload/testfiles/file1.txt | 1 + .../methods/upload/testfiles/file2.txt | 1 + .../methods/upload/testfiles/file3.txt | 1 + .../upload/testfiles/longline/longline.txt | 1 + .../upload/testfiles/space dir/file4.txt | 1 + .../methods/upload/testfiles/upload.txt | 1 + .../utilities/Utilities.system.test.ts | 23 +- .../__system__/CancelJobs.system.test.ts | 4 +- .../__system__/DownloadJobs.system.test.ts | 4 +- .../__system__/GetJobs.system.test.ts | 4 +- .../__system__/ModifyJobs.system.test.ts | 4 +- .../__system__/MonitorJobs.system.test.ts | 4 +- .../__system__/SearchJobs.system.test.ts | 2 +- .../__system__/SubmitJobs.system.test.ts | 2 +- 63 files changed, 1263 insertions(+), 1914 deletions(-) create mode 100644 packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams.temp create mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file1.txt create mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file2.txt create mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file3.txt create mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/longline/longline.txt create mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/space dir/file4.txt create mode 100644 packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt diff --git a/__tests__/__src__/TestUtils.ts b/__tests__/__src__/TestUtils.ts index 9ffd278f44..b3eea01a26 100644 --- a/__tests__/__src__/TestUtils.ts +++ b/__tests__/__src__/TestUtils.ts @@ -11,13 +11,10 @@ import { randomBytes } from "crypto"; import * as fs from "fs"; -import { Imperative, Headers, AbstractSession, IO } from "@zowe/imperative"; +import { Imperative, Headers, AbstractSession } from "@zowe/imperative"; import { ZosmfRestClient } from "../../packages/core/src"; import { ZosFilesConstants, Delete } from "../../packages/zosfiles/src"; import { DeleteJobs, ICommonJobParms, IDeleteJobParms, IJob } from "../../packages/zosjobs/src"; -import { posix } from "path"; -import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process"; -import { ITestEnvironment } from "./environment/ITestEnvironment"; import { promisify } from "util"; /** @@ -28,12 +25,7 @@ export function deleteLocalFile(filePath: string): void { try { fs.unlinkSync(filePath); } catch { - // If fs.unlinkSync fails, try to delete it with IO.deleteFile - try { - IO.deleteFile(posix.basename(filePath)); - } catch { - throw new Error(`Error deleting local file: ${filePath}`); - } + throw new Error(`Error deleting local file: ${filePath}`); } } @@ -47,7 +39,7 @@ export function deleteLocalDirectories(directories: string[]): void { if (fs.existsSync(dir)) { fs.rmdirSync(dir, { recursive: true }); } - } catch (err) { + } catch { throw new Error(`Error deleting directory: ${dir}`); } }); diff --git a/__tests__/__src__/environment/ITestEnvironment.ts b/__tests__/__src__/environment/ITestEnvironment.ts index e43351d413..7424d5b4ac 100644 --- a/__tests__/__src__/environment/ITestEnvironment.ts +++ b/__tests__/__src__/environment/ITestEnvironment.ts @@ -17,7 +17,7 @@ import { ITestEnvironmentResources } from "./ITestEnvironmentResources"; * @export * @interface ITestEnvironment */ -export interface ITestEnvironment extends IBaseTestEnvironment{ +export interface ITestEnvironment extends IBaseTestEnvironment{ /** * A collection of resources used within the test environment that need to be cleaned up once test finishes. * @type {ITestEnvironmentResources} diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index dd1dfe4333..d967af4763 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -53,7 +53,7 @@ export class TestEnvironment extends BaseTestEnvironment { jobs: [], jobData: [], datasets: [], - session: result.resources?.session || null + session: params.skipProperties ? null : TestEnvironment.createZosmfSession(result) }; // Return the test environment including working directory that the tests should be using return result; @@ -75,31 +75,25 @@ export class TestEnvironment extends BaseTestEnvironment { // Deleting resources (if they exist) if (testEnvironment?.resources?.session) { const session = testEnvironment.resources.session; - try{ - for (const file of testEnvironment.resources.localFiles) { - deleteLocalFile(file); - } - for (const file of testEnvironment.resources.files) { - await deleteFiles(session, file); - } - for (const job of testEnvironment.resources.jobs) { - await deleteJob(session, job); - } - for (const jobData of testEnvironment.resources.jobData) { - if (jobData.jobname && jobData.jobid) { - await deleteJobCommon(session, jobData); - } else { - Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); - } - } - for (const dataset of testEnvironment.resources.datasets) { - await deleteDataset(session, dataset); - } - }catch (error){ - if (error.mDetails?.httpStatus !== 404) { - throw error; + for (const file of testEnvironment.resources.localFiles) { + deleteLocalFile(file); + } + for (const file of testEnvironment.resources.files) { + await deleteFiles(session, file); + } + for (const job of testEnvironment.resources.jobs) { + await deleteJob(session, job); + } + for (const jobData of testEnvironment.resources.jobData) { + if (jobData.jobname && jobData.jobid) { + await deleteJobCommon(session, jobData); + } else { + Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); } } + for (const dataset of testEnvironment.resources.datasets) { + await deleteDataset(session, dataset); + } testEnvironment.resources = { localFiles: [], diff --git a/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts b/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts index 312134ab74..cd8ae968ad 100644 --- a/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts @@ -16,7 +16,7 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environm import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName, wait, waitTime } from "../../../../../../../__tests__/__src__/TestUtils"; import { CreateWorkflow, DeleteWorkflow } from "@zowe/zos-workflows-for-zowe-sdk"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; import { runCliScript } from "@zowe/cli-test-utils"; @@ -53,15 +53,10 @@ describe("List active workflow details cli system tests", () => { }); describe("Create workflow using uss file", () => { beforeAll(async () => { - let error; - // Upload files only for successful scenarios - try { - await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } + await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); + await wait(waitTime); //wait 2 seconds + testEnvironment.resources.files.push(definitionFile); // Create a workflow instance in zOS/MF to list const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); @@ -69,27 +64,13 @@ describe("List active workflow details cli system tests", () => { wfKey = response.workflowKey; }); afterAll(async () => { - let error; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } - // deleting wf instance const response: any = await ZosmfRestClient.getExpectJSON(REAL_SESSION, "/zosmf/workflow/rest/1.0/workflows?workflowName=" + wfName); response.workflows.forEach(async (element: any) => { if (element.workflowName === wfName) { - wfKey = element.workflowKey; try { - await DeleteWorkflow.deleteWorkflow(REAL_SESSION, wfKey); - } catch (err) { - error = err; - } + await DeleteWorkflow.deleteWorkflow(REAL_SESSION, element.workflowKey); + } catch { /* Do nothing */ } } }); }); diff --git a/packages/cli/__tests__/workflows/__system__/List/retrieveWorkflowDefinition/cli.workflows.list.retrieveWorkflowDefinition.system.test.ts b/packages/cli/__tests__/workflows/__system__/List/retrieveWorkflowDefinition/cli.workflows.list.retrieveWorkflowDefinition.system.test.ts index d3020da689..06b0c03045 100644 --- a/packages/cli/__tests__/workflows/__system__/List/retrieveWorkflowDefinition/cli.workflows.list.retrieveWorkflowDefinition.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/List/retrieveWorkflowDefinition/cli.workflows.list.retrieveWorkflowDefinition.system.test.ts @@ -9,14 +9,14 @@ * */ -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; +import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -49,19 +49,7 @@ describe("Retrieve workflow definition cli system tests", () => { beforeAll(async () => { // Upload files only for successful scenarios await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); describe("Success Scenarios", () => { it("Should return the details of a workflow definition file.", async () => { diff --git a/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts b/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts index db1762b2eb..53727050d4 100644 --- a/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts @@ -11,13 +11,14 @@ import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; import { DeleteWorkflow } from "@zowe/zos-workflows-for-zowe-sdk"; -import { Upload, Create, CreateDataSetTypeEnum, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; +import { Upload, Create, CreateDataSetTypeEnum } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -57,19 +58,7 @@ describe("Create workflow cli system tests", () => { beforeAll(async () => { // Upload files only for successful scenarios await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); describe("Success Scenarios", () => { afterEach(async () => { @@ -184,20 +173,7 @@ describe("Create workflow cli system tests", () => { error = err; } await Upload.fileToDataset(REAL_SESSION, workflowDs, definitionDs); - - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_DS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + "/" + definitionDs; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.datasets.push(definitionDs); }); describe("Success Scenarios", () => { afterEach(async () => { diff --git a/packages/cli/__tests__/workflows/__system__/delete/cli.workflows.delete.common.system.test.ts b/packages/cli/__tests__/workflows/__system__/delete/cli.workflows.delete.common.system.test.ts index 72bb9d25af..76ffabce59 100644 --- a/packages/cli/__tests__/workflows/__system__/delete/cli.workflows.delete.common.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/delete/cli.workflows.delete.common.system.test.ts @@ -9,15 +9,15 @@ * */ -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; +import { deleteFiles, getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; import { CreateWorkflow } from "@zowe/zos-workflows-for-zowe-sdk"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -56,17 +56,7 @@ describe("Delete workflow cli system tests", () => { await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true}); }); afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + await deleteFiles(REAL_SESSION, definitionFile); }); beforeEach(async () => { const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); @@ -108,17 +98,7 @@ describe("Delete workflow cli system tests", () => { await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); }); afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + await deleteFiles(REAL_SESSION, definitionFile); }); beforeEach(async () => { await CreateWorkflow.createWorkflow(REAL_SESSION, wfName + "a", definitionFile, system, owner); diff --git a/packages/cli/__tests__/workflows/__system__/deleteArchived/cli.workflows.delete.common.system.test.ts b/packages/cli/__tests__/workflows/__system__/deleteArchived/cli.workflows.delete.common.system.test.ts index e08ec69fa4..240b2ffcfe 100644 --- a/packages/cli/__tests__/workflows/__system__/deleteArchived/cli.workflows.delete.common.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/deleteArchived/cli.workflows.delete.common.system.test.ts @@ -9,15 +9,15 @@ * */ -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import { Session } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; import { ArchiveWorkflow, CreateWorkflow } from "@zowe/zos-workflows-for-zowe-sdk"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -54,19 +54,7 @@ describe("Delete workflow cli system tests", () => { beforeAll(async () => { // Upload files only for successful scenarios await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); beforeEach(async () => { const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); diff --git a/packages/cli/__tests__/workflows/__system__/start/cli.workflows.start.common.system.test.ts b/packages/cli/__tests__/workflows/__system__/start/cli.workflows.start.common.system.test.ts index ba3664273e..875a9c6748 100644 --- a/packages/cli/__tests__/workflows/__system__/start/cli.workflows.start.common.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/start/cli.workflows.start.common.system.test.ts @@ -9,16 +9,16 @@ * */ -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import { Session, Imperative } from "@zowe/imperative"; -import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; import { join } from "path"; import { CreateWorkflow, PropertiesWorkflow, DeleteWorkflow, startT, IWorkflowInfo, WorkflowConstants, IStepInfo } from "@zowe/zos-workflows-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; const resolveConflict: startT = "outputFileValue"; const stepName = "echo"; @@ -56,19 +56,7 @@ describe("Start workflow cli system tests", () => { beforeAll(async () => { // Upload files only for successful scenarios await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); describe("Success Scenarios", () => { afterEach(async () => { diff --git a/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts index 4b266bc962..89f97840a5 100644 --- a/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/download/uss/cli.files.download.uss.system.test.ts @@ -14,9 +14,8 @@ import * as path from "path"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; -import { ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; +import { deleteFiles, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; @@ -60,32 +59,11 @@ describe("Download USS File", () => { defaultSys = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; const data: string = "abcdefghijklmnopqrstuvwxyz"; - const endpoint: string = - ZosFilesConstants.RESOURCE + - ZosFilesConstants.RES_USS_FILES + - ussname; - await ZosmfRestClient.putExpectString( - REAL_SESSION, - endpoint, - [], - data - ); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); }); afterAll(async () => { - const endpoint: string = - ZosFilesConstants.RESOURCE + - ZosFilesConstants.RES_USS_FILES + - ussname; - - try { - await ZosmfRestClient.deleteExpectString( - REAL_SESSION, - endpoint - ); - } catch (err) { - Imperative.console.error(err); - } + await deleteFiles(REAL_SESSION, ussname); await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); @@ -129,32 +107,11 @@ describe("Download USS File", () => { describe("Success scenarios", () => { beforeAll(async () => { const data: string = "abcdefghijklmnopqrstuvwxyz"; - const endpoint: string = - ZosFilesConstants.RESOURCE + - ZosFilesConstants.RES_USS_FILES + - ussname; - await ZosmfRestClient.putExpectString( - REAL_SESSION, - endpoint, - [], - data - ); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); }); afterAll(async () => { - const endpoint: string = - ZosFilesConstants.RESOURCE + - ZosFilesConstants.RES_USS_FILES + - ussname; - - try { - await ZosmfRestClient.deleteExpectString( - REAL_SESSION, - endpoint - ); - } catch (err) { - Imperative.console.error(err); - } + await deleteFiles(REAL_SESSION, ussname); }); it("should download an uss file", () => { diff --git a/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts index 93f74afb60..02c93b548b 100644 --- a/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts @@ -10,7 +10,7 @@ * */ -import { Imperative, Session } from "@zowe/imperative"; +import { Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; @@ -42,11 +42,9 @@ describe("Mount and unmount file system", () => { REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); fsname = getUniqueDatasetName(defaultSystem.zosmf.user); - TEST_ENVIRONMENT.resources.datasets.push(fsname); // Track the dataset for cleanup const dirname = getUniqueDatasetName(defaultSystem.zosmf.user).split(".")[1]; mountPoint = "//tmp/" + dirname; - TEST_ENVIRONMENT.resources.files.push(mountPoint); // Track the USS directory for cleanup const sshCommand = "mkdir " + mountPoint; @@ -59,19 +57,14 @@ describe("Mount and unmount file system", () => { }); afterAll(async () => { - try { - const sshCommand = "rmdir " + mountPoint; - runCliScript(__dirname + "/__scripts__/command/command_teardown.sh", - TEST_ENVIRONMENT, [sshCommand, fsname, - defaultSystem.ssh.host, - defaultSystem.ssh.port, - defaultSystem.ssh.user, - defaultSystem.ssh.password]); - } catch (err) { - Imperative.console.info(`Error cleaning up USS directory: ${err}`); - } - - // Clean up any resources tracked by the test environment + const sshCommand = "rmdir " + mountPoint; + runCliScript(__dirname + "/__scripts__/command/command_teardown.sh", + TEST_ENVIRONMENT, [sshCommand, fsname, + defaultSystem.ssh.host, + defaultSystem.ssh.port, + defaultSystem.ssh.user, + defaultSystem.ssh.password]); + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts index 81a19d8ec4..dadb6e1ff1 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts @@ -15,7 +15,7 @@ import * as fs from "fs"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getTag, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { deleteFiles, getTag, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { Get, ZosFilesUtils } from "@zowe/zos-files-for-zowe-sdk"; import { runCliScript } from "@zowe/cli-test-utils"; @@ -37,15 +37,11 @@ describe("Upload directory to USS", () => { tempProfileTypes: ["zosmf"], testName: "zos_files_upload_directory_to_uss_with_profile" }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); defaultSystem = TEST_ENVIRONMENT.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILES.UPLOAD`); dsname = dsname.replace(/\./g, ""); - ussname = `${defaultSystem.unix.testdir}/${dsname}`; - TEST_ENVIRONMENT.resources.session = REAL_SESSION; - TEST_ENVIRONMENT.resources.datasets.push(dsname); - TEST_ENVIRONMENT.resources.files.push(ussname); Imperative.console.info("Using ussDir:" + ussname); binaryFile = "bin_file.pax"; binaryFiles = "bin_file.pax,subdir_bin_file1.pax,subdir_bin_file2.pax.Z"; @@ -67,8 +63,10 @@ describe("Upload directory to USS", () => { defaultSys = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; Imperative.console.info("Using ussDir:" + ussname); - TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; - TEST_ENVIRONMENT_NO_PROF.resources.files.push(ussname); + }); + + afterEach(async () => { + await deleteFiles(REAL_SESSION, ussname); }); afterAll(async () => { @@ -104,6 +102,10 @@ describe("Upload directory to USS", () => { describe("Success scenarios", () => { + afterEach(async () => { + await deleteFiles(REAL_SESSION, ussname); + }); + it("should upload local directory to USS directory", async () => { const localDirName = path.join(__dirname, "__data__", "command_upload_dtu_dir/command_upload_dtu_subdir_ascii"); const shellScript = path.join(__dirname, "__scripts__", "command", "command_upload_dtu.sh"); @@ -357,6 +359,9 @@ describe("Upload directory to USS", () => { error = err; } expect(error).toBeDefined(); + + const ussResponse = await Get.USSFile(REAL_SESSION, ussname + "/uploaded_dir/uploaded_file"); + expect(ussResponse).toBeInstanceOf(Buffer); }); it("wild cards should work with * and mixed casing on tagging and ignore", async () => { diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts index e6ad2f98fd..8ef46cf73b 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/ftu/cli.files.upload.ftu.system.test.ts @@ -15,8 +15,8 @@ import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { runCliScript } from "@zowe/cli-test-utils"; -import { Get, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; +import { Get } from "@zowe/zos-files-for-zowe-sdk"; +import { deleteFiles } from "../../../../../../../__tests__/__src__/TestUtils"; let REAL_SESSION: Session; let TEST_ENVIRONMENT: ITestEnvironment; @@ -88,16 +88,7 @@ describe("Upload uss file", () => { describe("Success scenarios", () => { afterEach(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - - try { - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - } catch (err) { - error = err; - } + await deleteFiles(REAL_SESSION, ussname); }); it("should upload USS file from local file", async () => { diff --git a/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts index d01eb1ac7c..3a12e98b20 100644 --- a/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/view/uss/View.uss.system.test.ts @@ -12,11 +12,11 @@ import { Imperative, Session } from "@zowe/imperative"; import * as path from "path"; -import { ZosFilesConstants, ZosmfRestClient, ZosmfHeaders, Upload } from "@zowe/cli"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getRandomBytes, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; +import { deleteFiles, getRandomBytes, getUniqueDatasetName } from "../../../../../../../__tests__/__src__/TestUtils"; import { runCliScript } from "@zowe/cli-test-utils"; let REAL_SESSION: Session; @@ -47,35 +47,13 @@ describe("View uss file", () => { }); describe("Success scenarios", () => { - beforeEach(async () => { - let response; - let error; - const data = "{\"type\":\"file\",\"mode\":\"RWXRW-RW-\"}"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - try { - response = await ZosmfRestClient.postExpectString(REAL_SESSION, endpoint, [], data); - } catch (err) { - error = err; - } - }); - afterEach(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - - try { - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - } catch (err) { - error = err; - } + await deleteFiles(REAL_SESSION, ussname); }); it("should view uss file", async () => { const data: string = "abcdefghijklmnopqrstuvwxyz"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); const shellScript = path.join(__dirname, "__scripts__", "command", "command_view_uss_file.sh"); const response = runCliScript(shellScript, testEnvironment, [ussname.substring(1, ussname.length)]); @@ -86,8 +64,7 @@ describe("View uss file", () => { }); it("should view uss file in binary", async () => { const data: string = "abcdefghijklmnopqrstuvwxyz"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [ZosmfHeaders.X_IBM_BINARY], data); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data), { binary: true }); const shellScript = path.join(__dirname, "__scripts__", "command", "command_view_uss_file.sh"); const response = runCliScript(shellScript, testEnvironment, [ussname.substring(1, ussname.length), "--binary"]); @@ -97,7 +74,7 @@ describe("View uss file", () => { expect(response.stdout.toString().trim()).toEqual(data); }); it("should view large uss file in binary", async () => { - const rawData:Buffer = await getRandomBytes(1024*64); + const rawData: Buffer = await getRandomBytes(1024*64); const data = encodeURIComponent(rawData.toLocaleString()); await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data), { binary: true }); @@ -111,8 +88,7 @@ describe("View uss file", () => { }); it("should view uss file with range", async () => { const data: string = "abcdefghijklmnopqrstuvwxyz\nabcdefghijklmnopqrstuvwxyz\nabcdefghijklmnopqrstuvwxyz\n"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); const shellScript = path.join(__dirname, "__scripts__", "command", "command_view_uss_file.sh"); const response = runCliScript(shellScript, testEnvironment, [ussname.substring(1, ussname.length), "--range", "0,1"]); diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index a535f1b716..86c868e52f 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -30,7 +30,7 @@ describe("zos-jobs cancel job command", () => { testName: "zos_jobs_cancel_job_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); TEST_ENVIRONMENT.resources.session = REAL_SESSION; const systemProps = TEST_ENVIRONMENT.systemTestProperties; const jcl = JobTestsUtils.getSleepJCL(systemProps.zosmf.user, systemProps.tso.account, systemProps.zosjobs.jobclass); @@ -121,7 +121,7 @@ describe("zos-jobs cancel job command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_cancel_job_without_profiles" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts index 78f8dec5ee..a1e08fd410 100644 --- a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts @@ -29,7 +29,7 @@ describe("zos-jobs download output command", () => { testName: "zos_jobs_download_output_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); TEST_ENVIRONMENT.resources.session = REAL_SESSION; IEFBR14_JCL = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; @@ -85,7 +85,7 @@ describe("zos-jobs download output command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_download_output_without_profiles" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts index 8c8f6d4584..52330a8119 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts @@ -41,7 +41,7 @@ describe("zos-jobs list jobs command", () => { testName: "zos_jobs_list_jobs_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); TEST_ENVIRONMENT.resources.session = REAL_SESSION; const systemProps = TEST_ENVIRONMENT.systemTestProperties; IEFBR14_JOB = systemProps.zosjobs.iefbr14Member; @@ -117,7 +117,7 @@ describe("zos-jobs list jobs command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_job_without_profiles" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts index 3a038d26a9..041f406155 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts @@ -42,7 +42,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { testName: "zos_jobs_list_spool_files_by_jobid_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); TEST_ENVIRONMENT.resources.session = REAL_SESSION; IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; @@ -140,7 +140,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_spool_files_by_jobid_without_profiles" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index 97968fa168..6f3b3bdbcf 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -36,7 +36,7 @@ describe("zos-jobs search job command", () => { testName: "zos_jobs_search_job_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); // Use testEnvironment for accessing properties defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts index a92cc11fbf..b274f0f045 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts @@ -35,7 +35,7 @@ describe("zos-jobs submit data-set command", () => { testName: "zos_jobs_submit_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = TEST_ENVIRONMENT.systemTestProperties.tso.account; jclMember = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; psJclDataSet = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14PSDataSet; @@ -146,7 +146,7 @@ describe("zos-jobs submit data-set command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_submit_data_set_without_profiles" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); 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 19bdf1bd5f..1b9f94fa92 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 @@ -35,7 +35,7 @@ describe("zos-jobs submit local-file command", () => { testName: "zos_jobs_submit_local_file_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = await TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); systemProps = TEST_ENVIRONMENT.systemTestProperties; account = systemProps.tso.account; diff --git a/packages/cli/__tests__/zosuss/__system__/issue/cli.issue.ssh.system.test.ts b/packages/cli/__tests__/zosuss/__system__/issue/cli.issue.ssh.system.test.ts index fce953a4e2..d4bd68cfa1 100644 --- a/packages/cli/__tests__/zosuss/__system__/issue/cli.issue.ssh.system.test.ts +++ b/packages/cli/__tests__/zosuss/__system__/issue/cli.issue.ssh.system.test.ts @@ -9,14 +9,13 @@ * */ -import { Imperative, Session } from "@zowe/imperative"; +import { Session } from "@zowe/imperative"; import * as path from "path"; -import { ITestEnvironment, runCliScript, TempTestProfiles } from "@zowe/cli-test-utils"; +import { runCliScript, TempTestProfiles } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import { Shell } from "@zowe/zos-uss-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; // Test environment will be populated in the "beforeAll" @@ -65,31 +64,31 @@ describe("zowe uss issue ssh without running bash scripts", () => { await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); - it("should return operating system name", async () => { + it("should return operating system name", () => { const commandName = "uname"; // Imperative.console.info("Return OS command:" + commandName); - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); checkResponse(response, 0); expect(response.stdout.toString()).toMatch("OS/390"); }); - it("should resolve --cwd option", async () => { + it("should resolve --cwd option", () => { const commandName = "pwd"; const cwd = `${defaultSystem.unix.testdir}`; // Imperative.console.info("Resolve --cwd Command:" + commandName +"--cwd /" +cwd); - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_with_cwd.sh", TEST_ENVIRONMENT, [commandName, "/" + cwd]); + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_with_cwd.sh", TEST_ENVIRONMENT, [commandName, "/" + cwd]); checkResponse(response, 0); // match only "/"+cwd with no following alpha-numeric character e.g. "/cwd " expect(response.stdout.toString()).toMatch(new RegExp(cwd.substring(1) + "\\s")); }); - it("should get directory invalid --cwd option", async () => { + it("should get directory invalid --cwd option", () => { const commandName = "pwd"; const cwd = "/invaliddir"; // Imperative.console.info("Invalid directory Command:" + commandName +"--cwd /" +cwd); - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_with_cwd.sh", TEST_ENVIRONMENT, [commandName, "/" + cwd]); + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_with_cwd.sh", TEST_ENVIRONMENT, [commandName, "/" + cwd]); checkResponse(response, 1); expect(response.stdout.toString()).toContain("EDC5129I No such file or directory"); @@ -111,7 +110,7 @@ describe("Use a test directory to do stuff in that creates files", () => { // create a directory that the random dir will be created in const commandName = `mkdir ${directory}/usstest && cd ${directory}/usstest && pwd`; // Imperative.console.info("Make test directory cmd:" + commandName); - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); checkResponse(response, 0); expect(response.stdout.toString()).toContain(directory.substring(1) + "usstest"); }); @@ -120,21 +119,20 @@ describe("Use a test directory to do stuff in that creates files", () => { const directory = `${defaultSystem.unix.testdir}/`; const commandName = "rm -rf " + directory + "usstest"; // Imperative.console.info("Remove test directory cmd:" + commandName); - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); // Imperative.console.info("Remove Response:" + response.stdout.toString()); await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); // eslint-disable-next-line jest/expect-expect - it("should write a long directory", async () => { + it("should write a long directory", () => { const j = 200; const randomDir = generateRandomString(j); const directory = `${defaultSystem.unix.testdir}/`; - const testdir = directory + "test/"; - const commandName = "mkdir -p " + testdir + "usstest/" + randomDir + "; ls " + testdir + "usstest/" + randomDir; + const commandName = "mkdir -p " + directory + "usstest/" + randomDir + "; ls " + directory + "usstest/" + randomDir; // Imperative.console.info("Long Dir Command:" + commandName); - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); checkResponse(response, 0); }); }); @@ -164,6 +162,7 @@ describe("zowe uss issue ssh running bash scripts", () => { // Imperative.console.info("Response:" + response.stdout.toString()); expect(response.stdout.toString()).toContain("USS file uploaded successfully"); // Imperative.console.info("Uploaded :" + localFileName + "to" + ussname); + TEST_ENVIRONMENT.resources.files.push(ussname); ussname = `${defaultSystem.unix.testdir}/killItself.sh`; // Imperative.console.info("Using ussfile:" + ussname); @@ -172,42 +171,18 @@ describe("zowe uss issue ssh running bash scripts", () => { // Imperative.console.info("Response:" + response.stdout.toString()); expect(response.stdout.toString()).toContain("USS file uploaded successfully"); // Imperative.console.info("Uploaded :" + localFileName + "to" + ussname); - - + TEST_ENVIRONMENT.resources.files.push(ussname); }); afterAll(async () => { await TestEnvironment.cleanUp(TEST_ENVIRONMENT); - let response: any; - // delete uploaded test bash scripts - ussname = `${defaultSystem.unix.testdir}/exit64.sh`; - const exit64: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - - try { - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, exit64); - // Imperative.console.info("Deleted :" + ussname); - } catch (err) { - Imperative.console.error(err); - } - - ussname = `${defaultSystem.unix.testdir}/killItself.sh`; - const killItself: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - - try { - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, killItself); - // Imperative.console.info("Deleted :" + ussname); - } catch (err) { - Imperative.console.error(err); - } - - }); - it("script issues exit64", async () => { + it("script issues exit64", () => { const directory = `${defaultSystem.unix.testdir}`; const commandName = "cd " + directory + " && chmod 777 exit64.sh && exit64.sh"; // Imperative.console.info("Exit command:" + commandName); - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); const SIX_FOUR= 64; checkResponse(response, SIX_FOUR); @@ -215,11 +190,11 @@ describe("zowe uss issue ssh running bash scripts", () => { expect(response.stdout.toString()).not.toContain("It should not echo this"); }); - it("script kills itself", async () => { + it("script kills itself", () => { const directory = `${defaultSystem.unix.testdir}`; const commandName = " cd " + directory + " && chmod 777 killItself.sh && killItself.sh"; // Imperative.console.info("Script for kill command:" + commandName); - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); const ONE_FOUR_THREE = 143; checkResponse(response, ONE_FOUR_THREE); @@ -255,7 +230,7 @@ describe("zowe uss issue ssh passwords and passkeys", () => { { host, port, user, password }); // now check the command can run const command = "uname"; - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [command, "--ssh-p", onlyPassword]); checkResponse(response, 0); expect(response.stdout.toString()).toMatch("OS/390"); @@ -268,7 +243,7 @@ describe("zowe uss issue ssh passwords and passkeys", () => { { host, port, user, password, privateKey: bogusPrivateKey, keyPassphrase }); // now check the command can run const command = "uname"; - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [command, "--ssh-p", invalidPrivateKey]); expect(response.stderr.toString()).toMatch("no such file or directory, open 'bogusKey'"); }); @@ -280,7 +255,7 @@ describe("zowe uss issue ssh passwords and passkeys", () => { { host, port, user, password }); const command = "echo test"; - const response = await runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, + const response = runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [command, "--ssh-p", invalidCreds]); expect(response.stderr.toString()).toMatch("All configured authentication methods failed"); }); diff --git a/packages/workflows/__tests__/__system__/Archive.system.test.ts b/packages/workflows/__tests__/__system__/Archive.system.test.ts index f930010fce..80624f0a68 100644 --- a/packages/workflows/__tests__/__system__/Archive.system.test.ts +++ b/packages/workflows/__tests__/__system__/Archive.system.test.ts @@ -13,12 +13,12 @@ import { Session, Imperative } from "@zowe/imperative"; import { IArchivedWorkflow } from "../../src/doc/IArchivedWorkflow"; import { ArchiveWorkflow } from "../../src"; import { WorkflowConstants } from "../../src/WorkflowConstants"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { CreateWorkflow } from "../../src/Create"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; import { Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; let session: Session; let testEnvironment: ITestEnvironment; @@ -53,6 +53,7 @@ describe("Archive workflow unit tests - successful scenarios", () => { beforeAll(async () => { await setup(); await Upload.fileToUssFile(session, localWorkflowPath, remoteWorkflowPath, { binary: true}); + testEnvironment.resources.files.push(remoteWorkflowPath); }); beforeEach(async () => { const systemName = testEnvironment.systemTestProperties.workflows.system; @@ -164,6 +165,7 @@ describe("Errors caused by the user interaction", () => { beforeAll(async () => { await setup(); await Upload.fileToUssFile(session, localWorkflowPath, remoteWorkflowPath, { binary: true }); + testEnvironment.resources.files.push(remoteWorkflowPath); }); it("404 Not Found", async () => { try { diff --git a/packages/workflows/__tests__/__system__/Cancel.system.test.ts b/packages/workflows/__tests__/__system__/Cancel.system.test.ts index 678e72b757..b953ee956f 100644 --- a/packages/workflows/__tests__/__system__/Cancel.system.test.ts +++ b/packages/workflows/__tests__/__system__/Cancel.system.test.ts @@ -11,14 +11,14 @@ import { CancelWorkflow, CreateWorkflow, DeleteWorkflow } from "../../src"; import { Imperative, ImperativeError, Session } from "@zowe/imperative"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { inspect } from "util"; import { getUniqueDatasetName } from "../../../../__tests__/__src__/TestUtils"; import { noWorkflowKey, WrongWorkflowKey } from "../../src/WorkflowConstants"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient, nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -70,19 +70,7 @@ describe("Cancel workflow", () => { beforeAll(async () => { // Upload files only for successful scenarios await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // Deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); beforeEach(async () => { const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); diff --git a/packages/workflows/__tests__/__system__/api/ArchivedDelete.system.test.ts b/packages/workflows/__tests__/__system__/api/ArchivedDelete.system.test.ts index 53dc8ea5ad..6382dd6b60 100644 --- a/packages/workflows/__tests__/__system__/api/ArchivedDelete.system.test.ts +++ b/packages/workflows/__tests__/__system__/api/ArchivedDelete.system.test.ts @@ -9,16 +9,16 @@ * */ -import { ZosFilesConstants, Upload } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient, nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; import { Imperative, ImperativeError, Session } from "@zowe/imperative"; import { noWorkflowKey } from "../../../src/WorkflowConstants"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { ArchivedDeleteWorkflow, ArchiveWorkflow, CreateWorkflow } from "../../../src"; import { inspect } from "util"; import { getUniqueDatasetName } from "../../../../../__tests__/__src__/TestUtils"; +import { ITestEnvironment } from "../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; @@ -64,19 +64,7 @@ describe("Delete archived workflow", () => { beforeAll(async () => { // Upload files only for successful scenarios await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // Deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); beforeEach(async () => { const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); diff --git a/packages/workflows/__tests__/__system__/api/Create.system.test.ts b/packages/workflows/__tests__/__system__/api/Create.system.test.ts index 69e3d3c143..d7fe57a983 100644 --- a/packages/workflows/__tests__/__system__/api/Create.system.test.ts +++ b/packages/workflows/__tests__/__system__/api/Create.system.test.ts @@ -11,7 +11,6 @@ import { CreateWorkflow, DeleteWorkflow } from "../../../src"; import { Imperative, ImperativeError, Session } from "@zowe/imperative"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { ICreatedWorkflow } from "../../../src/doc/ICreatedWorkflow"; @@ -25,8 +24,9 @@ import { wrongOwner } from "../../../src/WorkflowConstants"; import { ICreatedWorkflowLocal } from "../../../src/doc/ICreatedWorkflowLocal"; -import { Upload, ZosFilesConstants, Delete } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient, nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { Upload, Delete } from "@zowe/zos-files-for-zowe-sdk"; +import { nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -74,25 +74,7 @@ describe("Create workflow", () => { // Upload files only for successful scenarios await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); await Upload.fileToUssFile(REAL_SESSION, vars, inputFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } - try { - const inputEndpoint = endpoint + inputFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, inputEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile, inputFile); }); afterEach(async () => { // deleting workflow diff --git a/packages/workflows/__tests__/__system__/api/Definition.system.test.ts b/packages/workflows/__tests__/__system__/api/Definition.system.test.ts index a1a0da3afe..b7996de06b 100644 --- a/packages/workflows/__tests__/__system__/api/Definition.system.test.ts +++ b/packages/workflows/__tests__/__system__/api/Definition.system.test.ts @@ -12,14 +12,14 @@ import { DefinitionWorkflow } from "../../../src"; import { Imperative, ImperativeError, Session } from "@zowe/imperative"; import { noWorkflowDefinitionFile } from "../../../src/WorkflowConstants"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { inspect } from "util"; import { getUniqueDatasetName } from "../../../../../__tests__/__src__/TestUtils"; import { IWorkflowDefinition } from "../../../src/doc/IWorkflowDefinition"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient, nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -64,19 +64,7 @@ describe("Properties workflow", () => { describe("Success Scenarios", () => { beforeAll(async () => { await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); it("Successful call without optional parameters returns definition response", async () => { let error; @@ -191,22 +179,6 @@ describe("Properties workflow", () => { }); }); describe("Fail scenarios", () => { - beforeAll(async () => { - await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } - }); it("Throws an error with undefined session.", async () => { let error: ImperativeError; let response: any; diff --git a/packages/workflows/__tests__/__system__/api/Delete.system.test.ts b/packages/workflows/__tests__/__system__/api/Delete.system.test.ts index 3fd4549ff9..18439d8a3d 100644 --- a/packages/workflows/__tests__/__system__/api/Delete.system.test.ts +++ b/packages/workflows/__tests__/__system__/api/Delete.system.test.ts @@ -12,13 +12,13 @@ import { CreateWorkflow, DeleteWorkflow } from "../../../src"; import { Imperative, ImperativeError, Session } from "@zowe/imperative"; import { noWorkflowKey } from "../../../src/WorkflowConstants"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { inspect } from "util"; import { getUniqueDatasetName } from "../../../../../__tests__/__src__/TestUtils"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient, nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -63,19 +63,7 @@ describe("Delete workflow", () => { beforeAll(async () => { // Upload files only for successful scenarios await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); beforeEach(async () => { const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); diff --git a/packages/workflows/__tests__/__system__/api/ListArchivedWorkflows.system.test.ts b/packages/workflows/__tests__/__system__/api/ListArchivedWorkflows.system.test.ts index 41fcc0396b..77f0a9a03e 100644 --- a/packages/workflows/__tests__/__system__/api/ListArchivedWorkflows.system.test.ts +++ b/packages/workflows/__tests__/__system__/api/ListArchivedWorkflows.system.test.ts @@ -14,14 +14,14 @@ import { ArchivedDeleteWorkflow } from "../../../src/ArchivedDelete"; import { ListArchivedWorkflows } from "../../../src/ListArchivedWorkflows"; import { ArchiveWorkflow } from "../../../src/ArchiveWorkflow"; import { Imperative, ImperativeError, Session } from "@zowe/imperative"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient, nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; import { TestEnvironment } from "../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { ICreatedWorkflow } from "../../../src/doc/ICreatedWorkflow"; import { inspect } from "util"; import { getUniqueDatasetName } from "../../../../../__tests__/__src__/TestUtils"; +import { ITestEnvironment } from "../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; @@ -73,19 +73,7 @@ describe("List archived workflows", () => { beforeAll(async () => { // Upload files only for successful scenarios await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // Deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); beforeEach(async () => { const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); diff --git a/packages/workflows/__tests__/__system__/api/ListWorkflows.system.test.ts b/packages/workflows/__tests__/__system__/api/ListWorkflows.system.test.ts index 0ba83c8b51..62895f83ff 100644 --- a/packages/workflows/__tests__/__system__/api/ListWorkflows.system.test.ts +++ b/packages/workflows/__tests__/__system__/api/ListWorkflows.system.test.ts @@ -11,7 +11,6 @@ import { CreateWorkflow, DeleteWorkflow, ListWorkflows } from "../../../src"; import { Imperative, ImperativeError, Session } from "@zowe/imperative"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { ICreatedWorkflow } from "../../../src/doc/ICreatedWorkflow"; @@ -19,8 +18,9 @@ import { inspect } from "util"; import { getUniqueDatasetName } from "../../../../../__tests__/__src__/TestUtils"; import { wrongString } from "../../../src/WorkflowConstants"; import { IWorkflowsInfo } from "../../../src/doc/IWorkflowsInfo"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient, nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -71,19 +71,7 @@ describe("List workflows", () => { beforeAll(async () => { // Upload files only for successful scenarios await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // Deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); beforeEach(async () => { const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); diff --git a/packages/workflows/__tests__/__system__/api/Properties.system.test.ts b/packages/workflows/__tests__/__system__/api/Properties.system.test.ts index 3f6269d9ab..efd524e7f3 100644 --- a/packages/workflows/__tests__/__system__/api/Properties.system.test.ts +++ b/packages/workflows/__tests__/__system__/api/Properties.system.test.ts @@ -11,15 +11,15 @@ import { Imperative, ImperativeError, Session } from "@zowe/imperative"; import { noWorkflowKey } from "../../../src/WorkflowConstants"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { CreateWorkflow, DeleteWorkflow, PropertiesWorkflow } from "../../../src"; import { inspect } from "util"; import { getUniqueDatasetName } from "../../../../../__tests__/__src__/TestUtils"; import { IWorkflowInfo } from "../../../src/doc/IWorkflowInfo"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient, nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -65,19 +65,7 @@ describe("Properties workflow", () => { describe("Success Scenarios", () => { beforeAll(async () => { await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + testEnvironment.resources.files.push(definitionFile); }); beforeEach(async () => { const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); @@ -198,30 +186,6 @@ describe("Properties workflow", () => { }); }); describe("Fail scenarios", () => { - beforeAll(async () => { - await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } - }); - beforeEach(async () => { - const response = await CreateWorkflow.createWorkflow(REAL_SESSION, wfName, definitionFile, system, owner); - wfKey = response.workflowKey; - }); - afterEach(async () => { - // deleting workflow - await DeleteWorkflow.deleteWorkflow(REAL_SESSION, wfKey); - }); it("Throws an error with undefined session.", async () => { let error: ImperativeError; let response: any; diff --git a/packages/workflows/__tests__/__system__/api/Start.system.test.ts b/packages/workflows/__tests__/__system__/api/Start.system.test.ts index 623f78b4fe..fcf6e478fe 100644 --- a/packages/workflows/__tests__/__system__/api/Start.system.test.ts +++ b/packages/workflows/__tests__/__system__/api/Start.system.test.ts @@ -11,7 +11,6 @@ import { Imperative, ImperativeError, Session } from "@zowe/imperative"; import { noWorkflowKey, WorkflowConstants } from "../../../src/WorkflowConstants"; -import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { CreateWorkflow, DeleteWorkflow, PropertiesWorkflow, StartWorkflow } from "../../../src"; @@ -19,8 +18,9 @@ import { inspect } from "util"; import { getUniqueDatasetName } from "../../../../../__tests__/__src__/TestUtils"; import { IWorkflowInfo } from "../../../src/doc/IWorkflowInfo"; import { IStepInfo } from "../../../src/doc/IStepInfo"; -import { Upload, ZosFilesConstants } from "@zowe/zos-files-for-zowe-sdk"; -import { ZosmfRestClient, nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { Upload } from "@zowe/zos-files-for-zowe-sdk"; +import { nozOSMFVersion, noSession } from "@zowe/core-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -64,28 +64,8 @@ describe("Start workflow", () => { describe("Success Scenarios", () => { beforeAll(async () => { // Upload files only for successful scenarios - let error; - let response; - try { - response = await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error upload: " + inspect(error)); - } - }); - afterAll(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES; - // deleting uploaded workflow file - try { - const wfEndpoint = endpoint + definitionFile; - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, wfEndpoint); - } catch (err) { - error = err; - } + await Upload.fileToUssFile(REAL_SESSION, workflow, definitionFile, { binary: true }); + testEnvironment.resources.files.push(definitionFile); }); beforeEach(async () => { let error; diff --git a/packages/zosfiles/__tests__/__system__/methods/copy/Copy.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/copy/Copy.system.test.ts index a9df2f890b..312fd5dd0b 100644 --- a/packages/zosfiles/__tests__/__system__/methods/copy/Copy.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/copy/Copy.system.test.ts @@ -41,9 +41,6 @@ describe("Copy", () => { REAL_TARGET_SESSION = REAL_SESSION; fromDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.DATA.ORIGINAL`; toDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.DATA.COPY`; - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(fromDataSetName, toDataSetName); }); afterAll(async () => { @@ -1025,8 +1022,6 @@ describe("Copy - Encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); fromDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.DATA.ENCO#ED.ORIGINAL`; toDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.ENCO#ED.DATA.COPY`; - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(fromDataSetName, toDataSetName); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts index fec0e8ccc8..3da39c1af0 100644 --- a/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts @@ -51,8 +51,6 @@ describe("Create data set", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.DATA.SET`; - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { @@ -170,9 +168,6 @@ describe("Create data set - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.ENCO#ED.DATA.SET`; - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { @@ -256,8 +251,6 @@ describe("Allocate Like", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsnameLike = `${dsname}.LIKE`; - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(dsnameLike); await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_CLASSIC, dsname, options); }); @@ -319,8 +312,6 @@ describe("Allocate Like - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsnameLike = `${dsname}.ENCO#ED.LIKE`; - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(dsnameLike); await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_CLASSIC, dsname, options); }); @@ -375,9 +366,6 @@ describe("Create VSAM", () => { volume = defaultSystem.datasets.vol; dsname = getUniqueDatasetName(defaultSystem.zosmf.user); - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { @@ -459,9 +447,6 @@ describe("Create VSAM - encoded", () => { volume = defaultSystem.datasets.vol; dsname = getUniqueDatasetName(defaultSystem.zosmf.user, true); - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { @@ -522,9 +507,6 @@ describe("Create z/OS file system", () => { fsname = getUniqueDatasetName(defaultSystem.zosmf.user); volume = defaultSystem.datasets.vol; - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(fsname); }); afterAll(async () => { @@ -617,9 +599,6 @@ describe("Create z/OS file system - encoded", () => { fsname = getUniqueDatasetName(defaultSystem.zosmf.user, true); volume = defaultSystem.datasets.vol; - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(fsname); }); afterAll(async () => { @@ -688,9 +667,6 @@ describe("Create uss file", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); basePath = defaultSystem.unix.testdir; // `${defaultSystem.zosmf.basePath.trim()}`; filename = `${basePath}/test.txt`.replace(/\./g, ""); - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -767,8 +743,6 @@ describe("Create uss file - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); basePath = defaultSystem.unix.testdir; // `${defaultSystem.zosmf.basePath.trim()}`; filename = `${basePath}/enco#edtest.txt`.replace(/\./g, ""); - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -824,8 +798,6 @@ describe("Create uss directory", () => { // dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.DATA.SET`; basePath = defaultSystem.unix.testdir; // `${defaultSystem.zosmf.basePath.trim()}`; filename = `${basePath}/testDir`.replace(/\./g, ""); - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -901,8 +873,6 @@ describe("Create uss directory - encoded", () => { // dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.DATA.SET`; basePath = defaultSystem.unix.testdir; // `${defaultSystem.zosmf.basePath.trim()}`; filename = `${basePath}/testEnco#edDir`.replace(/\./g, ""); - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(filename); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteDataset.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteDataset.system.test.ts index f573e495f8..e2ff4859fa 100644 --- a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteDataset.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteDataset.system.test.ts @@ -30,10 +30,7 @@ describe("Delete Dataset", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.DATA.SET.DELETE`; - testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { @@ -140,9 +137,6 @@ describe("Delete Dataset - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = `${defaultSystem.zosmf.user.trim().toUpperCase()}.TEST.ENCO#ED.DATA.SET.DELETE`; - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(dsname); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts index 0b316215d6..ecb0633e63 100644 --- a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts @@ -31,10 +31,7 @@ describe("Delete a USS File", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - ussname = `${defaultSystem.zosmf.user.trim()}`; - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(ussname); + ussname = `${defaultSystem.unix.testdir}/${defaultSystem.zosmf.user.trim()}`; }); afterAll(async () => { @@ -45,7 +42,7 @@ describe("Delete a USS File", () => { beforeEach(async () => { let error; let response; - filename = `${defaultSystem.unix.testdir}/${ussname}.aTestUssFileSingle`.replace(/\./g, ""); + filename = `${ussname}.aTestUssFileSingle`.replace(/\./g, ""); try { response = await Create.uss(REAL_SESSION, filename, "file"); } catch (err) { @@ -156,10 +153,7 @@ describe("Delete a USS File - encoded", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - ussname = `${defaultSystem.zosmf.user.trim() + ".Enco#ed"}`; - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(ussname); + ussname = `${defaultSystem.unix.testdir}/${defaultSystem.zosmf.user.trim() + ".Enco#ed"}`; }); afterAll(async () => { @@ -169,7 +163,7 @@ describe("Delete a USS File - encoded", () => { describe("Success scenarios", () => { beforeEach(async () => { let error; - filename = `${defaultSystem.unix.testdir}/${ussname}.aTestUssFileSingle`.replace(/\./g, ""); + filename = `${ussname}.aTestUssFileSingle`.replace(/\./g, ""); try { await Create.uss(REAL_SESSION, filename, "file"); } catch (err) { @@ -226,9 +220,6 @@ describe("Delete USS Directory", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); filename = `${defaultSystem.unix.testdir}/${ussname}.aTestUssFolderDelete`.replace(/\./g, ""); - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -328,9 +319,6 @@ describe("Delete USS Directory - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); filename = `${defaultSystem.unix.testdir}/${ussname}.Enco#ed.aTestUssFolderDelete`.replace(/\./g, ""); - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -379,9 +367,6 @@ describe("Delete USS Directory with children", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); filename = `${defaultSystem.unix.testdir}/${ussname}.aTestUssFileDelete`.replace(/\./g, ""); - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(filename); }); afterAll(async () => { @@ -490,9 +475,6 @@ describe("Delete USS Directory with children - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); filename = `${defaultSystem.unix.testdir}/${ussname}.Enco#ed.aTestUssFileDelete`.replace(/\./g, ""); - - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.files.push(filename); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteZfs.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteZfs.system.test.ts index 6b0044d183..ebb5f50ce7 100644 --- a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteZfs.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteZfs.system.test.ts @@ -43,8 +43,6 @@ describe("Delete a z/OS File System", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); fsname = getUniqueDatasetName(defaultSystem.zosmf.user); createOptions.volumes = [defaultSystem.datasets.vol]; - testEnvironment.resources.session = REAL_SESSION; - testEnvironment.resources.datasets.push(fsname); }); afterAll(async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index e81f88337b..ecddd8231e 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -19,7 +19,6 @@ import { IZosFilesResponse, Tag, Utilities, - ZosFilesConstants, ZosFilesMessages, ICreateZfsOptions, IMountFsOptions, @@ -32,8 +31,7 @@ import { inspect } from "util"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getUniqueDatasetName, stripNewLines, wait } from "../../../../../../__tests__/__src__/TestUtils"; -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; +import { deleteFiles, getUniqueDatasetName, stripNewLines, wait } from "../../../../../../__tests__/__src__/TestUtils"; import * as fs from "fs"; import { posix } from "path"; import { Shell } from "@zowe/zos-uss-for-zowe-sdk"; @@ -62,10 +60,8 @@ describe.each([false, true])("Download Data Set - Encoded: %s", (encoded: boolea defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.DOWNLOAD`, encoded); - testEnvironment.resources.datasets.push(dsname); Imperative.console.info("Using dsname:" + dsname); // using unique DS function to generate unique USS file name @@ -78,8 +74,6 @@ describe.each([false, true])("Download Data Set - Encoded: %s", (encoded: boolea ussDirname = `${defaultSystem.unix.testdir}/zos_file_download`; localDirname = `${testEnvironment.workingDir}/ussDir`; } - testEnvironment.resources.files.push(ussname, ussDirname); - testEnvironment.resources.localFiles.push(localDirname); }); afterAll(async () => { @@ -1013,14 +1007,7 @@ describe.each([false, true])("Download Data Set - Encoded: %s", (encoded: boolea describe("Download USS File", () => { afterAll(async () => { // Delete created uss file - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - await wait(delayTime); - } catch (err) { - Imperative.console.error(err); - } + await deleteFiles(REAL_SESSION, ussname); // Delete created local file IO.deleteFile(`./${posix.basename(ussname)}`); diff --git a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts index b27274bcef..7de7bf0d49 100644 --- a/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/get/Get.system.test.ts @@ -9,13 +9,12 @@ * */ -import { Create, CreateDataSetTypeEnum, Delete, Get, IGetOptions, List, ZosFilesConstants } from "../../../../src"; +import { Create, CreateDataSetTypeEnum, Delete, Get, IGetOptions, List, Upload } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { getRandomBytes, getUniqueDatasetName, stripNewLines } from "../../../../../../__tests__/__src__/TestUtils"; -import { ZosmfRestClient, ZosmfHeaders } from "@zowe/core-for-zowe-sdk"; +import { deleteFiles, getRandomBytes, getUniqueDatasetName, stripNewLines } from "../../../../../../__tests__/__src__/TestUtils"; import { IZosmfListResponse } from "../../../../src/methods/list/doc/IZosmfListResponse"; let REAL_SESSION: Session; @@ -30,10 +29,9 @@ describe("Get", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_view" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - defaultSystem = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`); Imperative.console.info("Using dsname:" + dsname); @@ -78,8 +76,7 @@ describe("Get", () => { let response: Buffer; const data: string = "abcdefghijklmnopqrstuvwxyz\n"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_DS_FILES + "/" + dsname; - const rc = await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(data), dsname); try { response = await Get.dataSet(REAL_SESSION, dsname); @@ -96,8 +93,7 @@ describe("Get", () => { let response: Buffer; const data: string = "abcdefghijklmnopqrstuvwxyz\n"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_DS_FILES + "/" + dsname; - const rc = await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(data), dsname); try { response = await Get.dataSet(REAL_SESSION, dsname, {responseTimeout: 5}); @@ -116,8 +112,7 @@ describe("Get", () => { const options: IGetOptions = {}; const data: string = "abcdefghijklmnopqrstuvwxyz\n"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_DS_FILES + "/" + dsname; - const rc = await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(data), dsname); const listOfDataSets = await List.dataSet(REAL_SESSION, dsname, {attributes: true}); listOfDataSets.apiResponse.items.forEach((dataSetObj: IZosmfListResponse) => { options.volume = dataSetObj.vol; @@ -143,8 +138,7 @@ describe("Get", () => { const randomByteLength = 60; const data: Buffer = await getRandomBytes(randomByteLength); - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_DS_FILES + "/" + dsname; - const rc = await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [ZosmfHeaders.X_IBM_BINARY], data); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(data), dsname, { binary: true }); try { response = await Get.dataSet(REAL_SESSION, dsname, options); @@ -165,8 +159,7 @@ describe("Get", () => { }; const data: string = "abcdefghijklmnopqrstuvwxyz\n"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_DS_FILES + "/" + dsname; - const rc = await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(data), dsname); try { response = await Get.dataSet(REAL_SESSION, dsname, options); @@ -184,30 +177,8 @@ describe("Get", () => { }); }); describe("USS File", () => { - beforeEach(async () => { - let response; - let error; - const data = "{\"type\":\"file\",\"mode\":\"RWXRW-RW-\"}"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - - try { - response = await ZosmfRestClient.postExpectString(REAL_SESSION, endpoint, [], data); - } catch (err) { - error = err; - } - }); - afterEach(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - - try { - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - } catch (err) { - error = err; - } + await deleteFiles(REAL_SESSION, ussname); }); it("should get uss file content", async () => { @@ -215,8 +186,7 @@ describe("Get", () => { let response: Buffer; const data: string = "abcdefghijklmnopqrstuvwxyz\n"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - const rc = await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); try { response = await Get.USSFile(REAL_SESSION, ussname); @@ -238,8 +208,7 @@ describe("Get", () => { const randomByteLength = 60; const data: Buffer = await getRandomBytes(randomByteLength); - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - const rc = await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [ZosmfHeaders.X_IBM_BINARY], data); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data), { binary: true }); try { response = await Get.USSFile(REAL_SESSION, ussname, options); @@ -256,8 +225,7 @@ describe("Get", () => { let response: Buffer; const data: string = "abcdefghijklmnopqrstuvwxyz\nabcdefghijklmnopqrstuvwxyz\nabcdefghijklmnopqrstuvwxyz\n"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - const rc = await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); try { response = await Get.USSFile(REAL_SESSION, ussname, {range: "0,1"}); @@ -343,8 +311,8 @@ describe("Get", () => { const record = true; const data: string = "abcdefghijklmnopqrstuvwxyz\n"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - const rc = await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); + testEnvironment.resources.files.push(ussname); try { response = await Get.USSFile(REAL_SESSION, ussname, {record}); @@ -354,7 +322,6 @@ describe("Get", () => { expect(response).toBeFalsy(); expect(error).toBeTruthy(); expect(stripNewLines(error.message)).toContain("Unsupported data type 'record' specified for USS file operation."); - testEnvironment.resources.files.push(ussname); }); }); }); @@ -367,10 +334,9 @@ describe("Get - encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_view" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - defaultSystem = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.VIEW`, true); Imperative.console.info("Using dsname:" + dsname); @@ -409,8 +375,7 @@ describe("Get - encoded", () => { let response: Buffer; const data: string = "abcdefghijklmnopqrstuvwxyz\n"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_DS_FILES + "/" + encodeURIComponent(dsname); - await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToDataSet(REAL_SESSION, Buffer.from(data), dsname); try { response = await Get.dataSet(REAL_SESSION, dsname); @@ -424,25 +389,8 @@ describe("Get - encoded", () => { }); describe("USS File", () => { - beforeEach(async () => { - const data = "{\"type\":\"file\",\"mode\":\"RWXRW-RW-\"}"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); - - try { - await ZosmfRestClient.postExpectString(REAL_SESSION, endpoint, [], data); - } catch (err) { - // Do nothing - } - }); - afterEach(async () => { - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); - - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - } catch (err) { - // Do nothing - } + await deleteFiles(REAL_SESSION, ussname); }); it("should get uss file content", async () => { @@ -450,8 +398,7 @@ describe("Get - encoded", () => { let response: Buffer; const data: string = "abcdefghijklmnopqrstuvwxyz\n"; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); - await ZosmfRestClient.putExpectString(REAL_SESSION, endpoint, [], data); + await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(data)); try { response = await Get.USSFile(REAL_SESSION, ussname); diff --git a/packages/zosfiles/__tests__/__system__/methods/hDelete/HDelete.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/hDelete/HDelete.system.test.ts index 20b971f090..0dde3c7be4 100644 --- a/packages/zosfiles/__tests__/__system__/methods/hDelete/HDelete.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/hDelete/HDelete.system.test.ts @@ -29,8 +29,6 @@ describe("Delete Migrated Dataset", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - dataSet1 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.SDATA.DEL`; dataSet2 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.PDATA.DEL`; dataSet3 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.FAIL.DEL`; diff --git a/packages/zosfiles/__tests__/__system__/methods/hMigrate/HMigrate.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/hMigrate/HMigrate.system.test.ts index dd50e26233..090e259e98 100644 --- a/packages/zosfiles/__tests__/__system__/methods/hMigrate/HMigrate.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/hMigrate/HMigrate.system.test.ts @@ -31,8 +31,6 @@ describe("Migrate Dataset", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - dataSet1 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.SDATA.MIGR`; dataSet2 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.PDATA.MIGR`; dataSet3 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.FAIL.MIGR`; diff --git a/packages/zosfiles/__tests__/__system__/methods/hRecall/HRecall.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/hRecall/HRecall.system.test.ts index ec1964fa39..61d4c127e1 100644 --- a/packages/zosfiles/__tests__/__system__/methods/hRecall/HRecall.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/hRecall/HRecall.system.test.ts @@ -31,8 +31,6 @@ describe("Recall Dataset", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - dataSet1 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.SDATA.REC`; dataSet2 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.PDATA.REC`; dataSet3 = `${defaultSystem.zosmf.user.trim().toUpperCase()}.FAIL.REC`; diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams.temp b/packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams.temp new file mode 100644 index 0000000000..40fc391aed --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams.temp @@ -0,0 +1 @@ +DEFINE CLUSTER (NAME (JOHTI04.ZOSFILE.ENCO#ED.VSAM.A1394590.A196498) CYLINDERS (5 2 ) VOLUMES(TSOA20)) \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts index cd9767b888..fcbdd749ce 100644 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts @@ -10,7 +10,7 @@ */ import * as fs from "fs"; -import { Imperative, IO, Session, TextUtils } from "@zowe/imperative"; +import { Imperative, Session, TextUtils } from "@zowe/imperative"; import { inspect } from "util"; import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; @@ -19,7 +19,6 @@ import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/prope import { ZosFilesMessages } from "../../../../src/constants/ZosFiles.messages"; import { Invoke } from "../../../../src/methods/invoke/Invoke"; import { getUniqueDatasetName } from "../../../../../../__tests__/__src__/TestUtils"; -import { posix } from "path"; let testEnvironment: ITestEnvironment; let systemProps: ITestPropertiesSchema; @@ -34,10 +33,9 @@ describe("Invoke AMS", () => { tempProfileTypes: ["zosmf"], testName: "zos_create_VSAM_dataset" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - systemProps = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); }); @@ -77,7 +75,7 @@ describe("Invoke AMS", () => { expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); // Delete the temp file - IO.deleteFile(posix.basename(controlStatementFile)); + fs.unlinkSync(controlStatementFile); // create a temporary file from the template file that has the proper high level qualifier to delete the VSAM file controlStatementFile = @@ -97,8 +95,8 @@ describe("Invoke AMS", () => { expect(response.success).toBe(true); expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - // Delete created temp local file - IO.deleteFile(posix.basename(controlStatementFile)); + // Delete the temp file + fs.unlinkSync(controlStatementFile); }); it("should create and delete a VSAM data set from command statement in files with response timeout", async () => { @@ -212,22 +210,15 @@ describe("Invoke AMS - encoded", () => { tempProfileTypes: ["zosmf"], testName: "zos_create_VSAM_dataset" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - systemProps = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = getUniqueDatasetName(`${systemProps.zosmf.user}.ZOSFILE.ENCO#ED.VSAM`); volume = systemProps.datasets.vol.toUpperCase(); }); afterAll(async () => { await TestEnvironment.cleanUp(testEnvironment); - try { - fs.unlinkSync(__dirname + "/DefineVSAM.ams.temp"); - fs.unlinkSync(__dirname + "/DeleteVSAM.ams.temp"); - } catch (err) { - // do nothing - } }); function createTestAMSStatementFileFromTemplate(templateFile: string) { diff --git a/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts index 4cf39470de..4e3981e4ae 100644 --- a/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/list/List.system.test.ts @@ -33,8 +33,6 @@ describe("List command group", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.LIST`, false, 1); Imperative.console.info("Using dsname:" + dsname); @@ -670,9 +668,8 @@ describe("List command group - encoded", () => { testName: "zos_file_list" }); defaultSystem = testEnvironment.systemTestProperties; - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.LIST`, true); Imperative.console.info("Using dsname:" + dsname); diff --git a/packages/zosfiles/__tests__/__system__/methods/mount/Mount.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/mount/Mount.system.test.ts index b92b6d9b36..3e695baaec 100644 --- a/packages/zosfiles/__tests__/__system__/methods/mount/Mount.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/mount/Mount.system.test.ts @@ -59,8 +59,6 @@ describe("Mount and unmount a file system", () => { volume = defaultSystem.datasets.vol; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - fsname = getUniqueDatasetName(defaultSystem.zosmf.user); const dirname = getUniqueDatasetName(defaultSystem.zosmf.user).split(".")[1]; mountPoint = "/tmp/" + dirname; @@ -263,8 +261,6 @@ describe("Mount and unmount a file system - encoded", () => { volume = defaultSystem.datasets.vol; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - fsname = getUniqueDatasetName(defaultSystem.zosmf.user, true); const dirname = getUniqueDatasetName(defaultSystem.zosmf.user, true).split(".")[1]; mountPoint = "/tmp/" + dirname; diff --git a/packages/zosfiles/__tests__/__system__/methods/rename/Rename.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/rename/Rename.system.test.ts index 237d75a0c8..7b45beb974 100644 --- a/packages/zosfiles/__tests__/__system__/methods/rename/Rename.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/rename/Rename.system.test.ts @@ -33,8 +33,6 @@ describe("Rename", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - beforeDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.BEFORE.SET`; afterDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.AFTER.SET`; }); @@ -428,8 +426,6 @@ describe("Rename - encoded", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - beforeDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.ENCO#ED.BEFORE.SET`; afterDataSetName = `${defaultSystem.zosmf.user.trim().toUpperCase()}.ENCO#ED.AFTER.SET`; }); diff --git a/packages/zosfiles/__tests__/__system__/methods/search/Search.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/search/Search.system.test.ts index df78a236b3..db839abc14 100644 --- a/packages/zosfiles/__tests__/__system__/methods/search/Search.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/search/Search.system.test.ts @@ -34,7 +34,6 @@ describe("Search", () => { }); defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; // We can't test color related stuff in GitHub Actions or Jenkins oldForceColor = process.env.FORCE_COLOR; diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index 026463006a..00f1f56950 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -10,15 +10,14 @@ */ import { Create, CreateDataSetTypeEnum, Delete, IUploadOptions, IZosFilesResponse, - Upload, ZosFilesMessages, Download, Get, ZosFilesConstants, IUploadMap, Utilities } from "../../../../src"; + Upload, ZosFilesMessages, Download, Get, IUploadMap, Utilities } from "../../../../src"; import { Imperative, Session } from "@zowe/imperative"; -import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { inspect } from "util"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; +import { deleteFiles, getUniqueDatasetName, stripNewLines, wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; import * as fs from "fs"; -import { getUniqueDatasetName, deleteLocalDirectories, inspect, - stripNewLines, wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; @@ -29,256 +28,168 @@ const inputfile = __dirname + "/testfiles/upload.txt"; const testdata = "abcdefghijklmnopqrstuvwxyz"; const uploadOptions: IUploadOptions = {} as any; -describe("All Upload Tests", () => { - const localDir = `${__dirname}/testfiles`; - const localDirWithSpaces = `${__dirname}/testfiles/space dir`; - const failedTestFilesDir = `${__dirname}/failtestfiles`; +describe("Upload Data Set", () => { beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_file_upload" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - defaultSystem = testEnvironment.systemTestProperties; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); - Imperative.console.info("Using dsname:" + dsname); - - try { - // Create test file directories - - if (!fs.existsSync(localDir)) { - fs.mkdirSync(localDir, { recursive: true }); - testEnvironment.resources.localFiles.push(localDir); - } - if (!fs.existsSync(localDirWithSpaces)) { - fs.mkdirSync(localDirWithSpaces, { recursive: true }); - testEnvironment.resources.localFiles.push(localDirWithSpaces); - } - if (!fs.existsSync(failedTestFilesDir)) { - fs.mkdirSync(failedTestFilesDir, { recursive: true }); - testEnvironment.resources.localFiles.push(failedTestFilesDir); - } - if (!fs.existsSync(`${localDir}/longline`)) { - fs.mkdirSync(`${localDir}/longline`, { recursive: true }); - testEnvironment.resources.localFiles.push(`${localDir}/longline`); - } - - // Create and write files with their contents - - // failedtestfiles/test1.txt - const test1FilePath = `${failedTestFilesDir}/test1.txt`; - fs.writeFileSync(test1FilePath, "fake data"); - testEnvironment.resources.localFiles.push(test1FilePath); - - // longline/longline.txt - const longlineFilePath = `${localDir}/longline/longline.txt`; - fs.writeFileSync(longlineFilePath, - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrs"+ - "tuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); - testEnvironment.resources.localFiles.push(longlineFilePath); - - // space dir/file4.txt - const file4Path = `${localDirWithSpaces}/file4.txt`; - fs.writeFileSync(file4Path, "abcdefghijklmnopqrstuvwxyz"); - testEnvironment.resources.localFiles.push(file4Path); - - // file1.txt, file2.txt, file3.txt, and upload.txt - const filesToCreate = [ - `${localDir}/file1.txt`, - `${localDir}/file2.txt`, - `${localDir}/file3.txt`, - `${localDir}/upload.txt` - ]; - - filesToCreate.forEach((filepath) => { - fs.writeFileSync(filepath, "abcdefghijklmnopqrstuvwxyz"); - testEnvironment.resources.localFiles.push(filepath); - }); - // main.exe is too complex to build from scratch + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - } catch (err) { - Imperative.console.info("Error setting up test files and directories:", err); - } + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); + Imperative.console.info("Using dsname:" + dsname); }); afterAll(async () => { await TestEnvironment.cleanUp(testEnvironment); - - // Delete directories using the utility function - const dirsToDelete = [localDir, localDirWithSpaces]; - deleteLocalDirectories(dirsToDelete); }); - describe("Upload Data Set", () => { + describe("Success Scenarios", () => { - describe("Success Scenarios", () => { + describe("Physical sequential", () => { - describe("Physical sequential", () => { - - beforeEach(async () => { - let error; - let response; - uploadOptions.etag = undefined; - uploadOptions.returnEtag = undefined; + beforeEach(async () => { + let error; + let response; + uploadOptions.etag = undefined; + uploadOptions.returnEtag = undefined; - try { - response = await Create.dataSet(REAL_SESSION, - CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - } catch (err) { - error = err; - } - }); + try { + response = await Create.dataSet(REAL_SESSION, + CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); + } catch (err) { + error = err; + } + }); - afterEach(async () => { - let error; - let response; + afterEach(async () => { + let error; + let response; - try { - response = await Delete.dataSet(REAL_SESSION, dsname); - } catch (err) { - error = err; - } - }); + try { + response = await Delete.dataSet(REAL_SESSION, dsname); + } catch (err) { + error = err; + } + }); - it("should upload a file to a physical sequential data set using full path", async () => { - let error; - let response: IZosFilesResponse; + it("should upload a file to a physical sequential data set using full path", async () => { + let error; + let response: IZosFilesResponse; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - it("should upload a file to a physical sequential data set with response timeout", async () => { - let error; - let response: IZosFilesResponse; + it("should upload a file to a physical sequential data set with response timeout", async () => { + let error; + let response: IZosFilesResponse; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname, {responseTimeout: 5}); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname, {responseTimeout: 5}); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - it("should upload a file to a physical sequential data set while passing correct Etag", async () => { - let error; - let response: IZosFilesResponse; + it("should upload a file to a physical sequential data set while passing correct Etag", async () => { + let error; + let response: IZosFilesResponse; - // first we have to get the Etag, so we can compare it. We do it by preemtively downloading the file and requesting Etag - await Upload.fileToDataset(REAL_SESSION, __dirname + "/testfiles/upload.txt", dsname); - const downloadOptions = {file: __dirname + "/testfiles/upload.txt", returnEtag: true}; - const downloadResponse = await Download.dataSet(REAL_SESSION, dsname, downloadOptions); - expect(downloadResponse.success).toBeTruthy(); - expect(downloadResponse.apiResponse.etag).toBeDefined(); + // first we have to get the Etag, so we can compare it. We do it by preemtively downloading the file and requesting Etag + await Upload.fileToDataset(REAL_SESSION, __dirname + "/testfiles/upload.txt", dsname); + const downloadOptions = {file: __dirname + "/testfiles/upload.txt", returnEtag: true}; + const downloadResponse = await Download.dataSet(REAL_SESSION, dsname, downloadOptions); + expect(downloadResponse.success).toBeTruthy(); + expect(downloadResponse.apiResponse.etag).toBeDefined(); - try { - uploadOptions.etag = downloadResponse.apiResponse.etag; - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, __dirname + "/testfiles/upload.txt", dsname, uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + try { + uploadOptions.etag = downloadResponse.apiResponse.etag; + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, __dirname + "/testfiles/upload.txt", dsname, uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - it("should upload a file to a physical sequential data set and return the Etag", async () => { - let error; - let response: IZosFilesResponse; - uploadOptions.returnEtag = true; + it("should upload a file to a physical sequential data set and return the Etag", async () => { + let error; + let response: IZosFilesResponse; + uploadOptions.returnEtag = true; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname, uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - expect(response.apiResponse[0].etag).toBeDefined(); - }); + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname, uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + expect(response.apiResponse[0].etag).toBeDefined(); + }); - it("should upload a file to a physical sequential data set using relative path", async () => { - let error; - let response: IZosFilesResponse; + it("should upload a file to a physical sequential data set using relative path", async () => { + let error; + let response: IZosFilesResponse; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - "./packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + "./packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - // Since this test is platform specific, only run it on Windows - (process.platform === "win32" ? it : it.skip)("should upload a file to a physical sequential data set using Windows relative path", - async () => { - let error; - let response: IZosFilesResponse; - - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - ".\\packages\\zosfiles\\__tests__\\__system__\\methods\\upload\\testfiles\\upload.txt", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); - - it("should upload a file to a physical sequential data set in binary mode", async () => { + // Since this test is platform specific, only run it on Windows + (process.platform === "win32" ? it : it.skip)("should upload a file to a physical sequential data set using Windows relative path", + async () => { let error; let response: IZosFilesResponse; - uploadOptions.binary = true; - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ + // packages/zosfiles/__tests__/__system__/api/methods/upload/ response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname, uploadOptions); + ".\\packages\\zosfiles\\__tests__\\__system__\\methods\\upload\\testfiles\\upload.txt", dsname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -290,254 +201,89 @@ describe("All Upload Tests", () => { expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should upload a file to a physical sequential data set in binary mode with record specified", async () => { - let error; - let response: IZosFilesResponse; - - uploadOptions.binary = true; - uploadOptions.record = true; - - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname, uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + it("should upload a file to a physical sequential data set in binary mode", async () => { + let error; + let response: IZosFilesResponse; - it("should upload a file to a physical sequential data set in record mode", async () => { - let error; - let response: IZosFilesResponse; + uploadOptions.binary = true; - uploadOptions.record = true; + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname, uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname, uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + it("should upload a file to a physical sequential data set in binary mode with record specified", async () => { + let error; + let response: IZosFilesResponse; - it("should display proper error when specifying dir instead of a file", async () => { - let error; - let response: IZosFilesResponse; + uploadOptions.binary = true; + uploadOptions.record = true; - try { - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); - }); + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname, uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - describe("Partitioned data set", () => { + it("should upload a file to a physical sequential data set in record mode", async () => { + let error; + let response: IZosFilesResponse; - beforeEach(async () => { - let error; - let response; + uploadOptions.record = true; - try { - response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - } catch (err) { - error = err; - } - }); - - afterEach(async () => { - let error; - let response; - - try { - response = await Delete.dataSet(REAL_SESSION, dsname); - } catch (err) { - error = err; - } - }); - - it("should upload a file to a partitioned data set member using full path", async () => { - let error; - let response: IZosFilesResponse; - - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)"); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); - - it("should upload a file to a partitioned data set member with response timeout", async () => { - let error; - let response: IZosFilesResponse; - - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)", {responseTimeout: 5}); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); - - it("should upload a file to a partitioned data set member using relative path", async () => { - let error; - let response: IZosFilesResponse; - - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - "./packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt", dsname + "(member)"); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); - - // Since this test is platform specific, only run it on Windows - (process.platform === "win32" ? it : it.skip)("should upload a file to a partitioned data set member using Windows relative path", - async () => { - let error; - let response: IZosFilesResponse; - - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - ".\\packages\\zosfiles\\__tests__\\__system__\\methods\\upload\\testfiles\\upload.txt", dsname + "(member)"); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); - - it("should upload a file to a partitioned data set member in binary mode", async () => { - let error; - let response: IZosFilesResponse; - - uploadOptions.binary = true; - - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); - - it("should upload a file to a partitioned data set member in binary mode with record specified", async () => { - let error; - let response: IZosFilesResponse; - - uploadOptions.binary = true; - uploadOptions.record = true; - - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); - - it("should upload a file to a partitioned data set member in record mode", async () => { - let error; - let response: IZosFilesResponse; - - uploadOptions.record = true; - - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); - - it("should upload files in a directory to a partitioned data set member using full path", async () => { - let error; - let response: IZosFilesResponse; + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname, uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); - try { + it("should display proper error when specifying dir instead of a file", async () => { + let error; + let response: IZosFilesResponse; - response = await Upload.dirToPds(REAL_SESSION, __dirname + "/testfiles", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); + try { + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); }); }); - describe("Failure Scenarios", () => { + describe("Partitioned data set", () => { beforeEach(async () => { let error; @@ -561,922 +307,1061 @@ describe("All Upload Tests", () => { } }); - it("should display proper error when not specifying file", async () => { + it("should upload a file to a partitioned data set member using full path", async () => { let error; let response: IZosFilesResponse; try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles", dsname); + __dirname + "/testfiles/upload.txt", dsname + "(member)"); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should display proper error when not specifying data set", async () => { + it("should upload a file to a partitioned data set member with response timeout", async () => { let error; let response: IZosFilesResponse; try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.text", ""); + __dirname + "/testfiles/upload.txt", dsname + "(member)", {responseTimeout: 5}); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingDatasetName.message); + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should display proper error when specifying file instead of directory", async () => { + it("should upload a file to a partitioned data set member using relative path", async () => { let error; let response: IZosFilesResponse; try { - response = await Upload.dirToPds(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname); + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + "./packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt", dsname + "(member)"); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain("is not a directory"); // pathIsNotDirectory error + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should display proper error when specifying dir instead of a file", async () => { + // Since this test is platform specific, only run it on Windows + (process.platform === "win32" ? it : it.skip)("should upload a file to a partitioned data set member using Windows relative path", + async () => { + let error; + let response: IZosFilesResponse; + + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + ".\\packages\\zosfiles\\__tests__\\__system__\\methods\\upload\\testfiles\\upload.txt", dsname + "(member)"); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); + + it("should upload a file to a partitioned data set member in binary mode", async () => { let error; let response: IZosFilesResponse; + uploadOptions.binary = true; + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles", dsname); + __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should display proper error when uploading the contents of a dir to a partitioned data set member", async () => { + it("should upload a file to a partitioned data set member in binary mode with record specified", async () => { let error; let response: IZosFilesResponse; + uploadOptions.binary = true; + uploadOptions.record = true; + try { // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.dirToPds(REAL_SESSION, - __dirname + "/testfiles", dsname + "(member)"); + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(response).toBeFalsy(); - expect(error).toBeTruthy(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.uploadDirectoryToDatasetMember.message); + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should display proper error is line in file exceeds record length of data set", async () => { + it("should upload a file to a partitioned data set member in record mode", async () => { let error; let response: IZosFilesResponse; + uploadOptions.record = true; + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles//longline/longline.txt", dsname); + __dirname + "/testfiles/upload.txt", dsname + "(member)", uploadOptions); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); + }); + + it("should upload files in a directory to a partitioned data set member using full path", async () => { + let error; + let response: IZosFilesResponse; + + try { + + response = await Upload.dirToPds(REAL_SESSION, __dirname + "/testfiles", dsname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } + expect(error).toBeFalsy(); expect(response).toBeTruthy(); - expect(response.success).toBeFalsy(); - expect(stripNewLines(response.commandResponse)).toContain("Truncation of a record occurred during an I/O operation"); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); }); }); - describe("Upload Data Set - encoded", () => { + describe("Failure Scenarios", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload" - }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; + beforeEach(async () => { + let error; + let response; - defaultSystem = testEnvironment.systemTestProperties; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); - Imperative.console.info("Using dsname:" + dsname); + try { + response = await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); + } catch (err) { + error = err; + } }); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); + afterEach(async () => { + let error; + let response; + + try { + response = await Delete.dataSet(REAL_SESSION, dsname); + } catch (err) { + error = err; + } }); - describe("Success Scenarios", () => { + it("should display proper error when not specifying file", async () => { + let error; + let response: IZosFilesResponse; + + try { + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); + }); - describe("Physical sequential", () => { + it("should display proper error when not specifying data set", async () => { + let error; + let response: IZosFilesResponse; + + try { + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.text", ""); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingDatasetName.message); + }); - beforeEach(async () => { - uploadOptions.etag = undefined; - uploadOptions.returnEtag = undefined; + it("should display proper error when specifying file instead of directory", async () => { + let error; + let response: IZosFilesResponse; + + try { + response = await Upload.dirToPds(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain("is not a directory"); // pathIsNotDirectory error + }); - try { - await Create.dataSet(REAL_SESSION, - CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); - } catch (err) { - // Do nothing - } - }); + it("should display proper error when specifying dir instead of a file", async () => { + let error; + let response: IZosFilesResponse; + + try { + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputFile.message); + }); - afterEach(async () => { - try { - await Delete.dataSet(REAL_SESSION, dsname); - } catch (err) { - // Do nothing - } - }); + it("should display proper error when uploading the contents of a dir to a partitioned data set member", async () => { + let error; + let response: IZosFilesResponse; + + try { + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.dirToPds(REAL_SESSION, + __dirname + "/testfiles", dsname + "(member)"); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(response).toBeFalsy(); + expect(error).toBeTruthy(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.uploadDirectoryToDatasetMember.message); + }); - it("should upload a file to a physical sequential data set using full path", async () => { - let error; - let response: IZosFilesResponse; + it("should display proper error is line in file exceeds record length of data set", async () => { + let error; + let response: IZosFilesResponse; + + try { + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles//longline/longline.txt", dsname); + Imperative.console.info("Response: " + inspect(response)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + expect(response).toBeTruthy(); + expect(response.success).toBeFalsy(); + expect(stripNewLines(response.commandResponse)).toContain("Truncation of a record occurred during an I/O operation"); + }); + }); +}); - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); - }); - - describe("Partitioned data set", () => { - - beforeEach(async () => { - try { - await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); - } catch (err) { - // Do nothing - } - }); +describe("Upload Data Set - encoded", () => { - afterEach(async () => { - try { - await Delete.dataSet(REAL_SESSION, dsname); - } catch (err) { - // Do nothing - } - }); + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload" + }); + defaultSystem = testEnvironment.systemTestProperties; - it("should upload a file to a partitioned data set member using full path", async () => { - let error; - let response: IZosFilesResponse; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - try { - // packages/zosfiles/__tests__/__system__/api/methods/upload/ - response = await Upload.fileToDataset(REAL_SESSION, - __dirname + "/testfiles/upload.txt", dsname + "(member)"); - Imperative.console.info("Response: " + inspect(response)); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(response.success).toBeTruthy(); - expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); - }); - }); - }); + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); + Imperative.console.info("Using dsname:" + dsname); }); - describe("Upload USS file", () => { - - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload_uss" - }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - defaultSystem = testEnvironment.systemTestProperties; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); - ussname = dsname.replace(/\./g, ""); - ussname = `${defaultSystem.unix.testdir}/${ussname}`; - Imperative.console.info("Using ussfile:" + ussname); - }); + describe("Success Scenarios", () => { - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - - describe("Success Scenarios", () => { + describe("Physical sequential", () => { beforeEach(async () => { uploadOptions.etag = undefined; - fs.writeFileSync(inputfile, testdata); - }); - - afterEach(async () => { - let error; - let response; - - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; + uploadOptions.returnEtag = undefined; try { - response = await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); + await Create.dataSet(REAL_SESSION, + CreateDataSetTypeEnum.DATA_SET_SEQUENTIAL, dsname); } catch (err) { - error = err; + // Do nothing } }); - it("should upload a USS file", async () => { - let error; - let uploadResponse; - let getResponse; - const data: Buffer = Buffer.from(testdata); - + afterEach(async () => { try { - uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data); - getResponse = await Get.USSFile(REAL_SESSION, ussname); + await Delete.dataSet(REAL_SESSION, dsname); } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); + // Do nothing } - - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(data.toString())); - }); - it("should upload a USS file in binary mode", async () => { + + it("should upload a file to a physical sequential data set using full path", async () => { let error; - let uploadResponse; - let getResponse; - const data: Buffer = Buffer.from(testdata); + let response: IZosFilesResponse; try { - uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data, { binary: true }); - getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname); + Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(data.toString())); - + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should upload a USS file from local file", async () => { - let error; - let uploadResponse; - let getResponse; - let tagResponse; + }); + + describe("Partitioned data set", () => { + beforeEach(async () => { try { - uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname); - getResponse = await Get.USSFile(REAL_SESSION, ussname); - tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_PARTITIONED, dsname); } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); + // Do nothing } - - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(testdata)); - expect(tagResponse).toBe(false); - }); - it("should upload a USS file from local file in binary mode", async () => { - let error; - let uploadResponse; - let getResponse; - let tagResponse; + afterEach(async () => { try { - uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, { binary: true }); - getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); - tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); + await Delete.dataSet(REAL_SESSION, dsname); } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); + // Do nothing } - - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(testdata)); - expect(tagResponse).toBe(true); - }); - it("should upload a USS file while passing correct Etag", async () => { - let error; - let uploadResponse; - // first we have to get the Etag, so we can compare it. We do it by preemtively downloading the file and requesting Etag - await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {returnEtag: false}); - const downloadResponse = await Download.ussFile(REAL_SESSION, ussname, {file: inputfile, returnEtag: true}); - expect(downloadResponse.success).toBeTruthy(); - expect(downloadResponse.apiResponse.etag).toBeDefined(); + it("should upload a file to a partitioned data set member using full path", async () => { + let error; + let response: IZosFilesResponse; try { - uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {etag: downloadResponse.apiResponse.etag}); - Imperative.console.info("Response: " + inspect(uploadResponse)); + // packages/zosfiles/__tests__/__system__/api/methods/upload/ + response = await Upload.fileToDataset(REAL_SESSION, + __dirname + "/testfiles/upload.txt", dsname + "(member)"); + Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } - expect(error).toBeFalsy(); - expect(uploadResponse).toBeTruthy(); - expect(uploadResponse.success).toBeTruthy(); - expect(uploadResponse.commandResponse).toContain(ZosFilesMessages.ussFileUploadedSuccessfully.message); + expect(response).toBeTruthy(); + expect(response.success).toBeTruthy(); + expect(response.commandResponse).toContain(ZosFilesMessages.dataSetUploadedSuccessfully.message); }); - it("should upload a USS file and return Etag", async () => { - let error; - let uploadResponse; - let getResponse; + }); + }); +}); - try { - uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {returnEtag: true}); - getResponse = await Get.USSFile(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } +describe("Upload USS file", () => { - expect(error).toBeFalsy(); - expect(uploadResponse).toBeTruthy(); - expect(uploadResponse.success).toBeTruthy(); - expect(uploadResponse.apiResponse.etag).toBeDefined(); - }); + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload_uss" }); + defaultSystem = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); + ussname = dsname.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/${ussname}`; + Imperative.console.info("Using ussfile:" + ussname); }); - describe("Upload USS file - encoded", () => { + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload_uss" - }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; + describe("Success Scenarios", () => { - defaultSystem = testEnvironment.systemTestProperties; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); - ussname = dsname.replace(/\./g, ""); - ussname = `${defaultSystem.unix.testdir}/ENCO#ED${ussname}`; - Imperative.console.info("Using ussfile:" + ussname); + beforeEach(async () => { + uploadOptions.etag = undefined; + fs.writeFileSync(inputfile, testdata); }); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); + afterEach(async () => { + await deleteFiles(REAL_SESSION, ussname); }); - describe("Success Scenarios", () => { + it("should upload a USS file", async () => { + let error; + let uploadResponse; + let getResponse; + const data: Buffer = Buffer.from(testdata); + + try { + uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data); + getResponse = await Get.USSFile(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - beforeEach(async () => { - uploadOptions.etag = undefined; - fs.writeFileSync(inputfile, testdata); - }); + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(data.toString())); - afterEach(async () => { - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); + }); + it("should upload a USS file in binary mode", async () => { + let error; + let uploadResponse; + let getResponse; + const data: Buffer = Buffer.from(testdata); + + try { + uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data, { binary: true }); + getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint); - } catch (err) { - // Do nothing - } - }); + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(data.toString())); - it("should upload a USS file", async () => { - let error; - let getResponse; - const data: Buffer = Buffer.from(testdata); + }); + it("should upload a USS file from local file", async () => { + let error; + let uploadResponse; + let getResponse; + let tagResponse; + + try { + uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname); + getResponse = await Get.USSFile(REAL_SESSION, ussname); + tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - try { - await Upload.bufferToUssFile(REAL_SESSION, ussname, data); - getResponse = await Get.USSFile(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(testdata)); + expect(tagResponse).toBe(false); - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(data.toString())); + }); + it("should upload a USS file from local file in binary mode", async () => { + let error; + let uploadResponse; + let getResponse; + let tagResponse; + + try { + uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, { binary: true }); + getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); + tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - }); + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(testdata)); + expect(tagResponse).toBe(true); - it("should upload a USS file from local file", async () => { - let error; - let getResponse; - let tagResponse; + }); + it("should upload a USS file while passing correct Etag", async () => { + let error; + let uploadResponse; + + // first we have to get the Etag, so we can compare it. We do it by preemtively downloading the file and requesting Etag + await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {returnEtag: false}); + const downloadResponse = await Download.ussFile(REAL_SESSION, ussname, {file: inputfile, returnEtag: true}); + expect(downloadResponse.success).toBeTruthy(); + expect(downloadResponse.apiResponse.etag).toBeDefined(); + + try { + uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {etag: downloadResponse.apiResponse.etag}); + Imperative.console.info("Response: " + inspect(uploadResponse)); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - try { - await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname); - getResponse = await Get.USSFile(REAL_SESSION, ussname); - tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(uploadResponse).toBeTruthy(); + expect(uploadResponse.success).toBeTruthy(); + expect(uploadResponse.commandResponse).toContain(ZosFilesMessages.ussFileUploadedSuccessfully.message); + }); + it("should upload a USS file and return Etag", async () => { + let error; + let uploadResponse; + let getResponse; + + try { + uploadResponse = await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname, {returnEtag: true}); + getResponse = await Get.USSFile(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeFalsy(); - expect(getResponse).toEqual(Buffer.from(testdata)); - expect(tagResponse).toBe(false); + expect(error).toBeFalsy(); + expect(uploadResponse).toBeTruthy(); + expect(uploadResponse.success).toBeTruthy(); + expect(uploadResponse.apiResponse.etag).toBeDefined(); + }); + }); +}); - }); +describe("Upload USS file - encoded", () => { + + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload_uss" }); + defaultSystem = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); + ussname = dsname.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/ENCO#ED${ussname}`; + Imperative.console.info("Using ussfile:" + ussname); }); - describe("Upload a local directory to USS directory", () => { - describe("Success scenarios", () => { - const localDir = `${__dirname}/testfiles`; - const localDirWithSpaces = `${__dirname}/testfiles/space dir`; - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload_dir_to_uss" - }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - defaultSystem = testEnvironment.systemTestProperties; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); - ussname = dsname.replace(/\./g, ""); - ussname = `${defaultSystem.unix.testdir}/${ussname}`; - Imperative.console.info("Using ussfile:" + ussname); - }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - afterAll(async () => { - let error; - await TestEnvironment.cleanUp(testEnvironment); - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, - ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname + " space dir"), - [{"X-IBM-Option": "recursive"}]); - } catch (err) { - error = err; - } - }); + describe("Success Scenarios", () => { - afterEach(async () => { - let error; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); - await wait(waitTime); //wait 2 seconds - } catch (err) { - error = err; - } - }); + beforeEach(async () => { + uploadOptions.etag = undefined; + fs.writeFileSync(inputfile, testdata); + }); - it("should upload local directory to USS", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: boolean; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname); - await wait(waitTime); //wait 2 seconds - Imperative.console.info(`THIS IS USS ${ussname}/testfiles`); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + afterEach(async () => { + await deleteFiles(REAL_SESSION, ussname); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + it("should upload a USS file", async () => { + let error; + let getResponse; + const data: Buffer = Buffer.from(testdata); + + try { + await Upload.bufferToUssFile(REAL_SESSION, ussname, data); + getResponse = await Get.USSFile(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should upload local directory (with space in name) to USS", async () => { - let error; - let tempUssname; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: boolean; - try { - tempUssname = ussname + " space dir"; - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDirWithSpaces, tempUssname); - await wait(waitTime); //wait 2 seconds - Imperative.console.info(`THIS IS USS ${tempUssname}`); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, tempUssname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(data.toString())); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + }); - it("should upload local directory to USS recursively", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: any; - try { - uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false}); - await wait(waitTime); //wait 2 seconds - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + it("should upload a USS file from local file", async () => { + let error; + let getResponse; + let tagResponse; + + try { + await Upload.fileToUssFile(REAL_SESSION, inputfile, ussname); + getResponse = await Get.USSFile(REAL_SESSION, ussname); + tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + expect(error).toBeFalsy(); + expect(getResponse).toEqual(Buffer.from(testdata)); + expect(tagResponse).toBe(false); - it("should upload local directory to USS in binary mode", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: any; - let getResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname, {binary: true}); - await wait(waitTime); //wait 2 seconds - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); - getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: true}); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + }); + }); +}); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - expect(getResponse).toEqual(Buffer.from(testdata)); +describe("Upload a local directory to USS directory", () => { + describe("Success scenarios", () => { + const localDir = `${__dirname}/testfiles`; + const localDirWithSpaces = `${__dirname}/testfiles/space dir`; + let tempUssname: string; + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload_dir_to_uss" }); + defaultSystem = testEnvironment.systemTestProperties; - it("should upload local directory to USS recursively and all files in binary mode", async () => { - let error; - let uploadResponse: IZosFilesResponse; - const magicNum = 6; - let isDirectoryExist: any; - let getResponse; - let longResponse: string = ""; - try { - uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: true}); - await wait(waitTime); //wait 2 seconds - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); - getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: true}); - for (let i = 0; i < magicNum; i++) { - longResponse += testdata; - } - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - expect(getResponse).toEqual(Buffer.from(longResponse)); - }); + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); + ussname = dsname.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/${ussname}`; + Imperative.console.info("Using ussfile:" + ussname); + }); - it("should upload local directory to USS some files need to be uploaded as binary", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: any; - let getResponseFile3; - let getResponseFile1; - let getResponseLongFile; - let longResponse: string = ""; - const magicNum = 6; - const fileMap: IUploadMap = {binary: true, fileNames: ["file3.txt", "longline.txt"]}; - try { - uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false, filesMap: fileMap}); - await wait(waitTime); //wait 2 seconds - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); - // file3.txt should be binary as it is mentioned in filesMap - getResponseFile3 = await Get.USSFile(REAL_SESSION, `${ussname}/file3.txt`, {binary: true}); - // longline/longline.txt should be binary as it is mentioned in filesMap - getResponseLongFile = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: true}); - // file1.txt should be ASCII like other files not mentioned in filesMap - getResponseFile1 = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: false}); - for (let i = 0; i < magicNum; i++) { - longResponse += testdata; - } - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + beforeEach(() => { + tempUssname = null; + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - expect(getResponseFile3).toEqual(Buffer.from(testdata)); - expect(getResponseLongFile).toEqual(Buffer.from(longResponse)); - expect(getResponseFile1.toString()).toEqual(testdata); - }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - it("should upload local directory to USS some files need to be uploaded as ASCII", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: any; - let getResponseFile3; - let getResponseFile1; - let getResponseLongFile; - let longResponse: string = ""; - const magicNum = 6; - const filesMap: IUploadMap = {binary: false, fileNames: ["file3.txt", "longline.txt"]}; - try { - uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: true, filesMap}); - await wait(waitTime); //wait 2 seconds - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); - // file3.txt should be ASCII as it is mentioned in filesMap - getResponseFile3 = await Get.USSFile(REAL_SESSION, `${ussname}/file3.txt`, {binary: false}); - // longline/longline.txt should be ASCII as it is mentioned in filesMap - getResponseLongFile = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: false}); - // file1.txt should be binary like other files not mentioned in filesMap - getResponseFile1 = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: true}); - for (let i = 0; i < magicNum; i++) { - longResponse += testdata; - } - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + afterEach(async () => { + await deleteFiles(REAL_SESSION, tempUssname ?? ussname); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - expect(getResponseFile3).toEqual(Buffer.from(testdata)); - expect(getResponseLongFile).toEqual(Buffer.from(longResponse)); - expect(getResponseFile1).toEqual(Buffer.from(testdata)); - }); + it("should upload local directory to USS", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: boolean; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname); + await wait(waitTime); + Imperative.console.info(`THIS IS USS ${ussname}/testfiles`); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); }); - describe("Fail scenarios", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload_dir_to_uss" - }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; + it("should upload local directory (with space in name) to USS", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: boolean; + try { + tempUssname = ussname + " space dir"; + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDirWithSpaces, tempUssname); + await wait(waitTime); + Imperative.console.info(`THIS IS USS ${tempUssname}`); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, tempUssname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - defaultSystem = testEnvironment.systemTestProperties; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + }); - // Initialize `ussname` properly - ussname = dsname.replace(/\./g, ""); // Removing dots to avoid issues in path - ussname = `${defaultSystem.unix.testdir}/${ussname}`; - Imperative.console.info("Using ussfile:" + ussname); - }); + it("should upload local directory to USS recursively", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: any; + try { + uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false}); + await wait(waitTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - let error; - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + ussname; - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); - } catch (err) { - error = err; - } - }); + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + }); - it("should throw an error if local directory is null", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, null, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + it("should upload local directory to USS in binary mode", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: any; + let getResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname, {binary: true}); + await wait(waitTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); + getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: true}); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); - expect(uploadResponse).not.toBeDefined(); - }); + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + expect(getResponse).toEqual(Buffer.from(testdata)); + }); - it("should throw an error if local directory is empty string", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "", ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); + it("should upload local directory to USS recursively and all files in binary mode", async () => { + let error; + let uploadResponse: IZosFilesResponse; + const magicNum = 6; + let isDirectoryExist: any; + let getResponse; + let longResponse: string = ""; + try { + uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: true}); + await wait(waitTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); + getResponse = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: true}); + for (let i = 0; i < magicNum; i++) { + longResponse += testdata; } + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); - expect(uploadResponse).not.toBeDefined(); - }); + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + expect(getResponse).toEqual(Buffer.from(longResponse)); + }); - it("should throw an error if passed local directory doesn't exist", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); + it("should upload local directory to USS some files need to be uploaded as binary", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: any; + let getResponseFile3; + let getResponseFile1; + let getResponseLongFile; + let longResponse: string = ""; + const magicNum = 6; + const fileMap: IUploadMap = {binary: true, fileNames: ["file3.txt", "longline.txt"]}; + try { + uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false, filesMap: fileMap}); + await wait(waitTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); + // file3.txt should be binary as it is mentioned in filesMap + getResponseFile3 = await Get.USSFile(REAL_SESSION, `${ussname}/file3.txt`, {binary: true}); + // longline/longline.txt should be binary as it is mentioned in filesMap + getResponseLongFile = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: true}); + // file1.txt should be ASCII like other files not mentioned in filesMap + getResponseFile1 = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: false}); + for (let i = 0; i < magicNum; i++) { + longResponse += testdata; } + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain("no such file or directory"); - expect(uploadResponse).not.toBeDefined(); - }); + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + expect(getResponseFile3).toEqual(Buffer.from(testdata)); + expect(getResponseLongFile).toEqual(Buffer.from(longResponse)); + expect(getResponseFile1.toString()).toEqual(testdata); + }); - it("should throw an error if passed local directory is file", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, `${__dirname}/testfiles/file1.txt`, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); + it("should upload local directory to USS some files need to be uploaded as ASCII", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: any; + let getResponseFile3; + let getResponseFile1; + let getResponseLongFile; + let longResponse: string = ""; + const magicNum = 6; + const filesMap: IUploadMap = {binary: false, fileNames: ["file3.txt", "longline.txt"]}; + try { + uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: true, filesMap}); + await wait(waitTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); + // file3.txt should be ASCII as it is mentioned in filesMap + getResponseFile3 = await Get.USSFile(REAL_SESSION, `${ussname}/file3.txt`, {binary: false}); + // longline/longline.txt should be ASCII as it is mentioned in filesMap + getResponseLongFile = await Get.USSFile(REAL_SESSION, `${ussname}/longline/longline.txt`, {binary: false}); + // file1.txt should be binary like other files not mentioned in filesMap + getResponseFile1 = await Get.USSFile(REAL_SESSION, `${ussname}/file1.txt`, {binary: true}); + for (let i = 0; i < magicNum; i++) { + longResponse += testdata; } + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + expect(getResponseFile3).toEqual(Buffer.from(testdata)); + expect(getResponseLongFile).toEqual(Buffer.from(longResponse)); + expect(getResponseFile1).toEqual(Buffer.from(testdata)); + }); + }); - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); - expect(uploadResponse).not.toBeDefined(); + describe("Fail scenarios", () => { + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload_dir_to_uss" }); + defaultSystem = testEnvironment.systemTestProperties; - it("should throw an error if USS directory path is null", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", null); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingUSSDirectoryName.message); - expect(uploadResponse).not.toBeDefined(); - }); + Imperative.console.info("Using ussfile:" + ussname); + testEnvironment.resources.files.push(ussname); + }); - it("should throw an error if USS directory path is empty string", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", ""); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - expect(error).toBeDefined(); - expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingUSSDirectoryName.message); - expect(uploadResponse).not.toBeDefined(); - }); + it("should throw an error if local directory is null", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, null, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should throw an error if uploading file is binary but we are uploading it as ASCII", async () => { - let error; - let uploadResponse: IZosFilesResponse; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, `${__dirname}/failtestfiles`, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); + expect(uploadResponse).not.toBeDefined(); + }); - expect(error).toBeDefined(); - expect(error.message).toContain("Illegal character sequence detected by iconv()"); - expect(uploadResponse).toBeUndefined(); - }); + it("should throw an error if local directory is empty string", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "", ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); + expect(uploadResponse).not.toBeDefined(); + }); + + it("should throw an error if passed local directory doesn't exist", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain("no such file or directory"); + expect(uploadResponse).not.toBeDefined(); + }); + + it("should throw an error if passed local directory is file", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, `${__dirname}/testfiles/file1.txt`, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingInputDirectory.message); + expect(uploadResponse).not.toBeDefined(); + }); + + it("should throw an error if USS directory path is null", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", null); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingUSSDirectoryName.message); + expect(uploadResponse).not.toBeDefined(); + }); + + it("should throw an error if USS directory path is empty string", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, "some/path", ""); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeDefined(); + expect(stripNewLines(error.message)).toContain(ZosFilesMessages.missingUSSDirectoryName.message); + expect(uploadResponse).not.toBeDefined(); + }); + + it("should throw an error if uploading file is binary but we are uploading it as ASCII", async () => { + let error; + let uploadResponse: IZosFilesResponse; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, `${__dirname}/failtestfiles`, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeDefined(); + expect(error.message).toContain("Illegal character sequence detected by iconv()"); + expect(uploadResponse).toBeUndefined(); }); }); +}); - describe("Upload a local directory to USS directory - encoded", () => { - describe("Success scenarios", () => { - const localDir = `${__dirname}/testfiles`; - const localDirWithSpaces = `${__dirname}/testfiles/space dir`; - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_file_upload_dir_to_uss" - }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - defaultSystem = testEnvironment.systemTestProperties; - dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); - ussname = dsname.replace(/\./g, ""); - ussname = `${defaultSystem.unix.testdir}/ENCO#ED${ussname}`; - Imperative.console.info("Using ussfile:" + ussname); +describe("Upload a local directory to USS directory - encoded", () => { + describe("Success scenarios", () => { + const localDir = `${__dirname}/testfiles`; + const localDirWithSpaces = `${__dirname}/testfiles/space dir`; + let tempUssname: string; + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_file_upload_dir_to_uss" }); + defaultSystem = testEnvironment.systemTestProperties; - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, - ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname + " space dir"), - [{"X-IBM-Option": "recursive"}]); - } catch (err) { - // Do nothing - } - }); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - afterEach(async () => { - const endpoint: string = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + encodeURIComponent(ussname); - try { - await ZosmfRestClient.deleteExpectString(REAL_SESSION, endpoint, [{"X-IBM-Option": "recursive"}]); - await wait(waitTime); //wait 2 seconds - } catch (err) { - // Do nothing - } - }); + dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`, true); + ussname = dsname.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/ENCO#ED${ussname}`; + Imperative.console.info("Using ussfile:" + ussname); + }); - it("should upload local directory to USS", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: boolean; - try { - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname); - await wait(waitTime); //wait 2 seconds - Imperative.console.info(`THIS IS USS ${ussname}/testfiles`); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + beforeEach(() => { + tempUssname = null; + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); - it("should upload local directory (with space in name) to USS", async () => { - let error; - let tempUssname; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: boolean; - try { - tempUssname = ussname + " space dir"; - uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDirWithSpaces, tempUssname); - await wait(waitTime); //wait 2 seconds - Imperative.console.info(`THIS IS USS ${tempUssname}`); - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, tempUssname); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + afterEach(async () => { + await deleteFiles(REAL_SESSION, tempUssname ?? ussname); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + it("should upload local directory to USS", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: boolean; + try { + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDir, ussname); + await wait(waitTime); + Imperative.console.info(`THIS IS USS ${ussname}/testfiles`); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, ussname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } - it("should upload local directory to USS recursively", async () => { - let error; - let uploadResponse: IZosFilesResponse; - let isDirectoryExist: any; - try { - uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false}); - await wait(waitTime); //wait 2 seconds - isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + }); - expect(error).toBeFalsy(); - expect(uploadResponse).toBeDefined(); - expect(uploadResponse.success).toBeTruthy(); - expect(isDirectoryExist).toBeDefined(); - expect(isDirectoryExist).toBeTruthy(); - }); + it("should upload local directory (with space in name) to USS", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: boolean; + try { + tempUssname = ussname + " space dir"; + uploadResponse = await Upload.dirToUSSDir(REAL_SESSION, localDirWithSpaces, tempUssname); + await wait(waitTime); + Imperative.console.info(`THIS IS USS ${tempUssname}`); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, tempUssname); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); + }); + it("should upload local directory to USS recursively", async () => { + let error; + let uploadResponse: IZosFilesResponse; + let isDirectoryExist: any; + try { + uploadResponse = await Upload.dirToUSSDirRecursive(REAL_SESSION, localDir, ussname, {binary: false}); + await wait(waitTime); + isDirectoryExist = await Upload.isDirectoryExist(REAL_SESSION, `${ussname}/longline`); + } catch (err) { + error = err; + Imperative.console.info("Error: " + inspect(error)); + } + + expect(error).toBeFalsy(); + expect(uploadResponse).toBeDefined(); + expect(uploadResponse.success).toBeTruthy(); + expect(isDirectoryExist).toBeDefined(); + expect(isDirectoryExist).toBeTruthy(); }); + }); }); diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file1.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file1.txt new file mode 100644 index 0000000000..e85d5b4528 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file1.txt @@ -0,0 +1 @@ +abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file2.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file2.txt new file mode 100644 index 0000000000..e85d5b4528 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file2.txt @@ -0,0 +1 @@ +abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file3.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file3.txt new file mode 100644 index 0000000000..e85d5b4528 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/file3.txt @@ -0,0 +1 @@ +abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/longline/longline.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/longline/longline.txt new file mode 100644 index 0000000000..4c96ed84c3 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/longline/longline.txt @@ -0,0 +1 @@ +abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/space dir/file4.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/space dir/file4.txt new file mode 100644 index 0000000000..e85d5b4528 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/space dir/file4.txt @@ -0,0 +1 @@ +abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt new file mode 100644 index 0000000000..e85d5b4528 --- /dev/null +++ b/packages/zosfiles/__tests__/__system__/methods/upload/testfiles/upload.txt @@ -0,0 +1 @@ +abcdefghijklmnopqrstuvwxyz \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts index 476425e85d..7473650100 100644 --- a/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/utilities/Utilities.system.test.ts @@ -29,8 +29,7 @@ describe("USS Utilities", () => { tempProfileTypes: ["zosmf"], testName: "zos_files_utilities" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); const defaultSystem = testEnvironment.systemTestProperties; let dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILE.UPLOAD`); @@ -46,39 +45,33 @@ describe("USS Utilities", () => { }); it("should tag a binary file", async () => { - const fileResponse = await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); - const fileName = fileResponse.apiResponse.to; + await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); await Utilities.chtag(REAL_SESSION, ussname, Tag.BINARY); const tag = await getTag(REAL_SESSION, ussname); expect(tag).toMatch("b binary"); const isBin = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); expect(isBin).toBe(true); - testEnvironment.resources.files.push(fileName); }); it("should tag a text file", async () => { - const fileResponse = await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); - const fileName = fileResponse.apiResponse.to; + await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "ISO8859-1"); const tag = await getTag(REAL_SESSION, ussname); expect(tag).toMatch("t ISO8859-1"); const isBin = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); expect(isBin).toBe(true); - testEnvironment.resources.files.push(fileName); }); it("should flag an EBCDIC file as text", async () => { - const fileResponse = await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); - const fileName = fileResponse.apiResponse.to; + await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); await Utilities.chtag(REAL_SESSION, ussname, Tag.TEXT, "IBM-1047"); const tag = await getTag(REAL_SESSION, ussname); expect(tag).toMatch("t IBM-1047"); const isBin = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); expect(isBin).toBe(false); - testEnvironment.resources.files.push(fileName); }); it("should rename USS file", async () => { @@ -128,14 +121,8 @@ describe("USS Utilities", () => { }); describe("applyTaggedEncoding", () => { - let fileName: string; beforeAll(async () => { - const fileResponse = await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); - fileName = fileResponse.apiResponse.to; - }); - - afterAll(async () => { - testEnvironment.resources.files.push(fileName); + await Upload.fileToUssFile(REAL_SESSION, localfile, ussname); }); it("should set binary property if file is tagged as binary", async () => { diff --git a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts index 9a74f14daa..d3104f0796 100644 --- a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts @@ -29,7 +29,7 @@ describe("CancelJobs System tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer @@ -190,7 +190,7 @@ describe("CancelJobs System tests - encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer diff --git a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts index db14f6f548..20d12926e2 100644 --- a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts @@ -44,7 +44,7 @@ describe("Download Jobs - System tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; outputDirectory = testEnvironment.workingDir + "/output"; @@ -359,7 +359,7 @@ describe("Download Jobs - System tests - Encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts index c7d689a72b..bd933e059e 100644 --- a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts @@ -63,7 +63,7 @@ describe("Get Jobs System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "get_jobs_system_test" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; defaultSystem = testEnvironment.systemTestProperties; @@ -1018,7 +1018,7 @@ describe("Get Jobs System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_get_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; diff --git a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts index 00e1dcbc9c..00b0da8c1a 100644 --- a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts @@ -32,7 +32,7 @@ describe("Modify Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; systemProps = testEnvironment.systemTestProperties; @@ -107,7 +107,7 @@ describe("Modify Jobs - System Tests - Encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; systemProps = testEnvironment.systemTestProperties; diff --git a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts index 052b214930..74c3342895 100644 --- a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts @@ -73,7 +73,7 @@ describe("System Tests - Monitor Jobs", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_monitor_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; defaultSystem = testEnvironment.systemTestProperties; @@ -691,7 +691,7 @@ describe("System Tests - Monitor Jobs", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_monitor_jobs_encoded" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts index 3438f7d222..aa2b397f10 100644 --- a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts @@ -58,7 +58,7 @@ describe("Search Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_search_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; defaultSystem = testEnvironment.systemTestProperties; diff --git a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts index b9c77df57b..1b45d2ffd1 100644 --- a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts @@ -36,7 +36,7 @@ describe("Submit Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_submit_jobs" }); - REAL_SESSION = await TestEnvironment.createZosmfSession(testEnvironment); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); testEnvironment.resources.session = REAL_SESSION; systemProps = testEnvironment.systemTestProperties; From 0a32123b6d81c26bb27442fa6d27dc0a61887a60 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Tue, 8 Oct 2024 17:30:26 -0400 Subject: [PATCH 59/65] Revert changes to cli-test-utils package Signed-off-by: Timothy Johnson --- __tests__/__packages__/cli-test-utils/CHANGELOG.md | 4 ---- .../cli-test-utils/src/environment/TestEnvironment.ts | 7 ++++--- .../cli-test-utils/src/environment/doc/index.ts | 2 +- .../src/environment/doc/response/ITestEnvironment.ts | 2 +- __tests__/__src__/TestUtils.ts | 2 +- .../__system__/mount/fs/cli.files.mount.fs.system.test.ts | 1 - .../upload/dtu/cli.dir.upload.dtu.system.test.ts | 4 +++- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/CHANGELOG.md b/__tests__/__packages__/cli-test-utils/CHANGELOG.md index 27305c3e3e..b447442988 100644 --- a/__tests__/__packages__/cli-test-utils/CHANGELOG.md +++ b/__tests__/__packages__/cli-test-utils/CHANGELOG.md @@ -2,10 +2,6 @@ All notable changes to the Zowe CLI test utils package will be documented in this file. -## Recent Changes - -- Updated `TestEnvironment`, `ITestEnvironment`, and `TestUtils` to simplify and automate the cleanup of test resources, such as datasets, USS files, jobs, and local files created during system tests. - ## `8.0.0` - MAJOR: v8.0.0 Release diff --git a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts index 0fedf65017..2ebefad416 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/TestEnvironment.ts @@ -11,10 +11,11 @@ import * as fs from "fs"; import * as nodePath from "path"; + import * as yaml from "js-yaml"; import { v4 as uuidv4 } from "uuid"; -import { AbstractSession, ImperativeError, ImperativeExpect, - IO, Logger, LoggingConfigurer, TextUtils } from "@zowe/imperative"; +import { ImperativeError, ImperativeExpect, IO, Logger, LoggingConfigurer, TextUtils } from "@zowe/imperative"; + import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { TempTestProfiles } from "./TempTestProfiles"; @@ -42,7 +43,7 @@ export class TestEnvironment { * @returns {Promise} * @memberof TestEnvironment */ - public static async setUp(params: ISetupEnvironmentParms, session?: AbstractSession): Promise> { + public static async setUp(params: ISetupEnvironmentParms): Promise> { // Validate the input parameters ImperativeExpect.toNotBeNullOrUndefined(params, `${TestEnvironment.ERROR_TAG} createTestEnv(): No parameters supplied.`); diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts index 804ada7677..3e9ef33593 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/index.ts @@ -10,4 +10,4 @@ */ export * from "./parms/ISetupEnvironmentParms"; -export * from "./response/ITestEnvironment"; \ No newline at end of file +export * from "./response/ITestEnvironment"; diff --git a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts index e707069e8d..2859aea890 100644 --- a/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts +++ b/__tests__/__packages__/cli-test-utils/src/environment/doc/response/ITestEnvironment.ts @@ -55,4 +55,4 @@ export interface ITestEnvironment { * Was the plugin installed in the working directory */ pluginInstalled?: boolean; -} \ No newline at end of file +} diff --git a/__tests__/__src__/TestUtils.ts b/__tests__/__src__/TestUtils.ts index b3eea01a26..3fe39d133c 100644 --- a/__tests__/__src__/TestUtils.ts +++ b/__tests__/__src__/TestUtils.ts @@ -186,4 +186,4 @@ export const waitTime = 2000; //wait 2 seconds */ export function inspect(obj: any) : string { return JSON.stringify(Object.keys(obj).reduce((newObj, key) => ({...newObj, [key]: obj[key]}), {})); -} \ No newline at end of file +} diff --git a/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts index 02c93b548b..20ec011b99 100644 --- a/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/mount/fs/cli.files.mount.fs.system.test.ts @@ -45,7 +45,6 @@ describe("Mount and unmount file system", () => { const dirname = getUniqueDatasetName(defaultSystem.zosmf.user).split(".")[1]; mountPoint = "//tmp/" + dirname; - const sshCommand = "mkdir " + mountPoint; runCliScript(__dirname + "/__scripts__/command/command_setup.sh", diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts index dadb6e1ff1..99af5f7f6f 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts @@ -42,6 +42,7 @@ describe("Upload directory to USS", () => { REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); dsname = getUniqueDatasetName(`${defaultSystem.zosmf.user}.ZOSFILES.UPLOAD`); dsname = dsname.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/${dsname}`; Imperative.console.info("Using ussDir:" + ussname); binaryFile = "bin_file.pax"; binaryFiles = "bin_file.pax,subdir_bin_file1.pax,subdir_bin_file2.pax.Z"; @@ -62,6 +63,7 @@ describe("Upload directory to USS", () => { }); defaultSys = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; + Imperative.console.info("Using ussDir:" + ussname); }); @@ -474,4 +476,4 @@ function testSuccessfulUpload(localDirName: string, additionalParameters?: strin const response = runCliScript(shellScript, TEST_ENVIRONMENT, parms); expect(response.stderr.toString()).toBe(""); expect(response.stdout.toString()).toContain("Directory uploaded successfully."); -} \ No newline at end of file +} From e3805fda165a86a9b46605c324822fb6d19f1fcb Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Tue, 8 Oct 2024 17:42:37 -0400 Subject: [PATCH 60/65] Clean up local files from vsam tests Signed-off-by: Timothy Johnson --- .../cli.files.invoke.amsFile.system.test.ts | 33 +++++-------------- .../methods/create/Create.system.test.ts | 2 ++ .../methods/invoke/DefineVSAM.ams.temp | 1 - .../methods/invoke/Invoke.system.test.ts | 25 +------------- 4 files changed, 11 insertions(+), 50 deletions(-) delete mode 100644 packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams.temp diff --git a/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts index 2db9b03e64..93462e7af2 100644 --- a/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts @@ -28,11 +28,12 @@ let volume: string; describe("Invoke AMS CLI", () => { - function createTestAMSStatementFileFromTemplate(templateFile: string, dsname?: string) { + function createTestAMSStatementFileFromTemplate(templateFile: string, testEnvironment: ITestEnvironment, dsname?: string) { // replace high-level-qualifier with user value const AMSStatement = fs.readFileSync(templateFile).toString(); const updatedStatement = TextUtils.renderWithMustache(AMSStatement, {DSN: dsname, VOL: volume}); fs.writeFileSync(templateFile + ".temp", updatedStatement); + testEnvironment.resources.localFiles.push(templateFile + ".temp"); return templateFile + ".temp"; } @@ -81,7 +82,7 @@ describe("Invoke AMS CLI", () => { // create a temporary file from the template file that has the proper high level qualifier to create the VSAM file let controlStatementFile: string = createTestAMSStatementFileFromTemplate( process.cwd() + "/packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams", - dsname); + TEST_ENVIRONMENT_NO_PROF, dsname); const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; @@ -103,13 +104,10 @@ describe("Invoke AMS CLI", () => { let testOutput = stripNewLines(response.stdout.toString()); expect(testOutput).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - // Delete the temp file - fs.unlinkSync(controlStatementFile); - // create a temporary file from the template file that has the proper high level qualifier to delete the VSAM file controlStatementFile = createTestAMSStatementFileFromTemplate( process.cwd() + "/packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams", - dsname); + TEST_ENVIRONMENT_NO_PROF, dsname); response = runCliScript(__dirname + "/__scripts__/command/command_invoke_ams_file_fully_qualified.sh", TEST_ENVIRONMENT_NO_PROF, @@ -122,9 +120,6 @@ describe("Invoke AMS CLI", () => { expect(response.status).toBe(0); testOutput = stripNewLines(response.stdout.toString()); expect(testOutput).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - - // Delete the temp file - fs.unlinkSync(controlStatementFile); }); }); @@ -136,7 +131,7 @@ describe("Invoke AMS CLI", () => { // create a temporary file from the template file that has the proper high level qualifier to create the VSAM file let controlStatementFile: string = createTestAMSStatementFileFromTemplate( process.cwd() + "/packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams", - dsname); + TEST_ENVIRONMENT, dsname); let response = runCliScript(__dirname + "/__scripts__/command/command_invoke_ams_file.sh", TEST_ENVIRONMENT, [controlStatementFile]); @@ -145,13 +140,10 @@ describe("Invoke AMS CLI", () => { let testOutput = stripNewLines(response.stdout.toString()); expect(testOutput).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - // Delete the temp file - fs.unlinkSync(controlStatementFile); - // create a temporary file from the template file that has the proper high level qualifier to delete the VSAM file controlStatementFile = createTestAMSStatementFileFromTemplate( process.cwd() + "/packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams", - dsname); + TEST_ENVIRONMENT, dsname); response = runCliScript(__dirname + "/__scripts__/command/command_invoke_ams_file.sh", TEST_ENVIRONMENT, [controlStatementFile]); @@ -159,9 +151,6 @@ describe("Invoke AMS CLI", () => { expect(response.status).toBe(0); testOutput = stripNewLines(response.stdout.toString()); expect(testOutput).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - - // Delete the temp file - fs.unlinkSync(controlStatementFile); }); it("should invoke ams to create and then delete a VSAM cluster using files with response timeout", async () => { const dsname = getUniqueDatasetName(defaultSystem.zosmf.user); @@ -169,7 +158,7 @@ describe("Invoke AMS CLI", () => { // create a temporary file from the template file that has the proper high level qualifier to create the VSAM file let controlStatementFile: string = createTestAMSStatementFileFromTemplate( process.cwd() + "/packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams", - dsname); + TEST_ENVIRONMENT, dsname); let response = runCliScript(__dirname + "/__scripts__/command/command_invoke_ams_file.sh", TEST_ENVIRONMENT, [controlStatementFile, "--responseTimeout 5"]); @@ -178,13 +167,10 @@ describe("Invoke AMS CLI", () => { let testOutput = stripNewLines(response.stdout.toString()); expect(testOutput).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - // Delete the temp file - fs.unlinkSync(controlStatementFile); - // create a temporary file from the template file that has the proper high level qualifier to delete the VSAM file controlStatementFile = createTestAMSStatementFileFromTemplate( process.cwd() + "/packages/zosfiles/__tests__/__system__/methods/invoke/DeleteVSAM.ams", - dsname); + TEST_ENVIRONMENT, dsname); response = runCliScript(__dirname + "/__scripts__/command/command_invoke_ams_file.sh", TEST_ENVIRONMENT, [controlStatementFile, "--responseTimeout 5"]); @@ -192,9 +178,6 @@ describe("Invoke AMS CLI", () => { expect(response.status).toBe(0); testOutput = stripNewLines(response.stdout.toString()); expect(testOutput).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - - // Delete the temp file - fs.unlinkSync(controlStatementFile); }); }); diff --git a/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts index 3da39c1af0..0f55e52cb0 100644 --- a/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/create/Create.system.test.ts @@ -251,6 +251,7 @@ describe("Allocate Like", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsnameLike = `${dsname}.LIKE`; + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_CLASSIC, dsname, options); }); @@ -312,6 +313,7 @@ describe("Allocate Like - encoded", () => { REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); dsnameLike = `${dsname}.ENCO#ED.LIKE`; + await Create.dataSet(REAL_SESSION, CreateDataSetTypeEnum.DATA_SET_CLASSIC, dsname, options); }); diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams.temp b/packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams.temp deleted file mode 100644 index 40fc391aed..0000000000 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/DefineVSAM.ams.temp +++ /dev/null @@ -1 +0,0 @@ -DEFINE CLUSTER (NAME (JOHTI04.ZOSFILE.ENCO#ED.VSAM.A1394590.A196498) CYLINDERS (5 2 ) VOLUMES(TSOA20)) \ No newline at end of file diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts index fcbdd749ce..5e8e361bc9 100644 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts @@ -49,6 +49,7 @@ describe("Invoke AMS", () => { const AMSStatement = fs.readFileSync(templateFile).toString(); const updatedStatement = TextUtils.renderWithMustache(AMSStatement, {DSN: dsname, VOL: volume}); fs.writeFileSync(templateFile + ".temp", updatedStatement); + testEnvironment.resources.localFiles.push(templateFile + ".temp"); return templateFile + ".temp"; } @@ -74,9 +75,6 @@ describe("Invoke AMS", () => { expect(response.success).toBe(true); expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - // Delete the temp file - fs.unlinkSync(controlStatementFile); - // create a temporary file from the template file that has the proper high level qualifier to delete the VSAM file controlStatementFile = createTestAMSStatementFileFromTemplate(__dirname + "/DeleteVSAM.ams"); @@ -94,9 +92,6 @@ describe("Invoke AMS", () => { expect(response.success).toBe(true); expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - - // Delete the temp file - fs.unlinkSync(controlStatementFile); }); it("should create and delete a VSAM data set from command statement in files with response timeout", async () => { @@ -121,9 +116,6 @@ describe("Invoke AMS", () => { expect(response.success).toBe(true); expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - // Delete the temp file - fs.unlinkSync(controlStatementFile); - // create a temporary file from the template file that has the proper high level qualifier to delete the VSAM file controlStatementFile = createTestAMSStatementFileFromTemplate(__dirname + "/DeleteVSAM.ams"); @@ -141,9 +133,6 @@ describe("Invoke AMS", () => { expect(response.success).toBe(true); expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - - // Delete the temp file - fs.unlinkSync(controlStatementFile); }); it("should create and delete a VSAM data set from command statements", async () => { @@ -251,9 +240,6 @@ describe("Invoke AMS - encoded", () => { expect(response.success).toBe(true); expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - // Delete the temp file - fs.unlinkSync(controlStatementFile); - // create a temporary file from the template file that has the proper high level qualifier to delete the VSAM file controlStatementFile = createTestAMSStatementFileFromTemplate(__dirname + "/DeleteVSAM.ams"); @@ -271,9 +257,6 @@ describe("Invoke AMS - encoded", () => { expect(response.success).toBe(true); expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - - // Delete the temp file - fs.unlinkSync(controlStatementFile); }); it("should create and delete a VSAM data set from command statement in files with response timeout", async () => { @@ -298,9 +281,6 @@ describe("Invoke AMS - encoded", () => { expect(response.success).toBe(true); expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - // Delete the temp file - fs.unlinkSync(controlStatementFile); - // create a temporary file from the template file that has the proper high level qualifier to delete the VSAM file controlStatementFile = createTestAMSStatementFileFromTemplate(__dirname + "/DeleteVSAM.ams"); @@ -318,9 +298,6 @@ describe("Invoke AMS - encoded", () => { expect(response.success).toBe(true); expect(response.commandResponse).toContain(ZosFilesMessages.amsCommandExecutedSuccessfully.message); - - // Delete the temp file - fs.unlinkSync(controlStatementFile); }); it("should create and delete a VSAM data set from command statements", async () => { From b2a3bac07cad43c148590766d736f6572eadbd99 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Fri, 11 Oct 2024 18:03:48 -0400 Subject: [PATCH 61/65] Fix failing zosjobs system tests Signed-off-by: Timothy Johnson --- __tests__/__src__/TestUtils.ts | 9 +- .../environment/ITestEnvironmentResources.ts | 12 +- .../__src__/environment/TestEnvironment.ts | 19 +- .../__scripts__/command/command_teardown.sh | 2 +- .../cli.zos-jobs.cancel.job.system.test.ts | 25 +- .../download_fully_qualified.sh | 2 +- ...li.zos-jobs.download.output.system.test.ts | 23 +- .../cli.zos-jobs.list.jobs.system.test.ts | 41 +- ...s.list.spool-files-by-jobid.system.test.ts | 32 +- .../search/cli.zos-jobs.search.job.test.ts | 6 +- ...li.zos-jobs.submit.data-set.system.test.ts | 15 +- ....zos-jobs.submit.local-file.system.test.ts | 26 +- .../cli.zos-jobs.submit.stdin.system.test.ts | 10 +- ...li.zos-jobs.submit.uss-file.system.test.ts | 10 - ...jobs.view.all-spool-content.system.test.ts | 1 - ...bs.view.job-status-by-jobid.system.test.ts | 5 +- ...-jobs.view.spool-file-by-id.system.test.ts | 4 +- .../__system__/CancelJobs.system.test.ts | 14 +- .../__system__/DeleteJobs.system.test.ts | 1 - .../__system__/DownloadJobs.system.test.ts | 11 +- .../__system__/GetJobs.system.test.ts | 2082 ++++++++--------- .../__system__/ModifyJobs.system.test.ts | 14 +- .../__system__/MonitorJobs.system.test.ts | 1553 +++++------- .../__system__/SearchJobs.system.test.ts | 4 +- .../__system__/SubmitJobs.system.test.ts | 39 +- 25 files changed, 1674 insertions(+), 2286 deletions(-) diff --git a/__tests__/__src__/TestUtils.ts b/__tests__/__src__/TestUtils.ts index 3fe39d133c..15d1533878 100644 --- a/__tests__/__src__/TestUtils.ts +++ b/__tests__/__src__/TestUtils.ts @@ -14,7 +14,7 @@ import * as fs from "fs"; import { Imperative, Headers, AbstractSession } from "@zowe/imperative"; import { ZosmfRestClient } from "../../packages/core/src"; import { ZosFilesConstants, Delete } from "../../packages/zosfiles/src"; -import { DeleteJobs, ICommonJobParms, IDeleteJobParms, IJob } from "../../packages/zosjobs/src"; +import { DeleteJobs, GetJobs, ICommonJobParms, IDeleteJobParms, IJob } from "../../packages/zosjobs/src"; import { promisify } from "util"; /** @@ -68,10 +68,13 @@ export async function deleteDataset(session: AbstractSession, dataSetName: strin /** * Delete a job from the mainframe using Zowe SDKs - IJob * @param {AbstractSession} session - z/OSMF connection info - * @param {IJob} job - the job that you want to delete + * @param {IJob | string} job - the job or job ID that you want to delete * @returns {Promise} A promise that resolves when the job is deleted. */ -export async function deleteJob(session: AbstractSession, job: IJob): Promise { +export async function deleteJob(session: AbstractSession, job: IJob | string): Promise { + if (typeof job === "string") { + job = await GetJobs.getJob(session, job); + } await DeleteJobs.deleteJobForJob(session, job); } diff --git a/__tests__/__src__/environment/ITestEnvironmentResources.ts b/__tests__/__src__/environment/ITestEnvironmentResources.ts index 35f7685ffe..756238096d 100644 --- a/__tests__/__src__/environment/ITestEnvironmentResources.ts +++ b/__tests__/__src__/environment/ITestEnvironmentResources.ts @@ -10,7 +10,7 @@ */ import { AbstractSession } from "@zowe/imperative"; -import { ICommonJobParms, IJob } from "../../../packages/zosjobs"; +import { IJob } from "../../../packages/zosjobs"; /** * Represents the resources used within the test environment. @@ -31,16 +31,10 @@ export interface ITestEnvironmentResources { files: string[]; /** - * Array of job objects representing jobs submitted to the mainframe during the test. + * Array of job objects or job IDs representing jobs submitted to the mainframe during the test. * @type {IJob[]} */ - jobs: IJob[]; - - /** - * Array of job data containing jobname and jobid, used to track jobs within the test environment. - * @type {ICommonJobParms[]} - */ - jobData: ICommonJobParms[]; // Contains jobname and jobid + jobs: (IJob | string)[]; /** * Array of dataset names used within the test environment. diff --git a/__tests__/__src__/environment/TestEnvironment.ts b/__tests__/__src__/environment/TestEnvironment.ts index d967af4763..20c6b67aa1 100644 --- a/__tests__/__src__/environment/TestEnvironment.ts +++ b/__tests__/__src__/environment/TestEnvironment.ts @@ -49,10 +49,9 @@ export class TestEnvironment extends BaseTestEnvironment { ].join(separator); result.resources = { localFiles: [], + datasets: [], files: [], jobs: [], - jobData: [], - datasets: [], session: params.skipProperties ? null : TestEnvironment.createZosmfSession(result) }; // Return the test environment including working directory that the tests should be using @@ -78,29 +77,21 @@ export class TestEnvironment extends BaseTestEnvironment { for (const file of testEnvironment.resources.localFiles) { deleteLocalFile(file); } + for (const dataset of testEnvironment.resources.datasets) { + await deleteDataset(session, dataset); + } for (const file of testEnvironment.resources.files) { await deleteFiles(session, file); } for (const job of testEnvironment.resources.jobs) { await deleteJob(session, job); } - for (const jobData of testEnvironment.resources.jobData) { - if (jobData.jobname && jobData.jobid) { - await deleteJobCommon(session, jobData); - } else { - Imperative.console.info('Error: Missing jobname or jobid for jobData:', jobData); - } - } - for (const dataset of testEnvironment.resources.datasets) { - await deleteDataset(session, dataset); - } testEnvironment.resources = { localFiles: [], + datasets: [], files: [], jobs: [], - jobData: [], - datasets: [], session: testEnvironment.resources.session }; } diff --git a/packages/cli/__tests__/zosfiles/__system__/mount/fs/__scripts__/command/command_teardown.sh b/packages/cli/__tests__/zosfiles/__system__/mount/fs/__scripts__/command/command_teardown.sh index 859ea282c2..ae9cad8fa5 100755 --- a/packages/cli/__tests__/zosfiles/__system__/mount/fs/__scripts__/command/command_teardown.sh +++ b/packages/cli/__tests__/zosfiles/__system__/mount/fs/__scripts__/command/command_teardown.sh @@ -15,5 +15,5 @@ then fi echo "================Z/OS FILES DELETE ZOS-FILE-SYSTEM===============" -zowe zos-files delete zos-file-system "$fsn" +zowe zos-files delete zos-file-system "$fsn" -f exit $? diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index 86c868e52f..d23f6847db 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -14,10 +14,9 @@ import { ITestEnvironment } from "../../../../../../__tests__/__src__/environmen import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { JobTestsUtils } from "../../../../../zosjobs/__tests__/__system__/JobTestsUtils"; -import { AbstractSession, IO } from "@zowe/imperative"; +import { IO } from "@zowe/imperative"; // Test Environment populated in the beforeAll(); -let REAL_SESSION: AbstractSession; let TEST_ENVIRONMENT: ITestEnvironment; const LOCAL_JCL_FILE: string = __dirname + "/" + "testFileOfLocalJCL.txt"; const jobDataRegexV1 = /Successfully submitted request to cancel job (\w+) \((JOB\d+)\)/; @@ -30,9 +29,8 @@ describe("zos-jobs cancel job command", () => { testName: "zos_jobs_cancel_job_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - TEST_ENVIRONMENT.resources.session = REAL_SESSION; const systemProps = TEST_ENVIRONMENT.systemTestProperties; + const jcl = JobTestsUtils.getSleepJCL(systemProps.zosmf.user, systemProps.tso.account, systemProps.zosjobs.jobclass); const bufferJCL: Buffer = Buffer.from(jcl); IO.createFileSync(LOCAL_JCL_FILE); @@ -59,12 +57,12 @@ describe("zos-jobs cancel job command", () => { runCliScript(__dirname + "/__scripts__/job/submit_job.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); const response = runCliScript(__dirname + "/__scripts__/job/cancel_job_v2_bad.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; - TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid }); + TEST_ENVIRONMENT.resources.jobs.push(jobid); // Calculate the previous job ID (one less) - jobid created by test before, inaccessible until now const jobidNumber = parseInt(jobid.replace('JOB', ''), 10); //Extract the numeric part of the job ID const previousJobid = 'JOB' + String(jobidNumber - 1).padStart(5, '0'); // then decrement by 1, assuming 5 digits in the job ID - TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid: previousJobid } ); + TEST_ENVIRONMENT.resources.jobs.push(previousJobid); expect(response.status).toBe(1); expect(response.stderr.toString()).toContain("Failed to cancel job"); @@ -83,7 +81,7 @@ describe("zos-jobs cancel job command", () => { expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully submitted request to cancel job"); - TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid }); + TEST_ENVIRONMENT.resources.jobs.push(jobid); }); it("should cancel a job v2", () => { @@ -95,7 +93,7 @@ describe("zos-jobs cancel job command", () => { expect(response.stdout.toString()).toContain("Successfully canceled job"); expect(response.stdout.toString()).not.toContain("Failed to cancel job"); - TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid }); + TEST_ENVIRONMENT.resources.jobs.push(jobid); }); it("should cancel a job default", () => { @@ -108,7 +106,7 @@ describe("zos-jobs cancel job command", () => { expect(response.stdout.toString()).not.toContain("Failed to cancel job"); expect(response.stdout.toString()).not.toContain("Failed to cancel job"); - TEST_ENVIRONMENT.resources.jobData.push({ jobname, jobid }); + TEST_ENVIRONMENT.resources.jobs.push(jobid); }); describe("without profiles", () => { @@ -121,8 +119,7 @@ describe("zos-jobs cancel job command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_cancel_job_without_profiles" }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); - TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; + DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); @@ -146,7 +143,7 @@ describe("zos-jobs cancel job command", () => { expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully submitted request to cancel job"); - TEST_ENVIRONMENT_NO_PROF.resources.jobData.push({ jobname, jobid }); + TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(jobid); }); it("cancel a job without a profile 2.0", async () => { @@ -165,7 +162,7 @@ describe("zos-jobs cancel job command", () => { expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully canceled job"); - TEST_ENVIRONMENT_NO_PROF.resources.jobData.push({ jobname, jobid }); + TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(jobid); }); it("cancel a job without a profile default", async () => { @@ -184,7 +181,7 @@ describe("zos-jobs cancel job command", () => { expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully canceled job"); - TEST_ENVIRONMENT_NO_PROF.resources.jobData.push({ jobname, jobid }); + TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(jobid); }); }); }); diff --git a/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download_fully_qualified.sh b/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download_fully_qualified.sh index 6a2ec9e2aa..cb7def1726 100755 --- a/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download_fully_qualified.sh +++ b/packages/cli/__tests__/zosjobs/__system__/download/__scripts__/download-output/download_fully_qualified.sh @@ -26,7 +26,7 @@ fi echo "Submitted job ID: $JOBID" # Loop until the job goes to the output queue -until [ $ATTEMPTS -le 0 ] +until [ $ATTEMPTS -gt 0 ] do STATUS=`zowe jobs view job-status-by-jobid $JOBID --host $HOST --port $PORT --user $USER --password $PASS --ru=false --rff status --rft string` RC=$? diff --git a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts index a1e08fd410..32ad3be62d 100644 --- a/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/download/cli.zos-jobs.download.output.system.test.ts @@ -13,12 +13,9 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { AbstractSession } from "@zowe/imperative"; import * as fs from "fs"; -import { GetJobs, IJob } from "@zowe/zos-jobs-for-zowe-sdk"; // Test Environment populated in the beforeAll(); -let REAL_SESSION: AbstractSession; let TEST_ENVIRONMENT: ITestEnvironment; let IEFBR14_JCL: string; @@ -29,9 +26,6 @@ describe("zos-jobs download output command", () => { testName: "zos_jobs_download_output_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - - TEST_ENVIRONMENT.resources.session = REAL_SESSION; IEFBR14_JCL = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; }); @@ -50,7 +44,7 @@ describe("zos-jobs download output command", () => { }); describe("output", () => { - it("should download all spool files of a job", async () => { + it("should download all spool files of a job", () => { const outdir: string = TEST_ENVIRONMENT.workingDir + "/output/JES2"; const response = runCliScript(__dirname + "/__scripts__/download-output/download.sh", TEST_ENVIRONMENT, [IEFBR14_JCL]); @@ -62,8 +56,7 @@ describe("zos-jobs download output command", () => { // Ensure the job ID was captured correctly expect(jobid).not.toBeNull(); - - const job: IJob = await GetJobs.getJob(REAL_SESSION, jobid); + TEST_ENVIRONMENT.resources.jobs.push(jobid); expect(response.status).toBe(0); expect(response.stderr.toString()).toBe(""); @@ -71,8 +64,6 @@ describe("zos-jobs download output command", () => { expect(fs.existsSync(`${outdir}/JESJCL.txt`)).toBeTruthy(); expect(fs.existsSync(`${outdir}/JESYSMSG.txt`)).toBeTruthy(); expect(response.stdout.toString()).toContain("Successfully downloaded"); - - TEST_ENVIRONMENT.resources.jobs.push(job); }); describe("without profiles", () => { @@ -85,8 +76,7 @@ describe("zos-jobs download output command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_download_output_without_profiles" }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); - TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; + DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); @@ -94,7 +84,7 @@ describe("zos-jobs download output command", () => { await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); - it("should download all spool files of a job", async () => { + it("should download all spool files of a job", () => { const outdir: string = TEST_ENVIRONMENT.workingDir + "/output/JES2"; const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; @@ -121,8 +111,7 @@ describe("zos-jobs download output command", () => { // Ensure the job ID was captured correctly expect(jobid).not.toBeNull(); - - const job: IJob = await GetJobs.getJob(REAL_SESSION, jobid); + TEST_ENVIRONMENT.resources.jobs.push(jobid); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); @@ -130,8 +119,6 @@ describe("zos-jobs download output command", () => { expect(fs.existsSync(`${outdir}/JESJCL.txt`)).toBeTruthy(); expect(fs.existsSync(`${outdir}/JESYSMSG.txt`)).toBeTruthy(); expect(response.stdout.toString()).toContain("Successfully downloaded"); - - TEST_ENVIRONMENT.resources.jobs.push(job); }); }); }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts index 52330a8119..82c6430d08 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.jobs.system.test.ts @@ -13,13 +13,12 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { AbstractSession } from "@zowe/imperative"; -import { IJob, GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; +import { Session } from "@zowe/imperative"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; let IEFBR14_JOB: string; -let REAL_SESSION: AbstractSession; +let REAL_SESSION: Session; let ACCOUNT: string; let JOB_NAME: string; let NON_HELD_JOBCLASS; @@ -41,10 +40,9 @@ describe("zos-jobs list jobs command", () => { testName: "zos_jobs_list_jobs_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - TEST_ENVIRONMENT.resources.session = REAL_SESSION; const systemProps = TEST_ENVIRONMENT.systemTestProperties; IEFBR14_JOB = systemProps.zosjobs.iefbr14Member; + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); ACCOUNT = systemProps.tso.account; const JOB_LENGTH = 6; @@ -58,7 +56,7 @@ describe("zos-jobs list jobs command", () => { describe("positive tests", () => { - it("should be able to submit two jobs and then find both in the output", async () => { + it("should be able to submit two jobs and then find both in the output", () => { const response = runCliScript(scriptDir + "/submit_and_list_jobs.sh", TEST_ENVIRONMENT, [TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member]); @@ -70,21 +68,14 @@ describe("zos-jobs list jobs command", () => { // Ensure both job IDs were captured correctly expect(jobIds.length).toBe(2); - const [job1Id, job2Id] = jobIds; + TEST_ENVIRONMENT.resources.jobs.push(...jobIds); - // Retrieve job details using the Zowe SDK - const job1: IJob = await GetJobs.getJob(REAL_SESSION, job1Id); - const job2: IJob = await GetJobs.getJob(REAL_SESSION, job2Id); - - expect(job1 && job2).toBeDefined(); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("found"); - - TEST_ENVIRONMENT.resources.jobs.push(job1, job2); }); - it("should be able to submit one job and then not see the job if we list jobs for a different user", async () => { + it("should be able to submit one job and then not see the job if we list jobs for a different user", () => { // note: this test could fail if your user Id starts with "FAKE" const response = runCliScript(scriptDir + "/submit_and_list_jobs_no_match.sh", TEST_ENVIRONMENT, [TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member]); @@ -95,16 +86,11 @@ describe("zos-jobs list jobs command", () => { const jobId = match ? match[1] : null; expect(jobId).not.toBeNull(); - - // Retrieve job details using the Zowe SDK - const job: IJob = await GetJobs.getJob(REAL_SESSION, jobId); - expect(job).toBeDefined(); + TEST_ENVIRONMENT.resources.jobs.push(jobId); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("test passed"); - - TEST_ENVIRONMENT.resources.jobs.push(job); }); describe("without profiles", () => { @@ -117,8 +103,6 @@ describe("zos-jobs list jobs command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_job_without_profiles" }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); - TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); @@ -126,7 +110,7 @@ describe("zos-jobs list jobs command", () => { await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); - it("should be able to submit two jobs and then find both in the output", async () => { + it("should be able to submit two jobs and then find both in the output", () => { const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; // if API Mediation layer is being used (basePath has a value) then @@ -153,18 +137,11 @@ describe("zos-jobs list jobs command", () => { // Ensure both job IDs were captured correctly expect(jobIds.length).toBe(2); - const [job1Id, job2Id] = jobIds; + TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(...jobIds); - // Retrieve job details using the Zowe SDK - const job1: IJob = await GetJobs.getJob(REAL_SESSION, job1Id); - const job2: IJob = await GetJobs.getJob(REAL_SESSION, job2Id); - - expect(job1 && job2).toBeDefined(); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("found"); - - TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(job1, job2); }); }); }); diff --git a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts index 041f406155..9d160aa2bd 100644 --- a/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/list/cli.zos-jobs.list.spool-files-by-jobid.system.test.ts @@ -13,8 +13,8 @@ import { TestEnvironment } from "../../../../../../__tests__/__src__/environment import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { AbstractSession, TextUtils } from "@zowe/imperative"; -import { IJob, GetJobs, SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; +import { Session, TextUtils } from "@zowe/imperative"; +import { IJob, SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; import * as fs from "fs"; import { join } from "path"; import { TEST_RESOURCES_DIR } from "@zowe/zos-jobs-for-zowe-sdk/__tests__/__src__/ZosJobsTestConstants"; @@ -22,7 +22,7 @@ import { TEST_RESOURCES_DIR } from "@zowe/zos-jobs-for-zowe-sdk/__tests__/__src_ // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; let IEFBR14_JOB: string; -let REAL_SESSION: AbstractSession; +let REAL_SESSION: Session; let ACCOUNT: string; let JOB_NAME: string; let NON_HELD_JOBCLASS: string; @@ -42,11 +42,11 @@ describe("zos-jobs list spool-files-by-jobid command", () => { testName: "zos_jobs_list_spool_files_by_jobid_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - TEST_ENVIRONMENT.resources.session = REAL_SESSION; IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 6; JOB_NAME = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + "SF"; @@ -82,7 +82,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { }); describe("response", () => { - it("should display the ddnames for a job", async () => { + it("should display the ddnames for a job", () => { const response = runCliScript(__dirname + "/__scripts__/spool-files-by-jobid/submit_and_list_dds.sh", TEST_ENVIRONMENT, [IEFBR14_JOB]); expect(response.stderr.toString()).toBe(""); @@ -95,16 +95,12 @@ describe("zos-jobs list spool-files-by-jobid command", () => { // Ensure the JOBID was captured correctly expect(jobId).not.toBeNull(); - - // Retrieve job details using the Zowe SDK - const job: IJob = await GetJobs.getJob(REAL_SESSION, jobId); + TEST_ENVIRONMENT.resources.jobs.push(jobId); // Validate DDs and output expect(response.stdout.toString()).toContain("JESMSGLG"); expect(response.stdout.toString()).toContain("JESJCL"); expect(response.stdout.toString()).toContain("JESYSMSG"); - - TEST_ENVIRONMENT.resources.jobs.push(job); }); it("should display the the procnames and ddnames for a job", async () => { @@ -115,6 +111,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { // Submit the job const job: IJob = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + TEST_ENVIRONMENT.resources.jobs.push(job); // View the DDs const response = runCliScript(__dirname + "/__scripts__/spool-files-by-jobid/list_dds.sh", @@ -126,8 +123,6 @@ describe("zos-jobs list spool-files-by-jobid command", () => { expect(response.stdout.toString()).toContain("SYSTSPRT"); expect(response.stdout.toString()).toContain("TSOSTEP1"); expect(response.stdout.toString()).toContain("TSOSTEP2"); - - TEST_ENVIRONMENT.resources.jobs.push(job); }, LONG_TIMEOUT); describe("without profiles", () => { @@ -140,8 +135,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_list_spool_files_by_jobid_without_profiles" }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); - TEST_ENVIRONMENT_NO_PROF.resources.session = REAL_SESSION; + SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); @@ -149,7 +143,7 @@ describe("zos-jobs list spool-files-by-jobid command", () => { await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); - it("should display the ddnames for a job", async () => { + it("should display the ddnames for a job", () => { const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; // if API Mediation layer is being used (basePath has a value) then @@ -177,16 +171,12 @@ describe("zos-jobs list spool-files-by-jobid command", () => { // Ensure the JOBID was captured correctly expect(jobId).not.toBeNull(); - - // Retrieve job details using the Zowe SDK - const job: IJob = await GetJobs.getJob(REAL_SESSION, jobId); + TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(jobId); // Validate DDs and output expect(response.stdout.toString()).toContain("JESMSGLG"); expect(response.stdout.toString()).toContain("JESJCL"); expect(response.stdout.toString()).toContain("JESYSMSG"); - - TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(job); }, LONG_TIMEOUT); }); }); diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts index 6f3b3bdbcf..bfb03dee69 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts @@ -14,13 +14,13 @@ import { ITestEnvironment } from "../../../../../../__tests__/__src__/environmen import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; -import { AbstractSession } from "@zowe/imperative"; +import { Session } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; // Test Environment populated in the beforeAll(); let testEnvironment: ITestEnvironment; let IEFBR14_JOB: string; -let REAL_SESSION: AbstractSession; +let REAL_SESSION: Session; let ACCOUNT: string; let JOB_NAME: string; let NON_HELD_JOBCLASS: string; @@ -30,8 +30,8 @@ let BAD_SEARCH_STRING: string; let defaultSystem: ITestPropertiesSchema; describe("zos-jobs search job command", () => { + // Create the unique test environment beforeAll(async () => { - // Initialize testEnvironment first! testEnvironment = await TestEnvironment.setUp({ testName: "zos_jobs_search_job_command", tempProfileTypes: ["zosmf"] diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts index b274f0f045..43ddb3599a 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/data-set/cli.zos-jobs.submit.data-set.system.test.ts @@ -13,15 +13,15 @@ import { TestEnvironment } from "../../../../../../../__tests__/__src__/environm import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { List } from "../../../../../../zosfiles/src/methods/list"; -import { AbstractSession } from "@zowe/imperative"; -import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk/lib/GetJobs"; +import { List } from "@zowe/zos-files-for-zowe-sdk"; +import { Session } from "@zowe/imperative"; +import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; process.env.FORCE_COLOR = "0"; // Test Environment populated in the beforeAll(); let TEST_ENVIRONMENT: ITestEnvironment; -let REAL_SESSION: AbstractSession; +let REAL_SESSION: Session; let JOB_NAME: string; const jobNameRegex = /jobname: (\w+)/; @@ -146,17 +146,12 @@ describe("zos-jobs submit data-set command", () => { TEST_ENVIRONMENT_NO_PROF = await TestEnvironment.setUp({ testName: "zos_jobs_submit_data_set_without_profiles" }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT_NO_PROF); SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); afterAll(async () => { - // Retrieve jobs by prefix - const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); - TEST_ENVIRONMENT.resources.jobs = jobs; - - await TestEnvironment.cleanUp(TEST_ENVIRONMENT); + await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); it("should submit a job in an existing valid data set from a PDS member", async () => { 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 1b9f94fa92..886c953762 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 @@ -15,7 +15,7 @@ import { runCliScript } from "@zowe/cli-test-utils"; 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"; +import { Get } from "@zowe/zos-files-for-zowe-sdk"; process.env.FORCE_COLOR = "0"; @@ -35,11 +35,11 @@ describe("zos-jobs submit local-file command", () => { testName: "zos_jobs_submit_local_file_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + systemProps = TEST_ENVIRONMENT.systemTestProperties; - account = systemProps.tso.account; - TEST_ENVIRONMENT.resources.session = REAL_SESSION; + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + account = systemProps.tso.account; // JCL to submit jcl = (await Get.dataSet(REAL_SESSION, systemProps.zosjobs.iefbr14Member)).toString(); @@ -64,7 +64,7 @@ describe("zos-jobs submit local-file command", () => { }); describe("Live system tests", () => { - it("should submit a job in an existing valid local file", async () => { + it("should submit a job in an existing valid local file", () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_local_file.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt"]); @@ -78,7 +78,7 @@ describe("zos-jobs submit local-file command", () => { JOB_NAME = match ? match[1] : null; }); - it("should submit a job in an existing valid local file with explicit RECFM, LRECL, and encoding", async () => { + it("should submit a job in an existing valid local file with explicit RECFM, LRECL, and encoding", () => { 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"]); @@ -88,7 +88,7 @@ describe("zos-jobs submit local-file command", () => { expect(response.stdout.toString()).toContain("jobid"); }); - it("should submit a job in an existing valid local file with 'view-all-spool-content' option", async () => { + it("should submit a job in an existing valid local file with 'view-all-spool-content' option", () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_local_file_vasc.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt", "--vasc"]); @@ -98,7 +98,7 @@ describe("zos-jobs submit local-file command", () => { expect(response.stdout.toString()).toContain("JES2"); }); - it("should submit a job and wait for it to reach output status", async () => { + it("should submit a job and wait for it to reach output status", () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_local_file_wait.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt"]); @@ -110,7 +110,7 @@ describe("zos-jobs submit local-file command", () => { 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 () => { + it("should submit a job in an existing valid local file with 'directory' option", () => { const response = runCliScript(__dirname + "/__scripts__/submit_valid_local_file_with_directory.sh", TEST_ENVIRONMENT, [__dirname + "/testFileOfLocalJCL.txt", "--directory", "./"]); @@ -135,16 +135,10 @@ 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); }); - it("should submit a job in an existing valid local file", async () => { + it("should submit a job in an existing valid local file", () => { const ZOWE_OPT_BASE_PATH = "ZOWE_OPT_BASE_PATH"; // if API Mediation layer is being used (basePath has a value) then 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 c5385ac3b8..a130780f0e 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 @@ -15,7 +15,7 @@ import { runCliScript } from "@zowe/cli-test-utils"; 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"; +import { Get } from "@zowe/zos-files-for-zowe-sdk"; process.env.FORCE_COLOR = "0"; @@ -40,8 +40,6 @@ describe("zos-jobs submit stdin command", () => { REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = systemProps.tso.account; - TEST_ENVIRONMENT.resources.session = REAL_SESSION; - // JCL to submit jcl = (await Get.dataSet(REAL_SESSION, systemProps.zosjobs.iefbr14Member)).toString(); @@ -131,12 +129,6 @@ 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); }); diff --git a/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts index e326ec14d9..0a7cb895f7 100644 --- a/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/submit/uss-file/cli.zos-jobs.submit.uss-file.system.test.ts @@ -14,7 +14,6 @@ import { ITestEnvironment } from "../../../../../../../__tests__/__src__/environ import { runCliScript } from "@zowe/cli-test-utils"; import { ITestPropertiesSchema } from "../../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; import { Session } from "@zowe/imperative"; -import * as path from "path"; // Import path module for path handling import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; process.env.FORCE_COLOR = "0"; @@ -39,9 +38,6 @@ describe("zos-jobs submit uss-file command", () => { REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = TEST_ENVIRONMENT.systemTestProperties.tso.account; ussFile = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14USSFile; - - // Convert the USS file path to the correct format for Unix if needed - ussFile = path.posix.resolve(ussFile); }); afterAll(async () => { @@ -135,12 +131,6 @@ describe("zos-jobs submit uss-file command", () => { }); afterAll(async () => { - // Retrieve jobs by prefix and clean them up - if (JOB_NAME) { - const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); - TEST_ENVIRONMENT_NO_PROF.resources.jobs = jobs; - } - await TestEnvironment.cleanUp(TEST_ENVIRONMENT_NO_PROF); }); diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts index ac12fb6d9a..b815ad48ec 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.all-spool-content.system.test.ts @@ -38,7 +38,6 @@ describe("zos-jobs view all-spool-content command", () => { IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - TEST_ENVIRONMENT.resources.session = REAL_SESSION; ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 6; diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts index 1003645f6d..084f08432f 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.job-status-by-jobid.system.test.ts @@ -38,11 +38,9 @@ describe("zos-jobs view job-status-by-jobid command", () => { testName: "zos_jobs_view_job_status_by_jobid_command" }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - TEST_ENVIRONMENT.resources.session = REAL_SESSION; - systemProps = TEST_ENVIRONMENT.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); account = systemProps.tso.account; jclMember = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; psJclDataSet = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14PSDataSet; @@ -113,7 +111,6 @@ describe("zos-jobs view job-status-by-jobid command", () => { testName: "zos_jobs_view_job_status_by_jobid_command_without_profiles" }); REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - TEST_ENVIRONMENT.resources.session = REAL_SESSION; DEFAULT_SYSTEM_PROPS = TEST_ENVIRONMENT_NO_PROF.systemTestProperties; }); diff --git a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts index e77d9b0988..f160bcf731 100644 --- a/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/view/cli.zos-jobs.view.spool-file-by-id.system.test.ts @@ -38,10 +38,10 @@ describe("zos-jobs view spool-file-by-id command", () => { tempProfileTypes: ["zosmf"] }); - REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); - TEST_ENVIRONMENT.resources.session = REAL_SESSION; IEFBR14_JOB = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; const defaultSystem = TEST_ENVIRONMENT.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + ACCOUNT = defaultSystem.tso.account; const JOB_LENGTH = 6; JOB_NAME = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + "SF"; diff --git a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts index d3104f0796..5ce5b20883 100644 --- a/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/CancelJobs.system.test.ts @@ -9,14 +9,14 @@ * */ -import { ImperativeError, RestClientError, AbstractSession } from "@zowe/imperative"; +import { ImperativeError, Session, RestClientError } from "@zowe/imperative"; import { CancelJobs, SubmitJobs, IJob } from "../../src"; import { JobTestsUtils } from "./JobTestsUtils"; import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -let REAL_SESSION: AbstractSession; +let REAL_SESSION: Session; let sleepJCL: string; let systemProps: ITestPropertiesSchema; @@ -29,11 +29,12 @@ describe("CancelJobs System tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs" }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer - testEnvironment.resources.session = REAL_SESSION; sleepJCL = JobTestsUtils.getSleepJCL(REAL_SESSION.ISession.user, ACCOUNT, systemProps.zosjobs.jobclass, maxStepNum); }); @@ -190,11 +191,12 @@ describe("CancelJobs System tests - encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_cancel_jobs_encoded" }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); systemProps = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + const ACCOUNT = systemProps.tso.account; const maxStepNum = 6; // Use lots of steps to make the job stay in INPUT status longer - testEnvironment.resources.session = REAL_SESSION; sleepJCL = JobTestsUtils.getSleepJCL(REAL_SESSION.ISession.user, ACCOUNT, systemProps.zosjobs.jobclass, maxStepNum, true); }); diff --git a/packages/zosjobs/__tests__/__system__/DeleteJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/DeleteJobs.system.test.ts index b0ba31d305..d0f96bf6bf 100644 --- a/packages/zosjobs/__tests__/__system__/DeleteJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/DeleteJobs.system.test.ts @@ -34,7 +34,6 @@ describe("DeleteJobs System tests", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; const ACCOUNT = defaultSystem.tso.account; diff --git a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts index 20d12926e2..ba34e0f1ed 100644 --- a/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/DownloadJobs.system.test.ts @@ -9,7 +9,7 @@ * */ -import { DeleteJobs, DownloadJobs, GetJobs, ICommonJobParms, IJobFile, SubmitJobs } from "../../src"; +import { DownloadJobs, GetJobs, IJobFile, SubmitJobs } from "../../src"; import { ImperativeError, IO, Session, TextUtils } from "@zowe/imperative"; import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; @@ -44,12 +44,12 @@ describe("Download Jobs - System tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs" }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + // download the valid IEFBR14 from the data set specified in the properties file iefbr14DataSet = testEnvironment.systemTestProperties.zosjobs.iefbr14Member; iefbr14JCL = (await Get.dataSet(REAL_SESSION, iefbr14DataSet)).toString(); @@ -80,7 +80,6 @@ describe("Download Jobs - System tests", () => { }); afterAll(async () => { - testEnvironment.resources.jobData.push({ jobname: jobname, jobid: jobid } as ICommonJobParms); await TestEnvironment.cleanUp(testEnvironment); }); @@ -359,11 +358,10 @@ describe("Download Jobs - System tests - Encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_download_jobs_encoded" }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; outputDirectory = testEnvironment.workingDir + "/output"; defaultSystem = testEnvironment.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); const ACCOUNT = defaultSystem.tso.account; const iefbr14JCL = JobTestsUtils.getIefbr14JCL(REAL_SESSION.ISession.user, ACCOUNT, defaultSystem.zosjobs.jobclass, 1, true); @@ -393,7 +391,6 @@ describe("Download Jobs - System tests - Encoded", () => { }); afterAll(async () => { - await DeleteJobs.deleteJob(REAL_SESSION, jobname, jobid); await TestEnvironment.cleanUp(testEnvironment); }); diff --git a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts index bd933e059e..5ca70448c9 100644 --- a/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/GetJobs.system.test.ts @@ -10,29 +10,34 @@ */ import { JOB_STATUS } from "./../../src/types/JobStatus"; -import { AbstractSession, ImperativeError, Session, TextUtils } from "@zowe/imperative"; +import { ImperativeError, Session, TextUtils } from "@zowe/imperative"; +import { DeleteJobs, GetJobs, IJob, JOB_STATUS_ORDER, SubmitJobs } from "../../src"; import * as fs from "fs"; +import { TEST_RESOURCES_DIR } from "../__src__/ZosJobsTestConstants"; import { join } from "path"; -import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { TEST_RESOURCES_DIR } from "../__src__/ZosJobsTestConstants"; -import { GetJobs, DeleteJobs, IJob, JOB_STATUS_ORDER, SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; -import { wait, waitTime } from "../../../../__tests__/__src__/TestUtils"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; +import { wait } from "../../../../__tests__/__src__/TestUtils"; +/**********************************************************************************/ let ACCOUNT: string; +// The job class for holding jobs on the input queue let JOBCLASS: string; let SYSAFF: string; -let REAL_SESSION: AbstractSession; -let defaultSystem: ITestPropertiesSchema; -let testEnvironment: ITestEnvironment; +// Session to use for the tests +let REAL_SESSION: Session; +// Invalid credentials session let INVALID_SESSION: Session; +// The job name - should be the same for cleanup, etc. +const SIX_CHARS = 6; let MONITOR_JOB_NAME: string; const TEST_JOB_NAME = "TSTMB"; -let JCL: string; //TODO: replace by JCL resources +// Sample JCL - TODO replace by JCL resources +let JCL: string; const trimMessage = (message: string) => { // don't use more than one space or tab when checking error details @@ -40,6 +45,9 @@ const trimMessage = (message: string) => { return message.replace(/( {2,})|\t/g, " "); }; +let defaultSystem: ITestPropertiesSchema; +let testEnvironment: ITestEnvironment; + // Utility function to cleanup async function cleanTestJobs(prefix: string) { // The tests may submit jobs - we will clean every job that may have been left by failures, etc. @@ -47,7 +55,7 @@ async function cleanTestJobs(prefix: string) { if (jobs.length > 0) { for (const job of jobs) { try { - await DeleteJobs.deleteJob(REAL_SESSION, job.jobname, job.jobid); + const response = await DeleteJobs.deleteJob(REAL_SESSION, job.jobname, job.jobid); } catch (e) { // Don't worry about it } @@ -57,59 +65,61 @@ async function cleanTestJobs(prefix: string) { const LONG_TIMEOUT = 200000; -describe("Get Jobs System Tests", () => { - describe("Non-Encoded System Tests", () => { - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "get_jobs_system_test" - }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - defaultSystem = testEnvironment.systemTestProperties; +describe("Get Jobs - System Tests", () => { - INVALID_SESSION = new Session({ - user: "fakeuser", - password: "fake", - hostname: defaultSystem.zosmf.host, - port: defaultSystem.zosmf.port, - type: "basic", - rejectUnauthorized: false - }); + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_get_jobs" + }); + defaultSystem = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + + INVALID_SESSION = new Session({ + user: "fakeuser", + password: "fake", + hostname: defaultSystem.zosmf.host, + port: defaultSystem.zosmf.port, + basePath: defaultSystem.zosmf.basePath, + type: "basic", + rejectUnauthorized: false + }); - ACCOUNT = defaultSystem.tso.account; - MONITOR_JOB_NAME = REAL_SESSION.ISession.user?.toUpperCase().substring(0, 5) + "#G"; + ACCOUNT = defaultSystem.tso.account; + MONITOR_JOB_NAME = REAL_SESSION.ISession.user?.toUpperCase().substring(0, SIX_CHARS) + "G"; - JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; - SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; + JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; + SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; - JCL = `//${MONITOR_JOB_NAME} JOB '${ACCOUNT}',CLASS=${JOBCLASS}\n//IEFBR14 EXEC PGM=IEFBR14`; - }); + // TODO: What string goes in the removed section? + JCL = + "//" + MONITOR_JOB_NAME + " JOB '" + ACCOUNT + "',CLASS=" + JOBCLASS + "\n" + + "//IEFBR14 EXEC PGM=IEFBR14"; // GetJobs + }); - afterAll(async () => { - // For deleting jobs/resources - await TestEnvironment.cleanUp(testEnvironment); - }); + // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently + // outstanding) when the tests run + beforeEach(async () => { + await cleanTestJobs(MONITOR_JOB_NAME); + await cleanTestJobs(TEST_JOB_NAME); + }); + afterEach(async () => { + await cleanTestJobs(MONITOR_JOB_NAME); + await cleanTestJobs(TEST_JOB_NAME); + }); - // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently - // outstanding) when the tests run - beforeEach(async () => { - await cleanTestJobs(MONITOR_JOB_NAME); - await cleanTestJobs(TEST_JOB_NAME); - }); - afterEach(async () => { - await cleanTestJobs(MONITOR_JOB_NAME); - await cleanTestJobs(TEST_JOB_NAME); - }); + /**********************************************/ + // API methods "getJobs..." system tests + describe("Get Jobs APIs", () => { /**********************************************/ - // API methods "getJobsByPrefix" system tests - describe("get jobs by prefix API", () => { - describe("invalid request handling", () => { + // API methods "getJobs" system tests + describe("get jobs API", () => { + describe("invalid request error handling", () => { it("should detect and surface an error for an invalid user", async () => { let err; try { - const resp = await GetJobs.getJobsByPrefix(INVALID_SESSION, "TEST"); + await GetJobs.getJobs(INVALID_SESSION); } catch (e) { err = e; } @@ -117,28 +127,10 @@ describe("Get Jobs System Tests", () => { expect(err instanceof ImperativeError).toBe(true); expect(err.message).toContain("status 401"); // unauthorized - bad credentials }); - - it("should detect and surface an error for an invalid prefix (by z/OS standards)", async () => { - let err; - try { - await GetJobs.getJobsByPrefix(REAL_SESSION, "~~~~~"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(4); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("prefix query parameter"); - }); }); describe("list jobs", () => { - it("should return all jobs for the prefix of the user id and the owner is the session user id", async () => { + it("should return all jobs for the user in the session", async () => { // Read the JCL template file const NUM_JOBS = 3; const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); @@ -157,13 +149,13 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); jobs.push(job); - testEnvironment.resources.jobs.push(job); } + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); - await wait(waitTime); // Waits for 2 seconds - - // Obtain the three jobs submitted - const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, MONITOR_JOB_NAME + "*"); + // Obtain all jobs for the user + const allJobs: IJob[] = await GetJobs.getJobs(REAL_SESSION); expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); // Search all jobs returned for each of the submitted jobs @@ -179,848 +171,851 @@ describe("Get Jobs System Tests", () => { }); }, LONG_TIMEOUT); - it("should throw an error if we specify a job ID that doesn't exist", async () => { - let err: ImperativeError; - try { - await GetJobs.getJob(REAL_SESSION, "J999999"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err.causeErrors).toContain("Zero jobs"); - }); - - it("should return no jobs for a prefix that doesn't match anything", async () => { - const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, "FAKENE"); - expect(allJobs.length).toBe(0); - }); - - it("should return all jobs for the non user id prefix specified and the owner is the session user id", async () => { + it("should be able to get a single job by job ID", async () => { // Read the JCL template file - const NUM_JOBS = 3; const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - // Submit a few jobs to list - const jobs: IJob[] = []; - for (let x = 0; x < NUM_JOBS; x++) { - - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: TEST_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // submit a job that we can list + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); - jobs.push(job); - testEnvironment.resources.jobs.push(job); - } + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); - await wait(waitTime); // Waits for 2 seconds - // Obtain the three jobs submitted - const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, TEST_JOB_NAME + "*"); - expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); // Search all jobs returned for each of the submitted jobs - jobs.forEach((submittedJob) => { - let found = false; - for (const returnedJob of allJobs) { - if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { - found = true; - break; - } - } - expect(found).toBe(true); - }); + const foundJob = await GetJobs.getJob(REAL_SESSION, job.jobid); + expect(foundJob).toBeDefined(); + expect(foundJob.jobid).toEqual(job.jobid); + expect(foundJob.jobname).toEqual(job.jobname); }, LONG_TIMEOUT); }); - }); - /**********************************************/ - // API methods "getJobs..." system tests - describe("Get Jobs APIs", () => { - /**********************************************/ - // API methods "getJobs" system tests - describe("get jobs API", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for an invalid user", async () => { - let err; - try { - await GetJobs.getJobs(INVALID_SESSION); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - expect(err.message).toContain("status 401"); // unauthorized - bad credentials - }); - }); + it("should be able to get a single job by job ID with jobid parm on the getJobs API", async () => { + // Read the JCL template file + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + + // submit a job that we can list + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + + + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); + + // Search all jobs returned for each of the submitted jobs + const foundJobs = await GetJobs.getJobsCommon(REAL_SESSION, {jobid: job.jobid}); + expect(foundJobs).toBeDefined(); + expect(foundJobs.length).toEqual(1); + expect(foundJobs[0].jobid).toEqual(job.jobid); + expect(foundJobs[0].jobname).toEqual(job.jobname); + }, LONG_TIMEOUT); + }); + }); - describe("list jobs", () => { - it("should return all jobs for the user in the session", async () => { - // Read the JCL template file - const NUM_JOBS = 3; - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + /**********************************************/ + // API methods "getJobsByPrefix" system tests + describe("get jobs by prefix API", () => { + describe("invalid request handling", () => { + it("should detect and surface an error for an invalid user", async () => { + let err; + try { + const resp = await GetJobs.getJobsByPrefix(INVALID_SESSION, "TEST"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + expect(err.message).toContain("status 401"); // unauthorized - bad credentials + }); - // Submit a few jobs to list - const jobs: IJob[] = []; - for (let x = 0; x < NUM_JOBS; x++) { + it("should detect and surface an error for an invalid prefix (by z/OS standards)", async () => { + let err; + try { + await GetJobs.getJobsByPrefix(REAL_SESSION, "~~~~~"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(4); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("prefix query parameter"); + }); + }); - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + describe("list jobs", () => { + it("should return all jobs for the prefix of the user id and the owner is the session user id", async () => { + // Read the JCL template file + const NUM_JOBS = 3; + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); - jobs.push(job); - testEnvironment.resources.jobs.push(job); - } - await wait(waitTime); // Waits for 2 seconds + // Submit a few jobs to list + const jobs: IJob[] = []; + for (let x = 0; x < NUM_JOBS; x++) { - // Obtain all jobs for the user - const allJobs: IJob[] = await GetJobs.getJobs(REAL_SESSION); - expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Search all jobs returned for each of the submitted jobs - jobs.forEach((submittedJob) => { - let found = false; - for (const returnedJob of allJobs) { - if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { - found = true; - break; - } - } - expect(found).toBe(true); - }); - }, LONG_TIMEOUT); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + jobs.push(job); + } - it("should be able to get a single job by job ID", async () => { - // Read the JCL template file - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); - // submit a job that we can list - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Obtain the three jobs submitted + const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, MONITOR_JOB_NAME + "*"); + expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); + // Search all jobs returned for each of the submitted jobs + jobs.forEach((submittedJob) => { + let found = false; + for (const returnedJob of allJobs) { + if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { + found = true; + break; + } + } + expect(found).toBe(true); + }); + }, LONG_TIMEOUT); + + it("should throw an error if we specify a job ID that doesn't exist", async () => { + let err: ImperativeError; + try { + await GetJobs.getJob(REAL_SESSION, "J999999"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err.causeErrors).toContain("Zero jobs"); + }); - await wait(waitTime); // Waits for 2 seconds + it("should return no jobs for a prefix that doesn't match anything", async () => { + const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, "FAKENE"); + expect(allJobs.length).toBe(0); + }); - // Search all jobs returned for each of the submitted jobs - const foundJob = await GetJobs.getJob(REAL_SESSION, job.jobid); - expect(foundJob).toBeDefined(); - expect(foundJob.jobid).toEqual(job.jobid); - expect(foundJob.jobname).toEqual(job.jobname); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - }); + it("should return all jobs for the non user id prefix specified and the owner is the session user id", async () => { + // Read the JCL template file + const NUM_JOBS = 3; + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - it("should be able to get a single job by job ID with jobid parm on the getJobs API", async () => { - // Read the JCL template file - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + // Submit a few jobs to list + const jobs: IJob[] = []; + for (let x = 0; x < NUM_JOBS; x++) { - // submit a job that we can list // Render the job with increasing job name const jobRender = iefbr14JclTemplate; const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + "S", ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + {JOBNAME: TEST_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); // Submit the job const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); + jobs.push(job); + } - await wait(waitTime); // Waits for 2 seconds + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); - // Search all jobs returned for each of the submitted jobs - const foundJobs = await GetJobs.getJobsCommon(REAL_SESSION, {jobid: job.jobid}); - expect(foundJobs).toBeDefined(); - expect(foundJobs.length).toEqual(1); - expect(foundJobs[0].jobid).toEqual(job.jobid); - expect(foundJobs[0].jobname).toEqual(job.jobname); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - }); - }); + // Obtain the three jobs submitted + const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, TEST_JOB_NAME + "*"); + expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); - /**********************************************/ - // API methods "getJobsByPrefix" system tests - describe("get jobs by owner API", () => { - describe("invalid request handling", () => { - it("should detect and surface an error for an invalid user", async () => { - let err; - try { - await GetJobs.getJobsByPrefix(INVALID_SESSION, "TEST"); - } catch (e) { - err = e; + // Search all jobs returned for each of the submitted jobs + jobs.forEach((submittedJob) => { + let found = false; + for (const returnedJob of allJobs) { + if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { + found = true; + break; + } } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - expect(err.message).toContain("status 401"); // unauthorized - bad credentials + expect(found).toBe(true); }); + }, LONG_TIMEOUT); + }); + }); - it("should detect and surface an error for an invalid owner (by z/OS standards)", async () => { - let err; - try { - await GetJobs.getJobsByOwner(REAL_SESSION, "~~~~~"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(4); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("owner query parameter"); - }); + /**********************************************/ + // API methods "getJobsByPrefix" system tests + describe("get jobs by owner API", () => { + describe("invalid request handling", () => { + it("should detect and surface an error for an invalid user", async () => { + let err; + try { + await GetJobs.getJobsByPrefix(INVALID_SESSION, "TEST"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + expect(err.message).toContain("status 401"); // unauthorized - bad credentials }); - describe("list jobs", () => { - it("should return no jobs for a nonexistent owner", async () => { - // Obtain the three jobs submitted - const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, "FAKENE"); - expect(allJobs.length).toBe(0); - }); + it("should detect and surface an error for an invalid owner (by z/OS standards)", async () => { + let err; + try { + await GetJobs.getJobsByOwner(REAL_SESSION, "~~~~~"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(4); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("owner query parameter"); + }); + }); - it("should return all jobs for the user (of the session) when specified as the owner", async () => { - // Read the JCL template file - const NUM_JOBS = 3; - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + describe("list jobs", () => { + it("should return no jobs for a nonexistent owner", async () => { + // Obtain the three jobs submitted + const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, "FAKENE"); + expect(allJobs.length).toBe(0); + }); - // Submit a few jobs to list - const jobs: IJob[] = []; - for (let x = 0; x < NUM_JOBS; x++) { + it("should return all jobs for the user (of the session) when specified as the owner", async () => { + // Read the JCL template file + const NUM_JOBS = 3; + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - // Render the job with increasing job name - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Submit a few jobs to list + const jobs: IJob[] = []; + for (let x = 0; x < NUM_JOBS; x++) { - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - expect(job.status).toEqual("OUTPUT"); - expect(job.retcode).toEqual("CC 0000"); - jobs.push(job); - testEnvironment.resources.jobs.push(job); - } - - await wait(waitTime); // Waits for 2 seconds - - // Obtain all jobs for ***REMOVED*** - const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, REAL_SESSION.ISession.user); - expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); + // Render the job with increasing job name + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME + x.toString(), ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Search all jobs returned for each of the submitted jobs - jobs.forEach((submittedJob) => { - let found = false; - for (const returnedJob of allJobs) { - if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { - found = true; - break; - } + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + expect(job.status).toEqual("OUTPUT"); + expect(job.retcode).toEqual("CC 0000"); + jobs.push(job); + } + + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); + // Obtain all jobs for ***REMOVED*** + const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, REAL_SESSION.ISession.user); + expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); + + // Search all jobs returned for each of the submitted jobs + jobs.forEach((submittedJob) => { + let found = false; + for (const returnedJob of allJobs) { + if (returnedJob.jobname === submittedJob.jobname && returnedJob.jobid === submittedJob.jobid) { + found = true; + break; } - expect(found).toBe(true); - }); - }, LONG_TIMEOUT); - }); + } + expect(found).toBe(true); + }); + }, LONG_TIMEOUT); }); + }); - /**********************************************/ - // API methods "getStatus..." system tests - describe("Get Status APIs", () => { - - /**********************************************/ - // API methods "getStatus" system tests - describe("get status API", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for an invalid user", - async () => { - let err; - try { - await GetJobs.getStatus(INVALID_SESSION, "FAKE", "FAKE"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - expect(err.message).toContain("status 401"); // unauthorized - bad credentials - } - ); + /**********************************************/ + // API methods "getStatus..." system tests + describe("Get Status APIs", () => { - it("should detect and surface an error for an invalid jobname", async () => { + /**********************************************/ + // API methods "getStatus" system tests + describe("get status API", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for an invalid user", + async () => { let err; try { - await GetJobs.getStatus(REAL_SESSION, "))))))))", "JOB123"); + await GetJobs.getStatus(INVALID_SESSION, "FAKE", "FAKE"); } catch (e) { err = e; } expect(err).toBeDefined(); expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - }); + expect(err.message).toContain("status 401"); // unauthorized - bad credentials + } + ); - it("should detect and surface an error for an invalid jobid", async () => { - let err; - try { - await GetJobs.getStatus(REAL_SESSION, "***REMOVED***1", "))))))))))"); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - }); + it("should detect and surface an error for an invalid jobname", async () => { + let err; + try { + await GetJobs.getStatus(REAL_SESSION, "))))))))", "JOB123"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); }); - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - testEnvironment.resources.jobs.push(job); - }); + it("should detect and surface an error for an invalid jobid", async () => { + let err; + try { + await GetJobs.getStatus(REAL_SESSION, "***REMOVED***1", "))))))))))"); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + }); + }); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect the jobname to match - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); - testEnvironment.resources.jobs.push(job); - }); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + }); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + // Expect the jobname to match + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); }); - }); - /**********************************************/ - // API methods "getStatusCommon" system tests - describe("get status common API", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for an invalid user", async () => { - let err; - try { - await GetJobs.getStatusCommon(INVALID_SESSION, {jobname: "FAKE", jobid: "FAKE"}); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - expect(err.message).toContain("status 401"); // unauthorized - bad credentials - }); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - it("should detect and surface an error for an invalid jobname", async () => { - let err; - try { - await GetJobs.getStatusCommon(REAL_SESSION, {jobname: "))))))))", jobid: "JOB123"}); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("JOB123"); - }); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - it("should detect and surface an error for an invalid jobid", async () => { - let err; - try { - await GetJobs.getStatusCommon(REAL_SESSION, {jobname: "***REMOVED***1", jobid: "))))))))))"}); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - }); - }); + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + }, LONG_TIMEOUT); + }); + }); - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + /**********************************************/ + // API methods "getStatusCommon" system tests + describe("get status common API", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for an invalid user", async () => { + let err; + try { + await GetJobs.getStatusCommon(INVALID_SESSION, {jobname: "FAKE", jobid: "FAKE"}); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + expect(err.message).toContain("status 401"); // unauthorized - bad credentials + }); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + it("should detect and surface an error for an invalid jobname", async () => { + let err; + try { + await GetJobs.getStatusCommon(REAL_SESSION, {jobname: "))))))))", jobid: "JOB123"}); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("JOB123"); + }); - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - testEnvironment.resources.jobs.push(job); - }); + it("should detect and surface an error for an invalid jobid", async () => { + let err; + try { + await GetJobs.getStatusCommon(REAL_SESSION, {jobname: "***REMOVED***1", jobid: "))))))))))"}); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + }); + }); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is input - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); - testEnvironment.resources.jobs.push(job); - }); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + }); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + // Expect that the status is input + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); }); - }); - /**********************************************/ - // API methods "getStatusForJob" system tests - describe("get status for job API", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for an invalid user", async () => { - let err; - try { - const job: any = {jobname: "FAKE", jobid: "fake"}; - await GetJobs.getStatusForJob(INVALID_SESSION, job); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - expect(trimmedErrorMessage).toContain("status 401"); - }); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - it("should be able to get a job that was submitted and get proper error when the job is deleted", async () => { - const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - await DeleteJobs.deleteJobForJob(REAL_SESSION, job); + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - await wait(3000); //Wait for 3 seconds + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - let error; - try { - await GetJobs.getStatusForJob(REAL_SESSION, job); - } catch (thrownError) { - error = thrownError; - } - expect(error).toBeDefined(); - const trimmedErrorMessage = trimMessage(error.message); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain(job.jobid); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - - it("should detect and surface an error for an invalid jobname", async () => { - let err; - try { - await GetJobs.getStatusForJob(REAL_SESSION, {jobname: "))))))))", jobid: "JOB123"} as any); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - }); + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + }, LONG_TIMEOUT); + }); + }); - it("should detect and surface an error for an invalid jobid", async () => { - let err; - try { - await GetJobs.getStatusForJob(REAL_SESSION, {jobname: "***REMOVED***1", jobid: "))))))))))"} as any); - } catch (e) { - err = e; - } - expect(err).toBeDefined(); - expect(err instanceof ImperativeError).toBe(true); - const trimmedErrorMessage = trimMessage(err.message); - const jsonCauseErrors = JSON.parse(err.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - }); + /**********************************************/ + // API methods "getStatusForJob" system tests + describe("get status for job API", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for an invalid user", async () => { + let err; + try { + const job: any = {jobname: "FAKE", jobid: "fake"}; + await GetJobs.getStatusForJob(INVALID_SESSION, job); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + expect(trimmedErrorMessage).toContain("status 401"); }); - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + it("should be able to get a job that was submitted and get proper error when the job is deleted", async () => { + const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); + const jobStatus = await GetJobs.getStatusForJob(REAL_SESSION, job); - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + await DeleteJobs.deleteJobForJob(REAL_SESSION, job); + await wait(3000); // make sure jobs is deleted + let error; + try { + await GetJobs.getStatusForJob(REAL_SESSION, job); + } catch (thrownError) { + error = thrownError; + } + expect(error).toBeDefined(); + expect(JSON.parse(error.causeErrors).rc).toEqual(4); + expect(JSON.parse(error.causeErrors).reason).toEqual(10); + expect(JSON.parse(error.causeErrors).category).toEqual(6); + }, LONG_TIMEOUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + it("should detect and surface an error for an invalid jobname", async () => { + let err; + try { + await GetJobs.getStatusForJob(REAL_SESSION, {jobname: "))))))))", jobid: "JOB123"} as any); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + }); - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - testEnvironment.resources.jobs.push(job); - }); + it("should detect and surface an error for an invalid jobid", async () => { + let err; + try { + await GetJobs.getStatusForJob(REAL_SESSION, {jobname: "***REMOVED***1", jobid: "))))))))))"} as any); + } catch (e) { + err = e; + } + expect(err).toBeDefined(); + expect(err instanceof ImperativeError).toBe(true); + const trimmedErrorMessage = trimMessage(err.message); + const jsonCauseErrors = JSON.parse(err.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + }); + }); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is input - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); - testEnvironment.resources.jobs.push(job); - }); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + }); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + // Expect that the status is input + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); }); - }); - }); - /**********************************************/ - // API methods "getSpool..." system tests - describe("Get spool APIs", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for getting spool content that doesnt exist", async () => { - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - await DeleteJobs.deleteJobForJob(REAL_SESSION, job); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - await wait(3000); //Wait for 3 seconds + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - let error; - try { - await GetJobs.getSpoolContent(REAL_SESSION, files[0]); - } catch (thrownError) { - error = thrownError; - } - expect(error).toBeDefined(); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - testEnvironment.resources.jobs.push(job); + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); }, LONG_TIMEOUT); }); + }); + }); - describe("list spool files/dds", () => { - it("should be able to get all spool files in a job", async () => { - const NUM_OF_SPOOL_FILES = 3; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - files.forEach((file) => { - expect(file.jobname).toEqual(job.jobname); // verify jobname is in each jobfile - }); - testEnvironment.resources.jobs.push(job); + /**********************************************/ + // API methods "getSpool..." system tests + describe("Get spool APIs", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for getting spool content that doesnt exist", async () => { + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + await DeleteJobs.deleteJobForJob(REAL_SESSION, job); + await wait(3000); + let error; + try { + const content = await GetJobs.getSpoolContent(REAL_SESSION, files[0]); + } catch (thrownError) { + error = thrownError; + } + expect(error).toBeDefined(); + expect(JSON.parse(error.causeErrors).rc).toEqual(4); + expect(JSON.parse(error.causeErrors).reason).toEqual(10); + expect(JSON.parse(error.causeErrors).category).toEqual(6); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + }, LONG_TIMEOUT); + }); + + describe("list spool files/dds", () => { + it("should be able to get all spool files in a job", async () => { + const NUM_OF_SPOOL_FILES = 3; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + files.forEach((file) => { + expect(file.jobname).toEqual(job.jobname); // verify jobname is in each jobfile }); + await DeleteJobs.deleteJobForJob(REAL_SESSION, job); }); + }); - describe("download spool files", () => { - it("Should get spool content from a job", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - let found = false; - - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file); - expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - found = true; - } + describe("download spool files", () => { + it("Should get spool content from a job", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + let found = false; + + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file); + expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + found = true; } - expect(found).toBe(true); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - - it("Should get spool content from a job with encoding", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY¬¬"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - let found = false; - - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file, "IBM-037"); - expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - expect(dataContent).toContain("PUTTYPUTTYPUTTY"); - expect(dataContent).not.toContain("¬¬"); - expect(dataContent).toContain("^^"); - found = true; - } + } + expect(found).toBe(true); + }, LONG_TIMEOUT); + + it("Should get spool content from a job with encoding", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY¬¬"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + let found = false; + + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file, "IBM-037"); + expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + expect(dataContent).toContain("PUTTYPUTTYPUTTY"); + expect(dataContent).not.toContain("¬¬"); + expect(dataContent).toContain("^^"); + found = true; } - expect(found).toBe(true); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - - it("Should get spool content for a single job", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id); - expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - break; - } + } + expect(found).toBe(true); + }, LONG_TIMEOUT); + + it("Should get spool content for a single job", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id); + expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + break; } - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - - it("Should get spool content for a single job with encoding", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY¬¬"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id, "IBM-037"); - expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - expect(content).toContain("PUTTYPUTTYPUTTY"); - expect(content).not.toContain("¬¬"); - expect(content).toContain("^^"); - break; - } + } + }, LONG_TIMEOUT); + + it("Should get spool content for a single job with encoding", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY¬¬"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id, "IBM-037"); + expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + expect(content).toContain("PUTTYPUTTYPUTTY"); + expect(content).not.toContain("¬¬"); + expect(content).toContain("^^"); + break; } - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - }); + } + }, LONG_TIMEOUT); }); + }); - /**********************************************/ - // API methods "getJcl..." system tests - describe("Get JCL APIs", () => { - describe("invalid request error handling", () => { - it("should detect and surface an error for getting JCL that doesnt exist", async () => { - const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); - - await DeleteJobs.deleteJobForJob(REAL_SESSION, job); - - await wait(3000); //Wait for 3 seconds - - let error; - try { - await GetJobs.getJclForJob(REAL_SESSION, job); - } catch (thrownError) { - error = thrownError; - } - expect(error).toBeDefined(); - const trimmedErrorMessage = trimMessage(error.message); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain(job.jobid); - testEnvironment.resources.jobs.push(job); - }); + /**********************************************/ + // API methods "getJcl..." system tests + describe("Get JCL APIs", () => { + describe("invalid request error handling", () => { + it("should detect and surface an error for getting JCL that doesnt exist", async () => { + const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); + await DeleteJobs.deleteJobForJob(REAL_SESSION, job); + await wait(3000); + let error; + try { + await GetJobs.getJclForJob(REAL_SESSION, job); + } catch (thrownError) { + error = thrownError; + } + expect(error).toBeDefined(); + expect(JSON.parse(error.causeErrors).rc).toEqual(4); + expect(JSON.parse(error.causeErrors).reason).toEqual(10); + expect(JSON.parse(error.causeErrors).category).toEqual(6); + const trimmedErrorMessage = trimMessage(error.message); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain(job.jobid); }); + }); - describe("download JCL", () => { - it("should be able to get jcl from a job that was submitted", async () => { - const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); - const jcl = await GetJobs.getJclForJob(REAL_SESSION, job); - expect(jcl).toContain("EXEC PGM=IEFBR14"); - expect(jcl).toContain("JOB"); - testEnvironment.resources.jobs.push(job); - }); + describe("download JCL", () => { + it("should be able to get jcl from a job that was submitted", async () => { + const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); + const jcl = await GetJobs.getJclForJob(REAL_SESSION, job); + expect(jcl).toContain("EXEC PGM=IEFBR14"); + expect(jcl).toContain("JOB"); }); }); }); - describe("Encoded System Tests", () => { - beforeAll(async () => { + describe("Get Jobs - System Tests - Encoded", () => { + beforeAll(async () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_get_jobs_encoded" }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; + defaultSystem = testEnvironment.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); INVALID_SESSION = new Session({ user: "fakeuser", @@ -1042,13 +1037,21 @@ describe("Get Jobs System Tests", () => { "//" + MONITOR_JOB_NAME + " JOB '" + ACCOUNT + "',CLASS=" + JOBCLASS + "\n" + "//IEFBR14 EXEC PGM=IEFBR14"; // GetJobs }); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); + + // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently + // outstanding) when the tests run + beforeEach(async () => { + await cleanTestJobs(MONITOR_JOB_NAME); + await cleanTestJobs(TEST_JOB_NAME); + }); + afterEach(async () => { + await cleanTestJobs(MONITOR_JOB_NAME); + await cleanTestJobs(TEST_JOB_NAME); }); /**********************************************/ // API methods "getJobs..." system tests - describe("Get Jobs APIs - Encoded", () => { + describe("Get Jobs APIs", () => { /**********************************************/ // API methods "getJobs" system tests @@ -1073,10 +1076,10 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); jobs.push(job); - testEnvironment.resources.jobs.push(job); } - - await wait(waitTime); // Waits for 2 seconds + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); // Obtain all jobs for the user const allJobs: IJob[] = await GetJobs.getJobs(REAL_SESSION); @@ -1110,14 +1113,16 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); - await wait(waitTime); // Waits for 2 seconds + + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); // Search all jobs returned for each of the submitted jobs const foundJob = await GetJobs.getJob(REAL_SESSION, job.jobid); expect(foundJob).toBeDefined(); expect(foundJob.jobid).toEqual(job.jobid); expect(foundJob.jobname).toEqual(job.jobname); - testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); }); @@ -1136,7 +1141,10 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); - await wait(waitTime); // Waits for 2 seconds + + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); // Search all jobs returned for each of the submitted jobs const foundJobs = await GetJobs.getJobsCommon(REAL_SESSION, {jobid: job.jobid}); @@ -1144,14 +1152,13 @@ describe("Get Jobs System Tests", () => { expect(foundJobs.length).toEqual(1); expect(foundJobs[0].jobid).toEqual(job.jobid); expect(foundJobs[0].jobname).toEqual(job.jobname); - testEnvironment.resources.jobs.push(job); }, LONG_TIMEOUT); }); }); /**********************************************/ // API methods "getJobsByPrefix" system tests - describe("get jobs by prefix API - Encoded", () => { + describe("get jobs by prefix API", () => { describe("list jobs", () => { it("should return all jobs for the prefix of the user id and the owner is the session user id", async () => { // Read the JCL template file @@ -1172,10 +1179,11 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); jobs.push(job); - testEnvironment.resources.jobs.push(job); } - await wait(waitTime); // Waits for 2 seconds + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); // Obtain the three jobs submitted const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, MONITOR_JOB_NAME + "*"); @@ -1229,10 +1237,11 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); jobs.push(job); - testEnvironment.resources.jobs.push(job); } - await wait(waitTime); // Waits for 2 seconds + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); // Obtain the three jobs submitted const allJobs: IJob[] = await GetJobs.getJobsByPrefix(REAL_SESSION, TEST_JOB_NAME + "*"); @@ -1255,7 +1264,7 @@ describe("Get Jobs System Tests", () => { /**********************************************/ // API methods "getJobsByPrefix" system tests - describe("get jobs by owner API - Encoded", () => { + describe("get jobs by owner API", () => { describe("list jobs", () => { it("should return no jobs for a nonexistent owner", async () => { // Obtain the three jobs submitted @@ -1282,11 +1291,11 @@ describe("Get Jobs System Tests", () => { expect(job.status).toEqual("OUTPUT"); expect(job.retcode).toEqual("CC 0000"); jobs.push(job); - testEnvironment.resources.jobs.push(job); } - await wait(waitTime); // Waits for 2 seconds - + // TODO: this is a workaround for an issue where listing jobs immediately after they are completed + // results in the jobs being omitted from the results + await wait(3000); // Obtain all jobs for ***REMOVED*** const allJobs: IJob[] = await GetJobs.getJobsByOwner(REAL_SESSION, REAL_SESSION.ISession.user); expect(allJobs.length).toBeGreaterThanOrEqual(NUM_JOBS); @@ -1305,306 +1314,295 @@ describe("Get Jobs System Tests", () => { }, LONG_TIMEOUT); }); }); + }); - describe("Get Status APIs - Encoded", () => { - /**********************************************/ - // API methods "getStatus" system tests - describe("get status API", () => { - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + describe("Get Status APIs - Encoded", () => { - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + /**********************************************/ + // API methods "getStatus" system tests + describe("get status API", () => { + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - testEnvironment.resources.jobs.push(job); - }); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + }); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // Expect the jobname to match - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + // Expect the jobname to match + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); - testEnvironment.resources.jobs.push(job); - }); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); + }); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - // Get the status of the job submitted - const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - }); + // Get the status of the job submitted + const status = await GetJobs.getStatus(REAL_SESSION, job.jobname, job.jobid); + + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + }, LONG_TIMEOUT); }); + }); - /**********************************************/ - // API methods "getStatusCommon" system tests - describe("get status common API", () => { - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + /**********************************************/ + // API methods "getStatusCommon" system tests + describe("get status common API", () => { + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - testEnvironment.resources.jobs.push(job); - }); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + }); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is input - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is input + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); - testEnvironment.resources.jobs.push(job); - }); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); + }); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); + // Get the status of the job submitted + const status = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: job.jobname, jobid: job.jobid}); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - }); + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + }, LONG_TIMEOUT); }); + }); - /**********************************************/ - // API methods "getStatusForJob" system tests - describe("get status for job API", () => { - describe("obtain job status", () => { - it("should be able to get the status of a recently submitted job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + /**********************************************/ + // API methods "getStatusForJob" system tests + describe("get status for job API", () => { + describe("obtain job status", () => { + it("should be able to get the status of a recently submitted job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is one of the three possible - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + // Expect that the status is one of the three possible + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(job.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); - // Expect that the status is one of the three possible - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); - testEnvironment.resources.jobs.push(job); - }); + // Expect that the status is one of the three possible + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(JOB_STATUS_ORDER.indexOf(status.status as JOB_STATUS)).toBeGreaterThanOrEqual(0); + }); - it("should be able to get the status of a recently submitted job on INPUT queue", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); + it("should be able to get the status of a recently submitted job on INPUT queue", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: ",TYPRUN=HOLD", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Expect that the status is input - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.INPUT); + // Expect that the status is input + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.INPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); - // Expect that the status is input - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.INPUT); - testEnvironment.resources.jobs.push(job); - }); + // Expect that the status is input + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.INPUT); + }); - it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { - // Render the job with increasing job name - const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const jobRender = iefbr14JclTemplate; - const renderedJcl = TextUtils.renderWithMustache(jobRender, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should be able to get the status of a recently submitted and completed (OUTPUT) job", async () => { + // Render the job with increasing job name + const iefbr14JclTemplate = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const jobRender = iefbr14JclTemplate; + const renderedJcl = TextUtils.renderWithMustache(jobRender, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // Submit the job - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + // Submit the job + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - // Expect that the status is output - expect(job.jobname).toBe(MONITOR_JOB_NAME); - expect(job.status).toBe(JOB_STATUS.OUTPUT); + // Expect that the status is output + expect(job.jobname).toBe(MONITOR_JOB_NAME); + expect(job.status).toBe(JOB_STATUS.OUTPUT); - // Get the status of the job submitted - const status = await GetJobs.getStatusForJob(REAL_SESSION, job); + // Get the status of the job submitted + const status = await GetJobs.getStatusForJob(REAL_SESSION, job); - // Expect that the status is output - expect(status.jobname).toBe(MONITOR_JOB_NAME); - expect(status.status).toBe(JOB_STATUS.OUTPUT); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - }); + // Expect that the status is output + expect(status.jobname).toBe(MONITOR_JOB_NAME); + expect(status.status).toBe(JOB_STATUS.OUTPUT); + }, LONG_TIMEOUT); }); }); + }); - describe("Get spool APIs - encoded", () => { - describe("list spool files/dds", () => { - it("should be able to get all spool files in a job", async () => { - const NUM_OF_SPOOL_FILES = 3; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - files.forEach((file) => { - expect(file.jobname).toEqual(job.jobname); // verify jobname is in each jobfile - }); - testEnvironment.resources.jobs.push(job); + describe("Get spool APIs - encoded", () => { + describe("list spool files/dds", () => { + it("should be able to get all spool files in a job", async () => { + const NUM_OF_SPOOL_FILES = 3; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, JCL); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + files.forEach((file) => { + expect(file.jobname).toEqual(job.jobname); // verify jobname is in each jobfile }); + await DeleteJobs.deleteJobForJob(REAL_SESSION, job); }); + }); - describe("download spool files", () => { - it("Should get spool content from a job", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - let found = false; - - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file); - expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - found = true; - } + describe("download spool files", () => { + it("Should get spool content from a job", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + let found = false; + + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const dataContent = await GetJobs.getSpoolContent(REAL_SESSION, file); + expect(dataContent).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + found = true; } - expect(found).toBe(true); - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - - it("Should get spool content for a single job", async () => { - const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); - const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; - const renderedJcl = TextUtils.renderWithMustache(idcams, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); - const NUM_OF_SPOOL_FILES = 4; - const DD_WITH_CONTENT = "SYSTSPRT"; - const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); - const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); - expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs - for (const file of files) { - if (file.ddname === DD_WITH_CONTENT) { - const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id); - expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); - break; - } + } + expect(found).toBe(true); + }, LONG_TIMEOUT); + + it("Should get spool content for a single job", async () => { + const idcams = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_content.jcl")).toString(); + const DATA_TO_CHECK = "PUTTYPUTTYPUTTYPUTTY"; + const renderedJcl = TextUtils.renderWithMustache(idcams, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF, CONTENT: DATA_TO_CHECK}); + const NUM_OF_SPOOL_FILES = 4; + const DD_WITH_CONTENT = "SYSTSPRT"; + const job = await SubmitJobs.submitJclNotify(REAL_SESSION, renderedJcl); + const files = await GetJobs.getSpoolFilesForJob(REAL_SESSION, job); + expect(files.length).toBe(NUM_OF_SPOOL_FILES); // verify expected number of DDs + for (const file of files) { + if (file.ddname === DD_WITH_CONTENT) { + const content = await GetJobs.getSpoolContentById(REAL_SESSION, job.jobname, job.jobid, file.id); + expect(content).toContain("NUMBER OF RECORDS PROCESSED WAS 3"); + break; } - testEnvironment.resources.jobs.push(job); - }, LONG_TIMEOUT); - }); + } + }, LONG_TIMEOUT); + }); + }); - /**********************************************/ - // API methods "getJcl..." system tests - describe("Get JCL APIs - encoded", () => { - describe("download JCL", () => { - it("should be able to get jcl from a job that was submitted", async () => { - const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); - const jcl = await GetJobs.getJclForJob(REAL_SESSION, job); - expect(jcl).toContain("EXEC PGM=IEFBR14"); - expect(jcl).toContain("JOB"); - testEnvironment.resources.jobs.push(job); - }); - }); + /**********************************************/ + // API methods "getJcl..." system tests + describe("Get JCL APIs - encoded", () => { + describe("download JCL", () => { + it("should be able to get jcl from a job that was submitted", async () => { + const job = await SubmitJobs.submitJcl(REAL_SESSION, JCL); + const jcl = await GetJobs.getJclForJob(REAL_SESSION, job); + expect(jcl).toContain("EXEC PGM=IEFBR14"); + expect(jcl).toContain("JOB"); }); }); }); -}); \ No newline at end of file +}); diff --git a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts index 00b0da8c1a..2ccc7fff18 100644 --- a/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/ModifyJobs.system.test.ts @@ -32,21 +32,18 @@ describe("Modify Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs" }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - systemProps = testEnvironment.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); account = systemProps.tso.account; jobclass = testEnvironment.systemTestProperties.zosjobs.jobclass; modifiedJobClass = testEnvironment.systemTestProperties.zosjobs.modifiedJobclass; iefbr14Job = await SubmitJobs.submitJob(REAL_SESSION, testEnvironment.systemTestProperties.zosjobs.iefbr14Member ); + testEnvironment.resources.jobs.push(iefbr14Job); }); afterAll(async () => { - // Add the job to resources for automatic cleanup - testEnvironment.resources.jobData.push({jobname: iefbr14Job.jobname, jobid: iefbr14Job.jobid}); await TestEnvironment.cleanUp(testEnvironment); }); @@ -107,10 +104,8 @@ describe("Modify Jobs - System Tests - Encoded", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_modify_jobs_encoded" }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - systemProps = testEnvironment.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); account = systemProps.tso.account; jobclass = systemProps.zosjobs.jobclass; modifiedJobClass = systemProps.zosjobs.modifiedJobclass; @@ -118,11 +113,10 @@ describe("Modify Jobs - System Tests - Encoded", () => { const maxStepNum = 6; const sleepJCL = JobTestsUtils.getSleepJCL(REAL_SESSION.ISession.user, account, systemProps.zosjobs.jobclass, maxStepNum, true); sleepJCLJob = await SubmitJobs.submitJcl(REAL_SESSION, sleepJCL); + testEnvironment.resources.jobs.push(sleepJCLJob); }); afterAll(async () => { - // Add the sleep job to resources for automatic cleanup - testEnvironment.resources.jobData.push({jobname: sleepJCLJob.jobname, jobid: sleepJCLJob.jobid}); await TestEnvironment.cleanUp(testEnvironment); }); diff --git a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts index 74c3342895..5ba150128f 100644 --- a/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/MonitorJobs.system.test.ts @@ -15,9 +15,9 @@ import { ImperativeError, Session, TextUtils } from "@zowe/imperative"; import * as fs from "fs"; import { join } from "path"; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk"; -import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { ITestEnvironment } from "../../../../__tests__/__src__/environment/ITestEnvironment"; // long running test timeout const LONG_TIMEOUT = 100000; @@ -66,1123 +66,622 @@ const trimMessage = (message: string) => { return message.replace(/( {2,})|\t/g, " "); }; -describe("System Tests - Monitor Jobs", () => { - describe("Unencoded", () => { - - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_monitor_jobs" - }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - defaultSystem = testEnvironment.systemTestProperties; - ACCOUNT = defaultSystem.tso.account; - const JOB_LENGTH = 6; - MONITOR_JOB_NAME = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + "MJ"; +describe.each([false, true])("System Tests - Monitor Jobs - Encoded: %s", (encoded: boolean) => { - JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; - SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; + beforeAll(async () => { + testEnvironment = await TestEnvironment.setUp({ + testName: "zos_monitor_jobs" }); + defaultSystem = testEnvironment.systemTestProperties; - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently - // outstanding) when the tests run - beforeEach(async () => { - GetJobs.getStatusCommon = ORIG_JOBS_STATUS; - await cleanTestJobs(); - }); - afterEach(async () => { - GetJobs.getStatusCommon = ORIG_JOBS_STATUS; - await cleanTestJobs(); - }); - - /**********************************************/ - // API method "waitForOutputStatus" system tests - describe("api method wait for output status", () => { - - // Single error situation - the majority are tested via the common method (which this method invokes) - describe("invalid request error handling", () => { - it("should detect and surface an error if the job requested is not found", async () => { - let error; - try { - const response = await MonitorJobs.waitForOutputStatus(REAL_SESSION, "JOB1", "JOB123"); - } catch (e) { - error = e; - } - expect(error).toBeDefined(); - expect(error instanceof ImperativeError).toBe(true); - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No job found for reference"); - }); - }); + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - // Single polling situation - the majority are tested via the common method (which this method invokes) - describe("polling/transitions", () => { - // eslint-disable-next-line jest/no-done-callback - it("should detect when a job transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); - - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForOutputStatus(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); - - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { - if (!doneCalled) { - doneCalled = true; - done(`Release error: ${releaseErr.message}`); - } - }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - }); - }); + ACCOUNT = defaultSystem.tso.account; + if (encoded) { + const JOB_LENGTH = 5; + MONITOR_JOB_NAME = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + "#MJ"; + } else { + const JOB_LENGTH = 6; + MONITOR_JOB_NAME = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase() + "MJ"; + } - /**********************************************/ - // API method "waitForJobOutputStatus" system tests - describe("api method wait for job output status", () => { - - // Single error situation - the majority are tested via the common method (which this method invokes) - describe("invalid request error handling", () => { - it("should detect and surface an error if the job requested is not found", async () => { - let error; - try { - const params: any = {jobname: "JOB1", jobid: "JOB123"}; - const response = await MonitorJobs.waitForJobOutputStatus(REAL_SESSION, params); - } catch (e) { - error = e; - } - expect(error).toBeDefined(); - expect(error instanceof ImperativeError).toBe(true); - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No job found for reference"); - }); - }); + JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; + SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; + }); - // Single polling situation - the majority are tested via the common method (which this method invokes) - describe("polling/transitions", () => { - // eslint-disable-next-line jest/no-done-callback - it("should detect when the job submitted transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); - - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForJobOutputStatus(REAL_SESSION, jobInfo).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); + // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently + // outstanding) when the tests run + beforeEach(async () => { + GetJobs.getStatusCommon = ORIG_JOBS_STATUS; + await cleanTestJobs(); + }); + afterEach(async () => { + GetJobs.getStatusCommon = ORIG_JOBS_STATUS; + await cleanTestJobs(); + }); - // Release the job - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { - if (!doneCalled) { - doneCalled = true; - done(`Release error: ${releaseErr.message}`); - } - }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + /**********************************************/ + // API method "waitForOutputStatus" system tests + describe("api method wait for output status", () => { + + // Single error situation - the majority are tested via the common method (which this method invokes) + describe("invalid request error handling", () => { + it("should detect and surface an error if the job requested is not found", async () => { + let error; + try { + const response = await MonitorJobs.waitForOutputStatus(REAL_SESSION, "JOB1", "JOB123"); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error instanceof ImperativeError).toBe(true); + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No job found for reference"); }); }); - /**********************************************/ - // API method "waitForStatusCommon" system tests - describe("api method wait for output status common", () => { - - // All error situations/scenarios - negative system - describe("invalid request error handling", () => { - it("should detect and surface an error message if an invalid jobname is specified", async () => { - let error; - try { - const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "JOB123", jobname: "((((("}); - } catch (e) { - error = e; - } - expect(error).toBeDefined(); - expect(error instanceof ImperativeError).toBe(true); - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/invalid_jobname.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"(((((\" jobid \"JOB123\""); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No match for method GET and pathInfo"); - }); - - it("should detect and surface an error message if an invalid jobid is specified", async () => { - let error; - try { - const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "(", jobname: "JOB1"}); - } catch (e) { - error = e; - } - expect(error).toBeDefined(); - expect(error instanceof ImperativeError).toBe(true); - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/invalid_jobid.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"(\""); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(7); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No match for method GET and pathInfo"); - }); - - it("should detect and surface an error if the job requested is not found", async () => { - let error; - try { - const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "JOB123", jobname: "JOB1"}); - } catch (e) { - error = e; - } - expect(error).toBeDefined(); - expect(error instanceof ImperativeError).toBe(true); - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No job found for reference"); - }); - }); + // Single polling situation - the majority are tested via the common method (which this method invokes) + describe("polling/transitions", () => { + // eslint-disable-next-line jest/no-done-callback + it("should detect when a job transitions from INPUT to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - // Tests that do not initiate polling - should return immediately from a request - describe("initial status checks", () => { - it("should detect that a job is in INPUT status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // Initial status should be input because of HELD jobclass expect(jobInfo.status).toBe("INPUT"); - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is input - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "INPUT" - }); - - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("INPUT"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }); - - it("should detect that a job is in ACTIVE status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - - // Wait for the job to become active indefinitely - jest timeout will occur eventually - let jobCheck: IJob; - do { - jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); - } while (jobCheck.status !== "ACTIVE"); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is active - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "ACTIVE" - }); - - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }, LONG_TIMEOUT); - - it("should detect that a job is in OUTPUT status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - - // Wait for the job to become active indefinitely - jest timeout will occur eventually - let jobCheck: IJob; - do { - jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); - } while (jobCheck.status !== "OUTPUT"); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is output - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "OUTPUT" - }); - - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }, LONG_TIMEOUT); - }); - - // All tests that perform polling, etc to eventually obtain the status - describe("polling/transitions", () => { - /* eslint-disable jest/no-done-callback */ - it("should detect and surface an error if the job is purged/deleted while waiting for status", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForOutputStatus(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + done(); + }).catch((error) => { + if (!doneCalled) { + doneCalled = true; + done(`wait for status error: ${error.message}`); + } }); - GetJobs.getStatusCommon = mockedGetJobs; - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((status) => { - if (!doneCalled) { - doneCalled = true; - done(`Error - we should not have received a status of OUTPUT`); + // Change the jobclass after a period of time + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" } - }).catch((error) => { - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/polling_job_deleted.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname"); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No job found for reference"); + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { if (!doneCalled) { doneCalled = true; - done(); + done(`Release error: ${releaseErr.message}`); } }); + }, TIMEOUT_TEST_CHECK); - // Cancel and purge the job after a period of time - setTimeout(() => { - DeleteJobs.deleteJob(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`Error deleting the job: ${error.message}`); - } - }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - - it("should detect and surface an error if the max poll attempts are exceeded", (done) => { - // Attempts - const ATTEMPTS = 3; + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); + }); + }); - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + /**********************************************/ + // API method "waitForJobOutputStatus" system tests + describe("api method wait for job output status", () => { + + // Single error situation - the majority are tested via the common method (which this method invokes) + describe("invalid request error handling", () => { + it("should detect and surface an error if the job requested is not found", async () => { + let error; + try { + const params: any = {jobname: "JOB1", jobid: "JOB123"}; + const response = await MonitorJobs.waitForJobOutputStatus(REAL_SESSION, params); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error instanceof ImperativeError).toBe(true); + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No job found for reference"); + }); + }); - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); - }); - GetJobs.getStatusCommon = mockedGetJobs; + // Single polling situation - the majority are tested via the common method (which this method invokes) + describe("polling/transitions", () => { + // eslint-disable-next-line jest/no-done-callback + it("should detect when the job submitted transitions from INPUT to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // start checking the job status - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT", attempts: ATTEMPTS - }).then((status) => { - done(`Error - we should not have received a status of OUTPUT`); - }).catch((error) => { - expect(error instanceof ImperativeError).toBe(true); - expect(error.message).toContain("Error obtaining status for jobname"); - expect(error.message).toContain("Error Details: Reached max poll attempts of \"3\""); - expect(mockedGetJobs).toHaveBeenCalledTimes(ATTEMPTS); - done(); - }); + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForJobOutputStatus(REAL_SESSION, jobInfo).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + done(); + }).catch((error) => { + if (!doneCalled) { + doneCalled = true; + done(`wait for status error: ${error.message}`); + } }); - }, LONG_TIMEOUT); - - it("should detect when a job transitions from INPUT to ACTIVE", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); - - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); + // Release the job + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" } - }); - - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { - if (!doneCalled) { - doneCalled = true; - done(`Release error: ${releaseErr.message}`); - } - }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - - it("should detect when a job transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); - - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { if (!doneCalled) { doneCalled = true; - done(`wait for status error: ${error.message}`); + done(`Release error: ${releaseErr.message}`); } }); + }, TIMEOUT_TEST_CHECK); - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { - if (!doneCalled) { - doneCalled = true; - done(`Release error: ${releaseErr.message}`); - } - }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - - it("should detect when a job transitions from INPUT to ACTIVE to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Wait for the status to be active - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - - // Wait for the status to be output - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((nextStatus) => { - expect(nextStatus.jobid).toEqual(jobInfo.jobid); - expect(nextStatus.jobname).toEqual(jobInfo.jobname); - expect(nextStatus.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - done(`wait for status error: ${error.message}`); - }); - }).catch((error) => { - done(`wait for status error: ${error.message}`); - }); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - /* eslint-enable jest/no-done-callback */ - }); + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); }); }); - describe("Encoded", () => { - - beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ - testName: "zos_monitor_jobs_encoded" + /**********************************************/ + // API method "waitForStatusCommon" system tests + describe("api method wait for output status common", () => { + + // All error situations/scenarios - negative system + describe("invalid request error handling", () => { + it("should detect and surface an error message if an invalid jobname is specified", async () => { + let error; + try { + const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "JOB123", jobname: "((((("}); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error instanceof ImperativeError).toBe(true); + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/invalid_jobname.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"(((((\" jobid \"JOB123\""); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No match for method GET and pathInfo"); }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - - defaultSystem = testEnvironment.systemTestProperties; - ACCOUNT = defaultSystem.tso.account; - const JOB_LENGTH = 5; - MONITOR_JOB_NAME = REAL_SESSION.ISession.user?.substring(0, JOB_LENGTH).toUpperCase() + "#MJ"; - - JOBCLASS = testEnvironment.systemTestProperties.zosjobs.jobclass; - SYSAFF = testEnvironment.systemTestProperties.zosjobs.sysaff; - }); - - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); - - // Cleanup before & after each test - this will ensure that hopefully no jobs are left outstanding (or are currently - // outstanding) when the tests run - beforeEach(async () => { - GetJobs.getStatusCommon = ORIG_JOBS_STATUS; - await cleanTestJobs(); - }); - afterEach(async () => { - GetJobs.getStatusCommon = ORIG_JOBS_STATUS; - await cleanTestJobs(); - }); - - /**********************************************/ - // API method "waitForOutputStatus" system tests - describe("api method wait for output status", () => { - // Single polling situation - the majority are tested via the common method (which this method invokes) - describe("polling/transitions", () => { - // eslint-disable-next-line jest/no-done-callback - it("should detect when a job transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); - - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForOutputStatus(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { - if (!doneCalled) { - doneCalled = true; - done(`Release error: ${releaseErr.message}`); - } - }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + it("should detect and surface an error message if an invalid jobid is specified", async () => { + let error; + try { + const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "(", jobname: "JOB1"}); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error instanceof ImperativeError).toBe(true); + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/invalid_jobid.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"(\""); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(7); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No match for method GET and pathInfo"); }); - }); - /**********************************************/ - // API method "waitForJobOutputStatus" system tests - describe("api method wait for job output status", () => { - // Single polling situation - the majority are tested via the common method (which this method invokes) - describe("polling/transitions", () => { - // eslint-disable-next-line jest/no-done-callback - it("should detect when the job submitted transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); - - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForJobOutputStatus(REAL_SESSION, jobInfo).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`wait for status error: ${error.message}`); - } - }); - - // Release the job - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { - if (!doneCalled) { - doneCalled = true; - done(`Release error: ${releaseErr.message}`); - } - }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + it("should detect and surface an error if the job requested is not found", async () => { + let error; + try { + const response = await MonitorJobs.waitForStatusCommon(REAL_SESSION, {jobid: "JOB123", jobname: "JOB1"}); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error instanceof ImperativeError).toBe(true); + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/not_found_job.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname \"JOB1\" jobid \"JOB123\""); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No job found for reference"); }); }); - /**********************************************/ - // API method "waitForStatusCommon" system tests - describe("api method wait for output status common", () => { - // Tests that do not initiate polling - should return immediately from a request - describe("initial status checks", () => { - it("should detect that a job is in INPUT status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - expect(jobInfo.status).toBe("INPUT"); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); + // Tests that do not initiate polling - should return immediately from a request + describe("initial status checks", () => { + it("should detect that a job is in INPUT status", async () => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + + // submit the job + const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + expect(jobInfo.status).toBe("INPUT"); + + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); + }); + GetJobs.getStatusCommon = mockedGetJobs; + + // check that the status is input + const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, + { + jobname: jobInfo.jobname, + jobid: jobInfo.jobid, + status: "INPUT" }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is input - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "INPUT" - }); - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("INPUT"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }); + // verify that the status and info is correct + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("INPUT"); + expect(mockedGetJobs).toHaveBeenCalledTimes(1); + }); - it("should detect that a job is in ACTIVE status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + it("should detect that a job is in ACTIVE status", async () => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + // submit the job + const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - // Wait for the job to become active indefinitely - jest timeout will occur eventually - let jobCheck: IJob; - do { - jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); - } while (jobCheck.status !== "ACTIVE"); + // Wait for the job to become active indefinitely - jest timeout will occur eventually + let jobCheck: IJob; + do { + jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); + } while (jobCheck.status !== "ACTIVE"); - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); + }); + GetJobs.getStatusCommon = mockedGetJobs; + + // check that the status is active + const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, + { + jobname: jobInfo.jobname, + jobid: jobInfo.jobid, + status: "ACTIVE" }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is active - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "ACTIVE" - }); - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }, LONG_TIMEOUT); - - it("should detect that a job is in OUTPUT status", async () => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // submit the job - const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); - - // Wait for the job to become active indefinitely - jest timeout will occur eventually - let jobCheck: IJob; - do { - jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); - } while (jobCheck.status !== "OUTPUT"); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); + // verify that the status and info is correct + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("ACTIVE"); + expect(mockedGetJobs).toHaveBeenCalledTimes(1); + }, LONG_TIMEOUT); + + it("should detect that a job is in OUTPUT status", async () => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/iefbr14.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // submit the job + const jobInfo = await SubmitJobs.submitJcl(REAL_SESSION, renderedJcl); + + // Wait for the job to become active indefinitely - jest timeout will occur eventually + let jobCheck: IJob; + do { + jobCheck = await GetJobs.getStatusCommon(REAL_SESSION, {jobname: jobInfo.jobname, jobid: jobInfo.jobid}); + } while (jobCheck.status !== "OUTPUT"); + + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); + }); + GetJobs.getStatusCommon = mockedGetJobs; + + // check that the status is output + const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, + { + jobname: jobInfo.jobname, + jobid: jobInfo.jobid, + status: "OUTPUT" }); - GetJobs.getStatusCommon = mockedGetJobs; - - // check that the status is output - const status = await MonitorJobs.waitForStatusCommon(REAL_SESSION, - { - jobname: jobInfo.jobname, - jobid: jobInfo.jobid, - status: "OUTPUT" - }); - // verify that the status and info is correct - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - expect(mockedGetJobs).toHaveBeenCalledTimes(1); - }, LONG_TIMEOUT); - }); + // verify that the status and info is correct + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + expect(mockedGetJobs).toHaveBeenCalledTimes(1); + }, LONG_TIMEOUT); + }); - // All tests that perform polling, etc to eventually obtain the status - describe("polling/transitions", () => { - /* eslint-disable jest/no-done-callback */ - it("should detect and surface an error if the job is purged/deleted while waiting for status", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); + // All tests that perform polling, etc to eventually obtain the status + describe("polling/transitions", () => { + /* eslint-disable jest/no-done-callback */ + it("should detect and surface an error if the job is purged/deleted while waiting for status", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); + }); + GetJobs.getStatusCommon = mockedGetJobs; + + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" + }).then((status) => { + if (!doneCalled) { + doneCalled = true; + done(`Error - we should not have received a status of OUTPUT`); + } + }).catch((error) => { + // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/polling_job_deleted.regex").toString(), "g"); + // expect(regex.test(error.message)).toBe(true); + const trimmedErrorMessage = trimMessage(error.message); + const jsonCauseErrors = JSON.parse(error.causeErrors); + expect(trimmedErrorMessage).toContain("Error obtaining status for jobname"); + expect(jsonCauseErrors.category).toEqual(6); + expect(jsonCauseErrors.reason).toEqual(10); + expect(jsonCauseErrors.rc).toEqual(4); + expect(trimmedErrorMessage).toContain("status 400"); + expect(trimmedErrorMessage).toContain("No job found for reference"); + if (!doneCalled) { + doneCalled = true; + done(); + } }); - GetJobs.getStatusCommon = mockedGetJobs; - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((status) => { - if (!doneCalled) { - doneCalled = true; - done(`Error - we should not have received a status of OUTPUT`); - } - }).catch((error) => { - // const regex: RegExp = new RegExp(fs.readFileSync(TEST_REGEX_DIR + "/polling_job_deleted.regex").toString(), "g"); - // expect(regex.test(error.message)).toBe(true); - const trimmedErrorMessage = trimMessage(error.message); - const jsonCauseErrors = JSON.parse(error.causeErrors); - expect(trimmedErrorMessage).toContain("Error obtaining status for jobname"); - expect(jsonCauseErrors.category).toEqual(6); - expect(jsonCauseErrors.reason).toEqual(10); - expect(jsonCauseErrors.rc).toEqual(4); - expect(trimmedErrorMessage).toContain("status 400"); - expect(trimmedErrorMessage).toContain("No job found for reference"); + // Cancel and purge the job after a period of time + setTimeout(() => { + DeleteJobs.deleteJob(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).catch((error) => { if (!doneCalled) { doneCalled = true; - done(); + done(`Error deleting the job: ${error.message}`); } }); + }, TIMEOUT_TEST_CHECK); - // Cancel and purge the job after a period of time - setTimeout(() => { - DeleteJobs.deleteJob(REAL_SESSION, jobInfo.jobname, jobInfo.jobid).catch((error) => { - if (!doneCalled) { - doneCalled = true; - done(`Error deleting the job: ${error.message}`); - } - }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); - it("should detect and surface an error if the max poll attempts are exceeded", (done) => { - // Attempts - const ATTEMPTS = 3; + it("should detect and surface an error if the max poll attempts are exceeded", (done) => { + // Attempts + const ATTEMPTS = 3; - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - // "Mock" the function - which just invokes the actual function - const mockedGetJobs = jest.fn(async (session, parms) => { - return ORIG_JOBS_STATUS(session, parms); + // "Mock" the function - which just invokes the actual function + const mockedGetJobs = jest.fn(async (session, parms) => { + return ORIG_JOBS_STATUS(session, parms); + }); + GetJobs.getStatusCommon = mockedGetJobs; + + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // start checking the job status + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT", attempts: ATTEMPTS + }).then((status) => { + done(`Error - we should not have received a status of OUTPUT`); + }).catch((error) => { + expect(error instanceof ImperativeError).toBe(true); + expect(error.message).toContain("Error obtaining status for jobname"); + expect(error.message).toContain("Error Details: Reached max poll attempts of \"3\""); + expect(mockedGetJobs).toHaveBeenCalledTimes(ATTEMPTS); + done(); }); - GetJobs.getStatusCommon = mockedGetJobs; - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // start checking the job status - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT", attempts: ATTEMPTS - }).then((status) => { - done(`Error - we should not have received a status of OUTPUT`); - }).catch((error) => { - expect(error instanceof ImperativeError).toBe(true); - expect(error.message).toContain("Error obtaining status for jobname"); - expect(error.message).toContain("Error Details: Reached max poll attempts of \"3\""); - expect(mockedGetJobs).toHaveBeenCalledTimes(ATTEMPTS); - done(); - }); + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + it("should detect when a job transitions from INPUT to ACTIVE", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - it("should detect when a job transitions from INPUT to ACTIVE", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_forever_loop.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" + }).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("ACTIVE"); + done(); + }).catch((error) => { + if (!doneCalled) { + doneCalled = true; + done(`wait for status error: ${error.message}`); + } + }); - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - done(); - }).catch((error) => { + // Change the jobclass after a period of time + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" + } + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { if (!doneCalled) { doneCalled = true; - done(`wait for status error: ${error.message}`); + done(`Release error: ${releaseErr.message}`); } }); + }, TIMEOUT_TEST_CHECK); - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { - if (!doneCalled) { - doneCalled = true; - done(`Release error: ${releaseErr.message}`); - } - }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); - it("should detect when a job transitions from INPUT to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); + it("should detect when a job transitions from INPUT to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: TYPE_RUN_HOLD, SYSAFF}); - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - // Initial status should be input because of HELD jobclass - expect(jobInfo.status).toBe("INPUT"); + // Initial status should be input because of HELD jobclass + expect(jobInfo.status).toBe("INPUT"); - // start checking the job status - let doneCalled: boolean = false; - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("OUTPUT"); - done(); - }).catch((error) => { + // start checking the job status + let doneCalled: boolean = false; + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" + }).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("OUTPUT"); + done(); + }).catch((error) => { + if (!doneCalled) { + doneCalled = true; + done(`wait for status error: ${error.message}`); + } + }); + + // Change the jobclass after a period of time + setTimeout(() => { + new ZosmfRestClient(REAL_SESSION).request({ + resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, + request: "PUT", + reqHeaders: [{"Content-Type": "application/json"}], + writeData: { + request: "release", + version: "2.0" + } + }).then((response) => { + // Nothing to do here + }).catch((releaseErr) => { if (!doneCalled) { doneCalled = true; - done(`wait for status error: ${error.message}`); + done(`Release error: ${releaseErr.message}`); } }); + }, TIMEOUT_TEST_CHECK); - // Change the jobclass after a period of time - setTimeout(() => { - new ZosmfRestClient(REAL_SESSION).request({ - resource: `/zosmf/restjobs/jobs/${encodeURIComponent(jobInfo.jobname)}/${encodeURIComponent(jobInfo.jobid)}`, - request: "PUT", - reqHeaders: [{"Content-Type": "application/json"}], - writeData: { - request: "release", - version: "2.0" - } - }).then((response) => { - // Nothing to do here - }).catch((releaseErr) => { - if (!doneCalled) { - doneCalled = true; - done(`Release error: ${releaseErr.message}`); - } - }); - }, TIMEOUT_TEST_CHECK); - - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); - }); - }, LONG_TIMEOUT); - - it("should detect when a job transitions from INPUT to ACTIVE to OUTPUT", (done) => { - // Construct the JCL - const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); - const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, - {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); - - // submit the job - SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { - - // Wait for the status to be active + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); + + it("should detect when a job transitions from INPUT to ACTIVE to OUTPUT", (done) => { + // Construct the JCL + const iefbr14Jcl = fs.readFileSync(join(TEST_RESOURCES_DIR, "jcl/instream_rexx_delay.jcl")).toString(); + const renderedJcl = TextUtils.renderWithMustache(iefbr14Jcl, + {JOBNAME: MONITOR_JOB_NAME, ACCOUNT, JOBCLASS, TYPERUNPARM: "", SYSAFF}); + + // submit the job + SubmitJobs.submitJcl(REAL_SESSION, renderedJcl).then((jobInfo) => { + + // Wait for the status to be active + MonitorJobs.waitForStatusCommon(REAL_SESSION, { + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" + }).then((status) => { + expect(status.jobid).toEqual(jobInfo.jobid); + expect(status.jobname).toEqual(jobInfo.jobname); + expect(status.status).toBe("ACTIVE"); + + // Wait for the status to be output MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "ACTIVE" - }).then((status) => { - expect(status.jobid).toEqual(jobInfo.jobid); - expect(status.jobname).toEqual(jobInfo.jobname); - expect(status.status).toBe("ACTIVE"); - - // Wait for the status to be output - MonitorJobs.waitForStatusCommon(REAL_SESSION, { - jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" - }).then((nextStatus) => { - expect(nextStatus.jobid).toEqual(jobInfo.jobid); - expect(nextStatus.jobname).toEqual(jobInfo.jobname); - expect(nextStatus.status).toBe("OUTPUT"); - done(); - }).catch((error) => { - done(`wait for status error: ${error.message}`); - }); + jobname: jobInfo.jobname, jobid: jobInfo.jobid, status: "OUTPUT" + }).then((nextStatus) => { + expect(nextStatus.jobid).toEqual(jobInfo.jobid); + expect(nextStatus.jobname).toEqual(jobInfo.jobname); + expect(nextStatus.status).toBe("OUTPUT"); + done(); }).catch((error) => { done(`wait for status error: ${error.message}`); }); - }).catch((submitErr) => { - done(`Job submission error: ${submitErr.message}`); + }).catch((error) => { + done(`wait for status error: ${error.message}`); }); - }, LONG_TIMEOUT); - /* eslint-enable jest/no-done-callback */ - }); + }).catch((submitErr) => { + done(`Job submission error: ${submitErr.message}`); + }); + }, LONG_TIMEOUT); + /* eslint-enable jest/no-done-callback */ }); }); -}); \ No newline at end of file +}); diff --git a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts index aa2b397f10..baf25132ae 100644 --- a/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SearchJobs.system.test.ts @@ -58,10 +58,10 @@ describe("Search Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_search_jobs" }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; defaultSystem = testEnvironment.systemTestProperties; + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); + INVALID_SESSION = new Session({ user: "fakeuser", password: "fake", diff --git a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts index 1b45d2ffd1..9f24590386 100644 --- a/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts +++ b/packages/zosjobs/__tests__/__system__/SubmitJobs.system.test.ts @@ -36,10 +36,9 @@ describe("Submit Jobs - System Tests", () => { testEnvironment = await TestEnvironment.setUp({ testName: "zos_submit_jobs" }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - testEnvironment.resources.session = REAL_SESSION; - systemProps = testEnvironment.systemTestProperties; + + REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); account = systemProps.tso.account; jobDataSet = testEnvironment.systemTestProperties.zosjobs.iefbr14PSDataSet; jobUSSFile = testEnvironment.systemTestProperties.zosjobs.iefbr14USSFile; @@ -221,12 +220,16 @@ describe("Submit Jobs - System Tests", () => { }); it("should return the job info of a submitted JCL string with extended options", async () => { - const job: any = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", { + const jobOrSpoolFiles = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", { jclSource: "stdin", internalReaderFileEncoding: "IBM-037", internalReaderLrecl: "80", internalReaderRecfm: "F" }); + + // Now `jobOrSpoolFiles` is guaranteed to be of type `IJob` + const job: IJob = jobOrSpoolFiles as IJob; + expect(job.jobid).toBeDefined(); expect(job.jobname).toBeDefined(); testEnvironment.resources.jobs.push(job); @@ -234,31 +237,21 @@ describe("Submit Jobs - System Tests", () => { it("should return an array of spool content", async () => { // Submit the JCL and request spool content to be returned - const result = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", { + const jobOrSpoolFiles = await SubmitJobs.submitJclString(REAL_SESSION, "//JOBNAME1 JOB", { jclSource: "stdin", viewAllSpoolContent: true }); - let job: IJob; - let spoolFiles: ISpoolFile[]; - - if (Array.isArray(result)) { - // result is an array of spool files - spoolFiles = result as ISpoolFile[]; + // Now `jobOrSpoolFiles` is guaranteed to be of type `ISpoolFile[]` + const spoolFiles: ISpoolFile[] = jobOrSpoolFiles as ISpoolFile[]; - // Ensure the first spool file contains the expected content - expect(spoolFiles[0].data.toString()).toContain("J E S 2 J O B L O G"); - - // Extract job ID from the spool file content - const jobLogContent = spoolFiles[0].data.toString(); - const jobIdMatch = jobLogContent.match(/JOB\d{5}/).toString(); - - job = await GetJobs.getJob(REAL_SESSION, jobIdMatch); - } else { - // result is a job - job = result as IJob; - } + expect(spoolFiles.constructor === Array).toBe(true); + expect(spoolFiles[0].data.toString()).toContain("J E S 2 J O B L O G"); + // Extract job ID from the spool file content + const jobLogContent = spoolFiles[0].data.toString(); + const jobIdMatch = jobLogContent.match(/JOB\d{5}/).toString(); + const job = await GetJobs.getJob(REAL_SESSION, jobIdMatch); testEnvironment.resources.jobs.push(job); }); From 336d3e4fdf064e95f1398c9ac762756c230788a2 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Mon, 14 Oct 2024 08:25:09 -0400 Subject: [PATCH 62/65] Fix remaining errors in system tests Signed-off-by: Timothy Johnson --- ...rkflows.list.active.details.system.test.ts | 12 ++-- ...kflows.list.activeWorkflows.system.test.ts | 6 +- ....retrieveWorkflowDefinition.system.test.ts | 10 +-- ...cli.workflows.create.common.system.test.ts | 54 +++++++------- .../cli.workflows.start.common.system.test.ts | 14 ++-- .../cli.files.invoke.amsFile.system.test.ts | 9 ++- .../dtu/cli.dir.upload.dtu.system.test.ts | 4 ++ .../delete/DeleteUSSFile.system.test.ts | 72 +++++++------------ .../methods/invoke/Invoke.system.test.ts | 9 ++- .../methods/upload/Upload.system.test.ts | 8 +-- 10 files changed, 95 insertions(+), 103 deletions(-) diff --git a/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts b/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts index cd8ae968ad..46d2c78b12 100644 --- a/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/List/activeWorkflowDetails/cli.workflows.list.active.details.system.test.ts @@ -66,16 +66,16 @@ describe("List active workflow details cli system tests", () => { afterAll(async () => { // deleting wf instance const response: any = await ZosmfRestClient.getExpectJSON(REAL_SESSION, "/zosmf/workflow/rest/1.0/workflows?workflowName=" + wfName); - response.workflows.forEach(async (element: any) => { + for (const element of response.workflows) { if (element.workflowName === wfName) { try { await DeleteWorkflow.deleteWorkflow(REAL_SESSION, element.workflowKey); } catch { /* Do nothing */ } } - }); + } }); describe("Success Scenarios", () => { - it("Should list active workflow details using wf key.", async () => { + it("Should list active workflow details using wf key.", () => { const response = runCliScript(__dirname + "/__scripts__/command/list_active_workflow_key_details.sh", testEnvironment, [wfKey]); expect(response.stderr.toString()).toBe(""); @@ -83,7 +83,7 @@ describe("List active workflow details cli system tests", () => { expect(response.stdout.toString()).toContain("Workflow Details"); }); - it("Should list active workflow details using wf name.", async () => { + it("Should list active workflow details using wf name.", () => { const response = runCliScript(__dirname + "/__scripts__/command/list_active_workflow_name_details.sh", testEnvironment, [wfName]); expect(response.stderr.toString()).toBe(""); @@ -92,14 +92,14 @@ describe("List active workflow details cli system tests", () => { }); }); describe("Failure Scenarios", () => { - it("Should throw error if the workflow does not exist", async () => { + it("Should throw error if the workflow does not exist", () => { const response = runCliScript(__dirname + "/__scripts__/command/list_active_workflow_key_details.sh", testEnvironment, [fakeDefFile]); expect(response.status).toBe(1); expect(response.stderr.toString()).toContain("does not exist."); }); - it("Should throw error if the workflow name does not exist", async () => { + it("Should throw error if the workflow name does not exist", () => { const response = runCliScript(__dirname + "/__scripts__/command/list_active_workflow_name_details.sh", testEnvironment, [fakeDefFile]); expect(response.status).toBe(1); diff --git a/packages/cli/__tests__/workflows/__system__/List/activeWorkflows/cli.workflows.list.activeWorkflows.system.test.ts b/packages/cli/__tests__/workflows/__system__/List/activeWorkflows/cli.workflows.list.activeWorkflows.system.test.ts index 2bacd0116d..7769bbc0cf 100644 --- a/packages/cli/__tests__/workflows/__system__/List/activeWorkflows/cli.workflows.list.activeWorkflows.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/List/activeWorkflows/cli.workflows.list.activeWorkflows.system.test.ts @@ -64,16 +64,16 @@ describe("List workflow cli system tests", () => { } }); describe("Success Scenarios", () => { - it("Should return list of workflows in zOSMF.", async () => { + it("Should return list of workflows in zOSMF.", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_list_workflow.sh", testEnvironment, [wfName]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain(`${wfName}`); }); - it("Should return a message if search does not match any existing workflows", async () => { + it("Should return a message if search does not match any existing workflows", () => { const fakeName = `${wfName}${wfName}${wfName}`; - const response = await runCliScript(__dirname + "/__scripts__/command/command_list_workflow.sh", + const response = runCliScript(__dirname + "/__scripts__/command/command_list_workflow.sh", testEnvironment, [fakeName]); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("No workflows match the requested querry"); diff --git a/packages/cli/__tests__/workflows/__system__/List/retrieveWorkflowDefinition/cli.workflows.list.retrieveWorkflowDefinition.system.test.ts b/packages/cli/__tests__/workflows/__system__/List/retrieveWorkflowDefinition/cli.workflows.list.retrieveWorkflowDefinition.system.test.ts index 06b0c03045..67d2d79e0d 100644 --- a/packages/cli/__tests__/workflows/__system__/List/retrieveWorkflowDefinition/cli.workflows.list.retrieveWorkflowDefinition.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/List/retrieveWorkflowDefinition/cli.workflows.list.retrieveWorkflowDefinition.system.test.ts @@ -52,23 +52,23 @@ describe("Retrieve workflow definition cli system tests", () => { testEnvironment.resources.files.push(definitionFile); }); describe("Success Scenarios", () => { - it("Should return the details of a workflow definition file.", async () => { + it("Should return the details of a workflow definition file.", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_definition_file_details.sh", testEnvironment, [`/${defaultSystem.unix.testdir.toLocaleLowerCase()}/${uniqueFileName}.xml`]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain(`success": true`); }); - it("Should return a message if search does not match any existing files", async () => { - const response = await runCliScript(__dirname + "/__scripts__/command/command_definition_file_details.sh", + it("Should return a message if search does not match any existing files", () => { + const response = runCliScript(__dirname + "/__scripts__/command/command_definition_file_details.sh", testEnvironment, [`/${defaultSystem.unix.testdir.toLocaleLowerCase()}/${uniqueFileName}`]); expect(response.status).toBe(1); expect(response.stdout.toString()).toContain("not found or cannot be accessed."); }); - it("Should return a message if search is for a diectory", async () => { + it("Should return a message if search is for a diectory", () => { const fakeName = `/${defaultSystem.unix.testdir.toLocaleLowerCase()}`; - const response = await runCliScript(__dirname + "/__scripts__/command/command_definition_file_details.sh", + const response = runCliScript(__dirname + "/__scripts__/command/command_definition_file_details.sh", testEnvironment, [fakeName]); expect(response.status).toBe(1); expect(response.stdout.toString()).toContain("is not a UNIX file"); diff --git a/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts b/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts index 53727050d4..6ff331aa12 100644 --- a/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts @@ -64,7 +64,7 @@ describe("Create workflow cli system tests", () => { afterEach(async () => { let error; const response: any = await ZosmfRestClient.getExpectJSON(REAL_SESSION, "/zosmf/workflow/rest/1.0/workflows?workflowName=" + wfName); - response.workflows.forEach(async (element: any) => { + for (const element of response.workflows) { if (element.workflowName === wfName) { wfKey = element.workflowKey; try { @@ -73,25 +73,25 @@ describe("Create workflow cli system tests", () => { error = err; } } - }); + } }); - it("Should create workflow in zOSMF.", async () => { + it("Should create workflow in zOSMF.", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", testEnvironment, [wfName, definitionFile, system, owner]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("workflowKey"); }); - it("Should throw error if workflow with the same name already exists", async () => { - const createWf = await runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", + it("Should throw error if workflow with the same name already exists", () => { + const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", testEnvironment, [wfName, definitionFile, system, owner]); const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", testEnvironment, [wfName, definitionFile, system, owner]); expect(response.status).toBe(1); expect(response.stderr.toString()).toContain("already exists."); }); - it("Should not throw error if workflow with the same name already exists and there is overwrite", async () => { - const createWf = await runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", + it("Should not throw error if workflow with the same name already exists and there is overwrite", () => { + const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", testEnvironment, [wfName, definitionFile, system, owner]); const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", testEnvironment, [wfName, definitionFile, system, owner, "--overwrite"]); @@ -101,7 +101,7 @@ describe("Create workflow cli system tests", () => { }); }); describe("Failure Scenarios", () => { - it("Should throw error if the uss file does not exist", async () => { + it("Should throw error if the uss file does not exist", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", testEnvironment, [wfName, fakeDefFile, system, owner]); expect(response.status).toBe(1); @@ -113,7 +113,7 @@ describe("Create workflow cli system tests", () => { describe("Success Scenarios", () => { afterEach(async () =>{ let error; - const response: any = await ZosmfRestClient.getExpectJSON(REAL_SESSION, "/zosmf/workflow/rest/1.0/workflows?workflowName=" + wfName); + const response: any = await ZosmfRestClient.getExpectJSON(REAL_SESSION, "/zosmf/workflow/rest/1.0/workflows?workflowName=" + wfName); let deleteWorkflow: any; for (deleteWorkflow of response.workflows) { if(deleteWorkflow.workflowName===wfName){ @@ -126,25 +126,25 @@ describe("Create workflow cli system tests", () => { } } }); - it("Should create workflow in zOSMF.", async () => { - const response = await runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", + it("Should create workflow in zOSMF.", () => { + const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", testEnvironment, [wfName, workflow, system, owner]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("workflowKey"); }); - it("Should throw error if workflow with the same name already exists", async () => { - const createWf = await runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", + it("Should throw error if workflow with the same name already exists", () => { + const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", testEnvironment, [wfName, workflow, system, owner]); - const response = await runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", + const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", testEnvironment, [wfName, workflow, system, owner]); expect(response.status).toBe(1); expect(response.stderr.toString()).toContain("already exists."); }); - it("Should not throw error if workflow with the same name already exists and there is overwrite", async () => { - const createWf = await runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", + it("Should not throw error if workflow with the same name already exists and there is overwrite", () => { + const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", testEnvironment, [wfName, workflow, system, owner]); - const response = await runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", + const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", testEnvironment, [wfName, workflow, system, owner, "--overwrite"]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); @@ -152,8 +152,8 @@ describe("Create workflow cli system tests", () => { }); }); describe("Failure Scenarios", () => { - it("Should throw error if the local file does not exist", async () => { - const response = await runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", + it("Should throw error if the local file does not exist", () => { + const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", testEnvironment, [wfName, fakeLocalFile, system, owner]); expect(response.status).toBe(1); expect(response.stderr.toString()).toContain("no such file or directory"); @@ -179,7 +179,7 @@ describe("Create workflow cli system tests", () => { afterEach(async () => { let error; const response: any = await ZosmfRestClient.getExpectJSON(REAL_SESSION, "/zosmf/workflow/rest/1.0/workflows?workflowName=" + wfName); - response.workflows.forEach(async (element: any) => { + for (const element of response.workflows) { if (element.workflowName === wfName) { wfKey = element.workflowKey; try { @@ -188,25 +188,25 @@ describe("Create workflow cli system tests", () => { error = err; } } - }); + } }); - it("Should create workflow in zOSMF.", async () => { + it("Should create workflow in zOSMF.", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", testEnvironment, [wfName, definitionDs, system, owner]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("workflowKey"); }); - it("Should throw error if workflow with the same name already exists", async () => { - const createWf = await runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", + it("Should throw error if workflow with the same name already exists", () => { + const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", testEnvironment, [wfName, definitionDs, system, owner]); const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", testEnvironment, [wfName, definitionDs, system, owner]); expect(response.status).toBe(1); expect(response.stderr.toString()).toContain("already exists."); }); - it("Should not throw error if workflow with the same name already exists and there is overwrite", async () => { - const createWf = await runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", + it("Should not throw error if workflow with the same name already exists and there is overwrite", () => { + const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", testEnvironment, [wfName, definitionDs, system, owner]); const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", testEnvironment, [wfName, definitionDs, system, owner, "--overwrite"]); @@ -216,7 +216,7 @@ describe("Create workflow cli system tests", () => { }); }); describe("Failure Scenarios", () => { - it("Should throw error if the dataset does not exist", async () => { + it("Should throw error if the dataset does not exist", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", testEnvironment, [wfName, fakeDefFile, system, owner]); expect(response.status).toBe(1); diff --git a/packages/cli/__tests__/workflows/__system__/start/cli.workflows.start.common.system.test.ts b/packages/cli/__tests__/workflows/__system__/start/cli.workflows.start.common.system.test.ts index 875a9c6748..699a9d2e84 100644 --- a/packages/cli/__tests__/workflows/__system__/start/cli.workflows.start.common.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/start/cli.workflows.start.common.system.test.ts @@ -85,42 +85,42 @@ describe("Start workflow cli system tests", () => { Imperative.console.info(err); } }); - it("Should start full workflow using wf key in zOSMF.", async () => { + it("Should start full workflow using wf key in zOSMF.", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_start_workflow_key_full.sh", testEnvironment, [wfKey, resolveConflict]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Workflow"); }); - it("Should start full workflow using wf Name in zOSMF.", async () => { - const response = await runCliScript(__dirname + "/__scripts__/command/command_start_workflow_name_full.sh", + it("Should start full workflow using wf Name in zOSMF.", () => { + const response = runCliScript(__dirname + "/__scripts__/command/command_start_workflow_name_full.sh", testEnvironment, [wfName, resolveConflict]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Workflow"); }); - it("Should start one workflow using wf Key and step.", async () => { + it("Should start one workflow using wf Key and step.", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_start_workflow_key_step.sh", testEnvironment, [stepName, wfKey, resolveConflict]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Workflow step started."); }); - it("Should start one workflow using wf Name and step.", async () => { + it("Should start one workflow using wf Name and step.", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_start_workflow_name_step.sh", testEnvironment, [stepName, wfName, resolveConflict]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Workflow step started."); }); - it("Should start one workflow step using wf Key.", async () => { + it("Should start one workflow step using wf Key.", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_start_workflow_key_step_plus_following.sh", testEnvironment, [stepName, wfKey, resolveConflict, "--perform-following-steps"]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Workflow step started."); }); - it("Should start one workflow step using wf Name.", async () => { + it("Should start one workflow step using wf Name.", () => { const response = runCliScript(__dirname + "/__scripts__/command/command_start_workflow_name_step_plus_following.sh", testEnvironment, [stepName, wfName, resolveConflict, "--perform-following-steps"]); expect(response.stderr.toString()).toBe(""); diff --git a/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts index 93462e7af2..dfaa85ddd0 100644 --- a/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/invoke/amsFile/cli.files.invoke.amsFile.system.test.ts @@ -32,9 +32,12 @@ describe("Invoke AMS CLI", () => { // replace high-level-qualifier with user value const AMSStatement = fs.readFileSync(templateFile).toString(); const updatedStatement = TextUtils.renderWithMustache(AMSStatement, {DSN: dsname, VOL: volume}); - fs.writeFileSync(templateFile + ".temp", updatedStatement); - testEnvironment.resources.localFiles.push(templateFile + ".temp"); - return templateFile + ".temp"; + const filename = templateFile + ".temp"; + fs.writeFileSync(filename, updatedStatement); + if (!testEnvironment.resources.localFiles.includes(filename)) { + testEnvironment.resources.localFiles.push(filename); + } + return filename; } // Create the unique test environment diff --git a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts index 99af5f7f6f..1b44460015 100644 --- a/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts +++ b/packages/cli/__tests__/zosfiles/__system__/upload/dtu/cli.dir.upload.dtu.system.test.ts @@ -260,6 +260,10 @@ describe("Upload directory to USS", () => { }); describe("Scenarios using the .zosattributes file", () => { + afterEach(async () => { + await deleteFiles(REAL_SESSION, ussname); + }); + it("should ignore files marked with a -", async () => { const localDirName = path.join(__dirname, "__data__", "command_upload_dtu_dir/dir_with_ignored_files"); testSuccessfulUpload(localDirName); diff --git a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts index ecb0633e63..f65a035fde 100644 --- a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts @@ -20,7 +20,6 @@ let REAL_SESSION: Session; let testEnvironment: ITestEnvironment; let defaultSystem: ITestPropertiesSchema; let ussname: string; -let filename: string; describe("Delete a USS File", () => { @@ -31,7 +30,7 @@ describe("Delete a USS File", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - ussname = `${defaultSystem.unix.testdir}/${defaultSystem.zosmf.user.trim()}`; + ussname = `${defaultSystem.unix.testdir}/${defaultSystem.zosmf.user.trim()}.aTestUssFileSingle`.replace(/\./g, ""); }); afterAll(async () => { @@ -42,9 +41,8 @@ describe("Delete a USS File", () => { beforeEach(async () => { let error; let response; - filename = `${ussname}.aTestUssFileSingle`.replace(/\./g, ""); try { - response = await Create.uss(REAL_SESSION, filename, "file"); + response = await Create.uss(REAL_SESSION, ussname, "file"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -56,7 +54,7 @@ describe("Delete a USS File", () => { let response; try { - response = await Delete.ussFile(REAL_SESSION, filename); + response = await Delete.ussFile(REAL_SESSION, ussname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -74,7 +72,7 @@ describe("Delete a USS File", () => { let response; try { - response = await Delete.ussFile(REAL_SESSION, filename, undefined, {responseTimeout: 5}); + response = await Delete.ussFile(REAL_SESSION, ussname, undefined, {responseTimeout: 5}); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -92,7 +90,7 @@ describe("Delete a USS File", () => { let response; try { - response = await Delete.ussFile(REAL_SESSION, "//"+filename); + response = await Delete.ussFile(REAL_SESSION, "//"+ussname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -153,7 +151,7 @@ describe("Delete a USS File - encoded", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - ussname = `${defaultSystem.unix.testdir}/${defaultSystem.zosmf.user.trim() + ".Enco#ed"}`; + ussname = `${defaultSystem.unix.testdir}/${defaultSystem.zosmf.user.trim()}.Enco#ed.aTestUssFileSingle`.replace(/\./g, ""); }); afterAll(async () => { @@ -163,9 +161,8 @@ describe("Delete a USS File - encoded", () => { describe("Success scenarios", () => { beforeEach(async () => { let error; - filename = `${ussname}.aTestUssFileSingle`.replace(/\./g, ""); try { - await Create.uss(REAL_SESSION, filename, "file"); + await Create.uss(REAL_SESSION, ussname, "file"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -177,7 +174,7 @@ describe("Delete a USS File - encoded", () => { let response; try { - response = await Delete.ussFile(REAL_SESSION, filename); + response = await Delete.ussFile(REAL_SESSION, ussname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -195,7 +192,7 @@ describe("Delete a USS File - encoded", () => { let response; try { - response = await Delete.ussFile(REAL_SESSION, "//"+filename); + response = await Delete.ussFile(REAL_SESSION, "//"+ussname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -219,7 +216,7 @@ describe("Delete USS Directory", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - filename = `${defaultSystem.unix.testdir}/${ussname}.aTestUssFolderDelete`.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/${defaultSystem.zosmf.user.trim()}.aTestUssFolderDelete`.replace(/\./g, ""); }); afterAll(async () => { @@ -231,7 +228,7 @@ describe("Delete USS Directory", () => { let error; let response; try { - response = await Create.uss(REAL_SESSION, filename, "directory"); + response = await Create.uss(REAL_SESSION, ussname, "directory"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -243,7 +240,7 @@ describe("Delete USS Directory", () => { let response; try { - response = await Delete.ussFile(REAL_SESSION, filename); + response = await Delete.ussFile(REAL_SESSION, ussname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -258,21 +255,6 @@ describe("Delete USS Directory", () => { }); describe("Failure scenarios", () => { - beforeAll(async () => { - let error; - let response; - // ussname = ussname.replace(/\./g, ""); - filename = `${defaultSystem.unix.testdir}/${ussname}`; - try { - response = await Create.uss(REAL_SESSION, filename, "directory"); - } catch (err) { - error = err; - Imperative.console.info("Error: " + inspect(error)); - } - }); - afterAll(async () => { - await TestEnvironment.cleanUp(testEnvironment); - }); it("should display proper error message when called with invalid directory name", async () => { let error; let response; @@ -318,7 +300,7 @@ describe("Delete USS Directory - encoded", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - filename = `${defaultSystem.unix.testdir}/${ussname}.Enco#ed.aTestUssFolderDelete`.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/${defaultSystem.zosmf.user.trim()}.Enco#ed.aTestUssFolderDelete`.replace(/\./g, ""); }); afterAll(async () => { @@ -330,7 +312,7 @@ describe("Delete USS Directory - encoded", () => { let error; let response; try { - response = await Create.uss(REAL_SESSION, filename, "directory"); + response = await Create.uss(REAL_SESSION, ussname, "directory"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -342,7 +324,7 @@ describe("Delete USS Directory - encoded", () => { let response; try { - response = await Delete.ussFile(REAL_SESSION, filename); + response = await Delete.ussFile(REAL_SESSION, ussname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -366,7 +348,7 @@ describe("Delete USS Directory with children", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - filename = `${defaultSystem.unix.testdir}/${ussname}.aTestUssFileDelete`.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/${defaultSystem.zosmf.user.trim()}.aTestUssFileDelete`.replace(/\./g, ""); }); afterAll(async () => { @@ -378,13 +360,13 @@ describe("Delete USS Directory with children", () => { let error; let response; try { - response = await Create.uss(REAL_SESSION, filename, "directory"); + response = await Create.uss(REAL_SESSION, ussname, "directory"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } try { - response = await Create.uss(REAL_SESSION, `${filename}/aChild.txt`, "file"); + response = await Create.uss(REAL_SESSION, `${ussname}/aChild.txt`, "file"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -395,7 +377,7 @@ describe("Delete USS Directory with children", () => { let error; let response; try { - response = await Delete.ussFile(REAL_SESSION, filename, true); + response = await Delete.ussFile(REAL_SESSION, ussname, true); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -412,13 +394,13 @@ describe("Delete USS Directory with children", () => { beforeEach(async () => { let error; try { - await Create.uss(REAL_SESSION, filename, "directory"); + await Create.uss(REAL_SESSION, ussname, "directory"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } try { - await Create.uss(REAL_SESSION, `${filename}/aChild.txt`, "file"); + await Create.uss(REAL_SESSION, `${ussname}/aChild.txt`, "file"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -437,7 +419,7 @@ describe("Delete USS Directory with children", () => { let error; let response; try { - response = await Delete.ussFile(REAL_SESSION, filename); + response = await Delete.ussFile(REAL_SESSION, ussname); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -452,7 +434,7 @@ describe("Delete USS Directory with children", () => { let error; let response; try { - response = await Delete.ussFile(REAL_SESSION, filename, false); + response = await Delete.ussFile(REAL_SESSION, ussname, false); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; @@ -474,7 +456,7 @@ describe("Delete USS Directory with children - encoded", () => { defaultSystem = testEnvironment.systemTestProperties; REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - filename = `${defaultSystem.unix.testdir}/${ussname}.Enco#ed.aTestUssFileDelete`.replace(/\./g, ""); + ussname = `${defaultSystem.unix.testdir}/${defaultSystem.zosmf.user.trim()}.Enco#ed.aTestUssFileDelete`.replace(/\./g, ""); }); afterAll(async () => { @@ -485,13 +467,13 @@ describe("Delete USS Directory with children - encoded", () => { beforeEach(async () => { let error; try { - await Create.uss(REAL_SESSION, filename, "directory"); + await Create.uss(REAL_SESSION, ussname, "directory"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } try { - await Create.uss(REAL_SESSION, `${filename}/aChild.txt`, "file"); + await Create.uss(REAL_SESSION, `${ussname}/aChild.txt`, "file"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -502,7 +484,7 @@ describe("Delete USS Directory with children - encoded", () => { let error; let response; try { - response = await Delete.ussFile(REAL_SESSION, filename, true); + response = await Delete.ussFile(REAL_SESSION, ussname, true); Imperative.console.info("Response: " + inspect(response)); } catch (err) { error = err; diff --git a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts index 5e8e361bc9..a1daccc33d 100644 --- a/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/invoke/Invoke.system.test.ts @@ -48,9 +48,12 @@ describe("Invoke AMS", () => { // replace DSN with unique data set name const AMSStatement = fs.readFileSync(templateFile).toString(); const updatedStatement = TextUtils.renderWithMustache(AMSStatement, {DSN: dsname, VOL: volume}); - fs.writeFileSync(templateFile + ".temp", updatedStatement); - testEnvironment.resources.localFiles.push(templateFile + ".temp"); - return templateFile + ".temp"; + const filename = templateFile + ".temp"; + fs.writeFileSync(filename, updatedStatement); + if (!testEnvironment.resources.localFiles.includes(filename)) { + testEnvironment.resources.localFiles.push(filename); + } + return filename; } it("should create and delete a VSAM data set from command statement in files", async () => { diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index 00f1f56950..e0797df365 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -941,14 +941,14 @@ describe("Upload a local directory to USS directory", () => { Imperative.console.info("Using ussfile:" + ussname); }); - beforeEach(() => { - tempUssname = null; - }); - afterAll(async () => { await TestEnvironment.cleanUp(testEnvironment); }); + beforeEach(() => { + tempUssname = null; + }); + afterEach(async () => { await deleteFiles(REAL_SESSION, tempUssname ?? ussname); }); From 7068b6cf00802f52b70108b0f543b324d125b278 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Mon, 14 Oct 2024 14:58:40 -0400 Subject: [PATCH 63/65] Address unused variables found by CodeQL Signed-off-by: Timothy Johnson --- ...cli.workflows.create.common.system.test.ts | 12 +++++------ .../cli.zos-jobs.cancel.job.system.test.ts | 20 +++++++------------ .../issue/cli.issue.ssh.system.test.ts | 2 +- .../delete/DeleteUSSFile.system.test.ts | 14 +++++-------- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts b/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts index 6ff331aa12..7517ebed7b 100644 --- a/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts +++ b/packages/cli/__tests__/workflows/__system__/create/cli.workflows.create.common.system.test.ts @@ -83,7 +83,7 @@ describe("Create workflow cli system tests", () => { expect(response.stdout.toString()).toContain("workflowKey"); }); it("Should throw error if workflow with the same name already exists", () => { - const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", + runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", testEnvironment, [wfName, definitionFile, system, owner]); const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", testEnvironment, [wfName, definitionFile, system, owner]); @@ -91,7 +91,7 @@ describe("Create workflow cli system tests", () => { expect(response.stderr.toString()).toContain("already exists."); }); it("Should not throw error if workflow with the same name already exists and there is overwrite", () => { - const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", + runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", testEnvironment, [wfName, definitionFile, system, owner]); const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_uss.sh", testEnvironment, [wfName, definitionFile, system, owner, "--overwrite"]); @@ -134,7 +134,7 @@ describe("Create workflow cli system tests", () => { expect(response.stdout.toString()).toContain("workflowKey"); }); it("Should throw error if workflow with the same name already exists", () => { - const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", + runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", testEnvironment, [wfName, workflow, system, owner]); const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", testEnvironment, [wfName, workflow, system, owner]); @@ -142,7 +142,7 @@ describe("Create workflow cli system tests", () => { expect(response.stderr.toString()).toContain("already exists."); }); it("Should not throw error if workflow with the same name already exists and there is overwrite", () => { - const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", + runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", testEnvironment, [wfName, workflow, system, owner]); const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_local_file.sh", testEnvironment, [wfName, workflow, system, owner, "--overwrite"]); @@ -198,7 +198,7 @@ describe("Create workflow cli system tests", () => { expect(response.stdout.toString()).toContain("workflowKey"); }); it("Should throw error if workflow with the same name already exists", () => { - const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", + runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", testEnvironment, [wfName, definitionDs, system, owner]); const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", testEnvironment, [wfName, definitionDs, system, owner]); @@ -206,7 +206,7 @@ describe("Create workflow cli system tests", () => { expect(response.stderr.toString()).toContain("already exists."); }); it("Should not throw error if workflow with the same name already exists and there is overwrite", () => { - const createWf = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", + runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", testEnvironment, [wfName, definitionDs, system, owner]); const response = runCliScript(__dirname + "/__scripts__/command/command_create_workflow_ds.sh", testEnvironment, [wfName, definitionDs, system, owner, "--overwrite"]); diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index d23f6847db..8f52c7b7e1 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -56,7 +56,7 @@ describe("zos-jobs cancel job command", () => { it("should surface an error from z/OSMF if the jobid was already canceled", () => { runCliScript(__dirname + "/__scripts__/job/submit_job.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); const response = runCliScript(__dirname + "/__scripts__/job/cancel_job_v2_bad.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); - const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; + const jobid = response.stdout.toString().match(jobDataRegex).pop(); TEST_ENVIRONMENT.resources.jobs.push(jobid); // Calculate the previous job ID (one less) - jobid created by test before, inaccessible until now @@ -75,37 +75,34 @@ describe("zos-jobs cancel job command", () => { describe("successful scenario", () => { it("should cancel a job v1", () => { const response = runCliScript(__dirname + "/__scripts__/job/cancel_job_v1.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); - const [, jobname, jobid] = response.stdout.toString().match(jobDataRegexV1) || []; - expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully submitted request to cancel job"); + const jobid = response.stdout.toString().match(jobDataRegexV1).pop(); TEST_ENVIRONMENT.resources.jobs.push(jobid); }); it("should cancel a job v2", () => { const response = runCliScript(__dirname + "/__scripts__/job/cancel_job_v2.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); - const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; - expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully canceled job"); expect(response.stdout.toString()).not.toContain("Failed to cancel job"); + const jobid = response.stdout.toString().match(jobDataRegex).pop(); TEST_ENVIRONMENT.resources.jobs.push(jobid); }); it("should cancel a job default", () => { const response = runCliScript(__dirname + "/__scripts__/job/cancel_job.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); - const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; - expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully canceled job"); expect(response.stdout.toString()).not.toContain("Failed to cancel job"); expect(response.stdout.toString()).not.toContain("Failed to cancel job"); + const jobid = response.stdout.toString().match(jobDataRegex).pop(); TEST_ENVIRONMENT.resources.jobs.push(jobid); }); @@ -137,12 +134,11 @@ describe("zos-jobs cancel job command", () => { DEFAULT_SYSTEM_PROPS.zosmf.user, DEFAULT_SYSTEM_PROPS.zosmf.password, ]); - const [, jobname, jobid] = response.stdout.toString().match(jobDataRegexV1) || []; - expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully submitted request to cancel job"); + const jobid = response.stdout.toString().match(jobDataRegexV1).pop(); TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(jobid); }); @@ -156,12 +152,11 @@ describe("zos-jobs cancel job command", () => { DEFAULT_SYSTEM_PROPS.zosmf.user, DEFAULT_SYSTEM_PROPS.zosmf.password, ]); - const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; - expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully canceled job"); + const jobid = response.stdout.toString().match(jobDataRegex).pop(); TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(jobid); }); @@ -175,12 +170,11 @@ describe("zos-jobs cancel job command", () => { DEFAULT_SYSTEM_PROPS.zosmf.user, DEFAULT_SYSTEM_PROPS.zosmf.password, ]); - const [, jobname, jobid] = response.stdout.toString().match(jobDataRegex) || []; - expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Successfully canceled job"); + const jobid = response.stdout.toString().match(jobDataRegex).pop(); TEST_ENVIRONMENT_NO_PROF.resources.jobs.push(jobid); }); }); diff --git a/packages/cli/__tests__/zosuss/__system__/issue/cli.issue.ssh.system.test.ts b/packages/cli/__tests__/zosuss/__system__/issue/cli.issue.ssh.system.test.ts index d4bd68cfa1..b74ab3e7a5 100644 --- a/packages/cli/__tests__/zosuss/__system__/issue/cli.issue.ssh.system.test.ts +++ b/packages/cli/__tests__/zosuss/__system__/issue/cli.issue.ssh.system.test.ts @@ -119,7 +119,7 @@ describe("Use a test directory to do stuff in that creates files", () => { const directory = `${defaultSystem.unix.testdir}/`; const commandName = "rm -rf " + directory + "usstest"; // Imperative.console.info("Remove test directory cmd:" + commandName); - const response = runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); + runCliScript(__dirname + "/__scripts__/issue_ssh_no_cwd.sh", TEST_ENVIRONMENT, [commandName]); // Imperative.console.info("Remove Response:" + response.stdout.toString()); await TestEnvironment.cleanUp(TEST_ENVIRONMENT); diff --git a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts index f65a035fde..3c005f6d66 100644 --- a/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/delete/DeleteUSSFile.system.test.ts @@ -40,9 +40,8 @@ describe("Delete a USS File", () => { describe("Success scenarios", () => { beforeEach(async () => { let error; - let response; try { - response = await Create.uss(REAL_SESSION, ussname, "file"); + await Create.uss(REAL_SESSION, ussname, "file"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -226,9 +225,8 @@ describe("Delete USS Directory", () => { describe("Success scenarios", () => { beforeEach(async () => { let error; - let response; try { - response = await Create.uss(REAL_SESSION, ussname, "directory"); + await Create.uss(REAL_SESSION, ussname, "directory"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -310,9 +308,8 @@ describe("Delete USS Directory - encoded", () => { describe("Success scenarios", () => { beforeEach(async () => { let error; - let response; try { - response = await Create.uss(REAL_SESSION, ussname, "directory"); + await Create.uss(REAL_SESSION, ussname, "directory"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -358,15 +355,14 @@ describe("Delete USS Directory with children", () => { describe("Success scenarios", () => { beforeEach(async () => { let error; - let response; try { - response = await Create.uss(REAL_SESSION, ussname, "directory"); + await Create.uss(REAL_SESSION, ussname, "directory"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); } try { - response = await Create.uss(REAL_SESSION, `${ussname}/aChild.txt`, "file"); + await Create.uss(REAL_SESSION, `${ussname}/aChild.txt`, "file"); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); From f7f669672608c85d7c457ed449b2be3f48c5814c Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Mon, 14 Oct 2024 15:37:04 -0400 Subject: [PATCH 64/65] Fix system tests for cancel and search jobs Signed-off-by: Timothy Johnson --- .../cancel/__scripts__/job/submit_job.sh | 5 +- .../cli.zos-jobs.cancel.job.system.test.ts | 13 +-- ...job_submit.sh => missing_search_string.sh} | 7 +- .../__scripts__/job/search_job_regex.sh | 8 ++ .../__scripts__/job/search_job_string.sh | 8 ++ .../job/search_string_spool_content.sh | 27 ----- ...=> cli.zos-jobs.search.job.system.test.ts} | 108 ++++++------------ 7 files changed, 63 insertions(+), 113 deletions(-) rename packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/{search_no_job_submit.sh => missing_search_string.sh} (59%) mode change 100644 => 100755 create mode 100755 packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_job_regex.sh create mode 100755 packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_job_string.sh delete mode 100644 packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_string_spool_content.sh rename packages/cli/__tests__/zosjobs/__system__/search/{cli.zos-jobs.search.job.test.ts => cli.zos-jobs.search.job.system.test.ts} (50%) diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/__scripts__/job/submit_job.sh b/packages/cli/__tests__/zosjobs/__system__/cancel/__scripts__/job/submit_job.sh index 7ae64e877c..67035c9236 100755 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/__scripts__/job/submit_job.sh +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/__scripts__/job/submit_job.sh @@ -14,4 +14,7 @@ then echo $JOBID 1>&2 echo "Submit returned a non-zero return code" 1>&2 exit $RC -fi \ No newline at end of file +fi + +# Echo the JOBID for retrieval in tests +echo "Submitted job ID: $JOBID" diff --git a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts index 8f52c7b7e1..06bc908393 100644 --- a/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/cancel/cli.zos-jobs.cancel.job.system.test.ts @@ -54,15 +54,14 @@ describe("zos-jobs cancel job command", () => { }); it("should surface an error from z/OSMF if the jobid was already canceled", () => { - runCliScript(__dirname + "/__scripts__/job/submit_job.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); - const response = runCliScript(__dirname + "/__scripts__/job/cancel_job_v2_bad.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); - const jobid = response.stdout.toString().match(jobDataRegex).pop(); + let response = runCliScript(__dirname + "/__scripts__/job/submit_job.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); + const jobidRegex = /Submitted job ID: (JOB\d+)/; + let jobid = response.stdout.toString().match(jobidRegex).pop(); TEST_ENVIRONMENT.resources.jobs.push(jobid); - // Calculate the previous job ID (one less) - jobid created by test before, inaccessible until now - const jobidNumber = parseInt(jobid.replace('JOB', ''), 10); //Extract the numeric part of the job ID - const previousJobid = 'JOB' + String(jobidNumber - 1).padStart(5, '0'); // then decrement by 1, assuming 5 digits in the job ID - TEST_ENVIRONMENT.resources.jobs.push(previousJobid); + response = runCliScript(__dirname + "/__scripts__/job/cancel_job_v2_bad.sh", TEST_ENVIRONMENT, [LOCAL_JCL_FILE]); + jobid = response.stdout.toString().match(jobDataRegex).pop(); + TEST_ENVIRONMENT.resources.jobs.push(jobid); expect(response.status).toBe(1); expect(response.stderr.toString()).toContain("Failed to cancel job"); diff --git a/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_no_job_submit.sh b/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/missing_search_string.sh old mode 100644 new mode 100755 similarity index 59% rename from packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_no_job_submit.sh rename to packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/missing_search_string.sh index ccd3f9f253..60d1fa596f --- a/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_no_job_submit.sh +++ b/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/missing_search_string.sh @@ -1,11 +1,8 @@ #!/bin/bash -zowe jobs search job "$1" $2 +zowe jobs search job "$1" RC=$? -if [ $RC -gt 0 ] -then - echo $STATUS 1>&2 +if [ $RC -gt 0 ]; then echo "The search spool job command returned a non-zero rc: $RC" 1>&2 exit $RC fi - diff --git a/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_job_regex.sh b/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_job_regex.sh new file mode 100755 index 0000000000..f945ab2063 --- /dev/null +++ b/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_job_regex.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +zowe jobs search job "$1" --search-regex "$2" ${@:3} +RC=$? +if [ $RC -gt 0 ]; then + echo "The search spool job command returned a non-zero rc: $RC" 1>&2 + exit $RC +fi diff --git a/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_job_string.sh b/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_job_string.sh new file mode 100755 index 0000000000..da2bdb98c4 --- /dev/null +++ b/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_job_string.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +zowe jobs search job "$1" --search-string "$2" ${@:3} +RC=$? +if [ $RC -gt 0 ]; then + echo "The search spool job command returned a non-zero rc: $RC" 1>&2 + exit $RC +fi diff --git a/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_string_spool_content.sh b/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_string_spool_content.sh deleted file mode 100644 index 832ba5067a..0000000000 --- a/packages/cli/__tests__/zosjobs/__system__/search/__scripts__/job/search_string_spool_content.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Submit the job and ensure the RC is 0 -JOBID="$(zowe jobs submit ds "$1" --wfo true --rff jobid --rft string)" -CMDRC=$? -echo "Job ID: $JOBID" -if [ $CMDRC -gt 0 ]; then - echo "Job submission failed with return code $CMDRC" 1>&2 - exit $CMDRC -fi - -# Ensure the job ID is valid -if [ -z "$JOBID" ]; then - echo "Job ID is empty, cannot proceed with the search." 1>&2 - exit 1 -fi - -# Wait for a few seconds to ensure job output is available -sleep 5 - -# Search the job's spool files -zowe jobs search job "$JOBID" --search-string "$3" -RC=$? -if [ $RC -gt 0 ]; then - echo "The search spool job command returned a non-zero rc: $RC" 1>&2 - exit $RC -fi \ No newline at end of file diff --git a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.system.test.ts similarity index 50% rename from packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts rename to packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.system.test.ts index bfb03dee69..afbc82be18 100644 --- a/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.test.ts +++ b/packages/cli/__tests__/zosjobs/__system__/search/cli.zos-jobs.search.job.system.test.ts @@ -9,126 +9,88 @@ * */ -import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; -import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; import { runCliScript } from "@zowe/cli-test-utils"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { wait, waitTime } from "../../../../../../__tests__/__src__/TestUtils"; import { Session } from "@zowe/imperative"; -import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; +import { ITestEnvironment } from "../../../../../../__tests__/__src__/environment/ITestEnvironment"; +import { SubmitJobs } from "@zowe/zos-jobs-for-zowe-sdk"; // Test Environment populated in the beforeAll(); -let testEnvironment: ITestEnvironment; -let IEFBR14_JOB: string; +let TEST_ENVIRONMENT: ITestEnvironment; let REAL_SESSION: Session; -let ACCOUNT: string; let JOB_NAME: string; -let NON_HELD_JOBCLASS: string; -let SEARCH_STRING: string; -let REGEX_STRING: string; -let BAD_SEARCH_STRING: string; -let defaultSystem: ITestPropertiesSchema; +const SEARCH_STRING = "PGM=IEFBR14"; +const REGEX_STRING = "IEFBR14|RC=0000"; +const BAD_SEARCH_STRING = "bluhbluh"; describe("zos-jobs search job command", () => { + // Create the unique test environment beforeAll(async () => { - testEnvironment = await TestEnvironment.setUp({ + TEST_ENVIRONMENT = await TestEnvironment.setUp({ testName: "zos_jobs_search_job_command", tempProfileTypes: ["zosmf"] }); - REAL_SESSION = TestEnvironment.createZosmfSession(testEnvironment); - // Use testEnvironment for accessing properties - defaultSystem = testEnvironment.systemTestProperties; - IEFBR14_JOB = defaultSystem.zosjobs.iefbr14Member; - - ACCOUNT = defaultSystem.tso.account; - - const JOB_LENGTH = 5; // 5 letters from the user's id - const userIdPart = REAL_SESSION.ISession.user.substring(0, JOB_LENGTH).toUpperCase(); - JOB_NAME = `IEF${userIdPart}`; - - NON_HELD_JOBCLASS = defaultSystem.zosjobs.jobclass; - SEARCH_STRING = `PGM=${JOB_NAME}`; - REGEX_STRING = `${JOB_NAME}|RC=0000`; - BAD_SEARCH_STRING = "bluhbluh"; + REAL_SESSION = TestEnvironment.createZosmfSession(TEST_ENVIRONMENT); + const iefbr14Job = TEST_ENVIRONMENT.systemTestProperties.zosjobs.iefbr14Member; + const job = await SubmitJobs.submitJob(REAL_SESSION, iefbr14Job); + JOB_NAME = job.jobname; + TEST_ENVIRONMENT.resources.jobs.push(job); }); afterAll(async () => { - // Retrieve jobs by prefix - const jobs = await GetJobs.getJobsByPrefix(REAL_SESSION, JOB_NAME); - testEnvironment.resources.jobs = jobs; - - await TestEnvironment.cleanUp(testEnvironment); + await TestEnvironment.cleanUp(TEST_ENVIRONMENT); }); describe("Successful response", () => { - it("should be able to search for a string in every spool file for a job", async () => { - const response = runCliScript(__dirname + "/__scripts__/job/search_string_spool_content.sh", - testEnvironment, [IEFBR14_JOB, JOB_NAME, SEARCH_STRING]); - + it("should be able to search for a string in every spool file for a job", () => { + const response = runCliScript(__dirname + "/__scripts__/job/search_job_string.sh", + TEST_ENVIRONMENT, [JOB_NAME, SEARCH_STRING]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain(SEARCH_STRING); }); - it("should be able to search for a regex in every spool file for a job", async () => { - const argString = "--search-regex \"" + REGEX_STRING + "\""; - const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", - testEnvironment, [JOB_NAME, argString]); - - await wait(waitTime); // Waits for 2 seconds - + it("should be able to search for a regex in every spool file for a job", () => { + const response = runCliScript(__dirname + "/__scripts__/job/search_job_regex.sh", + TEST_ENVIRONMENT, [JOB_NAME, REGEX_STRING]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); - expect(response.stdout.toString()).toContain(`${JOB_NAME}`); + expect(response.stdout.toString()).toContain("IEFBR14"); expect(response.stdout.toString()).toContain("RC=0000"); }); - it("should limit the search when the --search-limit and --file-limit options are specified", async () => { - const argString = "--search-string \"" + SEARCH_STRING + "\" --search-limit 5 --file-limit 3"; - const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", - testEnvironment, [JOB_NAME, argString]); - - await wait(waitTime); // Waits for 2 seconds - + it("should limit the search when the --search-limit and --file-limit options are specified", () => { + const response = runCliScript(__dirname + "/__scripts__/job/search_job_string.sh", + TEST_ENVIRONMENT, [JOB_NAME, SEARCH_STRING, "--search-limit", "5", "--file-limit", "3"]); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain(SEARCH_STRING); }); }); - describe("error handling", () => { // Removed async from describe - it("should return a status code of 1 if the string is not found", async () => { - const argString = "--search-string \"" + BAD_SEARCH_STRING + "\""; - const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", - testEnvironment, [JOB_NAME, argString]); - - await wait(waitTime); // Waits for 2 seconds - + describe("error handling", () => { + it("should return a status code of 1 if the string is not found", () => { + const response = runCliScript(__dirname + "/__scripts__/job/search_job_string.sh", + TEST_ENVIRONMENT, [JOB_NAME, BAD_SEARCH_STRING]); expect(response.stderr.toString()).toContain("The search spool job command returned a non-zero rc: 1"); expect(response.status).toBe(1); expect(response.stdout.toString()).toBe(""); }); - it("should fail if no parameters are passed", async () => { - const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", - testEnvironment, [JOB_NAME, ""]); - - await wait(waitTime); // Waits for 2 seconds - + it("should fail if no parameters are passed", () => { + const response = runCliScript(__dirname + "/__scripts__/job/missing_search_string.sh", + TEST_ENVIRONMENT, [JOB_NAME]); expect(response.stderr.toString()).toContain("You must specify either the `--search-string` or `--search-regex` option"); expect(response.status).toBe(1); }); - it("should fail if --search-string and --search-regex parameters are passed", async () => { - const argString = "--search-regex \"" + REGEX_STRING +"\" --search-string \"" + SEARCH_STRING + "\""; - const response = runCliScript(__dirname + "/__scripts__/job/search_no_job_submit.sh", - testEnvironment, [JOB_NAME, argString]); - - await wait(waitTime); // Waits for 2 seconds - + it("should fail if --search-string and --search-regex parameters are passed", () => { + const response = runCliScript(__dirname + "/__scripts__/job/search_job_string.sh", + TEST_ENVIRONMENT, [JOB_NAME, SEARCH_STRING, "--search-regex", REGEX_STRING]); expect(response.stderr.toString()).toContain("You must specify either the `--search-string` or `--search-regex` option"); expect(response.status).toBe(1); }); From cacdd3a2e3a7cbf56280f067034a19f7e6423247 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Fri, 18 Oct 2024 10:36:51 -0400 Subject: [PATCH 65/65] Fix failing TSO system tests Signed-off-by: Timothy Johnson --- .../zostso/__system__/issue/__scripts__/as/change_proc.sh | 2 +- .../zostso/__tests__/__system__/api.TsoIssue.system.test.ts | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/cli/__tests__/zostso/__system__/issue/__scripts__/as/change_proc.sh b/packages/cli/__tests__/zostso/__system__/issue/__scripts__/as/change_proc.sh index 45fe3a1a85..792814e2fc 100755 --- a/packages/cli/__tests__/zostso/__system__/issue/__scripts__/as/change_proc.sh +++ b/packages/cli/__tests__/zostso/__system__/issue/__scripts__/as/change_proc.sh @@ -2,4 +2,4 @@ set -e zowe config set profiles.changed_proc_tso.properties.account $1 --gc zowe config set profiles.changed_proc_tso.properties.logonProcedure $2 --gc -zowe tso issue cmd "status" --tso-p "changed_proc_tso" +zowe tso issue cmd "status" --tso-p "changed_proc_tso" --ssm false diff --git a/packages/zostso/__tests__/__system__/api.TsoIssue.system.test.ts b/packages/zostso/__tests__/__system__/api.TsoIssue.system.test.ts index 22bf915403..d7697c68dd 100644 --- a/packages/zostso/__tests__/__system__/api.TsoIssue.system.test.ts +++ b/packages/zostso/__tests__/__system__/api.TsoIssue.system.test.ts @@ -16,7 +16,6 @@ import * as fs from "fs"; import { ITestEnvironment } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import { IIssueTsoCmdParms } from "../../src"; import { IIssueTsoCmdOpts } from "../../src/doc/input/IIssueTsoCmdOpts"; let testEnvironment: ITestEnvironment; let systemProperties: ITestPropertiesSchema; @@ -25,7 +24,6 @@ let ACCOUNT_NUMBER: string; let START_PARAMS: IStartTsoParms; let ISSUE_PARAMS: IIssueTsoParms; -let COMMAND_PARAMS: IIssueTsoCmdParms; let AS_OPTIONS: IIssueTsoCmdOpts; describe("IssueTso.issueTsoCommand", () => { @@ -52,9 +50,6 @@ describe("IssueTso.issueTsoCommand", () => { accountNumber: ACCOUNT_NUMBER, startParams: START_PARAMS }; - COMMAND_PARAMS = { - command: "TIME" - }; AS_OPTIONS = { addressSpaceOptions: START_PARAMS };