From 4bbe3f15896231f65d2b7e1b77b0aeaf998fbee1 Mon Sep 17 00:00:00 2001 From: Guillaume Lours Date: Wed, 13 May 2020 15:32:24 +0200 Subject: [PATCH] Add first compose to cloudformation conversion tests Signed-off-by: Guillaume Lours Signed-off-by: Nicolas De Loof --- ecs/tests/compose_command_test.go | 49 ++++++ .../simple-single-service-with-overrides.yaml | 4 + .../testdata/input/simple-single-service.yaml | 4 + .../simple-cloudformation-conversion.golden | 164 ++++++++++++++++++ ...formation-with-overrides-conversion.golden | 164 ++++++++++++++++++ 5 files changed, 385 insertions(+) create mode 100644 ecs/tests/compose_command_test.go create mode 100644 ecs/tests/testdata/input/simple-single-service-with-overrides.yaml create mode 100644 ecs/tests/testdata/input/simple-single-service.yaml create mode 100644 ecs/tests/testdata/simple/simple-cloudformation-conversion.golden create mode 100644 ecs/tests/testdata/simple/simple-cloudformation-with-overrides-conversion.golden diff --git a/ecs/tests/compose_command_test.go b/ecs/tests/compose_command_test.go new file mode 100644 index 000000000..0bdb94bc3 --- /dev/null +++ b/ecs/tests/compose_command_test.go @@ -0,0 +1,49 @@ +package tests + +import ( + "testing" + + "gotest.tools/v3/fs" + "gotest.tools/v3/golden" + "gotest.tools/v3/icmd" +) + +const ( + composeFileName = "compose.yaml" +) + +func TestSimpleConvert(t *testing.T) { + cmd, cleanup := dockerCli.createTestCmd() + defer cleanup() + + composeYAML := golden.Get(t, "input/simple-single-service.yaml") + tmpDir := fs.NewDir(t, t.Name(), + fs.WithFile(composeFileName, "", fs.WithBytes(composeYAML)), + ) + defer tmpDir.Remove() + + cmd.Command = dockerCli.Command("ecs", "compose", "--file="+tmpDir.Join(composeFileName), "--project-name", t.Name(), "convert") + result := icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined() + + expected := "simple/simple-cloudformation-conversion.golden" + golden.Assert(t, result, expected) +} + +func TestSimpleWithOverrides(t *testing.T) { + cmd, cleanup := dockerCli.createTestCmd() + defer cleanup() + + composeYAML := golden.Get(t, "input/simple-single-service.yaml") + overriddenComposeYAML := golden.Get(t, "input/simple-single-service-with-overrides.yaml") + tmpDir := fs.NewDir(t, t.Name(), + fs.WithFile(composeFileName, "", fs.WithBytes(composeYAML)), + fs.WithFile("overriddenService.yaml", "", fs.WithBytes(overriddenComposeYAML)), + ) + defer tmpDir.Remove() + cmd.Command = dockerCli.Command("ecs", "compose", "--file="+tmpDir.Join(composeFileName), "--file", + tmpDir.Join("overriddenService.yaml"), "--project-name", t.Name(), "convert") + result := icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined() + + expected := "simple/simple-cloudformation-with-overrides-conversion.golden" + golden.Assert(t, result, expected) +} diff --git a/ecs/tests/testdata/input/simple-single-service-with-overrides.yaml b/ecs/tests/testdata/input/simple-single-service-with-overrides.yaml new file mode 100644 index 000000000..3dc8a0b6f --- /dev/null +++ b/ecs/tests/testdata/input/simple-single-service-with-overrides.yaml @@ -0,0 +1,4 @@ +version: "3" +services: + simple: + image: haproxy diff --git a/ecs/tests/testdata/input/simple-single-service.yaml b/ecs/tests/testdata/input/simple-single-service.yaml new file mode 100644 index 000000000..4b3f9af21 --- /dev/null +++ b/ecs/tests/testdata/input/simple-single-service.yaml @@ -0,0 +1,4 @@ +version: "3" +services: + simple: + image: nginx \ No newline at end of file diff --git a/ecs/tests/testdata/simple/simple-cloudformation-conversion.golden b/ecs/tests/testdata/simple/simple-cloudformation-conversion.golden new file mode 100644 index 000000000..51a528b3a --- /dev/null +++ b/ecs/tests/testdata/simple/simple-cloudformation-conversion.golden @@ -0,0 +1,164 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": { + "Subnet1Id": { + "Description": "SubnetId,for Availability Zone 1 in the region in your VPC", + "Type": "AWS::EC2::Subnet::Id" + }, + "Subnet2Id": { + "Description": "SubnetId,for Availability Zone 1 in the region in your VPC", + "Type": "AWS::EC2::Subnet::Id" + }, + "VPCId": { + "Description": "ID of the VPC", + "Type": "AWS::EC2::VPC::Id" + } + }, + "Resources": { + "CloudMap": { + "Properties": { + "Description": "Service Map for Docker Compose project TestSimpleConvert", + "Name": "TestSimpleConvert.local", + "Vpc": { + "Ref": "VPCId" + } + }, + "Type": "AWS::ServiceDiscovery::PrivateDnsNamespace" + }, + "LogGroup": { + "Properties": { + "LogGroupName": "/docker-compose/TestSimpleConvert" + }, + "Type": "AWS::Logs::LogGroup" + }, + "simpleService": { + "Properties": { + "Cluster": "TestCluster", + "DesiredCount": 1, + "LaunchType": "FARGATE", + "NetworkConfiguration": { + "AwsvpcConfiguration": { + "AssignPublicIp": "ENABLED", + "Subnets": [ + { + "Ref": "Subnet1Id" + }, + { + "Ref": "Subnet2Id" + } + ] + } + }, + "SchedulingStrategy": "REPLICA", + "ServiceName": "simple", + "ServiceRegistries": [ + { + "RegistryArn": { + "Fn::GetAtt": [ + "simpleServiceDiscoveryEntry", + "Arn" + ] + } + } + ], + "TaskDefinition": { + "Ref": "simpleTaskDefinition" + } + }, + "Type": "AWS::ECS::Service" + }, + "simpleServiceDiscoveryEntry": { + "Properties": { + "Description": "\"simple\" service discovery entry in Cloud Map", + "DnsConfig": { + "DnsRecords": [ + { + "TTL": 300, + "Type": "A" + } + ], + "RoutingPolicy": "MULTIVALUE" + }, + "Name": "simple", + "NamespaceId": { + "Ref": "CloudMap" + } + }, + "Type": "AWS::ServiceDiscovery::Service" + }, + "simpleTaskDefinition": { + "Properties": { + "ContainerDefinitions": [ + { + "Environment": [ + { + "Name": "LOCALDOMAIN", + "Value": { + "Fn::Join": [ + "", + [ + { + "Ref": "AWS::Region" + }, + ".compute.internal", + " TestSimpleConvert.local" + ] + ] + } + } + ], + "Essential": true, + "Image": "docker.io/library/nginx", + "LinuxParameters": {}, + "LogConfiguration": { + "LogDriver": "awslogs", + "Options": { + "awslogs-group": { + "Ref": "LogGroup" + }, + "awslogs-region": { + "Ref": "AWS::Region" + }, + "awslogs-stream-prefix": "simple" + } + }, + "Name": "simple" + } + ], + "Cpu": "256", + "ExecutionRoleArn": { + "Ref": "simpleTaskExecutionRole" + }, + "Family": "TestSimpleConvert-simple", + "Memory": "512", + "NetworkMode": "awsvpc", + "RequiresCompatibilities": [ + "FARGATE" + ] + }, + "Type": "AWS::ECS::TaskDefinition" + }, + "simpleTaskExecutionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy" + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/ecs/tests/testdata/simple/simple-cloudformation-with-overrides-conversion.golden b/ecs/tests/testdata/simple/simple-cloudformation-with-overrides-conversion.golden new file mode 100644 index 000000000..2e8f5a4ad --- /dev/null +++ b/ecs/tests/testdata/simple/simple-cloudformation-with-overrides-conversion.golden @@ -0,0 +1,164 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": { + "Subnet1Id": { + "Description": "SubnetId,for Availability Zone 1 in the region in your VPC", + "Type": "AWS::EC2::Subnet::Id" + }, + "Subnet2Id": { + "Description": "SubnetId,for Availability Zone 1 in the region in your VPC", + "Type": "AWS::EC2::Subnet::Id" + }, + "VPCId": { + "Description": "ID of the VPC", + "Type": "AWS::EC2::VPC::Id" + } + }, + "Resources": { + "CloudMap": { + "Properties": { + "Description": "Service Map for Docker Compose project TestSimpleWithOverrides", + "Name": "TestSimpleWithOverrides.local", + "Vpc": { + "Ref": "VPCId" + } + }, + "Type": "AWS::ServiceDiscovery::PrivateDnsNamespace" + }, + "LogGroup": { + "Properties": { + "LogGroupName": "/docker-compose/TestSimpleWithOverrides" + }, + "Type": "AWS::Logs::LogGroup" + }, + "simpleService": { + "Properties": { + "Cluster": "TestCluster", + "DesiredCount": 1, + "LaunchType": "FARGATE", + "NetworkConfiguration": { + "AwsvpcConfiguration": { + "AssignPublicIp": "ENABLED", + "Subnets": [ + { + "Ref": "Subnet1Id" + }, + { + "Ref": "Subnet2Id" + } + ] + } + }, + "SchedulingStrategy": "REPLICA", + "ServiceName": "simple", + "ServiceRegistries": [ + { + "RegistryArn": { + "Fn::GetAtt": [ + "simpleServiceDiscoveryEntry", + "Arn" + ] + } + } + ], + "TaskDefinition": { + "Ref": "simpleTaskDefinition" + } + }, + "Type": "AWS::ECS::Service" + }, + "simpleServiceDiscoveryEntry": { + "Properties": { + "Description": "\"simple\" service discovery entry in Cloud Map", + "DnsConfig": { + "DnsRecords": [ + { + "TTL": 300, + "Type": "A" + } + ], + "RoutingPolicy": "MULTIVALUE" + }, + "Name": "simple", + "NamespaceId": { + "Ref": "CloudMap" + } + }, + "Type": "AWS::ServiceDiscovery::Service" + }, + "simpleTaskDefinition": { + "Properties": { + "ContainerDefinitions": [ + { + "Environment": [ + { + "Name": "LOCALDOMAIN", + "Value": { + "Fn::Join": [ + "", + [ + { + "Ref": "AWS::Region" + }, + ".compute.internal", + " TestSimpleWithOverrides.local" + ] + ] + } + } + ], + "Essential": true, + "Image": "docker.io/library/haproxy", + "LinuxParameters": {}, + "LogConfiguration": { + "LogDriver": "awslogs", + "Options": { + "awslogs-group": { + "Ref": "LogGroup" + }, + "awslogs-region": { + "Ref": "AWS::Region" + }, + "awslogs-stream-prefix": "simple" + } + }, + "Name": "simple" + } + ], + "Cpu": "256", + "ExecutionRoleArn": { + "Ref": "simpleTaskExecutionRole" + }, + "Family": "TestSimpleWithOverrides-simple", + "Memory": "512", + "NetworkMode": "awsvpc", + "RequiresCompatibilities": [ + "FARGATE" + ] + }, + "Type": "AWS::ECS::TaskDefinition" + }, + "simpleTaskExecutionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy" + ] + }, + "Type": "AWS::IAM::Role" + } + } +}