Skip to content

Commit

Permalink
Merge branch 'error-msg-help-version' of https://github.com/zowe/zowe…
Browse files Browse the repository at this point in the history
…-cli into error-msg-help-version
  • Loading branch information
ATorrise committed Nov 5, 2024
2 parents 0d670f7 + b459781 commit db09359
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 15 deletions.
1 change: 1 addition & 0 deletions __tests__/__packages__/cli-test-utils/src/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function runCliScript(scriptPath: string, testEnvironment: ITestEnvironme
env: childEnv,
encoding: "buffer"
});
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
if (process.platform === "darwin" && (response.error as ExecFileException)?.errno === -8) {
throw new Error(`The script file ${path.basename(scriptPath)} failed to execute. Check that it starts with a shebang line.`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe("Upload file-to-data-set handler", () => {
}
});

expect(apiMessage).toBe("");
expect(apiMessage).toBe("");

expect(logMessage).toMatch(/success:.*false/);
expect(logMessage).toMatch(/from:.*test-file/);
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
60 changes: 60 additions & 0 deletions packages/imperative/src/config/__tests__/Config.api.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ConfigConstants } from "../src/ConfigConstants";
import { IConfig } from "../src/doc/IConfig";
import { IConfigLayer } from "../src/doc/IConfigLayer";
import { IConfigProfile } from "../src/doc/IConfigProfile";
import { ImperativeError, TextUtils } from "../..";

const MY_APP = "my_app";

Expand Down Expand Up @@ -264,6 +265,65 @@ describe("Config API tests", () => {
expect(readFileSpy).toHaveBeenCalledTimes(1);
expect(secureLoadSpy).toHaveBeenCalledTimes(1);
});
it("should error when ignoreErrors is implicit false", async () => {
const config = await Config.load(MY_APP);
const existsSpy = jest.spyOn(fs, "existsSync").mockReturnValueOnce(true);
const readFileSpy = jest.spyOn(fs, "readFileSync");
const secureLoadSpy = jest.spyOn(config.api.secure, "loadCached");
const jsoncParseSpy = jest.spyOn(JSONC, "parse").mockImplementationOnce(() => { throw "failed to parse"; });
let caughtError: ImperativeError = {} as any;
try {
config.api.layers.read();
} catch(err) {
caughtError = err;
}
expect(existsSpy).toHaveBeenCalledTimes(5); // Once for each config layer and one more time for read
expect(readFileSpy).toHaveBeenCalledTimes(1);
expect(secureLoadSpy).toHaveBeenCalledTimes(0);
expect(jsoncParseSpy).toHaveBeenCalledTimes(1);
expect(caughtError.message).toContain("Please check this configuration file for errors");
});

it("should error when ignoreErrors is explicit false", async () => {
const config = await Config.load(MY_APP);
const existsSpy = jest.spyOn(fs, "existsSync").mockReturnValueOnce(true);
const readFileSpy = jest.spyOn(fs, "readFileSync");
const secureLoadSpy = jest.spyOn(config.api.secure, "loadCached");
const jsoncParseSpy = jest.spyOn(JSONC, "parse").mockImplementationOnce(() => { throw "failed to parse"; });
let caughtError: ImperativeError = {} as any;
try {
config.api.layers.read({user: false, global: false, ignoreErrors: false});
} catch(err) {
caughtError = err;
}
expect(existsSpy).toHaveBeenCalledTimes(5); // Once for each config layer and one more time for read
expect(readFileSpy).toHaveBeenCalledTimes(1);
expect(secureLoadSpy).toHaveBeenCalledTimes(0);
expect(jsoncParseSpy).toHaveBeenCalledTimes(1);
expect(caughtError.message).toContain("Please check this configuration file for errors");
});

it("should error when ignoreErrors is true", async () => {
const config = await Config.load(MY_APP);
const existsSpy = jest.spyOn(fs, "existsSync").mockReturnValueOnce(true);
const readFileSpy = jest.spyOn(fs, "readFileSync");
const secureLoadSpy = jest.spyOn(config.api.secure, "loadCached");
const jsoncParseSpy = jest.spyOn(JSONC, "parse").mockImplementationOnce(() => { throw "failed to parse"; });
const redSpy = jest.fn().mockImplementation((str: string) => str);
jest.spyOn(TextUtils, "chalk", "get").mockReturnValueOnce({red: redSpy});
let caughtError;
try {
config.api.layers.read({user: false, global: false, ignoreErrors: true});
} catch(err) {
caughtError = err;
}
expect(existsSpy).toHaveBeenCalledTimes(5); // Once for each config layer and one more time for read
expect(readFileSpy).toHaveBeenCalledTimes(1);
expect(secureLoadSpy).toHaveBeenCalledTimes(1);
expect(jsoncParseSpy).toHaveBeenCalledTimes(1);
expect(caughtError).toBeUndefined();
expect(redSpy.mock.calls[0][0]).toContain("Please check this configuration file for errors");
});
});
describe("write", () => {
it("should save the active config layer", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ exports[`Config API tests layers get should get the active layer 1`] = `
Object {
"exists": true,
"global": false,
"ignoreErrors": false,
"path": "project.config.user.json",
"properties": Object {
"autoStore": false,
Expand Down
3 changes: 1 addition & 2 deletions packages/imperative/src/config/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ export class Config {
properties: Config.empty(),
global: layer === Layers.GlobalUser || layer === Layers.GlobalConfig,
user: layer === Layers.ProjectUser || layer === Layers.GlobalUser,
ignoreErrors: process.argv.includes("--help") || process.argv.includes("--version")
|| process.argv[process.argv.length-1] === require.resolve('@zowe/cli')
ignoreErrors: opts?.ignoreErrors
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/imperative/src/imperative/src/Imperative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class Imperative {
ConfigurationValidator.validate(config);
ImperativeConfig.instance.loadedConfig = config;

// Detect CLI arguments to determine if errors should be ignored
// Detect CLI arguments to determine if errors should be ignored
const ignoreErrors = process.argv.includes(Constants.HELP_OPTION) ||
process.argv.includes(Constants.HELP_OPTION_ALIAS) ||
process.argv.includes(Constants.VERSION_OPTION) ||
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
2 changes: 1 addition & 1 deletion packages/zosfiles/src/methods/upload/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ export class Upload {
} else if(options.filesMap?.fileNames.indexOf(path.basename(localPath)) > -1) {
tempOptions.binary = options.filesMap.binary;

// Reset encoding to undefined if binary is true to avoid file tagging issues
// Reset encoding to undefined if binary is true to avoid file tagging issues
if(tempOptions.binary) tempOptions.encoding = undefined;
}

Expand Down

0 comments on commit db09359

Please sign in to comment.