use of com.amazonaws.services.cloudformation.model.UpdateStackSetResult in project pipeline-aws-plugin by jenkinsci.
the class CFNUpdateStackSetStepTest method updateWithRegionBatches.
@Test
public void updateWithRegionBatches() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
Mockito.when(stackSet.exists()).thenReturn(true);
String operationId = UUID.randomUUID().toString();
Mockito.when(stackSet.update(Mockito.anyString(), Mockito.anyString(), Mockito.any(UpdateStackSetRequest.class))).thenReturn(new UpdateStackSetResult().withOperationId(operationId));
Mockito.when(stackSet.findStackSetInstances()).thenReturn(asList(new StackInstanceSummary().withAccount("a1").withRegion("r1"), new StackInstanceSummary().withAccount("a2").withRegion("r1"), new StackInstanceSummary().withAccount("a2").withRegion("r2"), new StackInstanceSummary().withAccount("a3").withRegion("r3")));
job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " cfnUpdateStackSet(stackSet: 'foo'," + " pollInterval: 27," + " batchingOptions: [" + " regions: true" + " ]" + " )" + "}\n", true));
jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
PowerMockito.verifyNew(CloudFormationStackSet.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class), Mockito.eq(SleepStrategy.EXPONENTIAL_BACKOFF_STRATEGY));
ArgumentCaptor<UpdateStackSetRequest> requestCapture = ArgumentCaptor.forClass(UpdateStackSetRequest.class);
Mockito.verify(stackSet, Mockito.times(3)).update(Mockito.anyString(), Mockito.anyString(), requestCapture.capture());
Map<String, List<String>> capturedRegionAccounts = requestCapture.getAllValues().stream().flatMap(summary -> summary.getRegions().stream().flatMap(region -> summary.getAccounts().stream().map(accountId -> RegionAccountIdTuple.builder().accountId(accountId).region(region).build()))).collect(Collectors.groupingBy(RegionAccountIdTuple::getRegion, Collectors.mapping(RegionAccountIdTuple::getAccountId, Collectors.toList())));
Assertions.assertThat(capturedRegionAccounts).containsAllEntriesOf(new HashMap<String, List<String>>() {
{
put("r1", asList("a1", "a2"));
put("r2", singletonList("a2"));
put("r3", singletonList("a3"));
}
});
Mockito.verify(stackSet, Mockito.times(3)).waitForOperationToComplete(Mockito.any(), Mockito.any());
}
Aggregations