From 2bc1b710f2b11fe5b584815a638be92b87e708ab Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 30 Jun 2020 15:52:04 +0200 Subject: [PATCH] Testcase to check resources get tagged Signed-off-by: Nicolas De Loof --- ecs/pkg/amazon/backend/cloudformation_test.go | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ecs/pkg/amazon/backend/cloudformation_test.go b/ecs/pkg/amazon/backend/cloudformation_test.go index 001931b0a..fec167203 100644 --- a/ecs/pkg/amazon/backend/cloudformation_test.go +++ b/ecs/pkg/amazon/backend/cloudformation_test.go @@ -2,8 +2,11 @@ package backend import ( "fmt" + "reflect" "testing" + "github.com/docker/ecs-plugin/pkg/compose" + "github.com/aws/aws-sdk-go/service/elbv2" "github.com/awslabs/goformation/v4/cloudformation" "github.com/awslabs/goformation/v4/cloudformation/ec2" @@ -105,6 +108,31 @@ services: assert.Check(t, lb.Type == elbv2.LoadBalancerTypeEnumNetwork) } +func TestResourcesHaveProjectTagSet(t *testing.T) { + template := convertYaml(t, ` +version: "3" +services: + test: + image: nginx + ports: + - 80:80 + - 88:88 +`) + for _, r := range template.Resources { + tags := reflect.Indirect(reflect.ValueOf(r)).FieldByName("Tags") + if !tags.IsValid() { + continue + } + for i := 0; i < tags.Len(); i++ { + k := tags.Index(i).FieldByName("Key").String() + v := tags.Index(i).FieldByName("Value").String() + if k == compose.ProjectTag { + assert.Equal(t, v, "Test") + } + } + } +} + func convertResultAsString(t *testing.T, project *types.Project, clusterName string) string { client, err := NewBackend("", clusterName, "") assert.NilError(t, err)