Search in sources :

Example 1 with DeregisterContainerInstanceRequest

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");
}
Also used : ContainerInstance(com.amazonaws.services.ecs.model.ContainerInstance) TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) DeregisterContainerInstanceRequest(com.amazonaws.services.ecs.model.DeregisterContainerInstanceRequest) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest) DeregisterContainerInstanceResult(com.amazonaws.services.ecs.model.DeregisterContainerInstanceResult) Test(org.junit.jupiter.api.Test)

Aggregations

TerminateInstancesRequest (com.amazonaws.services.ec2.model.TerminateInstancesRequest)1 TerminateInstancesResult (com.amazonaws.services.ec2.model.TerminateInstancesResult)1 ContainerInstance (com.amazonaws.services.ecs.model.ContainerInstance)1 DeregisterContainerInstanceRequest (com.amazonaws.services.ecs.model.DeregisterContainerInstanceRequest)1 DeregisterContainerInstanceResult (com.amazonaws.services.ecs.model.DeregisterContainerInstanceResult)1 Test (org.junit.jupiter.api.Test)1