From 49a2724d768ed0194436f862bca5cd6c9b27c911 Mon Sep 17 00:00:00 2001 From: Toshiya Kawasaki Date: Mon, 20 Nov 2017 20:18:21 +0900 Subject: [PATCH] Set default value to elbv2 FakeTargetGroup (#1349) --- moto/elbv2/models.py | 14 +++++++------ tests/test_elbv2/test_elbv2.py | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/moto/elbv2/models.py b/moto/elbv2/models.py index e78cf348..52bef1d3 100644 --- a/moto/elbv2/models.py +++ b/moto/elbv2/models.py @@ -61,18 +61,20 @@ class FakeTargetGroup(BaseModel): unhealthy_threshold_count='2', matcher=None, target_type=None): + + # TODO: default values differs when you add Network Load balancer self.name = name self.arn = arn self.vpc_id = vpc_id self.protocol = protocol self.port = port - self.healthcheck_protocol = healthcheck_protocol + self.healthcheck_protocol = healthcheck_protocol or 'HTTP' self.healthcheck_port = healthcheck_port - self.healthcheck_path = healthcheck_path - self.healthcheck_interval_seconds = healthcheck_interval_seconds - self.healthcheck_timeout_seconds = healthcheck_timeout_seconds - self.healthy_threshold_count = healthy_threshold_count - self.unhealthy_threshold_count = unhealthy_threshold_count + self.healthcheck_path = healthcheck_path or '/' + self.healthcheck_interval_seconds = healthcheck_interval_seconds or 30 + self.healthcheck_timeout_seconds = healthcheck_timeout_seconds or 5 + self.healthy_threshold_count = healthy_threshold_count or 5 + self.unhealthy_threshold_count = unhealthy_threshold_count or 2 self.load_balancer_arns = [] self.tags = {} if matcher is None: diff --git a/tests/test_elbv2/test_elbv2.py b/tests/test_elbv2/test_elbv2.py index 4f0b1a9c..4fb52752 100644 --- a/tests/test_elbv2/test_elbv2.py +++ b/tests/test_elbv2/test_elbv2.py @@ -412,6 +412,43 @@ def test_create_target_group_and_listeners(): response = conn.describe_target_groups() response.get('TargetGroups').should.have.length_of(0) +@mock_elbv2 +@mock_ec2 +def test_create_target_group_without_non_required_parameters(): + conn = boto3.client('elbv2', region_name='us-east-1') + ec2 = boto3.resource('ec2', region_name='us-east-1') + + security_group = ec2.create_security_group( + GroupName='a-security-group', Description='First One') + vpc = ec2.create_vpc(CidrBlock='172.28.7.0/24', InstanceTenancy='default') + subnet1 = ec2.create_subnet( + VpcId=vpc.id, + CidrBlock='172.28.7.192/26', + AvailabilityZone='us-east-1a') + subnet2 = ec2.create_subnet( + VpcId=vpc.id, + CidrBlock='172.28.7.192/26', + AvailabilityZone='us-east-1b') + + response = conn.create_load_balancer( + Name='my-lb', + Subnets=[subnet1.id, subnet2.id], + SecurityGroups=[security_group.id], + Scheme='internal', + Tags=[{'Key': 'key_name', 'Value': 'a_value'}]) + + # request without HealthCheckIntervalSeconds parameter + # which is default to 30 seconds + response = conn.create_target_group( + Name='a-target', + Protocol='HTTP', + Port=8080, + VpcId=vpc.id, + HealthCheckProtocol='HTTP', + HealthCheckPort='8080' + ) + target_group = response.get('TargetGroups')[0] + target_group.should_not.be.none @mock_elbv2 @mock_ec2