@ -28,9 +28,17 @@ beforeAll(() => {
return actualUtils . getInputAsArray ( name , options ) ;
return actualUtils . getInputAsArray ( name , options ) ;
}
}
) ;
) ;
jest . spyOn ( actionUtils , "getInputAsBool" ) . mockImplementation (
( name , options ) = > {
const actualUtils = jest . requireActual ( "../src/utils/actionUtils" ) ;
return actualUtils . getInputAsBool ( name , options ) ;
}
) ;
} ) ;
} ) ;
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
jest . restoreAllMocks ( ) ;
process . env [ Events . Key ] = Events . Push ;
process . env [ Events . Key ] = Events . Push ;
process . env [ RefKey ] = "refs/heads/feature-branch" ;
process . env [ RefKey ] = "refs/heads/feature-branch" ;
@ -97,7 +105,8 @@ test("restore on GHES with AC available ", async () => {
const key = "node-test" ;
const key = "node-test" ;
testUtils . setInputs ( {
testUtils . setInputs ( {
path : path ,
path : path ,
key
key ,
enableCrossOsArchive : false
} ) ;
} ) ;
const infoMock = jest . spyOn ( core , "info" ) ;
const infoMock = jest . spyOn ( core , "info" ) ;
@ -113,7 +122,7 @@ test("restore on GHES with AC available ", async () => {
await run ( new StateProvider ( ) ) ;
await run ( new StateProvider ( ) ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ ] );
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ ] , { } , false );
expect ( stateMock ) . toHaveBeenCalledWith ( "CACHE_KEY" , key ) ;
expect ( stateMock ) . toHaveBeenCalledWith ( "CACHE_KEY" , key ) ;
expect ( setCacheHitOutputMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( setCacheHitOutputMock ) . toHaveBeenCalledTimes ( 1 ) ;
@ -152,13 +161,20 @@ test("restore with too many keys should fail", async () => {
testUtils . setInputs ( {
testUtils . setInputs ( {
path : path ,
path : path ,
key ,
key ,
restoreKeys
restoreKeys ,
enableCrossOsArchive : false
} ) ;
} ) ;
const failedMock = jest . spyOn ( core , "setFailed" ) ;
const failedMock = jest . spyOn ( core , "setFailed" ) ;
const restoreCacheMock = jest . spyOn ( cache , "restoreCache" ) ;
const restoreCacheMock = jest . spyOn ( cache , "restoreCache" ) ;
await run ( new StateProvider ( ) ) ;
await run ( new StateProvider ( ) ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , restoreKeys ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith (
[ path ] ,
key ,
restoreKeys ,
{ } ,
false
) ;
expect ( failedMock ) . toHaveBeenCalledWith (
expect ( failedMock ) . toHaveBeenCalledWith (
` Key Validation Error: Keys are limited to a maximum of 10. `
` Key Validation Error: Keys are limited to a maximum of 10. `
) ;
) ;
@ -169,13 +185,14 @@ test("restore with large key should fail", async () => {
const key = "foo" . repeat ( 512 ) ; // Over the 512 character limit
const key = "foo" . repeat ( 512 ) ; // Over the 512 character limit
testUtils . setInputs ( {
testUtils . setInputs ( {
path : path ,
path : path ,
key
key ,
enableCrossOsArchive : false
} ) ;
} ) ;
const failedMock = jest . spyOn ( core , "setFailed" ) ;
const failedMock = jest . spyOn ( core , "setFailed" ) ;
const restoreCacheMock = jest . spyOn ( cache , "restoreCache" ) ;
const restoreCacheMock = jest . spyOn ( cache , "restoreCache" ) ;
await run ( new StateProvider ( ) ) ;
await run ( new StateProvider ( ) ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ ] );
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ ] , { } , false );
expect ( failedMock ) . toHaveBeenCalledWith (
expect ( failedMock ) . toHaveBeenCalledWith (
` Key Validation Error: ${ key } cannot be larger than 512 characters. `
` Key Validation Error: ${ key } cannot be larger than 512 characters. `
) ;
) ;
@ -186,13 +203,14 @@ test("restore with invalid key should fail", async () => {
const key = "comma,comma" ;
const key = "comma,comma" ;
testUtils . setInputs ( {
testUtils . setInputs ( {
path : path ,
path : path ,
key
key ,
enableCrossOsArchive : false
} ) ;
} ) ;
const failedMock = jest . spyOn ( core , "setFailed" ) ;
const failedMock = jest . spyOn ( core , "setFailed" ) ;
const restoreCacheMock = jest . spyOn ( cache , "restoreCache" ) ;
const restoreCacheMock = jest . spyOn ( cache , "restoreCache" ) ;
await run ( new StateProvider ( ) ) ;
await run ( new StateProvider ( ) ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ ] );
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ ] , { } , false );
expect ( failedMock ) . toHaveBeenCalledWith (
expect ( failedMock ) . toHaveBeenCalledWith (
` Key Validation Error: ${ key } cannot contain commas. `
` Key Validation Error: ${ key } cannot contain commas. `
) ;
) ;
@ -203,7 +221,8 @@ test("restore with no cache found", async () => {
const key = "node-test" ;
const key = "node-test" ;
testUtils . setInputs ( {
testUtils . setInputs ( {
path : path ,
path : path ,
key
key ,
enableCrossOsArchive : false
} ) ;
} ) ;
const infoMock = jest . spyOn ( core , "info" ) ;
const infoMock = jest . spyOn ( core , "info" ) ;
@ -218,7 +237,7 @@ test("restore with no cache found", async () => {
await run ( new StateProvider ( ) ) ;
await run ( new StateProvider ( ) ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ ] );
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ ] , { } , false );
expect ( stateMock ) . toHaveBeenCalledWith ( "CACHE_KEY" , key ) ;
expect ( stateMock ) . toHaveBeenCalledWith ( "CACHE_KEY" , key ) ;
expect ( failedMock ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( failedMock ) . toHaveBeenCalledTimes ( 0 ) ;
@ -235,7 +254,8 @@ test("restore with restore keys and no cache found", async () => {
testUtils . setInputs ( {
testUtils . setInputs ( {
path : path ,
path : path ,
key ,
key ,
restoreKeys : [ restoreKey ]
restoreKeys : [ restoreKey ] ,
enableCrossOsArchive : false
} ) ;
} ) ;
const infoMock = jest . spyOn ( core , "info" ) ;
const infoMock = jest . spyOn ( core , "info" ) ;
@ -250,7 +270,13 @@ test("restore with restore keys and no cache found", async () => {
await run ( new StateProvider ( ) ) ;
await run ( new StateProvider ( ) ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ restoreKey ] ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith (
[ path ] ,
key ,
[ restoreKey ] ,
{ } ,
false
) ;
expect ( stateMock ) . toHaveBeenCalledWith ( "CACHE_KEY" , key ) ;
expect ( stateMock ) . toHaveBeenCalledWith ( "CACHE_KEY" , key ) ;
expect ( failedMock ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( failedMock ) . toHaveBeenCalledTimes ( 0 ) ;
@ -265,7 +291,8 @@ test("restore with cache found for key", async () => {
const key = "node-test" ;
const key = "node-test" ;
testUtils . setInputs ( {
testUtils . setInputs ( {
path : path ,
path : path ,
key
key ,
enableCrossOsArchive : false
} ) ;
} ) ;
const infoMock = jest . spyOn ( core , "info" ) ;
const infoMock = jest . spyOn ( core , "info" ) ;
@ -281,7 +308,7 @@ test("restore with cache found for key", async () => {
await run ( new StateProvider ( ) ) ;
await run ( new StateProvider ( ) ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ ] );
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ ] , { } , false );
expect ( stateMock ) . toHaveBeenCalledWith ( "CACHE_KEY" , key ) ;
expect ( stateMock ) . toHaveBeenCalledWith ( "CACHE_KEY" , key ) ;
expect ( setCacheHitOutputMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( setCacheHitOutputMock ) . toHaveBeenCalledTimes ( 1 ) ;
@ -298,7 +325,8 @@ test("restore with cache found for restore key", async () => {
testUtils . setInputs ( {
testUtils . setInputs ( {
path : path ,
path : path ,
key ,
key ,
restoreKeys : [ restoreKey ]
restoreKeys : [ restoreKey ] ,
enableCrossOsArchive : false
} ) ;
} ) ;
const infoMock = jest . spyOn ( core , "info" ) ;
const infoMock = jest . spyOn ( core , "info" ) ;
@ -314,7 +342,13 @@ test("restore with cache found for restore key", async () => {
await run ( new StateProvider ( ) ) ;
await run ( new StateProvider ( ) ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith ( [ path ] , key , [ restoreKey ] ) ;
expect ( restoreCacheMock ) . toHaveBeenCalledWith (
[ path ] ,
key ,
[ restoreKey ] ,
{ } ,
false
) ;
expect ( stateMock ) . toHaveBeenCalledWith ( "CACHE_KEY" , key ) ;
expect ( stateMock ) . toHaveBeenCalledWith ( "CACHE_KEY" , key ) ;
expect ( setCacheHitOutputMock ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( setCacheHitOutputMock ) . toHaveBeenCalledTimes ( 1 ) ;