Skip to content

Commit 6cb99a3

Browse files
another test
1 parent 241a335 commit 6cb99a3

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

__tests__/setup-go.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,38 @@ describe('setup-go', () => {
108108
);
109109
});
110110

111+
it('reports a failed download', async () => {
112+
let errMsg = 'unhandled download message';
113+
platSpy.mockImplementation(() => 'linux');
114+
archSpy.mockImplementation(() => 'x64');
115+
116+
inSpy.mockImplementation(() => '1.13.1');
117+
findSpy.mockImplementation(() => '');
118+
dlSpy.mockImplementation(() => {
119+
throw new Error(errMsg);
120+
});
121+
await run();
122+
123+
expect(cnSpy).toHaveBeenCalledWith(
124+
`::error::Failed to download version 1.13.1: Error: ${errMsg}${os.EOL}`
125+
);
126+
});
127+
128+
it('reports empty query results', async () => {
129+
let errMsg = 'unhandled download message';
130+
platSpy.mockImplementation(() => 'linux');
131+
archSpy.mockImplementation(() => 'x64');
132+
133+
inSpy.mockImplementation(() => '1.13.1');
134+
findSpy.mockImplementation(() => '');
135+
getSpy.mockImplementation(() => null);
136+
await run();
137+
138+
expect(cnSpy).toHaveBeenCalledWith(
139+
`::error::Failed to download version 1.13.1: Error: golang download url did not return results${os.EOL}`
140+
);
141+
});
142+
111143
it('can query versions', async () => {
112144
let versions: im.IGoVersion[] | null = await im.getVersions(
113145
'https://non.existant.com/path'

dist/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4617,7 +4617,7 @@ function findMatch(versionSpec, stable) {
46174617
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
46184618
let candidates = yield module.exports.getVersions(dlUrl);
46194619
if (!candidates) {
4620-
throw new Error(`golang download url did not return results: ${dlUrl}`);
4620+
throw new Error(`golang download url did not return results`);
46214621
}
46224622
let goFile;
46234623
for (let i = 0; i < candidates.length; i++) {
@@ -4656,8 +4656,7 @@ function getVersions(dlUrl) {
46564656
return __awaiter(this, void 0, void 0, function* () {
46574657
// this returns versions descending so latest is first
46584658
let http = new httpm.HttpClient('setup-go');
4659-
let candidates = (yield http.getJson(dlUrl)).result;
4660-
return candidates;
4659+
return (yield http.getJson(dlUrl)).result;
46614660
});
46624661
}
46634662
exports.getVersions = getVersions;

src/installer.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function findMatch(
6868
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
6969
let candidates: IGoVersion[] | null = await module.exports.getVersions(dlUrl);
7070
if (!candidates) {
71-
throw new Error(`golang download url did not return results: ${dlUrl}`);
71+
throw new Error(`golang download url did not return results`);
7272
}
7373

7474
let goFile: IGoVersionFile | undefined;
@@ -111,9 +111,5 @@ export async function findMatch(
111111
export async function getVersions(dlUrl: string): Promise<IGoVersion[] | null> {
112112
// this returns versions descending so latest is first
113113
let http: httpm.HttpClient = new httpm.HttpClient('setup-go');
114-
let candidates: IGoVersion[] | null = (await http.getJson<IGoVersion[]>(
115-
dlUrl
116-
)).result;
117-
118-
return candidates;
114+
return (await http.getJson<IGoVersion[]>(dlUrl)).result;
119115
}

0 commit comments

Comments
 (0)