@@ -13,6 +13,8 @@ let matchers = require('../matchers.json');
13
13
let goTestManifest = require ( './data/versions-manifest.json' ) ;
14
14
let matcherPattern = matchers . problemMatcher [ 0 ] . pattern [ 0 ] ;
15
15
let matcherRegExp = new RegExp ( matcherPattern . regexp ) ;
16
+ let win32Join = path . win32 . join ;
17
+ let posixJoin = path . posix . join ;
16
18
17
19
describe ( 'setup-go' , ( ) => {
18
20
let inputs = { } as any ;
@@ -27,8 +29,10 @@ describe('setup-go', () => {
27
29
let getSpy : jest . SpyInstance ;
28
30
let platSpy : jest . SpyInstance ;
29
31
let archSpy : jest . SpyInstance ;
32
+ let joinSpy : jest . SpyInstance ;
30
33
let dlSpy : jest . SpyInstance ;
31
34
let extractTarSpy : jest . SpyInstance ;
35
+ let extractZipSpy : jest . SpyInstance ;
32
36
let cacheSpy : jest . SpyInstance ;
33
37
let dbgSpy : jest . SpyInstance ;
34
38
let whichSpy : jest . SpyInstance ;
@@ -61,10 +65,21 @@ describe('setup-go', () => {
61
65
archSpy . mockImplementation ( ( ) => os [ 'arch' ] ) ;
62
66
execSpy = jest . spyOn ( cp , 'execSync' ) ;
63
67
68
+ // switch path join behaviour based on set os.platform
69
+ joinSpy = jest . spyOn ( path , 'join' ) ;
70
+ joinSpy . mockImplementation ( ( ...paths : string [ ] ) : string => {
71
+ if ( os [ 'platform' ] == 'win32' ) {
72
+ return win32Join ( ...paths ) ;
73
+ }
74
+
75
+ return posixJoin ( ...paths ) ;
76
+ } ) ;
77
+
64
78
// @actions /tool-cache
65
79
findSpy = jest . spyOn ( tc , 'find' ) ;
66
80
dlSpy = jest . spyOn ( tc , 'downloadTool' ) ;
67
81
extractTarSpy = jest . spyOn ( tc , 'extractTar' ) ;
82
+ extractZipSpy = jest . spyOn ( tc , 'extractZip' ) ;
68
83
cacheSpy = jest . spyOn ( tc , 'cacheDir' ) ;
69
84
getSpy = jest . spyOn ( im , 'getVersionsDist' ) ;
70
85
getManifestSpy = jest . spyOn ( tc , 'getManifestFromRepo' ) ;
@@ -325,6 +340,31 @@ describe('setup-go', () => {
325
340
expect ( cnSpy ) . toHaveBeenCalledWith ( `::add-path::${ expPath } ${ osm . EOL } ` ) ;
326
341
} ) ;
327
342
343
+ it ( 'downloads a version not in the cache (windows)' , async ( ) => {
344
+ os . platform = 'win32' ;
345
+ os . arch = 'x64' ;
346
+
347
+ inputs [ 'go-version' ] = '1.13.1' ;
348
+ process . env [ 'RUNNER_TEMP' ] = 'C:\\temp\\' ;
349
+
350
+ findSpy . mockImplementation ( ( ) => '' ) ;
351
+ dlSpy . mockImplementation ( ( ) => 'C:\\temp\\some\\path' ) ;
352
+ extractZipSpy . mockImplementation ( ( ) => 'C:\\temp\\some\\other\\path' ) ;
353
+
354
+ let toolPath = path . normalize ( 'C:\\cache\\go\\1.13.0\\x64' ) ;
355
+ cacheSpy . mockImplementation ( ( ) => toolPath ) ;
356
+
357
+ await main . run ( ) ;
358
+
359
+ let expPath = path . win32 . join ( toolPath , 'bin' ) ;
360
+ expect ( dlSpy ) . toHaveBeenCalledWith (
361
+ 'https://storage.googleapis.com/golang/go1.13.1.windows-amd64.zip' ,
362
+ 'C:\\temp\\go1.13.1.windows-amd64.zip' ,
363
+ undefined
364
+ ) ;
365
+ expect ( cnSpy ) . toHaveBeenCalledWith ( `::add-path::${ expPath } ${ osm . EOL } ` ) ;
366
+ } ) ;
367
+
328
368
it ( 'does not find a version that does not exist' , async ( ) => {
329
369
os . platform = 'linux' ;
330
370
os . arch = 'x64' ;
0 commit comments