@@ -92,14 +92,14 @@ test('save with large cache outputs should fail using', async () => {
92
92
expect ( getCompressionMock ) . toHaveBeenCalledTimes ( 1 )
93
93
} )
94
94
95
- test ( 'create cache entry failure' , async ( ) => {
95
+ test ( 'create cache entry failure on non-ok response ' , async ( ) => {
96
96
const paths = [ 'node_modules' ]
97
97
const key = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
98
98
const infoLogMock = jest . spyOn ( core , 'info' )
99
99
100
100
const createCacheEntryMock = jest
101
101
. spyOn ( CacheServiceClientJSON . prototype , 'CreateCacheEntry' )
102
- . mockReturnValue ( Promise . resolve ( { ok : false , signedUploadUrl : '' } ) )
102
+ . mockResolvedValue ( { ok : false , signedUploadUrl : '' } )
103
103
104
104
const createTarMock = jest . spyOn ( tar , 'createTar' )
105
105
const finalizeCacheEntryMock = jest . spyOn (
@@ -109,7 +109,7 @@ test('create cache entry failure', async () => {
109
109
const compression = CompressionMethod . Zstd
110
110
const getCompressionMock = jest
111
111
. spyOn ( cacheUtils , 'getCompressionMethod' )
112
- . mockReturnValueOnce ( Promise . resolve ( compression ) )
112
+ . mockResolvedValueOnce ( compression )
113
113
const archiveFileSize = 1024
114
114
jest
115
115
. spyOn ( cacheUtils , 'getArchiveFileSizeInBytes' )
@@ -133,6 +133,39 @@ test('create cache entry failure', async () => {
133
133
expect ( saveCacheMock ) . toHaveBeenCalledTimes ( 0 )
134
134
} )
135
135
136
+ test ( 'create cache entry fails on rejected promise' , async ( ) => {
137
+ const paths = [ 'node_modules' ]
138
+ const key = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
139
+ const infoLogMock = jest . spyOn ( core , 'info' )
140
+
141
+ const createCacheEntryMock = jest
142
+ . spyOn ( CacheServiceClientJSON . prototype , 'CreateCacheEntry' )
143
+ . mockRejectedValue ( new Error ( 'Failed to create cache entry' ) )
144
+
145
+ const createTarMock = jest . spyOn ( tar , 'createTar' )
146
+ const compression = CompressionMethod . Zstd
147
+ const getCompressionMock = jest
148
+ . spyOn ( cacheUtils , 'getCompressionMethod' )
149
+ . mockResolvedValueOnce ( compression )
150
+ const archiveFileSize = 1024
151
+ jest
152
+ . spyOn ( cacheUtils , 'getArchiveFileSizeInBytes' )
153
+ . mockReturnValueOnce ( archiveFileSize )
154
+
155
+ const cacheId = await saveCache ( paths , key )
156
+ expect ( cacheId ) . toBe ( - 1 )
157
+ expect ( infoLogMock ) . toHaveBeenCalledWith (
158
+ `Failed to save: Unable to reserve cache with key ${ key } , another job may be creating this cache.`
159
+ )
160
+
161
+ expect ( createCacheEntryMock ) . toHaveBeenCalledWith ( {
162
+ key,
163
+ version : cacheUtils . getCacheVersion ( paths , compression )
164
+ } )
165
+ expect ( createTarMock ) . toHaveBeenCalledTimes ( 1 )
166
+ expect ( getCompressionMock ) . toHaveBeenCalledTimes ( 1 )
167
+ } )
168
+
136
169
test ( 'save cache fails if a signedUploadURL was not passed' , async ( ) => {
137
170
const paths = 'node_modules'
138
171
const key = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
0 commit comments