| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  | import * as core from '@actions/core'; | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  | import * as io from '@actions/io'; | 
					
						
							|  |  |  | import * as tc from '@actions/tool-cache'; | 
					
						
							|  |  |  | import fs from 'fs'; | 
					
						
							|  |  |  | import cp from 'child_process'; | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  | import osm from 'os'; | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  | import path from 'path'; | 
					
						
							|  |  |  | import * as main from '../src/main'; | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  | import * as im from '../src/installer'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let goJsonData = require('./data/golang-dl.json'); | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  | let matchers = require('../matchers.json'); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  | let goTestManifest = require('./data/versions-manifest.json'); | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  | let matcherPattern = matchers.problemMatcher[0].pattern[0]; | 
					
						
							|  |  |  | let matcherRegExp = new RegExp(matcherPattern.regexp); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('setup-go', () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |   let inputs = {} as any; | 
					
						
							|  |  |  |   let os = {} as any; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   let inSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |   let getBooleanInputSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |   let exportVarSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  |   let findSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   let cnSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |   let logSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   let getSpy: jest.SpyInstance; | 
					
						
							|  |  |  |   let platSpy: jest.SpyInstance; | 
					
						
							|  |  |  |   let archSpy: jest.SpyInstance; | 
					
						
							|  |  |  |   let dlSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |   let extractTarSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  |   let cacheSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |   let dbgSpy: jest.SpyInstance; | 
					
						
							|  |  |  |   let whichSpy: jest.SpyInstance; | 
					
						
							|  |  |  |   let existsSpy: jest.SpyInstance; | 
					
						
							|  |  |  |   let mkdirpSpy: jest.SpyInstance; | 
					
						
							|  |  |  |   let execSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |   let getManifestSpy: jest.SpyInstance; | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |   beforeAll(async () => { | 
					
						
							|  |  |  |     process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
 | 
					
						
							|  |  |  |   }, 100000); | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |     process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     // @actions/core
 | 
					
						
							|  |  |  |     inputs = {}; | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |     inSpy = jest.spyOn(core, 'getInput'); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     inSpy.mockImplementation(name => inputs[name]); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |     getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput'); | 
					
						
							|  |  |  |     getBooleanInputSpy.mockImplementation(name => inputs[name]); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     exportVarSpy = jest.spyOn(core, 'exportVariable'); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     // node
 | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     os = {}; | 
					
						
							|  |  |  |     platSpy = jest.spyOn(osm, 'platform'); | 
					
						
							|  |  |  |     platSpy.mockImplementation(() => os['platform']); | 
					
						
							|  |  |  |     archSpy = jest.spyOn(osm, 'arch'); | 
					
						
							|  |  |  |     archSpy.mockImplementation(() => os['arch']); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     execSpy = jest.spyOn(cp, 'execSync'); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // @actions/tool-cache
 | 
					
						
							|  |  |  |     findSpy = jest.spyOn(tc, 'find'); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:29:21 -05:00
										 |  |  |     dlSpy = jest.spyOn(tc, 'downloadTool'); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     extractTarSpy = jest.spyOn(tc, 'extractTar'); | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  |     cacheSpy = jest.spyOn(tc, 'cacheDir'); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     getSpy = jest.spyOn(im, 'getVersionsDist'); | 
					
						
							|  |  |  |     getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo'); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     // io
 | 
					
						
							|  |  |  |     whichSpy = jest.spyOn(io, 'which'); | 
					
						
							|  |  |  |     existsSpy = jest.spyOn(fs, 'existsSync'); | 
					
						
							|  |  |  |     mkdirpSpy = jest.spyOn(io, 'mkdirP'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     // gets
 | 
					
						
							|  |  |  |     getManifestSpy.mockImplementation(() => <tc.IToolRelease[]>goTestManifest); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     // writes
 | 
					
						
							|  |  |  |     cnSpy = jest.spyOn(process.stdout, 'write'); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     logSpy = jest.spyOn(core, 'info'); | 
					
						
							|  |  |  |     dbgSpy = jest.spyOn(core, 'debug'); | 
					
						
							|  |  |  |     getSpy.mockImplementation(() => <im.IGoVersion[] | null>goJsonData); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |     cnSpy.mockImplementation(line => { | 
					
						
							|  |  |  |       // uncomment to debug
 | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |       // process.stderr.write('write:' + line + '\n');
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     logSpy.mockImplementation(line => { | 
					
						
							|  |  |  |       // uncomment to debug
 | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |       process.stderr.write('log:' + line + '\n'); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     dbgSpy.mockImplementation(msg => { | 
					
						
							|  |  |  |       // uncomment to see debug output
 | 
					
						
							|  |  |  |       // process.stderr.write(msg + '\n');
 | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   afterEach(() => { | 
					
						
							| 
									
										
										
										
											2020-02-09 14:39:34 -05:00
										 |  |  |     jest.resetAllMocks(); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |     jest.clearAllMocks(); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     //jest.restoreAllMocks();
 | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:00 -04:00
										 |  |  |   afterAll(async () => { | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |     jest.restoreAllMocks(); | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:00 -04:00
										 |  |  |   }, 100000); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |   it('can find 1.9.7 from manifest on osx', async () => { | 
					
						
							|  |  |  |     os.platform = 'darwin'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); | 
					
						
							|  |  |  |     expect(match).toBeDefined(); | 
					
						
							|  |  |  |     expect(match!.resolvedVersion).toBe('1.9.7'); | 
					
						
							|  |  |  |     expect(match!.type).toBe('manifest'); | 
					
						
							|  |  |  |     expect(match!.downloadUrl).toBe( | 
					
						
							|  |  |  |       'https://github.com/actions/go-versions/releases/download/1.9.7/go-1.9.7-darwin-x64.tar.gz' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('can find 1.9 from manifest on linux', async () => { | 
					
						
							|  |  |  |     os.platform = 'linux'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); | 
					
						
							|  |  |  |     expect(match).toBeDefined(); | 
					
						
							|  |  |  |     expect(match!.resolvedVersion).toBe('1.9.7'); | 
					
						
							|  |  |  |     expect(match!.type).toBe('manifest'); | 
					
						
							|  |  |  |     expect(match!.downloadUrl).toBe( | 
					
						
							|  |  |  |       'https://github.com/actions/go-versions/releases/download/1.9.7/go-1.9.7-linux-x64.tar.gz' | 
					
						
							| 
									
										
										
										
											2020-02-10 19:18:01 -05:00
										 |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |   it('can find 1.9 from manifest on windows', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 19:18:01 -05:00
										 |  |  |     os.platform = 'win32'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); | 
					
						
							| 
									
										
										
										
											2020-02-10 19:18:01 -05:00
										 |  |  |     expect(match).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     expect(match!.resolvedVersion).toBe('1.9.7'); | 
					
						
							|  |  |  |     expect(match!.type).toBe('manifest'); | 
					
						
							|  |  |  |     expect(match!.downloadUrl).toBe( | 
					
						
							|  |  |  |       'https://github.com/actions/go-versions/releases/download/1.9.7/go-1.9.7-win32-x64.zip' | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-02-10 19:18:01 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-09 19:05:20 -05:00
										 |  |  |   it('finds stable match for exact dot zero version', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     os.platform = 'darwin'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							| 
									
										
										
										
											2020-02-09 19:05:20 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // spec: 1.13.0 => 1.13
 | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |     let match: im.IGoVersion | undefined = await im.findMatch('1.13.0'); | 
					
						
							| 
									
										
										
										
											2020-02-09 19:05:20 -05:00
										 |  |  |     expect(match).toBeDefined(); | 
					
						
							|  |  |  |     let version: string = match ? match.version : ''; | 
					
						
							|  |  |  |     expect(version).toBe('go1.13'); | 
					
						
							|  |  |  |     let fileName = match ? match.files[0].filename : ''; | 
					
						
							|  |  |  |     expect(fileName).toBe('go1.13.darwin-amd64.tar.gz'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('finds latest patch version for minor version spec', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     os.platform = 'linux'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							| 
									
										
										
										
											2020-02-09 19:05:20 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // spec: 1.13 => 1.13.7 (latest)
 | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |     let match: im.IGoVersion | undefined = await im.findMatch('1.13'); | 
					
						
							| 
									
										
										
										
											2020-02-09 19:05:20 -05:00
										 |  |  |     expect(match).toBeDefined(); | 
					
						
							|  |  |  |     let version: string = match ? match.version : ''; | 
					
						
							|  |  |  |     expect(version).toBe('go1.13.7'); | 
					
						
							|  |  |  |     let fileName = match ? match.files[0].filename : ''; | 
					
						
							|  |  |  |     expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('finds latest patch version for caret version spec', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     os.platform = 'linux'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							| 
									
										
										
										
											2020-02-09 19:05:20 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // spec: ^1.13.6 => 1.13.7
 | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |     let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6'); | 
					
						
							| 
									
										
										
										
											2020-02-09 19:05:20 -05:00
										 |  |  |     expect(match).toBeDefined(); | 
					
						
							|  |  |  |     let version: string = match ? match.version : ''; | 
					
						
							|  |  |  |     expect(version).toBe('go1.13.7'); | 
					
						
							|  |  |  |     let fileName = match ? match.files[0].filename : ''; | 
					
						
							|  |  |  |     expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('finds latest version for major version spec', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     os.platform = 'win32'; | 
					
						
							|  |  |  |     os.arch = 'x32'; | 
					
						
							| 
									
										
										
										
											2020-02-09 19:05:20 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // spec: 1 => 1.13.7 (latest)
 | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |     let match: im.IGoVersion | undefined = await im.findMatch('1'); | 
					
						
							| 
									
										
										
										
											2020-02-09 19:05:20 -05:00
										 |  |  |     expect(match).toBeDefined(); | 
					
						
							|  |  |  |     let version: string = match ? match.version : ''; | 
					
						
							|  |  |  |     expect(version).toBe('go1.13.7'); | 
					
						
							|  |  |  |     let fileName = match ? match.files[0].filename : ''; | 
					
						
							|  |  |  |     expect(fileName).toBe('go1.13.7.windows-386.zip'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 19:18:01 -05:00
										 |  |  |   it('finds unstable pre-release version', async () => { | 
					
						
							|  |  |  |     os.platform = 'linux'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // spec: 1.14, stable=false => go1.14rc1
 | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |     let match: im.IGoVersion | undefined = await im.findMatch('1.14.0-rc.1'); | 
					
						
							| 
									
										
										
										
											2020-02-10 19:18:01 -05:00
										 |  |  |     expect(match).toBeDefined(); | 
					
						
							|  |  |  |     let version: string = match ? match.version : ''; | 
					
						
							|  |  |  |     expect(version).toBe('go1.14rc1'); | 
					
						
							|  |  |  |     let fileName = match ? match.files[0].filename : ''; | 
					
						
							|  |  |  |     expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |   it('evaluates to stable with input as true', async () => { | 
					
						
							|  |  |  |     inputs['go-version'] = '1.13.0'; | 
					
						
							|  |  |  |     inputs.stable = 'true'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let toolPath = path.normalize('/cache/go/1.13.0/x64'); | 
					
						
							|  |  |  |     findSpy.mockImplementation(() => toolPath); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     await main.run(); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |     expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('evaluates to stable with no input', async () => { | 
					
						
							|  |  |  |     inputs['go-version'] = '1.13.0'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inSpy.mockImplementation(name => inputs[name]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let toolPath = path.normalize('/cache/go/1.13.0/x64'); | 
					
						
							|  |  |  |     findSpy.mockImplementation(() => toolPath); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     await main.run(); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |     expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |   it('does not export any variables for Go versions >=1.9', async () => { | 
					
						
							| 
									
										
										
										
											2021-12-14 13:12:54 -05:00
										 |  |  |     inputs['go-version'] = '1.13.0'; | 
					
						
							|  |  |  |     inSpy.mockImplementation(name => inputs[name]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let toolPath = path.normalize('/cache/go/1.13.0/x64'); | 
					
						
							|  |  |  |     findSpy.mockImplementation(() => toolPath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-14 12:23:03 -04:00
										 |  |  |     let vars: {[key: string]: string} = {}; | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     exportVarSpy.mockImplementation((name: string, val: string) => { | 
					
						
							| 
									
										
										
										
											2021-12-14 13:12:54 -05:00
										 |  |  |       vars[name] = val; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await main.run(); | 
					
						
							| 
									
										
										
										
											2021-12-14 13:24:18 -05:00
										 |  |  |     expect(vars).toStrictEqual({}); | 
					
						
							| 
									
										
										
										
											2021-12-14 13:12:54 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |   it('exports GOROOT for Go versions <1.9', async () => { | 
					
						
							|  |  |  |     inputs['go-version'] = '1.8'; | 
					
						
							|  |  |  |     inSpy.mockImplementation(name => inputs[name]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let toolPath = path.normalize('/cache/go/1.8.0/x64'); | 
					
						
							|  |  |  |     findSpy.mockImplementation(() => toolPath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-14 12:23:03 -04:00
										 |  |  |     let vars: {[key: string]: string} = {}; | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     exportVarSpy.mockImplementation((name: string, val: string) => { | 
					
						
							|  |  |  |       vars[name] = val; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await main.run(); | 
					
						
							|  |  |  |     expect(vars).toStrictEqual({ | 
					
						
							| 
									
										
										
										
											2022-03-14 12:23:03 -04:00
										 |  |  |       GOROOT: toolPath | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   it('finds a version of go already in the cache', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     inputs['go-version'] = '1.13.0'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |     let toolPath = path.normalize('/cache/go/1.13.0/x64'); | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  |     findSpy.mockImplementation(() => toolPath); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     await main.run(); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let expPath = path.join(toolPath, 'bin'); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('finds a version in the cache and adds it to the path', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     inputs['go-version'] = '1.13.0'; | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |     let toolPath = path.normalize('/cache/go/1.13.0/x64'); | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  |     findSpy.mockImplementation(() => toolPath); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     await main.run(); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let expPath = path.join(toolPath, 'bin'); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('handles unhandled error and reports error', async () => { | 
					
						
							|  |  |  |     let errMsg = 'unhandled error message'; | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     inputs['go-version'] = '1.13.0'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  |     findSpy.mockImplementation(() => { | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |       throw new Error(errMsg); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     await main.run(); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     expect(cnSpy).toHaveBeenCalledWith('::error::' + errMsg + osm.EOL); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  |   it('downloads a version not in the cache', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     os.platform = 'linux'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inputs['go-version'] = '1.13.1'; | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     findSpy.mockImplementation(() => ''); | 
					
						
							|  |  |  |     dlSpy.mockImplementation(() => '/some/temp/path'); | 
					
						
							|  |  |  |     let toolPath = path.normalize('/cache/go/1.13.0/x64'); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     extractTarSpy.mockImplementation(() => '/some/other/temp/path'); | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  |     cacheSpy.mockImplementation(() => toolPath); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     await main.run(); | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let expPath = path.join(toolPath, 'bin'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(dlSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     expect(extractTarSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('does not find a version that does not exist', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     os.platform = 'linux'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inputs['go-version'] = '9.99.9'; | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     findSpy.mockImplementation(() => ''); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     await main.run(); | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(cnSpy).toHaveBeenCalledWith( | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |       `::error::Unable to find Go version '9.99.9' for platform linux and architecture x64.${osm.EOL}` | 
					
						
							| 
									
										
										
										
											2020-02-09 18:09:15 -05:00
										 |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |   it('downloads a version from a manifest match', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     os.platform = 'linux'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     let versionSpec = '1.12.16'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inputs['go-version'] = versionSpec; | 
					
						
							|  |  |  |     inputs['token'] = 'faketoken'; | 
					
						
							| 
									
										
										
										
											2020-02-09 18:48:40 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     let expectedUrl = | 
					
						
							|  |  |  |       'https://github.com/actions/go-versions/releases/download/1.12.16-20200616.20/go-1.12.16-linux-x64.tar.gz'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // ... but not in the local cache
 | 
					
						
							| 
									
										
										
										
											2020-02-09 18:48:40 -05:00
										 |  |  |     findSpy.mockImplementation(() => ''); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     dlSpy.mockImplementation(async () => '/some/temp/path'); | 
					
						
							|  |  |  |     let toolPath = path.normalize('/cache/go/1.12.16/x64'); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     cacheSpy.mockImplementation(async () => toolPath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     await main.run(); | 
					
						
							| 
									
										
										
										
											2020-02-09 18:48:40 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     let expPath = path.join(toolPath, 'bin'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(dlSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     expect(extractTarSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     expect(logSpy).not.toHaveBeenCalledWith( | 
					
						
							|  |  |  |       'Not found in manifest.  Falling back to download directly from Go' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |       `Acquiring 1.12.16 from ${expectedUrl}` | 
					
						
							| 
									
										
										
										
											2020-02-09 18:48:40 -05:00
										 |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(logSpy).toHaveBeenCalledWith(`Added go to the path`); | 
					
						
							|  |  |  |     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | 
					
						
							| 
									
										
										
										
											2020-02-09 18:48:40 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |   it('downloads a major and minor from a manifest match', async () => { | 
					
						
							|  |  |  |     os.platform = 'linux'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let versionSpec = '1.12'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inputs['go-version'] = versionSpec; | 
					
						
							|  |  |  |     inputs['token'] = 'faketoken'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let expectedUrl = | 
					
						
							|  |  |  |       'https://github.com/actions/go-versions/releases/download/1.12.17-20200616.21/go-1.12.17-linux-x64.tar.gz'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // ... but not in the local cache
 | 
					
						
							|  |  |  |     findSpy.mockImplementation(() => ''); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dlSpy.mockImplementation(async () => '/some/temp/path'); | 
					
						
							|  |  |  |     let toolPath = path.normalize('/cache/go/1.12.17/x64'); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     cacheSpy.mockImplementation(async () => toolPath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await main.run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let expPath = path.join(toolPath, 'bin'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(dlSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     expect(extractTarSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     expect(logSpy).not.toHaveBeenCalledWith( | 
					
						
							|  |  |  |       'Not found in manifest.  Falling back to download directly from Go' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |       `Acquiring 1.12.17 from ${expectedUrl}` | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(logSpy).toHaveBeenCalledWith(`Added go to the path`); | 
					
						
							|  |  |  |     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('falls back to a version from node dist', async () => { | 
					
						
							|  |  |  |     os.platform = 'linux'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let versionSpec = '1.12.14'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inputs['go-version'] = versionSpec; | 
					
						
							|  |  |  |     inputs['token'] = 'faketoken'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let expectedUrl = | 
					
						
							|  |  |  |       'https://github.com/actions/go-versions/releases/download/1.12.14-20200616.18/go-1.12.14-linux-x64.tar.gz'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // ... but not in the local cache
 | 
					
						
							|  |  |  |     findSpy.mockImplementation(() => ''); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dlSpy.mockImplementation(async () => '/some/temp/path'); | 
					
						
							|  |  |  |     let toolPath = path.normalize('/cache/go/1.12.14/x64'); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     cacheSpy.mockImplementation(async () => toolPath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await main.run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let expPath = path.join(toolPath, 'bin'); | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |     expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.12.14'); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     expect(findSpy).toHaveBeenCalled(); | 
					
						
							|  |  |  |     expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.12.14...'); | 
					
						
							|  |  |  |     expect(dlSpy).toHaveBeenCalled(); | 
					
						
							|  |  |  |     expect(logSpy).toHaveBeenCalledWith('matching 1.12.14...'); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |     expect(extractTarSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |       'Not found in manifest.  Falling back to download directly from Go' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(logSpy).toHaveBeenCalledWith(`Install from dist`); | 
					
						
							|  |  |  |     expect(logSpy).toHaveBeenCalledWith(`Added go to the path`); | 
					
						
							|  |  |  |     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('reports a failed download', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-09 18:48:40 -05:00
										 |  |  |     let errMsg = 'unhandled download message'; | 
					
						
							| 
									
										
										
										
											2020-02-10 15:21:04 -05:00
										 |  |  |     os.platform = 'linux'; | 
					
						
							|  |  |  |     os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inputs['go-version'] = '1.13.1'; | 
					
						
							| 
									
										
										
										
											2020-02-09 18:48:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     findSpy.mockImplementation(() => ''); | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |     dlSpy.mockImplementation(() => { | 
					
						
							|  |  |  |       throw new Error(errMsg); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |     await main.run(); | 
					
						
							| 
									
										
										
										
											2020-02-09 18:48:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(cnSpy).toHaveBeenCalledWith( | 
					
						
							| 
									
										
										
										
											2020-06-29 18:41:13 +03:00
										 |  |  |       `::error::Failed to download version 1.13.1: Error: ${errMsg}${osm.EOL}` | 
					
						
							| 
									
										
										
										
											2020-02-09 18:48:40 -05:00
										 |  |  |     ); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 00:55:12 -04:00
										 |  |  |   it('does not add BIN if go is not in path', async () => { | 
					
						
							|  |  |  |     whichSpy.mockImplementation(async () => { | 
					
						
							|  |  |  |       return ''; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     let added = await main.addBinToPath(); | 
					
						
							|  |  |  |     expect(added).toBeFalsy(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('adds bin if dir not exists', async () => { | 
					
						
							|  |  |  |     whichSpy.mockImplementation(async () => { | 
					
						
							|  |  |  |       return '/usr/local/go/bin/go'; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     execSpy.mockImplementation(() => { | 
					
						
							|  |  |  |       return '/Users/testuser/go'; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mkdirpSpy.mockImplementation(async () => {}); | 
					
						
							|  |  |  |     existsSpy.mockImplementation(path => { | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let added = await main.addBinToPath(); | 
					
						
							|  |  |  |     expect(added).toBeTruthy; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  |   interface Annotation { | 
					
						
							| 
									
										
										
										
											2020-03-27 19:58:10 -04:00
										 |  |  |     file: string; | 
					
						
							|  |  |  |     line: number; | 
					
						
							|  |  |  |     column: number; | 
					
						
							|  |  |  |     message: string; | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // problem matcher regex pattern tests
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function testMatch(line: string): Annotation { | 
					
						
							|  |  |  |     let annotation = <Annotation>{}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let match = matcherRegExp.exec(line); | 
					
						
							|  |  |  |     if (match) { | 
					
						
							|  |  |  |       annotation.line = parseInt(match[matcherPattern.line], 10); | 
					
						
							|  |  |  |       annotation.column = parseInt(match[matcherPattern.column], 10); | 
					
						
							|  |  |  |       annotation.file = match[matcherPattern.file].trim(); | 
					
						
							|  |  |  |       annotation.message = match[matcherPattern.message].trim(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return annotation; | 
					
						
							| 
									
										
										
										
											2020-03-27 19:58:10 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 20:14:29 -04:00
										 |  |  |   it('matches on relative unix path', async () => { | 
					
						
							|  |  |  |     let line = './main.go:13:2: undefined: fmt.Printl'; | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  |     let annotation = testMatch(line); | 
					
						
							|  |  |  |     expect(annotation).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2020-03-27 20:14:29 -04:00
										 |  |  |     expect(annotation.line).toBe(13); | 
					
						
							|  |  |  |     expect(annotation.column).toBe(2); | 
					
						
							|  |  |  |     expect(annotation.file).toBe('./main.go'); | 
					
						
							|  |  |  |     expect(annotation.message).toBe('undefined: fmt.Printl'); | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 20:14:29 -04:00
										 |  |  |   it('matches on unix path up the tree', async () => { | 
					
						
							|  |  |  |     let line = '../main.go:13:2: undefined: fmt.Printl'; | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  |     let annotation = testMatch(line); | 
					
						
							|  |  |  |     expect(annotation).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2020-03-27 20:14:29 -04:00
										 |  |  |     expect(annotation.line).toBe(13); | 
					
						
							|  |  |  |     expect(annotation.column).toBe(2); | 
					
						
							|  |  |  |     expect(annotation.file).toBe('../main.go'); | 
					
						
							|  |  |  |     expect(annotation.message).toBe('undefined: fmt.Printl'); | 
					
						
							| 
									
										
										
										
											2020-03-27 20:21:13 -04:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-17 16:47:05 +01:00
										 |  |  |   it('matches on unix path down the tree', async () => { | 
					
						
							|  |  |  |     let line = 'foo/main.go:13:2: undefined: fmt.Printl'; | 
					
						
							|  |  |  |     let annotation = testMatch(line); | 
					
						
							|  |  |  |     expect(annotation).toBeDefined(); | 
					
						
							|  |  |  |     expect(annotation.line).toBe(13); | 
					
						
							|  |  |  |     expect(annotation.column).toBe(2); | 
					
						
							|  |  |  |     expect(annotation.file).toBe('foo/main.go'); | 
					
						
							|  |  |  |     expect(annotation.message).toBe('undefined: fmt.Printl'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  |   it('matches on rooted unix path', async () => { | 
					
						
							|  |  |  |     let line = '/assert.go:4:1: missing return at end of function'; | 
					
						
							|  |  |  |     let annotation = testMatch(line); | 
					
						
							|  |  |  |     expect(annotation).toBeDefined(); | 
					
						
							|  |  |  |     expect(annotation.line).toBe(4); | 
					
						
							|  |  |  |     expect(annotation.column).toBe(1); | 
					
						
							|  |  |  |     expect(annotation.file).toBe('/assert.go'); | 
					
						
							|  |  |  |     expect(annotation.message).toBe('missing return at end of function'); | 
					
						
							| 
									
										
										
										
											2020-03-27 19:58:10 -04:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 10:46:01 -04:00
										 |  |  |   it('matches on unix path with spaces', async () => { | 
					
						
							| 
									
										
										
										
											2020-03-27 20:14:29 -04:00
										 |  |  |     let line = '   ./assert.go:5:2: missing return at end of function   '; | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  |     let annotation = testMatch(line); | 
					
						
							|  |  |  |     expect(annotation).toBeDefined(); | 
					
						
							|  |  |  |     expect(annotation.line).toBe(5); | 
					
						
							|  |  |  |     expect(annotation.column).toBe(2); | 
					
						
							| 
									
										
										
										
											2020-03-27 20:14:29 -04:00
										 |  |  |     expect(annotation.file).toBe('./assert.go'); | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  |     expect(annotation.message).toBe('missing return at end of function'); | 
					
						
							| 
									
										
										
										
											2020-03-27 19:58:10 -04:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-03-27 19:56:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 10:46:01 -04:00
										 |  |  |   it('matches on unix path with tabs', async () => { | 
					
						
							|  |  |  |     let line = '\t./assert.go:5:2: missing return at end of function   '; | 
					
						
							|  |  |  |     let annotation = testMatch(line); | 
					
						
							|  |  |  |     expect(annotation).toBeDefined(); | 
					
						
							|  |  |  |     expect(annotation.line).toBe(5); | 
					
						
							|  |  |  |     expect(annotation.column).toBe(2); | 
					
						
							|  |  |  |     expect(annotation.file).toBe('./assert.go'); | 
					
						
							|  |  |  |     expect(annotation.message).toBe('missing return at end of function'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 20:14:29 -04:00
										 |  |  |   it('matches on relative windows path', async () => { | 
					
						
							|  |  |  |     let line = '.\\main.go:13:2: undefined: fmt.Printl'; | 
					
						
							|  |  |  |     let annotation = testMatch(line); | 
					
						
							|  |  |  |     expect(annotation).toBeDefined(); | 
					
						
							|  |  |  |     expect(annotation.line).toBe(13); | 
					
						
							|  |  |  |     expect(annotation.column).toBe(2); | 
					
						
							|  |  |  |     expect(annotation.file).toBe('.\\main.go'); | 
					
						
							|  |  |  |     expect(annotation.message).toBe('undefined: fmt.Printl'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('matches on windows path up the tree', async () => { | 
					
						
							|  |  |  |     let line = '..\\main.go:13:2: undefined: fmt.Printl'; | 
					
						
							|  |  |  |     let annotation = testMatch(line); | 
					
						
							|  |  |  |     expect(annotation).toBeDefined(); | 
					
						
							|  |  |  |     expect(annotation.line).toBe(13); | 
					
						
							|  |  |  |     expect(annotation.column).toBe(2); | 
					
						
							|  |  |  |     expect(annotation.file).toBe('..\\main.go'); | 
					
						
							|  |  |  |     expect(annotation.message).toBe('undefined: fmt.Printl'); | 
					
						
							| 
									
										
										
										
											2020-03-27 20:21:13 -04:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-03-27 20:14:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 19:18:01 -05:00
										 |  |  |   // 1.13.1 => 1.13.1
 | 
					
						
							|  |  |  |   // 1.13 => 1.13.0
 | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |   // 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
 | 
					
						
							|  |  |  |   // 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
 | 
					
						
							| 
									
										
										
										
											2020-02-10 19:18:01 -05:00
										 |  |  |   it('converts prerelease versions', async () => { | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |     expect(im.makeSemver('1.10beta1')).toBe('1.10.0-beta.1'); | 
					
						
							|  |  |  |     expect(im.makeSemver('1.10rc1')).toBe('1.10.0-rc.1'); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:29:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 19:18:01 -05:00
										 |  |  |   it('converts dot zero versions', async () => { | 
					
						
							|  |  |  |     expect(im.makeSemver('1.13')).toBe('1.13.0'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-10 19:18:01 -05:00
										 |  |  |   it('does not convert exact versions', async () => { | 
					
						
							|  |  |  |     expect(im.makeSemver('1.13.1')).toBe('1.13.1'); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('check-latest flag', () => { | 
					
						
							|  |  |  |     it("use local version and don't check manifest if check-latest is not specified", async () => { | 
					
						
							|  |  |  |       os.platform = 'linux'; | 
					
						
							|  |  |  |       os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       inputs['go-version'] = '1.16'; | 
					
						
							|  |  |  |       inputs['check-latest'] = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const toolPath = path.normalize('/cache/go/1.16.1/x64'); | 
					
						
							|  |  |  |       findSpy.mockReturnValue(toolPath); | 
					
						
							|  |  |  |       await main.run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | 
					
						
							|  |  |  |       expect(logSpy).not.toHaveBeenCalledWith( | 
					
						
							|  |  |  |         'Attempting to resolve the latest version from the manifest...' | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('check latest version and resolve it from local cache', async () => { | 
					
						
							|  |  |  |       os.platform = 'linux'; | 
					
						
							|  |  |  |       os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       inputs['go-version'] = '1.16'; | 
					
						
							|  |  |  |       inputs['check-latest'] = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const toolPath = path.normalize('/cache/go/1.16.1/x64'); | 
					
						
							|  |  |  |       findSpy.mockReturnValue(toolPath); | 
					
						
							|  |  |  |       dlSpy.mockImplementation(async () => '/some/temp/path'); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |       extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |       cacheSpy.mockImplementation(async () => toolPath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await main.run(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |       expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.16'); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |       expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('check latest version and install it from manifest', async () => { | 
					
						
							|  |  |  |       os.platform = 'linux'; | 
					
						
							|  |  |  |       os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const versionSpec = '1.17'; | 
					
						
							|  |  |  |       const patchVersion = '1.17.6'; | 
					
						
							|  |  |  |       inputs['go-version'] = versionSpec; | 
					
						
							|  |  |  |       inputs['stable'] = 'true'; | 
					
						
							|  |  |  |       inputs['check-latest'] = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       findSpy.mockImplementation(() => ''); | 
					
						
							|  |  |  |       dlSpy.mockImplementation(async () => '/some/temp/path'); | 
					
						
							|  |  |  |       const toolPath = path.normalize('/cache/go/1.17.5/x64'); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |       extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |       cacheSpy.mockImplementation(async () => toolPath); | 
					
						
							|  |  |  |       const expectedUrl = | 
					
						
							|  |  |  |         'https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-darwin-x64.tar.gz'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await main.run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							| 
									
										
										
										
											2022-02-28 10:16:32 +03:00
										 |  |  |         `Setup go version spec ${versionSpec}` | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |       ); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         'Attempting to resolve the latest version from the manifest...' | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith(`Resolved as '${patchVersion}'`); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         `Attempting to download ${patchVersion}...` | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith('Extracting Go...'); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith('Added go to the path'); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         `Successfully setup go version ${versionSpec}` | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('fallback to dist if version is not found in manifest', async () => { | 
					
						
							|  |  |  |       os.platform = 'linux'; | 
					
						
							|  |  |  |       os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       let versionSpec = '1.13'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       inputs['go-version'] = versionSpec; | 
					
						
							|  |  |  |       inputs['check-latest'] = true; | 
					
						
							|  |  |  |       inputs['always-auth'] = false; | 
					
						
							|  |  |  |       inputs['token'] = 'faketoken'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // ... but not in the local cache
 | 
					
						
							|  |  |  |       findSpy.mockImplementation(() => ''); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       dlSpy.mockImplementation(async () => '/some/temp/path'); | 
					
						
							|  |  |  |       let toolPath = path.normalize('/cache/go/1.13.7/x64'); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |       extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |       cacheSpy.mockImplementation(async () => toolPath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await main.run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       let expPath = path.join(toolPath, 'bin'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(dlSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |       expect(extractTarSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         'Attempting to resolve the latest version from the manifest...' | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         `Failed to resolve version ${versionSpec} from manifest` | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         `Attempting to download ${versionSpec}...` | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('fallback to dist if manifest is not available', async () => { | 
					
						
							|  |  |  |       os.platform = 'linux'; | 
					
						
							|  |  |  |       os.arch = 'x64'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       let versionSpec = '1.13'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       process.env['GITHUB_PATH'] = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       inputs['go-version'] = versionSpec; | 
					
						
							|  |  |  |       inputs['check-latest'] = true; | 
					
						
							|  |  |  |       inputs['always-auth'] = false; | 
					
						
							|  |  |  |       inputs['token'] = 'faketoken'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // ... but not in the local cache
 | 
					
						
							|  |  |  |       findSpy.mockImplementation(() => ''); | 
					
						
							|  |  |  |       getManifestSpy.mockImplementation(() => { | 
					
						
							|  |  |  |         throw new Error('Unable to download manifest'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       dlSpy.mockImplementation(async () => '/some/temp/path'); | 
					
						
							|  |  |  |       let toolPath = path.normalize('/cache/go/1.13.7/x64'); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |       extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |       cacheSpy.mockImplementation(async () => toolPath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await main.run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       let expPath = path.join(toolPath, 'bin'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         `Failed to resolve version ${versionSpec} from manifest` | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(dlSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2022-03-14 12:21:30 -04:00
										 |  |  |       expect(extractTarSpy).toHaveBeenCalled(); | 
					
						
							| 
									
										
										
										
											2022-02-09 14:59:04 +03:00
										 |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         'Attempting to resolve the latest version from the manifest...' | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         'Unable to resolve a version from the manifest...' | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         `Failed to resolve version ${versionSpec} from manifest` | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(logSpy).toHaveBeenCalledWith( | 
					
						
							|  |  |  |         `Attempting to download ${versionSpec}...` | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-02-09 00:21:39 -05:00
										 |  |  | }); |