mirror of
https://code.forgejo.org/actions/setup-go.git
synced 2024-11-23 11:51:03 -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 archSpy: jest.SpyInstance;
|
||||||
let dlSpy: jest.SpyInstance;
|
let dlSpy: jest.SpyInstance;
|
||||||
let exSpy: 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(() => {
|
beforeEach(() => {
|
||||||
tcSpy = jest.spyOn(tc, 'find');
|
tcSpy = jest.spyOn(tc, 'find');
|
||||||
|
@ -30,13 +30,7 @@ describe('setup-go', () => {
|
||||||
archSpy = jest.spyOn(sys, 'getArch');
|
archSpy = jest.spyOn(sys, 'getArch');
|
||||||
dlSpy = jest.spyOn(tc, 'downloadTool');
|
dlSpy = jest.spyOn(tc, 'downloadTool');
|
||||||
exSpy = jest.spyOn(tc, 'extractTar');
|
exSpy = jest.spyOn(tc, 'extractTar');
|
||||||
getSpy = jest.spyOn(http, 'getJson');
|
getSpy = jest.spyOn(im, 'getVersions');
|
||||||
getSpy.mockImplementation(
|
|
||||||
() =>
|
|
||||||
<ITypedResponse<im.IGoVersion[]>>{
|
|
||||||
result: goJsonData
|
|
||||||
}
|
|
||||||
);
|
|
||||||
cnSpy.mockImplementation(line => {
|
cnSpy.mockImplementation(line => {
|
||||||
// uncomment to debug
|
// uncomment to debug
|
||||||
//process.stderr.write('write2:' + line + '\n');
|
//process.stderr.write('write2:' + line + '\n');
|
||||||
|
@ -82,19 +76,21 @@ describe('setup-go', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can mock go versions query', async () => {
|
it('can mock go versions query', async () => {
|
||||||
let r: ITypedResponse<im.IGoVersion[]> = await http.getJson<
|
getSpy.mockImplementation(
|
||||||
im.IGoVersion[]
|
() => <im.IGoVersion[]>goJsonData
|
||||||
>('https://asite.notexist.com/path');
|
);
|
||||||
expect(r).toBeDefined();
|
let versions: im.IGoVersion[] | null = await im.getVersions('https://non.existant.com/path');
|
||||||
let versions = r.result;
|
|
||||||
expect(versions).toBeDefined();
|
expect(versions).toBeDefined();
|
||||||
let l: number = versions ? versions.length : 0;
|
let l: number = versions ? versions.length : 0;
|
||||||
expect(l).toBe(76);
|
expect(l).toBe(91);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('finds stable match for exact version', async () => {
|
it('finds stable match for exact version', async () => {
|
||||||
platSpy.mockImplementation(() => 'linux');
|
platSpy.mockImplementation(() => 'linux');
|
||||||
archSpy.mockImplementation(() => 'amd64');
|
archSpy.mockImplementation(() => 'amd64');
|
||||||
|
getSpy.mockImplementation(
|
||||||
|
() => <im.IGoVersion[]>goJsonData
|
||||||
|
);
|
||||||
|
|
||||||
// get request is already mocked
|
// get request is already mocked
|
||||||
// spec: 1.13.1 => 1.13.1 (exact)
|
// 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:
|
/***/ 749:
|
||||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
/***/ (function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
@ -4614,9 +4614,7 @@ function findMatch(versionSpec, stable) {
|
||||||
let platFilter = sys.getPlatform();
|
let platFilter = sys.getPlatform();
|
||||||
let match;
|
let match;
|
||||||
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
|
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
|
||||||
// this returns versions descending so latest is first
|
let candidates = yield module.exports.getVersions(dlUrl);
|
||||||
let http = new httpm.HttpClient('setup-go');
|
|
||||||
let candidates = (yield http.getJson(dlUrl)).result;
|
|
||||||
if (!candidates) {
|
if (!candidates) {
|
||||||
throw new Error(`golang download url did not return results: ${dlUrl}`);
|
throw new Error(`golang download url did not return results: ${dlUrl}`);
|
||||||
}
|
}
|
||||||
|
@ -4647,6 +4645,15 @@ function findMatch(versionSpec, stable) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.findMatch = findMatch;
|
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 platFilter = sys.getPlatform();
|
||||||
|
|
||||||
let match: IGoVersion | undefined;
|
let match: IGoVersion | undefined;
|
||||||
|
|
||||||
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
|
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
|
||||||
|
let candidates: IGoVersion[] | null = await module.exports.getVersions(dlUrl);
|
||||||
// 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;
|
|
||||||
|
|
||||||
if (!candidates) {
|
if (!candidates) {
|
||||||
throw new Error(`golang download url did not return results: ${dlUrl}`);
|
throw new Error(`golang download url did not return results: ${dlUrl}`);
|
||||||
}
|
}
|
||||||
|
@ -98,3 +93,13 @@ export async function findMatch(
|
||||||
|
|
||||||
return match;
|
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