mirror of
https://github.com/actions/setup-go.git
synced 2025-06-23 05:27:58 +02:00
Handle .x version syntax with latest release (#13)
* get latest release for .x syntax version * added nock as dev dependency * added test for .x syntax * updated readme * updated http client name * use rest client for getting available versions * more .x handling * move nock to setup and teardown
This commit is contained in:

committed by
Danny McCormick

parent
5064ef8f2b
commit
632d18fc92
2482
__tests__/data/golang-tags.json
Normal file
2482
__tests__/data/golang-tags.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,9 +2,11 @@ import io = require('@actions/io');
|
||||
import fs = require('fs');
|
||||
import os = require('os');
|
||||
import path = require('path');
|
||||
import nock = require('nock');
|
||||
|
||||
const toolDir = path.join(__dirname, 'runner', 'tools');
|
||||
const tempDir = path.join(__dirname, 'runner', 'temp');
|
||||
const dataDir = path.join(__dirname, 'data');
|
||||
|
||||
process.env['RUNNER_TOOL_CACHE'] = toolDir;
|
||||
process.env['RUNNER_TEMP'] = tempDir;
|
||||
@ -28,8 +30,8 @@ describe('installer tests', () => {
|
||||
}, 100000);
|
||||
|
||||
it('Acquires version of go if no matching version is installed', async () => {
|
||||
await installer.getGo('1.10');
|
||||
const goDir = path.join(toolDir, 'go', '1.10.0', os.arch());
|
||||
await installer.getGo('1.10.8');
|
||||
const goDir = path.join(toolDir, 'go', '1.10.8', os.arch());
|
||||
|
||||
expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
|
||||
if (IS_WINDOWS) {
|
||||
@ -39,6 +41,55 @@ describe('installer tests', () => {
|
||||
}
|
||||
}, 100000);
|
||||
|
||||
describe('the latest release of a go version', () => {
|
||||
beforeEach(() => {
|
||||
nock('https://api.github.com')
|
||||
.get('/repos/golang/go/git/refs/tags')
|
||||
.replyWithFile(200, path.join(dataDir, 'golang-tags.json'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
nock.cleanAll();
|
||||
nock.enableNetConnect();
|
||||
});
|
||||
|
||||
it('Acquires latest release version of go 1.10 if using 1.10 and no matching version is installed', async () => {
|
||||
await installer.getGo('1.10');
|
||||
const goDir = path.join(toolDir, 'go', '1.10.8', os.arch());
|
||||
|
||||
expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
|
||||
if (IS_WINDOWS) {
|
||||
expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true);
|
||||
} else {
|
||||
expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true);
|
||||
}
|
||||
}, 100000);
|
||||
|
||||
it('Acquires latest release version of go 1.10 if using 1.10.x and no matching version is installed', async () => {
|
||||
await installer.getGo('1.10.x');
|
||||
const goDir = path.join(toolDir, 'go', '1.10.8', os.arch());
|
||||
|
||||
expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
|
||||
if (IS_WINDOWS) {
|
||||
expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true);
|
||||
} else {
|
||||
expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true);
|
||||
}
|
||||
}, 100000);
|
||||
|
||||
it('Acquires latest release version of go if using 1.x and no matching version is installed', async () => {
|
||||
await installer.getGo('1.x');
|
||||
const goDir = path.join(toolDir, 'go', '1.13.0-beta1', os.arch());
|
||||
|
||||
expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
|
||||
if (IS_WINDOWS) {
|
||||
expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true);
|
||||
} else {
|
||||
expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true);
|
||||
}
|
||||
}, 100000);
|
||||
});
|
||||
|
||||
it('Throws if no location contains correct go version', async () => {
|
||||
let thrown = false;
|
||||
try {
|
||||
|
Reference in New Issue
Block a user