From 6cb99a33d78355681be745070a4861d99ec7f71c Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Sun, 9 Feb 2020 18:48:40 -0500 Subject: [PATCH] another test --- __tests__/setup-go.test.ts | 32 ++++++++++++++++++++++++++++++++ dist/index.js | 5 ++--- src/installer.ts | 8 ++------ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 15e1c7d..fc63647 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -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' diff --git a/dist/index.js b/dist/index.js index 797b301..bad8d0a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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++) { @@ -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; diff --git a/src/installer.ts b/src/installer.ts index 4382d81..a3bcb57 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -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; @@ -111,9 +111,5 @@ export async function findMatch( export async function getVersions(dlUrl: string): Promise { // this returns versions descending so latest is first let http: httpm.HttpClient = new httpm.HttpClient('setup-go'); - let candidates: IGoVersion[] | null = (await http.getJson( - dlUrl - )).result; - - return candidates; + return (await http.getJson(dlUrl)).result; }