2020-01-18 02:29:06 +01:00
|
|
|
import * as main from '../src/main';
|
|
|
|
import * as io from '@actions/io';
|
|
|
|
import path from 'path';
|
|
|
|
import nock from 'nock';
|
2020-01-18 04:07:13 +01:00
|
|
|
import {Tool, Action} from '../src/constants';
|
2020-01-20 17:35:00 +01:00
|
|
|
import {FetchError} from 'node-fetch';
|
2020-01-18 02:29:06 +01:00
|
|
|
import jsonTestBrew from './data/brew.json';
|
|
|
|
// import jsonTestGithub from './data/github.json';
|
|
|
|
|
|
|
|
jest.setTimeout(30000);
|
|
|
|
|
|
|
|
describe('Integration testing run()', () => {
|
2020-01-20 17:35:00 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules();
|
|
|
|
});
|
|
|
|
|
2020-01-18 02:29:06 +01:00
|
|
|
afterEach(async () => {
|
2020-01-18 04:07:13 +01:00
|
|
|
const workDir = path.join(`${process.env.HOME}`, Action.WorkDirName);
|
|
|
|
await io.rmRF(workDir);
|
2020-01-20 17:35:00 +01:00
|
|
|
|
|
|
|
delete process.env['INPUT_HUGO-VERSION'];
|
|
|
|
nock.cleanAll();
|
2020-01-18 02:29:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('succeed in installing a custom version', async () => {
|
2020-01-18 04:07:13 +01:00
|
|
|
const testVersion = Tool.TestVersionSpec;
|
2020-01-18 02:29:06 +01:00
|
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
|
|
const result: main.ActionResult = await main.run();
|
|
|
|
expect(result.exitcode).toBe(0);
|
|
|
|
expect(result.output).toMatch(`Hugo Static Site Generator v${testVersion}`);
|
|
|
|
});
|
|
|
|
|
2020-01-18 04:33:56 +01:00
|
|
|
test('succeed in installing a custom extended version', async () => {
|
|
|
|
const testVersion = Tool.TestVersionSpec;
|
|
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
|
|
process.env['INPUT_EXTENDED'] = 'true';
|
|
|
|
const result: main.ActionResult = await main.run();
|
|
|
|
expect(result.exitcode).toBe(0);
|
|
|
|
expect(result.output).toMatch(`Hugo Static Site Generator v${testVersion}`);
|
|
|
|
expect(result.output).toMatch(`extended`);
|
|
|
|
});
|
|
|
|
|
2020-01-18 02:29:06 +01:00
|
|
|
test('succeed in installing the latest version', async () => {
|
|
|
|
const testVersion = 'latest';
|
|
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
|
|
nock('https://formulae.brew.sh')
|
2020-01-18 04:07:13 +01:00
|
|
|
.get(`/api/formula/${Tool.Repo}.json`)
|
2020-01-18 02:29:06 +01:00
|
|
|
.reply(200, jsonTestBrew);
|
|
|
|
const result: main.ActionResult = await main.run();
|
|
|
|
expect(result.exitcode).toBe(0);
|
2020-01-18 04:07:13 +01:00
|
|
|
expect(result.output).toMatch(
|
|
|
|
`Hugo Static Site Generator v${Tool.TestVersionLatest}`
|
|
|
|
);
|
2020-01-18 02:29:06 +01:00
|
|
|
});
|
2020-01-18 04:33:56 +01:00
|
|
|
|
|
|
|
test('succeed in installing the latest extended version', async () => {
|
|
|
|
const testVersion = 'latest';
|
|
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
|
|
process.env['INPUT_EXTENDED'] = 'true';
|
|
|
|
nock('https://formulae.brew.sh')
|
|
|
|
.get(`/api/formula/${Tool.Repo}.json`)
|
|
|
|
.reply(200, jsonTestBrew);
|
|
|
|
const result: main.ActionResult = await main.run();
|
|
|
|
expect(result.exitcode).toBe(0);
|
|
|
|
expect(result.output).toMatch(
|
|
|
|
`Hugo Static Site Generator v${Tool.TestVersionLatest}`
|
|
|
|
);
|
|
|
|
expect(result.output).toMatch(`extended`);
|
|
|
|
});
|
2020-01-20 17:35:00 +01:00
|
|
|
|
|
|
|
test('fail to install the latest version due to 404 of brew', async () => {
|
|
|
|
process.env['INPUT_HUGO-VERSION'] = 'latest';
|
|
|
|
nock('https://formulae.brew.sh')
|
|
|
|
.get(`/api/formula/${Tool.Repo}.json`)
|
|
|
|
.reply(404);
|
|
|
|
|
|
|
|
await expect(main.run()).rejects.toThrowError(FetchError);
|
|
|
|
});
|
2020-01-18 02:29:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('showVersion()', () => {
|
|
|
|
let result: main.ActionResult = {
|
|
|
|
exitcode: 0,
|
|
|
|
output: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
test('return version', async () => {
|
|
|
|
result = await main.showVersion('git', ['--version']);
|
|
|
|
expect(result.exitcode).toBe(0);
|
|
|
|
expect(result.output).toMatch(/git version/);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('return not found', async () => {
|
2020-01-18 03:11:17 +01:00
|
|
|
await expect(
|
|
|
|
main.showVersion('gitgit', ['--version'])
|
|
|
|
).rejects.toThrowError(Error);
|
2020-01-18 02:29:06 +01:00
|
|
|
});
|
|
|
|
});
|