|
30 | 30 |
|
31 | 31 | import static org.hamcrest.MatcherAssert.assertThat; |
32 | 32 | import static org.hamcrest.Matchers.equalTo; |
| 33 | +import static org.hamcrest.Matchers.not; |
| 34 | +import static org.hamcrest.Matchers.containsString; |
33 | 35 | import static org.hamcrest.Matchers.startsWith; |
34 | 36 | import static org.mockito.ArgumentMatchers.any; |
35 | 37 | import static org.mockito.Mockito.lenient; |
@@ -159,6 +161,46 @@ private static Stream<Arguments> provideStartExportTaskTestParameters() { |
159 | 161 | ); |
160 | 162 | } |
161 | 163 |
|
| 164 | + @ParameterizedTest |
| 165 | + @MethodSource("provideSnapshotIdsWithTrailingHyphens") |
| 166 | + void test_generateExportTaskId_handles_various_trailing_hyphen_scenarios(String snapshotIdWithTrailingHyphens, String expectedPrefix) { |
| 167 | + final String snapshotArn = "arn:aws:rds:us-east-1:123456789012:snapshot:" + snapshotIdWithTrailingHyphens; |
| 168 | + final String iamRoleArn = "arn:aws:iam:us-east-1:123456789012:role:" + UUID.randomUUID(); |
| 169 | + final String bucket = UUID.randomUUID().toString(); |
| 170 | + final String prefix = UUID.randomUUID().toString(); |
| 171 | + final String kmsKey = UUID.randomUUID().toString(); |
| 172 | + final StartExportTaskResponse response = mock(StartExportTaskResponse.class); |
| 173 | + when(rdsClient.startExportTask(any(StartExportTaskRequest.class))).thenReturn(response); |
| 174 | + when(response.status()).thenReturn("STARTING"); |
| 175 | + |
| 176 | + final String exportTaskId = exportTaskManager.startExportTask(snapshotArn, iamRoleArn, bucket, prefix, kmsKey, List.of()); |
| 177 | + |
| 178 | + final ArgumentCaptor<StartExportTaskRequest> exportTaskRequestArgumentCaptor = |
| 179 | + ArgumentCaptor.forClass(StartExportTaskRequest.class); |
| 180 | + verify(rdsClient).startExportTask(exportTaskRequestArgumentCaptor.capture()); |
| 181 | + |
| 182 | + final StartExportTaskRequest actualRequest = exportTaskRequestArgumentCaptor.getValue(); |
| 183 | + final String actualExportTaskId = actualRequest.exportTaskIdentifier(); |
| 184 | + |
| 185 | + // Verify that there are no consecutive hyphens in the export task identifier |
| 186 | + assertThat(actualExportTaskId, not(containsString("--"))); |
| 187 | + // Verify that it still contains the expected components |
| 188 | + assertThat(actualExportTaskId, containsString("-export-")); |
| 189 | + // Verify that it starts with the expected prefix (after removing trailing hyphens) |
| 190 | + assertThat(actualExportTaskId, startsWith(expectedPrefix)); |
| 191 | + } |
| 192 | + |
| 193 | + private static Stream<Arguments> provideSnapshotIdsWithTrailingHyphens() { |
| 194 | + return Stream.of( |
| 195 | + Arguments.of("snapshot-name-", "snapshot-name"), |
| 196 | + Arguments.of("snapshot-name--", "snapshot-name"), |
| 197 | + Arguments.of("snapshot-name---", "snapshot-name"), |
| 198 | + Arguments.of("my-cluster-snapshot-", "my-cluster-snapshot"), |
| 199 | + Arguments.of("complex-db-cluster-backup-snapshot-", "complex-db-cluster-backup-snapshot"), |
| 200 | + Arguments.of("normal-snapshot", "normal-snapshot") // No trailing hyphen case |
| 201 | + ); |
| 202 | + } |
| 203 | + |
162 | 204 | private ExportTaskManager createObjectUnderTest() { |
163 | 205 | return new ExportTaskManager(rdsClient, rdsSourceAggregateMetrics); |
164 | 206 | } |
|
0 commit comments