Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
another test
  • Loading branch information
Bryan MacFarlane committed Feb 9, 2020
1 parent 241a335 commit 6cb99a3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
32 changes: 32 additions & 0 deletions __tests__/setup-go.test.ts
Expand Up @@ -108,6 +108,38 @@ describe('setup-go', () => {
);
});

it('reports a failed download', async () => {
let errMsg = 'unhandled download message';
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'x64');

inSpy.mockImplementation(() => '1.13.1');
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(() => {
throw new Error(errMsg);
});
await run();

expect(cnSpy).toHaveBeenCalledWith(
`::error::Failed to download version 1.13.1: Error: ${errMsg}${os.EOL}`
);
});

it('reports empty query results', async () => {
let errMsg = 'unhandled download message';
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'x64');

inSpy.mockImplementation(() => '1.13.1');
findSpy.mockImplementation(() => '');
getSpy.mockImplementation(() => null);
await run();

expect(cnSpy).toHaveBeenCalledWith(
`::error::Failed to download version 1.13.1: Error: golang download url did not return results${os.EOL}`
);
});

it('can query versions', async () => {
let versions: im.IGoVersion[] | null = await im.getVersions(
'https://non.existant.com/path'
Expand Down
5 changes: 2 additions & 3 deletions dist/index.js
Expand Up @@ -4617,7 +4617,7 @@ function findMatch(versionSpec, stable) {
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
let candidates = yield module.exports.getVersions(dlUrl);
if (!candidates) {
throw new Error(`golang download url did not return results: ${dlUrl}`);
throw new Error(`golang download url did not return results`);
}
let goFile;
for (let i = 0; i < candidates.length; i++) {
Expand Down Expand Up @@ -4656,8 +4656,7 @@ function getVersions(dlUrl) {
return __awaiter(this, void 0, void 0, function* () {
// this returns versions descending so latest is first
let http = new httpm.HttpClient('setup-go');
let candidates = (yield http.getJson(dlUrl)).result;
return candidates;
return (yield http.getJson(dlUrl)).result;
});
}
exports.getVersions = getVersions;
Expand Down
8 changes: 2 additions & 6 deletions src/installer.ts
Expand Up @@ -68,7 +68,7 @@ export async function findMatch(
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
let candidates: IGoVersion[] | null = await module.exports.getVersions(dlUrl);
if (!candidates) {
throw new Error(`golang download url did not return results: ${dlUrl}`);
throw new Error(`golang download url did not return results`);
}

let goFile: IGoVersionFile | undefined;
Expand Down Expand Up @@ -111,9 +111,5 @@ export async function findMatch(
export async function getVersions(dlUrl: string): Promise<IGoVersion[] | null> {
// this returns versions descending so latest is first
let http: httpm.HttpClient = new httpm.HttpClient('setup-go');
let candidates: IGoVersion[] | null = (await http.getJson<IGoVersion[]>(
dlUrl
)).result;

return candidates;
return (await http.getJson<IGoVersion[]>(dlUrl)).result;
}

0 comments on commit 6cb99a3

Please sign in to comment.