test: Add fail to fetch latest due to 404 (#137)

This commit is contained in:
Shohei Ueda 2020-01-21 01:35:00 +09:00 committed by GitHub
parent 0311892edd
commit b55f1c81fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 11 deletions

View file

@ -3,25 +3,23 @@ import * as io from '@actions/io';
import path from 'path';
import nock from 'nock';
import {Tool, Action} from '../src/constants';
// import {FetchError} from 'node-fetch';
import {FetchError} from 'node-fetch';
import jsonTestBrew from './data/brew.json';
// import jsonTestGithub from './data/github.json';
jest.setTimeout(30000);
describe('Integration testing run()', () => {
beforeEach(() => {
jest.resetModules();
});
afterEach(() => {
delete process.env['INPUT_HUGO-VERSION'];
nock.cleanAll();
});
describe('Integration testing run()', () => {
afterEach(async () => {
const workDir = path.join(`${process.env.HOME}`, Action.WorkDirName);
await io.rmRF(workDir);
delete process.env['INPUT_HUGO-VERSION'];
nock.cleanAll();
});
test('succeed in installing a custom version', async () => {
@ -69,6 +67,15 @@ describe('Integration testing run()', () => {
);
expect(result.output).toMatch(`extended`);
});
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);
});
});
describe('showVersion()', () => {

View file

@ -56,6 +56,6 @@ export async function run(): Promise<ActionResult> {
return result;
} catch (e) {
core.setFailed(`Action failed with error ${e}`);
return e;
throw e;
}
}