diff --git a/src/test/java/io/floci/aws/services/lambda/LambdaServiceTest.java b/src/test/java/io/floci/aws/services/lambda/LambdaServiceTest.java index edcc83804c..2f898c6293 100644 --- a/src/test/java/io/floci/aws/services/lambda/LambdaServiceTest.java +++ b/src/test/java/io/floci/aws/services/lambda/LambdaServiceTest.java @@ -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);