mirror of
https://code.forgejo.org/actions/setup-go.git
synced 2024-11-06 04:35:48 -05:00
mocked tests work with no internet
This commit is contained in:
parent
cfc658b90a
commit
f4b0281c15
4 changed files with 12343 additions and 10220 deletions
File diff suppressed because it is too large
Load diff
|
@ -20,7 +20,7 @@ describe('setup-go', () => {
|
|||
let archSpy: jest.SpyInstance;
|
||||
let dlSpy: jest.SpyInstance;
|
||||
let exSpy: jest.SpyInstance;
|
||||
let http: httpm.HttpClient = new httpm.HttpClient('setup-go-tests');
|
||||
//let http: httpm.HttpClient = new httpm.HttpClient('setup-go-tests');
|
||||
|
||||
beforeEach(() => {
|
||||
tcSpy = jest.spyOn(tc, 'find');
|
||||
|
@ -30,13 +30,7 @@ describe('setup-go', () => {
|
|||
archSpy = jest.spyOn(sys, 'getArch');
|
||||
dlSpy = jest.spyOn(tc, 'downloadTool');
|
||||
exSpy = jest.spyOn(tc, 'extractTar');
|
||||
getSpy = jest.spyOn(http, 'getJson');
|
||||
getSpy.mockImplementation(
|
||||
() =>
|
||||
<ITypedResponse<im.IGoVersion[]>>{
|
||||
result: goJsonData
|
||||
}
|
||||
);
|
||||
getSpy = jest.spyOn(im, 'getVersions');
|
||||
cnSpy.mockImplementation(line => {
|
||||
// uncomment to debug
|
||||
//process.stderr.write('write2:' + line + '\n');
|
||||
|
@ -82,19 +76,21 @@ describe('setup-go', () => {
|
|||
});
|
||||
|
||||
it('can mock go versions query', async () => {
|
||||
let r: ITypedResponse<im.IGoVersion[]> = await http.getJson<
|
||||
im.IGoVersion[]
|
||||
>('https://asite.notexist.com/path');
|
||||
expect(r).toBeDefined();
|
||||
let versions = r.result;
|
||||
getSpy.mockImplementation(
|
||||
() => <im.IGoVersion[]>goJsonData
|
||||
);
|
||||
let versions: im.IGoVersion[] | null = await im.getVersions('https://non.existant.com/path');
|
||||
expect(versions).toBeDefined();
|
||||
let l: number = versions ? versions.length : 0;
|
||||
expect(l).toBe(76);
|
||||
expect(l).toBe(91);
|
||||
});
|
||||
|
||||
it('finds stable match for exact version', async () => {
|
||||
platSpy.mockImplementation(() => 'linux');
|
||||
archSpy.mockImplementation(() => 'amd64');
|
||||
getSpy.mockImplementation(
|
||||
() => <im.IGoVersion[]>goJsonData
|
||||
);
|
||||
|
||||
// get request is already mocked
|
||||
// spec: 1.13.1 => 1.13.1 (exact)
|
||||
|
|
15
dist/index.js
vendored
15
dist/index.js
vendored
|
@ -4558,7 +4558,7 @@ module.exports = require("fs");
|
|||
/***/ }),
|
||||
|
||||
/***/ 749:
|
||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
@ -4614,9 +4614,7 @@ function findMatch(versionSpec, stable) {
|
|||
let platFilter = sys.getPlatform();
|
||||
let match;
|
||||
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
|
||||
// this returns versions descending so latest is first
|
||||
let http = new httpm.HttpClient('setup-go');
|
||||
let candidates = (yield http.getJson(dlUrl)).result;
|
||||
let candidates = yield module.exports.getVersions(dlUrl);
|
||||
if (!candidates) {
|
||||
throw new Error(`golang download url did not return results: ${dlUrl}`);
|
||||
}
|
||||
|
@ -4647,6 +4645,15 @@ function findMatch(versionSpec, stable) {
|
|||
});
|
||||
}
|
||||
exports.findMatch = findMatch;
|
||||
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;
|
||||
});
|
||||
}
|
||||
exports.getVersions = getVersions;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
|
|
@ -56,14 +56,9 @@ export async function findMatch(
|
|||
let platFilter = sys.getPlatform();
|
||||
|
||||
let match: IGoVersion | undefined;
|
||||
|
||||
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
|
||||
|
||||
// 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;
|
||||
|
||||
let candidates: IGoVersion[] | null = await module.exports.getVersions(dlUrl);
|
||||
if (!candidates) {
|
||||
throw new Error(`golang download url did not return results: ${dlUrl}`);
|
||||
}
|
||||
|
@ -98,3 +93,13 @@ export async function findMatch(
|
|||
|
||||
return match;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue