@@ -3,11 +3,11 @@ import * as path from 'path'
3
3
import * as tar from '../src/internal/tar'
4
4
import * as config from '../src/internal/config'
5
5
import * as cacheUtils from '../src/internal/cacheUtils'
6
- import * as downloadCacheModule from '../src/internal/blob/download-cache '
6
+ import * as cacheHttpClient from '../src/internal/cacheHttpClient '
7
7
import { restoreCache } from '../src/cache'
8
8
import { CacheFilename , CompressionMethod } from '../src/internal/constants'
9
9
import { CacheServiceClientJSON } from '../src/generated/results/api/v1/cache.twirp'
10
- import { BlobDownloadResponseParsed } from '@azure/storage-blob '
10
+ import { DownloadOptions } from '../src/options '
11
11
12
12
jest . mock ( '../src/internal/cacheHttpClient' )
13
13
jest . mock ( '../src/internal/cacheUtils' )
@@ -142,6 +142,7 @@ test('restore with gzip compressed cache found', async () => {
142
142
const signedDownloadUrl = 'https://blob-storage.local?signed=true'
143
143
const cacheVersion =
144
144
'd90f107aaeb22920dba0c637a23c37b5bc497b4dfa3b07fe3f79bf88a273c11b'
145
+ const options = { useAzureSdk : true } as DownloadOptions
145
146
146
147
const getCacheVersionMock = jest . spyOn ( cacheUtils , 'getCacheVersion' )
147
148
getCacheVersionMock . mockReturnValue ( cacheVersion )
@@ -169,17 +170,7 @@ test('restore with gzip compressed cache found', async () => {
169
170
} )
170
171
171
172
const archivePath = path . join ( tempPath , CacheFilename . Gzip )
172
- const downloadCacheFileMock = jest . spyOn (
173
- downloadCacheModule ,
174
- 'downloadCacheFile'
175
- )
176
- downloadCacheFileMock . mockReturnValue (
177
- Promise . resolve ( {
178
- _response : {
179
- status : 200
180
- }
181
- } as BlobDownloadResponseParsed )
182
- )
173
+ const downloadCacheMock = jest . spyOn ( cacheHttpClient , 'downloadCache' )
183
174
184
175
const fileSize = 142
185
176
const getArchiveFileSizeInBytesMock = jest
@@ -189,7 +180,7 @@ test('restore with gzip compressed cache found', async () => {
189
180
const extractTarMock = jest . spyOn ( tar , 'extractTar' )
190
181
const unlinkFileMock = jest . spyOn ( cacheUtils , 'unlinkFile' )
191
182
192
- const cacheKey = await restoreCache ( paths , key )
183
+ const cacheKey = await restoreCache ( paths , key , [ ] , options )
193
184
194
185
expect ( cacheKey ) . toBe ( key )
195
186
expect ( getCacheVersionMock ) . toHaveBeenCalledWith (
@@ -203,9 +194,10 @@ test('restore with gzip compressed cache found', async () => {
203
194
version : cacheVersion
204
195
} )
205
196
expect ( createTempDirectoryMock ) . toHaveBeenCalledTimes ( 1 )
206
- expect ( downloadCacheFileMock ) . toHaveBeenCalledWith (
197
+ expect ( downloadCacheMock ) . toHaveBeenCalledWith (
207
198
signedDownloadUrl ,
208
- archivePath
199
+ archivePath ,
200
+ options
209
201
)
210
202
expect ( getArchiveFileSizeInBytesMock ) . toHaveBeenCalledWith ( archivePath )
211
203
expect ( logInfoMock ) . toHaveBeenCalledWith ( `Cache Size: ~0 MB (142 B)` )
@@ -226,6 +218,7 @@ test('restore with zstd compressed cache found', async () => {
226
218
const signedDownloadUrl = 'https://blob-storage.local?signed=true'
227
219
const cacheVersion =
228
220
'8e2e96a184cb0cd6b48285b176c06a418f3d7fce14c29d9886fd1bb4f05c513d'
221
+ const options = { useAzureSdk : true } as DownloadOptions
229
222
230
223
const getCacheVersionMock = jest . spyOn ( cacheUtils , 'getCacheVersion' )
231
224
getCacheVersionMock . mockReturnValue ( cacheVersion )
@@ -253,17 +246,7 @@ test('restore with zstd compressed cache found', async () => {
253
246
} )
254
247
255
248
const archivePath = path . join ( tempPath , CacheFilename . Zstd )
256
- const downloadCacheFileMock = jest . spyOn (
257
- downloadCacheModule ,
258
- 'downloadCacheFile'
259
- )
260
- downloadCacheFileMock . mockReturnValue (
261
- Promise . resolve ( {
262
- _response : {
263
- status : 200
264
- }
265
- } as BlobDownloadResponseParsed )
266
- )
249
+ const downloadCacheMock = jest . spyOn ( cacheHttpClient , 'downloadCache' )
267
250
268
251
const fileSize = 62915000
269
252
const getArchiveFileSizeInBytesMock = jest
@@ -273,7 +256,7 @@ test('restore with zstd compressed cache found', async () => {
273
256
const extractTarMock = jest . spyOn ( tar , 'extractTar' )
274
257
const unlinkFileMock = jest . spyOn ( cacheUtils , 'unlinkFile' )
275
258
276
- const cacheKey = await restoreCache ( paths , key )
259
+ const cacheKey = await restoreCache ( paths , key , [ ] , options )
277
260
278
261
expect ( cacheKey ) . toBe ( key )
279
262
expect ( getCacheVersionMock ) . toHaveBeenCalledWith (
@@ -287,9 +270,10 @@ test('restore with zstd compressed cache found', async () => {
287
270
version : cacheVersion
288
271
} )
289
272
expect ( createTempDirectoryMock ) . toHaveBeenCalledTimes ( 1 )
290
- expect ( downloadCacheFileMock ) . toHaveBeenCalledWith (
273
+ expect ( downloadCacheMock ) . toHaveBeenCalledWith (
291
274
signedDownloadUrl ,
292
- archivePath
275
+ archivePath ,
276
+ options
293
277
)
294
278
expect ( getArchiveFileSizeInBytesMock ) . toHaveBeenCalledWith ( archivePath )
295
279
expect ( logInfoMock ) . toHaveBeenCalledWith ( `Cache Size: ~60 MB (62915000 B)` )
@@ -311,6 +295,7 @@ test('restore with cache found for restore key', async () => {
311
295
const signedDownloadUrl = 'https://blob-storage.local?signed=true'
312
296
const cacheVersion =
313
297
'b8b58e9bd7b1e8f83d9f05c7e06ea865ba44a0330e07a14db74ac74386677bed'
298
+ const options = { useAzureSdk : true } as DownloadOptions
314
299
315
300
const getCacheVersionMock = jest . spyOn ( cacheUtils , 'getCacheVersion' )
316
301
getCacheVersionMock . mockReturnValue ( cacheVersion )
@@ -338,17 +323,7 @@ test('restore with cache found for restore key', async () => {
338
323
} )
339
324
340
325
const archivePath = path . join ( tempPath , CacheFilename . Gzip )
341
- const downloadCacheFileMock = jest . spyOn (
342
- downloadCacheModule ,
343
- 'downloadCacheFile'
344
- )
345
- downloadCacheFileMock . mockReturnValue (
346
- Promise . resolve ( {
347
- _response : {
348
- status : 200
349
- }
350
- } as BlobDownloadResponseParsed )
351
- )
326
+ const downloadCacheMock = jest . spyOn ( cacheHttpClient , 'downloadCache' )
352
327
353
328
const fileSize = 142
354
329
const getArchiveFileSizeInBytesMock = jest
@@ -358,7 +333,7 @@ test('restore with cache found for restore key', async () => {
358
333
const extractTarMock = jest . spyOn ( tar , 'extractTar' )
359
334
const unlinkFileMock = jest . spyOn ( cacheUtils , 'unlinkFile' )
360
335
361
- const cacheKey = await restoreCache ( paths , key , restoreKeys )
336
+ const cacheKey = await restoreCache ( paths , key , restoreKeys , options )
362
337
363
338
expect ( cacheKey ) . toBe ( restoreKeys [ 0 ] )
364
339
expect ( getCacheVersionMock ) . toHaveBeenCalledWith (
@@ -372,9 +347,10 @@ test('restore with cache found for restore key', async () => {
372
347
version : cacheVersion
373
348
} )
374
349
expect ( createTempDirectoryMock ) . toHaveBeenCalledTimes ( 1 )
375
- expect ( downloadCacheFileMock ) . toHaveBeenCalledWith (
350
+ expect ( downloadCacheMock ) . toHaveBeenCalledWith (
376
351
signedDownloadUrl ,
377
- archivePath
352
+ archivePath ,
353
+ options
378
354
)
379
355
expect ( getArchiveFileSizeInBytesMock ) . toHaveBeenCalledWith ( archivePath )
380
356
expect ( logInfoMock ) . toHaveBeenCalledWith ( `Cache Size: ~0 MB (142 B)` )
@@ -388,14 +364,14 @@ test('restore with cache found for restore key', async () => {
388
364
expect ( compressionMethodMock ) . toHaveBeenCalledTimes ( 1 )
389
365
} )
390
366
391
- test ( 'restore with dry run ' , async ( ) => {
367
+ test ( 'restore with lookup only enabled ' , async ( ) => {
392
368
const paths = [ 'node_modules' ]
393
369
const key = 'node-test'
394
- const options = { lookupOnly : true }
395
370
const compressionMethod = CompressionMethod . Gzip
396
371
const signedDownloadUrl = 'https://blob-storage.local?signed=true'
397
372
const cacheVersion =
398
373
'd90f107aaeb22920dba0c637a23c37b5bc497b4dfa3b07fe3f79bf88a273c11b'
374
+ const options = { lookupOnly : true , useAzureSdk : true } as DownloadOptions
399
375
400
376
const getCacheVersionMock = jest . spyOn ( cacheUtils , 'getCacheVersion' )
401
377
getCacheVersionMock . mockReturnValue ( cacheVersion )
@@ -416,10 +392,7 @@ test('restore with dry run', async () => {
416
392
)
417
393
418
394
const createTempDirectoryMock = jest . spyOn ( cacheUtils , 'createTempDirectory' )
419
- const downloadCacheFileMock = jest . spyOn (
420
- downloadCacheModule ,
421
- 'downloadCacheFile'
422
- )
395
+ const downloadCacheMock = jest . spyOn ( cacheHttpClient , 'downloadCache' )
423
396
424
397
const cacheKey = await restoreCache ( paths , key , undefined , options )
425
398
@@ -438,5 +411,5 @@ test('restore with dry run', async () => {
438
411
439
412
// creating a tempDir and downloading the cache are skipped
440
413
expect ( createTempDirectoryMock ) . toHaveBeenCalledTimes ( 0 )
441
- expect ( downloadCacheFileMock ) . toHaveBeenCalledTimes ( 0 )
414
+ expect ( downloadCacheMock ) . toHaveBeenCalledTimes ( 0 )
442
415
} )
0 commit comments