use of com.amazonaws.services.ecs.model.DeregisterContainerInstanceRequest in project gocd-ecs-elastic-agent by gocd.
the class TerminateOperationTest method shouldTerminateInstance.
@Test
void shouldTerminateInstance() {
final ContainerInstance instanceToDeregister = containerInstance("i-abcde12", "container-instance-arn");
final ArgumentCaptor<TerminateInstancesRequest> terminateInstancesRequestArgumentCaptor = ArgumentCaptor.forClass(TerminateInstancesRequest.class);
final ArgumentCaptor<DeregisterContainerInstanceRequest> deregisterContainerInstanceRequestArgumentCaptor = ArgumentCaptor.forClass(DeregisterContainerInstanceRequest.class);
when(pluginSettings.getClusterName()).thenReturn("GoCD");
when(ecsClient.deregisterContainerInstance(deregisterContainerInstanceRequestArgumentCaptor.capture())).thenReturn(new DeregisterContainerInstanceResult().withContainerInstance(instanceToDeregister));
when(ec2Client.terminateInstances(terminateInstancesRequestArgumentCaptor.capture())).thenReturn(new TerminateInstancesResult());
terminateOperation.execute(pluginSettings, instanceToDeregister);
final DeregisterContainerInstanceRequest deregisterContainerInstanceRequest = deregisterContainerInstanceRequestArgumentCaptor.getValue();
assertThat(deregisterContainerInstanceRequest.getCluster()).isEqualTo("GoCD");
assertThat(deregisterContainerInstanceRequest.getContainerInstance()).isEqualTo("container-instance-arn");
assertThat(deregisterContainerInstanceRequest.getForce()).isEqualTo(true);
final TerminateInstancesRequest terminateInstancesRequest = terminateInstancesRequestArgumentCaptor.getValue();
assertThat(terminateInstancesRequest.getInstanceIds()).hasSize(1).contains("i-abcde12");
}
Aggregations