Skip to content

Commit

Permalink
feat(test): Add ECS changes for CreateServerGroup for task definition…
Browse files Browse the repository at this point in the history
… artifacts (#4999)

Co-authored-by: Parag Bhingre <pbhingre@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 12, 2020
1 parent 8247c6c commit 2d5083f
Show file tree
Hide file tree
Showing 7 changed files with 565 additions and 44 deletions.
Expand Up @@ -37,6 +37,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
Expand All @@ -50,8 +51,11 @@
public class EcsSpec {
protected static final String TEST_OPERATIONS_LOCATION =
"src/integration/resources/testoperations";
protected static final String TEST_ARTIFACTS_LOCATION = "src/integration/resources/testartifacts";
protected final String ECS_ACCOUNT_NAME = "ecs-account";
protected final String TEST_REGION = "us-west-2";
protected final int TASK_RETRY_SECONDS = 3;
protected static final String CREATE_SG_TEST_PATH = "/ecs/ops/createServerGroup";

@Value("${ecs.enabled}")
Boolean ecsEnabled;
Expand All @@ -61,6 +65,8 @@ public class EcsSpec {

@LocalServerPort private int port;

@Autowired AccountCredentialsRepository accountCredentialsRepository;

@MockBean protected AmazonClientProvider mockAwsProvider;

@MockBean AmazonAccountsSynchronizer mockAccountsSyncer;
Expand Down Expand Up @@ -88,6 +94,10 @@ protected String generateStringFromTestFile(String path) throws IOException {
return new String(Files.readAllBytes(Paths.get(TEST_OPERATIONS_LOCATION, path)));
}

protected String generateStringFromTestArtifactFile(String path) throws IOException {
return new String(Files.readAllBytes(Paths.get(TEST_ARTIFACTS_LOCATION, path)));
}

protected String getTestUrl(String path) {
return "http://localhost:" + port + path;
}
Expand All @@ -114,4 +124,38 @@ protected void retryUntilTrue(BooleanSupplier func, String failMsg, int retrySec
}
fail(failMsg);
}

protected void setEcsAccountCreds() {
AmazonCredentials.AWSRegion testRegion = new AmazonCredentials.AWSRegion(TEST_REGION, null);

NetflixAssumeRoleAmazonCredentials ecsCreds =
new NetflixAssumeRoleAmazonCredentials(
ECS_ACCOUNT_NAME,
"test",
"test",
"123456789012",
null,
true,
Collections.singletonList(testRegion),
null,
null,
null,
null,
false,
null,
null,
null,
null,
null,
null,
null,
false,
false,
"SpinnakerManaged",
"SpinnakerSession",
false,
"");

accountCredentialsRepository.save(ECS_ACCOUNT_NAME, ecsCreds);
}
}
Expand Up @@ -28,14 +28,10 @@
import com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest;
import com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult;
import com.amazonaws.services.elasticloadbalancingv2.model.TargetGroup;
import com.netflix.spinnaker.clouddriver.aws.security.AmazonCredentials;
import com.netflix.spinnaker.clouddriver.aws.security.NetflixAmazonCredentials;
import com.netflix.spinnaker.clouddriver.aws.security.NetflixAssumeRoleAmazonCredentials;
import com.netflix.spinnaker.clouddriver.ecs.EcsSpec;
import com.netflix.spinnaker.clouddriver.security.AccountCredentialsRepository;
import io.restassured.http.ContentType;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -44,18 +40,12 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired;

public class CreateServerGroupSpec extends EcsSpec {

@Autowired AccountCredentialsRepository accountCredentialsRepository;

private final int TASK_RETRY_SECONDS = 3;
private AmazonECS mockECS = mock(AmazonECS.class);
private AmazonElasticLoadBalancing mockELB = mock(AmazonElasticLoadBalancing.class);

private static final String CREATE_SG_TEST_PATH = "/ecs/ops/createServerGroup";

@BeforeEach
public void setup() {
// mock ECS responses
Expand Down Expand Up @@ -375,38 +365,4 @@ public void createServerGroup_errorIfCreateServiceFails()
String.format("Failed to observe task failure after %s seconds", TASK_RETRY_SECONDS),
TASK_RETRY_SECONDS);
}

private void setEcsAccountCreds() {
AmazonCredentials.AWSRegion testRegion = new AmazonCredentials.AWSRegion(TEST_REGION, null);

NetflixAssumeRoleAmazonCredentials ecsCreds =
new NetflixAssumeRoleAmazonCredentials(
ECS_ACCOUNT_NAME,
"test",
"test",
"123456789012",
null,
true,
Collections.singletonList(testRegion),
null,
null,
null,
null,
false,
null,
null,
null,
null,
null,
null,
null,
false,
false,
"SpinnakerManaged",
"SpinnakerSession",
false,
"");

accountCredentialsRepository.save(ECS_ACCOUNT_NAME, ecsCreds);
}
}

0 comments on commit 2d5083f

Please sign in to comment.