Skip to content

Commit

Permalink
Deprecate duplicate functions
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew W. Harn <andrew.harn@broadcom.com>
  • Loading branch information
awharn committed Nov 5, 2024
1 parent 7d63b8b commit 90924fa
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class TestEnvironment {
public static createUniqueTestDataDir(testName: string): string {
const app = uuidv4() + "_" + testName + "/";
const path = nodePath.resolve(TEST_RESULT_DATA_DIR + "/" + app);
IO.mkdirp(path);
IO.createDirSync(path);
return path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { ITestEnvironment } from "../../../../../../__tests__/__src__/environmen
import { runCliScript } from "@zowe/cli-test-utils";
import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema";
import * as fs from "fs";
import { Session } from "@zowe/imperative";
import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk";

// Test Environment populated in the beforeAll();
let TEST_ENVIRONMENT: ITestEnvironment<ITestPropertiesSchema>;
Expand Down Expand Up @@ -49,14 +47,14 @@ describe("zos-jobs download output command", () => {
it("should download a job and wait for it to reach output status", async () => {
const response = runCliScript(__dirname + "/__scripts__/download-output/download_job_wait_for_output.sh",
TEST_ENVIRONMENT, [IEFBR14_JCL]);
expect(response.stderr.toString()).toBe("");
expect(response.status).toBe(0);
expect(response.stderr.toString()).toBe("");
expect(response.status).toBe(0);
});
it("should download a job and wait for it to reach active status", async () => {
const response = runCliScript(__dirname + "/__scripts__/download-output/download_job_wait_for_active.sh",
TEST_ENVIRONMENT, [IEFBR14_JCL]);
expect(response.stderr.toString()).toBe("");
expect(response.status).toBe(0);
expect(response.stderr.toString()).toBe("");
expect(response.status).toBe(0);
});
});
describe("output", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/daemon/DaemonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class DaemonUtil {
}
if (!IO.existsSync(daemonDir)) {
try {
IO.mkdirp(daemonDir);
IO.createDirSync(daemonDir);
const ownerReadWriteTraverse = 0o700;
fs.chmodSync(daemonDir, ownerReadWriteTraverse);
} catch(err) {
Expand Down
4 changes: 4 additions & 0 deletions packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

## Recent Changes

- BugFix: Deprecated `IO` functions `createDirsSync` and `mkdirp` due to code duplication. Please use `createDirSync`. [#2352](https://github.com/zowe/zowe-cli/pull/2352)

## `8.7.0`

- Enhancement: Added optional `proxy` object to ISession interface for extenders to pass a ProxyVariables object that would override the environment variables if in place. [#2330](https://github.com/zowe/zowe-cli/pull/2330)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("Plugin Management Facility", () => {
* expect to see them.
*/
const namespaceDirPath = join(testCliNodeModulePath, "@zowe");
IO.mkdirp(namespaceDirPath);
IO.createDirSync(namespaceDirPath);
const testCliImpSymLink = join(namespaceDirPath, "imperative");
IO.createSymlinkToDir(testCliImpSymLink, impLibDir);
});
Expand All @@ -42,7 +42,7 @@ describe("Plugin Management Facility", () => {
T.rimraf(home);
// Some test may still need this directory to exists in order to spawn zowe commands in that location
// (e.g. node --require ts-node/register <absolute-path-for-TestCLI.ts> config init)
IO.mkdirp(home);
IO.createDirSync(home);
});

afterAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe("WebHelpGenerator", () => {
*/
const webHelpDocsDirNm = webHelpDirNm + "/docs";
if (!existsSync(webHelpDocsDirNm)) {
IO.mkdirp(webHelpDocsDirNm);
IO.createDirSync(webHelpDocsDirNm);
}

const webHelpGen = new WebHelpGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe("WebHelpManager", () => {
// ensure that the plugins directory exists
instPluginsFileNm = path.join(mockCliHome, "plugins");
if (!fs.existsSync(instPluginsFileNm)) {
IO.mkdirp(instPluginsFileNm);
IO.createDirSync(instPluginsFileNm);
}

// add the plugins file name to the directory, and create an empty object
Expand All @@ -118,7 +118,7 @@ describe("WebHelpManager", () => {
*/
const webHelpDocsDirNm = webHelpDirNm + "/docs";
if (!fs.existsSync(webHelpDocsDirNm)) {
IO.mkdirp(webHelpDocsDirNm);
IO.createDirSync(webHelpDocsDirNm);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class PluginManagementFacility {
if (!existsSync(this.pmfConst.PLUGIN_JSON)) {
if (!existsSync(this.pmfConst.PMF_ROOT)) {
this.impLogger.debug("Creating PMF_ROOT directory");
IO.mkdirp(this.pmfConst.PMF_ROOT);
IO.createDirSync(this.pmfConst.PMF_ROOT);
}

this.impLogger.debug("Creating PLUGIN_JSON file");
Expand Down
5 changes: 5 additions & 0 deletions packages/imperative/src/io/__tests__/IO.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ describe("IO tests", () => {
it("should get an error for no input on createDirsSync", () => {
let error;
try {
// eslint-disable-next-line deprecation/deprecation
IO.createDirsSync(" ");
} catch (thrownError) {
error = thrownError;
Expand All @@ -152,6 +153,7 @@ describe("IO tests", () => {
});
const willBeADir = ["pretend", "to", "create"];
const dir = willBeADir.join(path.posix.sep);
// eslint-disable-next-line deprecation/deprecation
IO.createDirsSync(dir);
expect(fnFm).toHaveBeenCalledTimes(willBeADir.length);
});
Expand All @@ -168,6 +170,7 @@ describe("IO tests", () => {
});
const willBeADir = ["pretend", "to", "create"];
const dir = willBeADir.join(path.posix.sep);
// eslint-disable-next-line deprecation/deprecation
IO.createDirsSync(dir);
expect(fnFm).not.toHaveBeenCalled();

Check failure on line 175 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

IO tests › should not create several dirs if dirs already exist

expect(jest.fn()).not.toHaveBeenCalled() Expected number of calls: 0 Received number of calls: 3 1: "pretend/", {"recursive": true} 2: "pretend/to/", {"recursive": true} 3: "pretend/to/create/", {"recursive": true} at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:175:26)

Check failure on line 175 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

IO tests › should not create several dirs if dirs already exist

expect(jest.fn()).not.toHaveBeenCalled() Expected number of calls: 0 Received number of calls: 3 1: "pretend/", {"recursive": true} 2: "pretend/to/", {"recursive": true} 3: "pretend/to/create/", {"recursive": true} at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:175:26)

Check failure on line 175 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

IO tests › should not create several dirs if dirs already exist

expect(jest.fn()).not.toHaveBeenCalled() Expected number of calls: 0 Received number of calls: 3 1: "pretend/", {"recursive": true} 2: "pretend/to/", {"recursive": true} 3: "pretend/to/create/", {"recursive": true} at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:175:26)

Check failure on line 175 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

IO tests › should not create several dirs if dirs already exist

expect(jest.fn()).not.toHaveBeenCalled() Expected number of calls: 0 Received number of calls: 3 1: "pretend/", {"recursive": true} 2: "pretend/to/", {"recursive": true} 3: "pretend/to/create/", {"recursive": true} at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:175:26)

Check failure on line 175 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

IO tests › should not create several dirs if dirs already exist

expect(jest.fn()).not.toHaveBeenCalled() Expected number of calls: 0 Received number of calls: 3 1: "pretend/", {"recursive": true} 2: "pretend/to/", {"recursive": true} 3: "pretend/to/create/", {"recursive": true} at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:175:26)

Check failure on line 175 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

IO tests › should not create several dirs if dirs already exist

expect(jest.fn()).not.toHaveBeenCalled() Expected number of calls: 0 Received number of calls: 3 1: "pretend/", {"recursive": true} 2: "pretend/to/", {"recursive": true} 3: "pretend/to/create/", {"recursive": true} at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:175:26)
});
Expand All @@ -188,6 +191,7 @@ describe("IO tests", () => {
return pathSegments[0];
});
const dir = willBeADir.join(path.posix.sep);
// eslint-disable-next-line deprecation/deprecation
IO.createDirsSync(dir);
expect(fnFm).toHaveBeenCalledTimes(willBeADir.length - 1);

Check failure on line 196 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macos-14)

IO tests › should only create dirs that do not exist

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 2 Received number of calls: 3 at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:196:22)

Check failure on line 196 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

IO tests › should only create dirs that do not exist

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 2 Received number of calls: 3 at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:196:22)

Check failure on line 196 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-14)

IO tests › should only create dirs that do not exist

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 2 Received number of calls: 3 at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:196:22)

Check failure on line 196 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-22.04)

IO tests › should only create dirs that do not exist

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 2 Received number of calls: 3 at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:196:22)

Check failure on line 196 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

IO tests › should only create dirs that do not exist

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 2 Received number of calls: 3 at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:196:22)

Check failure on line 196 in packages/imperative/src/io/__tests__/IO.unit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

IO tests › should only create dirs that do not exist

expect(jest.fn()).toHaveBeenCalledTimes(expected) Expected number of calls: 2 Received number of calls: 3 at Object.<anonymous> (packages/imperative/src/io/__tests__/IO.unit.test.ts:196:22)
});
Expand Down Expand Up @@ -279,6 +283,7 @@ describe("IO tests", () => {
it("should get an error for no input on mkdirp", () => {
let error;
try {
// eslint-disable-next-line deprecation/deprecation
IO.mkdirp(" ");
} catch (thrownError) {
error = thrownError;
Expand Down
4 changes: 3 additions & 1 deletion packages/imperative/src/io/src/IO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class IO {
* @static
* @param {string} dir - directory to create all sub directories for
* @memberof IO
* @deprecated Please use IO.createDirSync
*/
public static createDirsSync(dir: string) {
ImperativeExpect.toBeDefinedAndNonBlank(dir, "dir");
Expand All @@ -153,7 +154,7 @@ export class IO {
*/
public static createDirsSyncFromFilePath(filePath: string) {
ImperativeExpect.toBeDefinedAndNonBlank(filePath, "filePath");
IO.createDirsSync(path.dirname(filePath));
IO.createDirSync(path.dirname(filePath));
}

/**
Expand Down Expand Up @@ -200,6 +201,7 @@ export class IO {
* @static
* @param {string} dir - the directory (do not include a file name)
* @memberof IO
* @deprecated Please use IO.createDirSync
*/
public static mkdirp(dir: string) {
ImperativeExpect.toBeDefinedAndNonBlank(dir, "dir");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ describe("AbstractRestClient tests", () => {
const result = privateRestClient.buildOptions(resource, request, reqHeaders);
expect(Object.keys(result)).toContain('agent');
expect(headerSpy).toHaveBeenCalledWith([{'Proxy-Authorization': restSession.ISession.proxy.proxy_authorization}]);
})
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("Proxy tests", () => {
const expected = {
proxyUrl: passedUrl,
protocol: HTTPS_PROTOCOL
}
};

beforeEach(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ export abstract class AbstractRestClient {
this.mLogger.info(`Using the following proxy setting for the request: ${proxyUrl.href}`);
if (this.session.ISession?.proxy?.proxy_authorization) {
reqHeaders.push({ 'Proxy-Authorization': this.session.ISession.proxy.proxy_authorization});
}
}
options.agent = ProxySettings.getProxyAgent(this.session.ISession);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("WebDiffGenerator", () => {
beforeAll(async () => {
// checking if fakewebdiffdir exists or not
if (!fs.existsSync(webDiffDir)) {
IO.mkdirp(webDiffDir);
IO.createDirSync(webDiffDir);
}
});
afterAll(async () => {
Expand Down

0 comments on commit 90924fa

Please sign in to comment.