From abca3d11dbded74592291771d6720df5dce0f85a Mon Sep 17 00:00:00 2001
From: Parag Bhingre
Date: Tue, 29 Sep 2020 09:32:14 -0700
Subject: [PATCH] feat(test): Add ECS CreateServerGroupTests for task
definition input
---
.../ecs/test/CreateServerGroupSpec.java | 74 +++++++++++++++++--
...tion-inputs-fargate-legacyTargetGroup.json | 28 +++++++
...on-inputs-fargate-targetGroupMappings.json | 33 +++++++++
3 files changed, 129 insertions(+), 6 deletions(-)
create mode 100644 clouddriver-ecs/src/integration/resources/testoperations/createServerGroupOperation-inputs-fargate-legacyTargetGroup.json
create mode 100644 clouddriver-ecs/src/integration/resources/testoperations/createServerGroupOperation-inputs-fargate-targetGroupMappings.json
diff --git a/clouddriver-ecs/src/integration/java/com/netflix/spinnaker/clouddriver/ecs/test/CreateServerGroupSpec.java b/clouddriver-ecs/src/integration/java/com/netflix/spinnaker/clouddriver/ecs/test/CreateServerGroupSpec.java
index 907a1c3f8d3..dcc4be4d868 100644
--- a/clouddriver-ecs/src/integration/java/com/netflix/spinnaker/clouddriver/ecs/test/CreateServerGroupSpec.java
+++ b/clouddriver-ecs/src/integration/java/com/netflix/spinnaker/clouddriver/ecs/test/CreateServerGroupSpec.java
@@ -30,10 +30,17 @@
import org.junit.jupiter.api.DisplayName;
import org.springframework.beans.factory.annotation.Autowired;
+/**
+ * TODO (allisaurus): Ideally these tests would go further and actually assert that the resulting
+ * ecs:create-service call is formed as expected, but for now, it asserts that the given operation
+ * is correctly validated and submitted as a task.
+ */
public class CreateServerGroupSpec extends EcsSpec {
@Autowired AccountCredentialsRepository accountCredentialsRepository;
+ private static final String CREATE_SG_TEST_PATH = "/ecs/ops/createServerGroup";
+
@DisplayName(
".\n===\n"
+ "Given description w/ inputs, EC2 launch type, and legacy target group fields, "
@@ -41,14 +48,9 @@ public class CreateServerGroupSpec extends EcsSpec {
+ "\n===")
@Test
public void createServerGroupOperationTest() throws IOException {
- /**
- * TODO (allisaurus): Ideally this test would go further and actually assert that the resulting
- * ecs:create-service call is formed as expected, but for now, it asserts that the given
- * operation is correctly validated and submitted as a task.
- */
// given
- String url = getTestUrl("/ecs/ops/createServerGroup");
+ String url = getTestUrl(CREATE_SG_TEST_PATH);
String requestBody = generateStringFromTestFile("/createServerGroup-inputs-ec2.json");
setEcsAccountCreds();
@@ -66,6 +68,66 @@ public void createServerGroupOperationTest() throws IOException {
.body("resourceUri", containsString("/task/"));
}
+ @DisplayName(
+ ".\n===\n"
+ + "Given description w/ task def inputs, FARGATE launch type, and legacy target group fields, "
+ + "successfully submit createServerGroup operation"
+ + "\n===")
+ @Test
+ public void createSGOWithInputsFargateLegacyTargetGroupTest() throws IOException {
+
+ // given
+ String url = getTestUrl(CREATE_SG_TEST_PATH);
+ String requestBody =
+ generateStringFromTestFile(
+ "/createServerGroupOperation-inputs-fargate-legacyTargetGroup.json");
+ setEcsAccountCreds();
+
+ // when
+ given()
+ .contentType(ContentType.JSON)
+ .body(requestBody)
+ .when()
+ .post(url)
+
+ // then
+ .then()
+ .statusCode(200)
+ .contentType(ContentType.JSON)
+ .body("id", notNullValue())
+ .body("resourceUri", containsString("/task/"));
+ }
+
+ @DisplayName(
+ ".\n===\n"
+ + "Given description w/ task def inputs, FARGATE launch type, and new target group fields, "
+ + "successfully submit createServerGroup operation"
+ + "\n===")
+ @Test
+ public void createSGOWithInputsFargateNewTargetGroupMappingsTest() throws IOException {
+
+ // given
+ String url = getTestUrl(CREATE_SG_TEST_PATH);
+ String requestBody =
+ generateStringFromTestFile(
+ "/createServerGroupOperation-inputs-fargate-targetGroupMappings.json");
+ setEcsAccountCreds();
+
+ // when
+ given()
+ .contentType(ContentType.JSON)
+ .body(requestBody)
+ .when()
+ .post(url)
+
+ // then
+ .then()
+ .statusCode(200)
+ .contentType(ContentType.JSON)
+ .body("id", notNullValue())
+ .body("resourceUri", containsString("/task/"));
+ }
+
private void setEcsAccountCreds() {
AmazonCredentials.AWSRegion testRegion = new AmazonCredentials.AWSRegion(TEST_REGION, null);
diff --git a/clouddriver-ecs/src/integration/resources/testoperations/createServerGroupOperation-inputs-fargate-legacyTargetGroup.json b/clouddriver-ecs/src/integration/resources/testoperations/createServerGroupOperation-inputs-fargate-legacyTargetGroup.json
new file mode 100644
index 00000000000..df25599d346
--- /dev/null
+++ b/clouddriver-ecs/src/integration/resources/testoperations/createServerGroupOperation-inputs-fargate-legacyTargetGroup.json
@@ -0,0 +1,28 @@
+{
+ "account": "ecs-account",
+ "application": "ecs",
+ "availabilityZones": {
+ "us-west-2": [
+ "us-west-2a",
+ "us-west-2c"
+ ]
+ },
+ "capacity": {
+ "desired": 1,
+ "max": 1,
+ "min": 1
+ },
+ "cloudProvider": "ecs",
+ "computeUnits": 256,
+ "containerPort": 80,
+ "credentials": "ecs-account",
+ "dockerImageAddress": "nginx",
+ "ecsClusterName": "spinnaker-deployment-cluster",
+ "launchType": "FARGATE",
+ "networkMode": "aws-vpc",
+ "placementStrategySequence": [],
+ "reservedMemory": 512,
+ "stack": "integTestStack",
+ "freeFormDetails" : "detailTest",
+ "targetGroup": "spin-fargate-instanceTG"
+}
diff --git a/clouddriver-ecs/src/integration/resources/testoperations/createServerGroupOperation-inputs-fargate-targetGroupMappings.json b/clouddriver-ecs/src/integration/resources/testoperations/createServerGroupOperation-inputs-fargate-targetGroupMappings.json
new file mode 100644
index 00000000000..aa880b12cb7
--- /dev/null
+++ b/clouddriver-ecs/src/integration/resources/testoperations/createServerGroupOperation-inputs-fargate-targetGroupMappings.json
@@ -0,0 +1,33 @@
+{
+ "account": "ecs-account",
+ "application": "ecs",
+ "availabilityZones": {
+ "us-west-2": [
+ "us-west-2a",
+ "us-west-2c"
+ ]
+ },
+ "capacity": {
+ "desired": 1,
+ "max": 1,
+ "min": 1
+ },
+ "cloudProvider": "ecs",
+ "computeUnits": 256,
+ "credentials": "ecs-account",
+ "dockerImageAddress": "nginx",
+ "ecsClusterName": "spinnaker-deployment-cluster",
+ "launchType": "FARGATE",
+ "networkMode": "aws-vpc",
+ "placementStrategySequence": [],
+ "reservedMemory": 512,
+ "stack": "integTestStack",
+ "freeFormDetails" : "detailTest",
+ "targetGroupMappings": [
+ {
+ "containerName" : "main",
+ "containerPort" : 80,
+ "targetGroup" : "spin-fargate-instanceTG"
+ }
+ ]
+}