@ -573,4 +573,158 @@ describe('setup-go', () => {
it ( 'does not convert exact versions' , async ( ) = > {
expect ( im . makeSemver ( '1.13.1' ) ) . toBe ( '1.13.1' ) ;
} ) ;
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 (
'Attempt to resolve the latest version from manifest...'
) ;
} ) ;
it ( 'check latest version and resolve it from local cache' , async ( ) = > {
os . platform = 'linux' ;
os . arch = 'x64' ;
inputs [ 'go-version' ] = '1.16.1' ;
inputs [ 'check-latest' ] = 'true' ;
const toolPath = path . normalize ( '/cache/go/1.16.1/x64' ) ;
findSpy . mockReturnValue ( toolPath ) ;
dlSpy . mockImplementation ( async ( ) = > '/some/temp/path' ) ;
exSpy . mockImplementation ( async ( ) = > '/some/other/temp/path' ) ;
cacheSpy . mockImplementation ( async ( ) = > toolPath ) ;
await main . run ( ) ;
expect ( logSpy ) . toHaveBeenCalledWith (
'Attempt to resolve the latest version from manifest...'
) ;
expect ( logSpy ) . toHaveBeenCalledWith ( "Resolved as '1.16.1'" ) ;
expect ( logSpy ) . toHaveBeenCalledWith ( ` Found in cache @ ${ toolPath } ` ) ;
} ) ;
it ( 'check latest version and install it from manifest' , async ( ) = > {
os . platform = 'linux' ;
os . arch = 'x64' ;
inputs [ 'go-version' ] = '1.16.13' ;
inputs [ 'check-latest' ] = 'true' ;
findSpy . mockImplementation ( ( ) = > '' ) ;
dlSpy . mockImplementation ( async ( ) = > '/some/temp/path' ) ;
const toolPath = path . normalize ( '/cache/go/1.16.13/x64' ) ;
exSpy . mockImplementation ( async ( ) = > '/some/other/temp/path' ) ;
cacheSpy . mockImplementation ( async ( ) = > toolPath ) ;
const expectedUrl =
'https://github.com/actions/go-versions/releases/download/1.16.13-1668091716/go-1.16.13-linux-x64.tar.gz' ;
await main . run ( ) ;
expect ( logSpy ) . toHaveBeenCalledWith (
'Attempt to resolve the latest version from manifest...'
) ;
// expect(logSpy).toHaveBeenCalledWith("Resolved as '1.16.13'");
expect ( logSpy ) . toHaveBeenCalledWith ( ) ;
expect ( logSpy ) . toHaveBeenCalledWith (
` Acquiring 1.16.13 from ${ expectedUrl } `
) ;
expect ( logSpy ) . toHaveBeenCalledWith ( 'Extracting ...' ) ;
} ) ;
it ( 'fallback to dist if version if not found in manifest' , async ( ) = > {
os . platform = 'linux' ;
os . arch = 'x64' ;
// a version which is not in the manifest but is in node dist
let versionSpec = '1.16' ;
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' ) ;
// TODO: What should be here?
let toolPath = path . normalize ( '/cache/go/1.15.15/x64' ) ;
exSpy . mockImplementation ( async ( ) = > '/some/other/temp/path' ) ;
cacheSpy . mockImplementation ( async ( ) = > toolPath ) ;
await main . run ( ) ;
let expPath = path . join ( toolPath , 'bin' ) ;
expect ( dlSpy ) . toHaveBeenCalled ( ) ;
expect ( exSpy ) . toHaveBeenCalled ( ) ;
expect ( logSpy ) . toHaveBeenCalledWith (
'Attempt to resolve the latest version from manifest...'
) ;
expect ( logSpy ) . toHaveBeenCalledWith (
` Failed to resolve version ${ versionSpec } from manifest `
) ;
expect ( logSpy ) . toHaveBeenCalledWith (
` Attempting to download ${ versionSpec } ... `
) ;
// TODO: Is this exists. Should be something like `extPath = path.join(extPath, 'go');`
// expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
} ) ;
it ( 'fallback to dist if manifest is not available' , async ( ) = > {
os . platform = 'linux' ;
os . arch = 'x64' ;
// a version which is not in the manifest but is in node dist
let versionSpec = '1.16' ;
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.16.1/x64' ) ;
exSpy . mockImplementation ( async ( ) = > '/some/other/temp/path' ) ;
cacheSpy . mockImplementation ( async ( ) = > toolPath ) ;
await main . run ( ) ;
let expPath = path . join ( toolPath , 'bin' ) ;
expect ( dlSpy ) . toHaveBeenCalled ( ) ;
expect ( exSpy ) . toHaveBeenCalled ( ) ;
expect ( logSpy ) . toHaveBeenCalledWith (
'Attempt to resolve the latest version from manifest...'
) ;
expect ( logSpy ) . toHaveBeenCalledWith (
'Unable to resolve version from 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}`);
} ) ;
} ) ;
} ) ;