From 6e81fc396e7c141176d3dec46a588681afd2513c Mon Sep 17 00:00:00 2001 From: Tarun Menon Date: Mon, 6 Mar 2023 16:59:46 +1100 Subject: [PATCH] Updated spec tests --- spec/ephemeral_storage_spec.rb | 73 ++++++++++++++++++- spec/extra_hosts_spec.rb | 2 +- spec/fargate_spec.rb | 2 +- spec/linux_parameters_spec.rb | 2 +- spec/multiple_links_spec.rb | 2 +- spec/multiple_scaling_policies_spec.rb | 2 +- spec/multiple_target_groups_parameter_spec.rb | 2 +- spec/multiple_target_groups_spec.rb | 6 +- spec/nginx_service_spec.rb | 2 +- spec/scheduling_strategy_replica_spec.rb | 2 +- spec/secrets_spec.rb | 6 +- spec/security_group_spec.rb | 2 +- spec/task_placement_constraint_spec.rb | 2 +- spec/user_spec.rb | 2 +- spec/volumes_spec.rb | 2 +- 15 files changed, 87 insertions(+), 22 deletions(-) diff --git a/spec/ephemeral_storage_spec.rb b/spec/ephemeral_storage_spec.rb index 60a4a65..b4d94b4 100644 --- a/spec/ephemeral_storage_spec.rb +++ b/spec/ephemeral_storage_spec.rb @@ -12,7 +12,23 @@ context "Resource" do + + context "LogGroup" do + let(:resource) { template["Resources"]["LogGroup"] } + it "is of type AWS::Logs::LogGroup" do + expect(resource["Type"]).to eq("AWS::Logs::LogGroup") + end + + it "to have property LogGroupName" do + expect(resource["Properties"]["LogGroupName"]).to eq({"Ref"=>"AWS::StackName"}) + end + + it "to have property RetentionInDays" do + expect(resource["Properties"]["RetentionInDays"]).to eq("7") + end + + end context "Task" do let(:resource) { template["Resources"]["Task"] } @@ -24,17 +40,66 @@ it "to have property ContainerDefinitions" do expect(resource["Properties"]["ContainerDefinitions"]).to eq([{"Name"=>"nginx", "Image"=>{"Fn::Join"=>["", ["nginx/", "nginx", ":", "latest"]]}, "LogConfiguration"=>{"LogDriver"=>"awslogs", "Options"=>{"awslogs-group"=>{"Ref"=>"LogGroup"}, "awslogs-region"=>{"Ref"=>"AWS::Region"}, "awslogs-stream-prefix"=>"nginx"}}}]) end - - it "to have property ContainerDefinitions" do - expect(resource["Properties"]["ContainerDefinitions"]).to eq([{"Name"=>"nginx", "Image"=>{"Fn::Join"=>["", ["nginx/", "nginx", ":", "latest"]]}, "LogConfiguration"=>{"LogDriver"=>"awslogs", "Options"=>{"awslogs-group"=>{"Ref"=>"LogGroup"}, "awslogs-region"=>{"Ref"=>"AWS::Region"}, "awslogs-stream-prefix"=>"nginx"}}}]) - end it "to have property EphemeralStorage" do expect(resource["Properties"]["EphemeralStorage"]).to eq({"SizeInGiB"=>50}) end + it "to have property Tags" do + expect(resource["Properties"]["Tags"]).to eq([{"Key"=>"Name", "Value"=>"ecs-service"}, {"Key"=>"Environment", "Value"=>{"Ref"=>"EnvironmentName"}}, {"Key"=>"EnvironmentType", "Value"=>{"Ref"=>"EnvironmentType"}}]) + end + + end + + context "Role" do + let(:resource) { template["Resources"]["Role"] } + + it "is of type AWS::IAM::Role" do + expect(resource["Type"]).to eq("AWS::IAM::Role") + end + + it "to have property AssumeRolePolicyDocument" do + expect(resource["Properties"]["AssumeRolePolicyDocument"]).to eq({"Version"=>"2012-10-17", "Statement"=>[{"Effect"=>"Allow", "Principal"=>{"Service"=>"ecs.amazonaws.com"}, "Action"=>"sts:AssumeRole"}]}) + end + + it "to have property Path" do + expect(resource["Properties"]["Path"]).to eq("/") + end + + it "to have property ManagedPolicyArns" do + expect(resource["Properties"]["ManagedPolicyArns"]).to eq(["arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole"]) + end + end + context "Service" do + let(:resource) { template["Resources"]["Service"] } + + it "is of type AWS::ECS::Service" do + expect(resource["Type"]).to eq("AWS::ECS::Service") + end + + it "to have property Cluster" do + expect(resource["Properties"]["Cluster"]).to eq({"Ref"=>"EcsCluster"}) + end + + it "to have property DesiredCount" do + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + end + + it "to have property DeploymentConfiguration" do + expect(resource["Properties"]["DeploymentConfiguration"]).to eq({"MinimumHealthyPercent"=>{"Ref"=>"MinimumHealthyPercent"}, "MaximumPercent"=>{"Ref"=>"MaximumPercent"}}) + end + + it "to have property TaskDefinition" do + expect(resource["Properties"]["TaskDefinition"]).to eq({"Ref"=>"Task"}) + end + + it "to have property Tags" do + expect(resource["Properties"]["Tags"]).to eq([{"Key"=>"Name", "Value"=>"ecs-service"}, {"Key"=>"Environment", "Value"=>{"Ref"=>"EnvironmentName"}}, {"Key"=>"EnvironmentType", "Value"=>{"Ref"=>"EnvironmentType"}}]) + end + + end end diff --git a/spec/extra_hosts_spec.rb b/spec/extra_hosts_spec.rb index d9dc445..8923bbc 100644 --- a/spec/extra_hosts_spec.rb +++ b/spec/extra_hosts_spec.rb @@ -80,7 +80,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/fargate_spec.rb b/spec/fargate_spec.rb index 2f48de0..5951d3e 100644 --- a/spec/fargate_spec.rb +++ b/spec/fargate_spec.rb @@ -83,7 +83,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/linux_parameters_spec.rb b/spec/linux_parameters_spec.rb index 0a0ab38..b614c18 100644 --- a/spec/linux_parameters_spec.rb +++ b/spec/linux_parameters_spec.rb @@ -80,7 +80,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/multiple_links_spec.rb b/spec/multiple_links_spec.rb index 15353ce..917ec6d 100644 --- a/spec/multiple_links_spec.rb +++ b/spec/multiple_links_spec.rb @@ -80,7 +80,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/multiple_scaling_policies_spec.rb b/spec/multiple_scaling_policies_spec.rb index a565a51..3066781 100644 --- a/spec/multiple_scaling_policies_spec.rb +++ b/spec/multiple_scaling_policies_spec.rb @@ -80,7 +80,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/multiple_target_groups_parameter_spec.rb b/spec/multiple_target_groups_parameter_spec.rb index 6c259b6..825b6a3 100644 --- a/spec/multiple_target_groups_parameter_spec.rb +++ b/spec/multiple_target_groups_parameter_spec.rb @@ -80,7 +80,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/multiple_target_groups_spec.rb b/spec/multiple_target_groups_spec.rb index ec31746..64d132b 100644 --- a/spec/multiple_target_groups_spec.rb +++ b/spec/multiple_target_groups_spec.rb @@ -88,7 +88,7 @@ end it "to have property Actions" do - expect(resource["Properties"]["Actions"]).to eq([{"Type"=>"forward", "TargetGroupArn"=>{"Ref"=>"nginxhttpTargetGroup"}}]) + expect(resource["Properties"]["Actions"]).to eq({"Fn::If"=>["EnableCognito", [{"Type"=>"forward", "Order"=>5000, "TargetGroupArn"=>{"Ref"=>"nginxhttpTargetGroup"}}, {"Type"=>"authenticate-cognito", "Order"=>1, "AuthenticateCognitoConfig"=>{"UserPoolArn"=>{"Ref"=>"UserPoolId"}, "UserPoolClientId"=>{"Ref"=>"UserPoolClientId"}, "UserPoolDomain"=>{"Ref"=>"UserPoolDomainName"}}}], [{"Type"=>"forward", "Order"=>5000, "TargetGroupArn"=>{"Ref"=>"nginxhttpTargetGroup"}}]]}) end it "to have property Conditions" do @@ -146,7 +146,7 @@ end it "to have property Actions" do - expect(resource["Properties"]["Actions"]).to eq([{"Type"=>"forward", "TargetGroupArn"=>{"Ref"=>"nginxhttpsTargetGroup"}}]) + expect(resource["Properties"]["Actions"]).to eq({"Fn::If"=>["EnableCognito", [{"Type"=>"forward", "Order"=>5000, "TargetGroupArn"=>{"Ref"=>"nginxhttpsTargetGroup"}}, {"Type"=>"authenticate-cognito", "Order"=>1, "AuthenticateCognitoConfig"=>{"UserPoolArn"=>{"Ref"=>"UserPoolId"}, "UserPoolClientId"=>{"Ref"=>"UserPoolClientId"}, "UserPoolDomain"=>{"Ref"=>"UserPoolDomainName"}}}], [{"Type"=>"forward", "Order"=>5000, "TargetGroupArn"=>{"Ref"=>"nginxhttpsTargetGroup"}}]]}) end it "to have property Conditions" do @@ -196,7 +196,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/nginx_service_spec.rb b/spec/nginx_service_spec.rb index 71ae3d8..77d0a4a 100644 --- a/spec/nginx_service_spec.rb +++ b/spec/nginx_service_spec.rb @@ -84,7 +84,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/scheduling_strategy_replica_spec.rb b/spec/scheduling_strategy_replica_spec.rb index a2bf7e3..ca66821 100644 --- a/spec/scheduling_strategy_replica_spec.rb +++ b/spec/scheduling_strategy_replica_spec.rb @@ -80,7 +80,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/secrets_spec.rb b/spec/secrets_spec.rb index 9ad7e33..be1e2fa 100644 --- a/spec/secrets_spec.rb +++ b/spec/secrets_spec.rb @@ -71,7 +71,7 @@ end it "to have property Policies" do - expect(resource["Properties"]["Policies"]).to eq([{"PolicyName"=>"ssm-secrets", "PolicyDocument"=>{"Statement"=>[{"Sid"=>"ssmsecrets", "Action"=>"ssm:GetParameters", "Resource"=>[{"Fn::Sub"=>"arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/nginx/${EnvironmentName}/api/key"}, {"Fn::Sub"=>"arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/nginx/${EnvironmentName}/api/secret"}], "Effect"=>"Allow"}]}}, {"PolicyName"=>"secretsmanager", "PolicyDocument"=>{"Statement"=>[{"Sid"=>"secretsmanager", "Action"=>"secretsmanager:GetSecretValue", "Resource"=>[{"Fn::Sub"=>"arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:/dont/use/accesskeys-*"}, {"Ref"=>"EnvironmentName"}], "Effect"=>"Allow"}]}}]) + expect(resource["Properties"]["Policies"]).to eq([{"PolicyName"=>"ssm-secrets", "PolicyDocument"=>{"Statement"=>[{"Sid"=>"ssmsecrets", "Action"=>"ssm:GetParameters", "Resource"=>[{"Fn::Sub"=>"arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/nginx/${EnvironmentName}/api/key*"}, {"Fn::Sub"=>"arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/nginx/${EnvironmentName}/api/secret*"}], "Effect"=>"Allow"}]}}, {"PolicyName"=>"secretsmanager", "PolicyDocument"=>{"Statement"=>[{"Sid"=>"secretsmanager", "Action"=>"secretsmanager:GetSecretValue", "Resource"=>[{"Fn::Sub"=>"arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:/dont/use/accesskeys*"}, {"Fn::Sub"=>"arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:{\"Ref\"=>\"EnvironmentName\"}*"}], "Effect"=>"Allow"}]}}]) end end @@ -84,7 +84,7 @@ end it "to have property ContainerDefinitions" do - expect(resource["Properties"]["ContainerDefinitions"]).to eq([{"Name"=>"nginx", "Image"=>{"Fn::Join"=>["", ["nginx/", "nginx", ":", "latest"]]}, "LogConfiguration"=>{"LogDriver"=>"awslogs", "Options"=>{"awslogs-group"=>{"Ref"=>"LogGroup"}, "awslogs-region"=>{"Ref"=>"AWS::Region"}, "awslogs-stream-prefix"=>"nginx"}}, "Secrets"=>[{"Name"=>"API_KEY", "ValueFrom"=>{"Fn::Sub"=>"arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/nginx/${EnvironmentName}/api/key"}}, {"Name"=>"API_SECRET", "ValueFrom"=>{"Fn::Sub"=>"arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/nginx/${EnvironmentName}/api/secret"}}, {"Name"=>"ACCESSKEY", "ValueFrom"=>{"Fn::Sub"=>"arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:/dont/use/accesskeys"}}, {"Name"=>"SECRETKEY", "ValueFrom"=>{"Ref"=>"EnvironmentName"}}]}]) + expect(resource["Properties"]["ContainerDefinitions"]).to eq([{"Name"=>"nginx", "Image"=>{"Fn::Join"=>["", ["nginx/", "nginx", ":", "latest"]]}, "LogConfiguration"=>{"LogDriver"=>"awslogs", "Options"=>{"awslogs-group"=>{"Ref"=>"LogGroup"}, "awslogs-region"=>{"Ref"=>"AWS::Region"}, "awslogs-stream-prefix"=>"nginx"}}, "Secrets"=>[{"Name"=>"API_KEY", "ValueFrom"=>{"Fn::Sub"=>"arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/nginx/${EnvironmentName}/api/key"}}, {"Name"=>"API_SECRET", "ValueFrom"=>{"Fn::Sub"=>"arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/nginx/${EnvironmentName}/api/secret"}}, {"Name"=>"ACCESSKEY", "ValueFrom"=>"/dont/use/accesskeys"}, {"Name"=>"SECRETKEY", "ValueFrom"=>{"Fn::Sub"=>"arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:{\"Ref\"=>\"EnvironmentName\"}"}}]}]) end it "to have property TaskRoleArn" do @@ -134,7 +134,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/security_group_spec.rb b/spec/security_group_spec.rb index 4e2228f..bab9018 100644 --- a/spec/security_group_spec.rb +++ b/spec/security_group_spec.rb @@ -104,7 +104,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/task_placement_constraint_spec.rb b/spec/task_placement_constraint_spec.rb index 799f006..e633e8e 100644 --- a/spec/task_placement_constraint_spec.rb +++ b/spec/task_placement_constraint_spec.rb @@ -84,7 +84,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/user_spec.rb b/spec/user_spec.rb index 7e9a661..b68c9de 100644 --- a/spec/user_spec.rb +++ b/spec/user_spec.rb @@ -80,7 +80,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do diff --git a/spec/volumes_spec.rb b/spec/volumes_spec.rb index cb16a92..e4f4a3c 100644 --- a/spec/volumes_spec.rb +++ b/spec/volumes_spec.rb @@ -109,7 +109,7 @@ end it "to have property DesiredCount" do - expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If" => ["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) + expect(resource["Properties"]["DesiredCount"]).to eq({"Fn::If"=>["NoDesiredCount", {"Ref"=>"AWS::NoValue"}, {"Ref"=>"DesiredCount"}]}) end it "to have property DeploymentConfiguration" do