mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-26 06:39:27 +08:00
Vidya reddy/prettier code (#203)
This commit is contained in:
@@ -1,61 +1,61 @@
|
||||
import * as core from "@actions/core";
|
||||
import { ExecOutput } from "@actions/exec";
|
||||
import { checkForErrors } from "./kubectlUtils";
|
||||
import * as core from '@actions/core'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
import {checkForErrors} from './kubectlUtils'
|
||||
|
||||
describe("Kubectl utils", () => {
|
||||
it("checks for errors", () => {
|
||||
const success: ExecOutput = { stderr: "", stdout: "success", exitCode: 0 };
|
||||
const successWithStderr: ExecOutput = {
|
||||
stderr: "error",
|
||||
stdout: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
const failWithExitCode: ExecOutput = {
|
||||
stderr: "",
|
||||
stdout: "",
|
||||
exitCode: 1,
|
||||
};
|
||||
const failWithExitWithStderr: ExecOutput = {
|
||||
stderr: "error",
|
||||
stdout: "",
|
||||
exitCode: 2,
|
||||
};
|
||||
describe('Kubectl utils', () => {
|
||||
it('checks for errors', () => {
|
||||
const success: ExecOutput = {stderr: '', stdout: 'success', exitCode: 0}
|
||||
const successWithStderr: ExecOutput = {
|
||||
stderr: 'error',
|
||||
stdout: '',
|
||||
exitCode: 0
|
||||
}
|
||||
const failWithExitCode: ExecOutput = {
|
||||
stderr: '',
|
||||
stdout: '',
|
||||
exitCode: 1
|
||||
}
|
||||
const failWithExitWithStderr: ExecOutput = {
|
||||
stderr: 'error',
|
||||
stdout: '',
|
||||
exitCode: 2
|
||||
}
|
||||
|
||||
// with throw behavior
|
||||
expect(() => checkForErrors([success])).not.toThrow();
|
||||
expect(() => checkForErrors([successWithStderr])).not.toThrow();
|
||||
expect(() => checkForErrors([success, successWithStderr])).not.toThrow();
|
||||
expect(() => checkForErrors([failWithExitCode])).toThrow();
|
||||
expect(() => checkForErrors([failWithExitWithStderr])).toThrow();
|
||||
expect(() => checkForErrors([success, failWithExitCode])).toThrow();
|
||||
expect(() =>
|
||||
checkForErrors([successWithStderr, failWithExitCode])
|
||||
).toThrow();
|
||||
expect(() =>
|
||||
checkForErrors([success, successWithStderr, failWithExitCode])
|
||||
).toThrow();
|
||||
expect(() =>
|
||||
checkForErrors([success, successWithStderr, failWithExitWithStderr])
|
||||
).toThrow();
|
||||
// with throw behavior
|
||||
expect(() => checkForErrors([success])).not.toThrow()
|
||||
expect(() => checkForErrors([successWithStderr])).not.toThrow()
|
||||
expect(() => checkForErrors([success, successWithStderr])).not.toThrow()
|
||||
expect(() => checkForErrors([failWithExitCode])).toThrow()
|
||||
expect(() => checkForErrors([failWithExitWithStderr])).toThrow()
|
||||
expect(() => checkForErrors([success, failWithExitCode])).toThrow()
|
||||
expect(() =>
|
||||
checkForErrors([successWithStderr, failWithExitCode])
|
||||
).toThrow()
|
||||
expect(() =>
|
||||
checkForErrors([success, successWithStderr, failWithExitCode])
|
||||
).toThrow()
|
||||
expect(() =>
|
||||
checkForErrors([success, successWithStderr, failWithExitWithStderr])
|
||||
).toThrow()
|
||||
|
||||
// with warn behavior
|
||||
jest.spyOn(core, "warning").mockImplementation(() => {});
|
||||
let warningCalls = 0;
|
||||
expect(() => checkForErrors([success], true)).not.toThrow();
|
||||
expect(core.warning).toBeCalledTimes(warningCalls);
|
||||
// with warn behavior
|
||||
jest.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
let warningCalls = 0
|
||||
expect(() => checkForErrors([success], true)).not.toThrow()
|
||||
expect(core.warning).toBeCalledTimes(warningCalls)
|
||||
|
||||
expect(() => checkForErrors([successWithStderr], true)).not.toThrow();
|
||||
expect(core.warning).toBeCalledTimes(++warningCalls);
|
||||
expect(() => checkForErrors([successWithStderr], true)).not.toThrow()
|
||||
expect(core.warning).toBeCalledTimes(++warningCalls)
|
||||
|
||||
expect(() =>
|
||||
checkForErrors([success, successWithStderr], true)
|
||||
).not.toThrow();
|
||||
expect(core.warning).toBeCalledTimes(++warningCalls);
|
||||
expect(() =>
|
||||
checkForErrors([success, successWithStderr], true)
|
||||
).not.toThrow()
|
||||
expect(core.warning).toBeCalledTimes(++warningCalls)
|
||||
|
||||
expect(() => checkForErrors([failWithExitCode], true)).not.toThrow();
|
||||
expect(core.warning).toBeCalledTimes(++warningCalls);
|
||||
expect(() => checkForErrors([failWithExitCode], true)).not.toThrow()
|
||||
expect(core.warning).toBeCalledTimes(++warningCalls)
|
||||
|
||||
expect(() => checkForErrors([failWithExitWithStderr], true)).not.toThrow();
|
||||
expect(core.warning).toBeCalledTimes(++warningCalls);
|
||||
});
|
||||
});
|
||||
expect(() => checkForErrors([failWithExitWithStderr], true)).not.toThrow()
|
||||
expect(core.warning).toBeCalledTimes(++warningCalls)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user