test(lambda): build the single-account S3 mock once in LambdaServiceTest (#9756)

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-11-29 12:26:06 -04:00
1 parent bdfc7c2161
commit 679c60cfb9
1 file changed
+15 -24
@@ -2496,9 +2496,7 @@ class LambdaServiceTest {
@Test
void anS3PackageOverTheCompressedLimitGetsTheExtractionError() {
S3Service s3 = mock(S3Service.class);
// One account owns every bucket here, so a function and the upload name the same bucket.
when(s3.getBucketOwnerAccountId(anyString())).thenReturn("000000000000");
S3Service s3 = singleAccountS3();
LambdaService s3Backed = s3BackedService(s3, mock(WarmPool.class), new ZipExtractor());
long size = 250L * 1024 * 1024 + 1;
when(s3.openObject("code-bucket", "function.zip", null)).thenReturn(new S3Service.ObjectRead(
@@ -2545,6 +2543,13 @@ class LambdaServiceTest {
assertEquals(List.of("customer-code"), s3.listBuckets().stream().map(b -> b.getName()).toList());
}
/** An S3 mock where one account owns every bucket, so a function and the upload name the same bucket. */
private static S3Service singleAccountS3() {
S3Service s3 = mock(S3Service.class);
when(s3.getBucketOwnerAccountId(anyString())).thenReturn("000000000000");
return s3;
}
private static LambdaService s3BackedService(S3Service s3, WarmPool warmPool, ZipExtractor extractor) {
return s3BackedService(s3, warmPool, extractor, null);
}
@@ -2572,9 +2577,7 @@ class LambdaServiceTest {
@Test
void reactiveSyncHoldsThePublicationLockThroughExtraction() throws Exception {
S3Service s3 = mock(S3Service.class);
// One account owns every bucket here, so a function and the upload name the same bucket.
when(s3.getBucketOwnerAccountId(anyString())).thenReturn("000000000000");
S3Service s3 = singleAccountS3();
WarmPool warmPool = mock(WarmPool.class);
ZipExtractor extractor = spy(new ZipExtractor());
LambdaService syncingService = s3BackedService(s3, warmPool, extractor);
@@ -2621,9 +2624,7 @@ class LambdaServiceTest {
@Test
void reactiveSyncDisabled_leavesTheFunctionOnItsDeployedCode() throws Exception {
S3Service s3 = mock(S3Service.class);
// One account owns every bucket here, so a function and the upload name the same bucket.
when(s3.getBucketOwnerAccountId(anyString())).thenReturn("000000000000");
S3Service s3 = singleAccountS3();
WarmPool warmPool = mock(WarmPool.class);
LambdaService syncingService = s3BackedService(s3, warmPool, new ZipExtractor(),
reactiveS3SyncConfig(false, false));
@@ -2642,9 +2643,7 @@ class LambdaServiceTest {
@Test
void asyncReactiveSync_returnsBeforeTheRedeployAndReportsInProgressUntilItFinishes() throws Exception {
S3Service s3 = mock(S3Service.class);
// One account owns every bucket here, so a function and the upload name the same bucket.
when(s3.getBucketOwnerAccountId(anyString())).thenReturn("000000000000");
S3Service s3 = singleAccountS3();
WarmPool warmPool = mock(WarmPool.class);
ZipExtractor extractor = spy(new ZipExtractor());
LambdaService syncingService = s3BackedService(s3, warmPool, extractor, reactiveS3SyncConfig(true, true));
@@ -2676,9 +2675,7 @@ class LambdaServiceTest {
@Test
void asyncReactiveSync_coalescesUploadsThatArriveWhileOneIsRunning() throws Exception {
S3Service s3 = mock(S3Service.class);
// One account owns every bucket here, so a function and the upload name the same bucket.
when(s3.getBucketOwnerAccountId(anyString())).thenReturn("000000000000");
S3Service s3 = singleAccountS3();
WarmPool warmPool = mock(WarmPool.class);
ZipExtractor extractor = spy(new ZipExtractor());
LambdaService syncingService = s3BackedService(s3, warmPool, extractor, reactiveS3SyncConfig(true, true));
@@ -2716,9 +2713,7 @@ class LambdaServiceTest {
@Test
void asyncReactiveSync_deploysAnUploadToANewSourceWhileTheOldOneIsStillQueued() throws Exception {
S3Service s3 = mock(S3Service.class);
// One account owns every bucket here, so a function and the upload name the same bucket.
when(s3.getBucketOwnerAccountId(anyString())).thenReturn("000000000000");
S3Service s3 = singleAccountS3();
WarmPool warmPool = mock(WarmPool.class);
LambdaService syncingService = s3BackedService(s3, warmPool, new ZipExtractor(),
reactiveS3SyncConfig(true, true));
@@ -2748,9 +2743,7 @@ class LambdaServiceTest {
@Test
void failedReactiveSync_reportsFailedUntilTheNextCodeUpdate() throws Exception {
S3Service s3 = mock(S3Service.class);
// One account owns every bucket here, so a function and the upload name the same bucket.
when(s3.getBucketOwnerAccountId(anyString())).thenReturn("000000000000");
S3Service s3 = singleAccountS3();
WarmPool warmPool = mock(WarmPool.class);
LambdaService syncingService = s3BackedService(s3, warmPool, new ZipExtractor(),
reactiveS3SyncConfig(true, false));
@@ -2769,9 +2762,7 @@ class LambdaServiceTest {
@Test
void failedReactiveSync_isClearedByAConfigurationUpdate() throws Exception {
S3Service s3 = mock(S3Service.class);
// One account owns every bucket here, so a function and the upload name the same bucket.
when(s3.getBucketOwnerAccountId(anyString())).thenReturn("000000000000");
S3Service s3 = singleAccountS3();
LambdaService syncingService = s3BackedService(s3, mock(WarmPool.class), new ZipExtractor(),
reactiveS3SyncConfig(true, false));
LambdaFunction latest = functionWhoseLastSyncFailed(syncingService, s3);