Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(test): Add ECS CreateServerGroupTests for task definition input #4957

Merged
merged 2 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
]
}