@@ -8,14 +8,16 @@ import {
8
8
S3Client ,
9
9
} from '@aws-sdk/client-s3' ;
10
10
import { mockClient } from 'aws-sdk-client-mock' ;
11
- import { partial } from '../../../../../test/util' ;
11
+ import { fs , partial } from '../../../../../test/util' ;
12
12
import { GlobalConfig } from '../../../../config/global' ;
13
13
import { logger } from '../../../../logger' ;
14
14
import { parseS3Url } from '../../../s3' ;
15
15
import type { RepoCacheRecord } from '../schema' ;
16
16
import { CacheFactory } from './cache-factory' ;
17
17
import { RepoCacheS3 } from './s3' ;
18
18
19
+ jest . mock ( '../../../fs' ) ;
20
+
19
21
function createGetObjectCommandInput (
20
22
repository : string ,
21
23
url : string ,
@@ -57,7 +59,7 @@ describe('util/cache/repository/impl/s3', () => {
57
59
let s3Cache : RepoCacheS3 ;
58
60
59
61
beforeEach ( ( ) => {
60
- GlobalConfig . set ( { platform : 'github' } ) ;
62
+ GlobalConfig . set ( { cacheDir : '/tmp/cache' , platform : 'github' } ) ;
61
63
s3Mock . reset ( ) ;
62
64
s3Cache = new RepoCacheS3 ( repository , '0123456789abcdef' , url ) ;
63
65
getObjectCommandInput = createGetObjectCommandInput ( repository , url ) ;
@@ -196,4 +198,19 @@ describe('util/cache/repository/impl/s3', () => {
196
198
const cache = CacheFactory . get ( repository , '0123456789abcdef' , url ) ;
197
199
expect ( cache instanceof RepoCacheS3 ) . toBeTrue ( ) ;
198
200
} ) ;
201
+
202
+ it ( 'should persists data locally after uploading to s3' , async ( ) => {
203
+ process . env . RENOVATE_X_REPO_CACHE_FORCE_LOCAL = 'true' ;
204
+ const putObjectCommandOutput : PutObjectCommandOutput = {
205
+ $metadata : { attempts : 1 , httpStatusCode : 200 , totalRetryDelay : 0 } ,
206
+ } ;
207
+ s3Mock
208
+ . on ( PutObjectCommand , putObjectCommandInput )
209
+ . resolvesOnce ( putObjectCommandOutput ) ;
210
+ await s3Cache . write ( repoCache ) ;
211
+ expect ( fs . outputCacheFile ) . toHaveBeenCalledWith (
212
+ 'renovate/repository/github/org/repo.json' ,
213
+ JSON . stringify ( repoCache ) ,
214
+ ) ;
215
+ } ) ;
199
216
} ) ;
0 commit comments