Grabbed the upstream integration tests and brought them here. Removed bash script. Added validateKubectl.py to /test folder for integration tests.

This commit is contained in:
Tommy Barnes 2022-01-03 17:51:01 -05:00
parent 3c28691302
commit 83ac6564e3
6 changed files with 159 additions and 82 deletions

View file

@ -1,5 +1,5 @@
import * as run from './run'
import * as helpers from './helpers'
import { getkubectlDownloadURL, getKubectlArch, getExecutableExtension } from './helpers';
import * as os from 'os';
import * as toolCache from '@actions/tool-cache';
import * as fs from 'fs';
@ -11,14 +11,14 @@ describe('Testing all functions in run file.', () => {
test('getExecutableExtension() - return .exe when os is Windows', () => {
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
expect(helpers.getExecutableExtension()).toBe('.exe');
expect(getExecutableExtension()).toBe('.exe');
expect(os.type).toBeCalled();
});
test('getExecutableExtension() - return empty string for non-windows OS', () => {
jest.spyOn(os, 'type').mockReturnValue('Darwin');
expect(helpers.getExecutableExtension()).toBe('');
expect(getExecutableExtension()).toBe('');
expect(os.type).toBeCalled();
});
@ -29,7 +29,7 @@ describe('Testing all functions in run file.', () => {
])("getKubectlArch() - return on %s os arch %s kubectl arch", (osArch, kubectlArch) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
expect(helpers.getKubectlArch()).toBe(kubectlArch);
expect(getKubectlArch()).toBe(kubectlArch);
expect(os.arch).toBeCalled();
});
@ -41,7 +41,7 @@ describe('Testing all functions in run file.', () => {
jest.spyOn(os, 'type').mockReturnValue('Linux');
const kubectlLinuxUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/linux/%s/kubectl', arch);
expect(helpers.getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl);
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl);
expect(os.type).toBeCalled();
});
@ -53,7 +53,7 @@ describe('Testing all functions in run file.', () => {
jest.spyOn(os, 'type').mockReturnValue('Darwin');
const kubectlDarwinUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/darwin/%s/kubectl', arch);
expect(helpers.getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl);
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl);
expect(os.type).toBeCalled();
});
@ -65,7 +65,7 @@ describe('Testing all functions in run file.', () => {
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
const kubectlWindowsUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/windows/%s/kubectl.exe', arch);
expect(helpers.getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlWindowsUrl);
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlWindowsUrl);
expect(os.type).toBeCalled();
});

View file

@ -5,7 +5,7 @@ import * as fs from 'fs';
import * as toolCache from '@actions/tool-cache';
import * as core from '@actions/core';
import * as helpers from './helpers';
import { getkubectlDownloadURL, getKubectlArch, getExecutableExtension } from './helpers';
const kubectlToolName = 'kubectl';
const stableKubectlVersion = 'v1.15.0';
@ -20,7 +20,7 @@ export async function run() {
core.addPath(path.dirname(cachedPath));
console.log(`Kubectl tool version: '${version}' has been cached at ${cachedPath}`);
core.debug(`Kubectl tool version: '${version}' has been cached at ${cachedPath}`);
core.setOutput('kubectl-path', cachedPath);
}
@ -41,10 +41,10 @@ export async function getStableKubectlVersion(): Promise<string> {
export async function downloadKubectl(version: string): Promise<string> {
let cachedToolpath = toolCache.find(kubectlToolName, version);
let kubectlDownloadPath = '';
const arch = helpers.getKubectlArch();
const arch = getKubectlArch();
if (!cachedToolpath) {
try {
kubectlDownloadPath = await toolCache.downloadTool(helpers.getkubectlDownloadURL(version, arch));
kubectlDownloadPath = await toolCache.downloadTool(getkubectlDownloadURL(version, arch));
} catch (exception) {
if (exception instanceof toolCache.HTTPError && exception.httpStatusCode === 404) {
throw new Error(util.format("Kubectl '%s' for '%s' arch not found.", version, arch));
@ -53,10 +53,10 @@ export async function downloadKubectl(version: string): Promise<string> {
}
}
cachedToolpath = await toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + helpers.getExecutableExtension(), kubectlToolName, version);
cachedToolpath = await toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + getExecutableExtension(), kubectlToolName, version);
}
const kubectlPath = path.join(cachedToolpath, kubectlToolName + helpers.getExecutableExtension());
const kubectlPath = path.join(cachedToolpath, kubectlToolName + getExecutableExtension());
fs.chmodSync(kubectlPath, '777');
return kubectlPath;
}