mirror of
https://gitea.com/actions/setup-go.git
synced 2024-11-22 01:29:32 +01:00
another test
This commit is contained in:
parent
241a335117
commit
6cb99a33d7
3 changed files with 36 additions and 9 deletions
|
@ -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'
|
||||
|
|
5
dist/index.js
vendored
5
dist/index.js
vendored
|
@ -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;
|
||||
|
|
|
@ -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<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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue