Skip to content

Commit

Permalink
test: Add fail to fetch latest due to 404 (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris authored Jan 20, 2020
1 parent 0311892 commit b55f1c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

beforeEach(() => {
jest.resetModules();
});

afterEach(() => {
delete process.env['INPUT_HUGO-VERSION'];
nock.cleanAll();
});

describe('Integration testing run()', () => {
beforeEach(() => {
jest.resetModules();
});

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 () => {
Expand Down Expand Up @@ -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()', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit b55f1c8

Please sign in to comment.