Skip to content

Commit

Permalink
feat(test): Add ECS CreateServerGroupTests for task definition input (#…
Browse files Browse the repository at this point in the history
…4957)

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 authored Sep 30, 2020
1 parent fca2c06 commit c16032c
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,27 @@
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, "
+ "successfully submit createServerGroup operation"
+ "\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();

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}

0 comments on commit c16032c

Please sign in to comment.