mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-17 03:56:04 +08:00
Provider Info in annotations and test case fixes
This commit is contained in:
parent
7da7f474fa
commit
09a3895635
@ -17,6 +17,7 @@ import { getkubectlDownloadURL } from "../src/utilities/kubectl-util";
|
|||||||
import { mocked } from 'ts-jest/utils';
|
import { mocked } from 'ts-jest/utils';
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
const os = require("os");
|
||||||
|
|
||||||
const coreMock = mocked(core, true);
|
const coreMock = mocked(core, true);
|
||||||
const ioMock = mocked(io, true);
|
const ioMock = mocked(io, true);
|
||||||
@ -224,36 +225,30 @@ test("deployment - deploy() - Invokes with manifestfiles", async () => {
|
|||||||
expect(kubeCtl.getResource).toBeCalledWith("ingress", "AppName");
|
expect(kubeCtl.getResource).toBeCalledWith("ingress", "AppName");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("run() - deploy force flag on", async () => {
|
test("deployment - deploy() - deploy force flag on", async () => {
|
||||||
const kubectlVersion = 'v1.18.0'
|
|
||||||
//Mocks
|
//Mocks
|
||||||
coreMock.getInput = jest.fn().mockImplementation((name) => {
|
|
||||||
if (name == 'manifests') {
|
|
||||||
return 'manifests/deployment.yaml';
|
|
||||||
}
|
|
||||||
if (name == 'action') {
|
|
||||||
return 'deploy';
|
|
||||||
}
|
|
||||||
if (name == 'strategy') {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (name == 'force') {
|
|
||||||
return 'true';
|
|
||||||
}
|
|
||||||
return kubectlVersion;
|
|
||||||
});
|
|
||||||
|
|
||||||
inputParamMock.forceDeployment = true;
|
inputParamMock.forceDeployment = true;
|
||||||
coreMock.setFailed = jest.fn();
|
const applyResMock = {
|
||||||
toolCacheMock.find = jest.fn().mockReturnValue('validPath');
|
'code': 0,
|
||||||
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
|
'stderr': '',
|
||||||
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
|
'error': Error(""),
|
||||||
fileUtility.chmodSync = jest.fn();
|
'stdout': 'changes configured'
|
||||||
utilityMock.checkForErrors = jest.fn();
|
};
|
||||||
const deploySpy = jest.spyOn(Kubectl.prototype, 'apply').mockImplementation();
|
const KubernetesManifestUtilityMock = mocked(KubernetesManifestUtility, true);
|
||||||
|
const KubernetesObjectUtilityMock = mocked(KubernetesObjectUtility, true);
|
||||||
|
const kubeCtl: jest.Mocked<Kubectl> = new Kubectl("") as any;
|
||||||
|
KubernetesObjectUtilityMock.getResources = jest.fn().mockReturnValue(resources);
|
||||||
|
kubeCtl.getResource = jest.fn().mockReturnValue(getNamespaceMock);
|
||||||
|
kubeCtl.getAllPods = jest.fn().mockReturnValue(getAllPodsMock);
|
||||||
|
kubeCtl.describe = jest.fn().mockReturnValue("");
|
||||||
|
kubeCtl.annotateFiles = jest.fn().mockReturnValue("");
|
||||||
|
kubeCtl.annotate = jest.fn().mockReturnValue("");
|
||||||
|
KubernetesManifestUtilityMock.checkManifestStability = jest.fn().mockReturnValue("");
|
||||||
|
|
||||||
|
const deploySpy = jest.spyOn(kubeCtl, 'apply').mockImplementation(() => applyResMock);
|
||||||
|
|
||||||
//Invoke and assert
|
//Invoke and assert
|
||||||
await expect(action.run()).resolves.not.toThrow();
|
await expect(deployment.deploy(kubeCtl, ['manifests/deployment.yaml'], undefined)).resolves.not.toThrowError();
|
||||||
expect(deploySpy).toBeCalledWith(expect.anything(), true);
|
expect(deploySpy).toBeCalledWith(expect.anything(), true);
|
||||||
deploySpy.mockRestore();
|
deploySpy.mockRestore();
|
||||||
});
|
});
|
||||||
@ -277,4 +272,31 @@ test("deployment - deploy() - Annotate resources", async () => {
|
|||||||
await expect(deployment.deploy(kubeCtl, ['manifests/deployment.yaml'], undefined)).resolves.not.toThrowError();
|
await expect(deployment.deploy(kubeCtl, ['manifests/deployment.yaml'], undefined)).resolves.not.toThrowError();
|
||||||
expect(kubeCtl.annotateFiles).toBeCalledWith(["~/Deployment_testapp_currentTimestamp"], workflowAnnotations, true);
|
expect(kubeCtl.annotateFiles).toBeCalledWith(["~/Deployment_testapp_currentTimestamp"], workflowAnnotations, true);
|
||||||
expect(kubeCtl.annotate).toBeCalledTimes(2);
|
expect(kubeCtl.annotate).toBeCalledTimes(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("deployment - deploy() - Annotate resources failed", async () => {
|
||||||
|
//Mocks
|
||||||
|
inputParamMock.forceDeployment = true;
|
||||||
|
const annotateMock = {
|
||||||
|
'code': 1,
|
||||||
|
'stderr': 'kubectl annotate failed',
|
||||||
|
'error': Error(""),
|
||||||
|
'stdout': ''
|
||||||
|
};
|
||||||
|
const KubernetesManifestUtilityMock = mocked(KubernetesManifestUtility, true);
|
||||||
|
const KubernetesObjectUtilityMock = mocked(KubernetesObjectUtility, true);
|
||||||
|
const kubeCtl: jest.Mocked<Kubectl> = new Kubectl("") as any;
|
||||||
|
KubernetesObjectUtilityMock.getResources = jest.fn().mockReturnValue(resources);
|
||||||
|
kubeCtl.apply = jest.fn().mockReturnValue("");
|
||||||
|
kubeCtl.getResource = jest.fn().mockReturnValue(getNamespaceMock);
|
||||||
|
kubeCtl.getAllPods = jest.fn().mockReturnValue(getAllPodsMock);
|
||||||
|
kubeCtl.describe = jest.fn().mockReturnValue("");
|
||||||
|
kubeCtl.annotateFiles = jest.fn().mockReturnValue("");
|
||||||
|
kubeCtl.annotate = jest.fn().mockReturnValue(annotateMock);
|
||||||
|
KubernetesManifestUtilityMock.checkManifestStability = jest.fn().mockReturnValue("");
|
||||||
|
|
||||||
|
const consoleOutputSpy = jest.spyOn(process.stdout, "write").mockImplementation();
|
||||||
|
//Invoke and assert
|
||||||
|
await expect(deployment.deploy(kubeCtl, ['manifests/deployment.yaml'], undefined)).resolves.not.toThrowError();
|
||||||
|
expect(consoleOutputSpy).toHaveBeenNthCalledWith(2, '##[warning]kubectl annotate failed' + os.EOL)
|
||||||
});
|
});
|
||||||
@ -34,5 +34,6 @@ exports.workflowAnnotations = [
|
|||||||
`runUri=https://github.com/${process.env['GITHUB_REPOSITORY']}/actions/runs/${process.env['GITHUB_RUN_ID']}`,
|
`runUri=https://github.com/${process.env['GITHUB_REPOSITORY']}/actions/runs/${process.env['GITHUB_RUN_ID']}`,
|
||||||
`commit=${process.env['GITHUB_SHA']}`,
|
`commit=${process.env['GITHUB_SHA']}`,
|
||||||
`branch=${process.env['GITHUB_REF']}`,
|
`branch=${process.env['GITHUB_REF']}`,
|
||||||
`deployTimestamp=${Date.now()}`
|
`deployTimestamp=${Date.now()}`,
|
||||||
|
`provider=GitHub`
|
||||||
];
|
];
|
||||||
|
|||||||
@ -34,5 +34,6 @@ export const workflowAnnotations = [
|
|||||||
`runUri=https://github.com/${process.env['GITHUB_REPOSITORY']}/actions/runs/${process.env['GITHUB_RUN_ID']}`,
|
`runUri=https://github.com/${process.env['GITHUB_REPOSITORY']}/actions/runs/${process.env['GITHUB_RUN_ID']}`,
|
||||||
`commit=${process.env['GITHUB_SHA']}`,
|
`commit=${process.env['GITHUB_SHA']}`,
|
||||||
`branch=${process.env['GITHUB_REF']}`,
|
`branch=${process.env['GITHUB_REF']}`,
|
||||||
`deployTimestamp=${Date.now()}`
|
`deployTimestamp=${Date.now()}`,
|
||||||
|
`provider=GitHub`
|
||||||
];
|
];
|
||||||
Loading…
x
Reference in New Issue
Block a user