Skip to content

Commit

Permalink
Merge pull request #350 from inokappa/add-have_tags-for-elb-and-other…
Browse files Browse the repository at this point in the history
…-fix

Add `have_tag` to elb resource type
  • Loading branch information
k1LoW authored Feb 6, 2018
2 parents c087356 + eec65aa commit a2db5ab
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/_resource_types/cloudfront_distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ end
### have_custom_response_error_code

```ruby
describe cloudfront_distribution('123456789zyxw.cloudfront.net') do
it do
should have_custom_response_error_code(400)
.error_caching_min_ttl(60)
Expand All @@ -33,6 +34,7 @@ end
should have_custom_response_error_code(500)
.error_caching_min_ttl(60)
end
end
```

### have_origin
Expand Down
9 changes: 9 additions & 0 deletions doc/_resource_types/elb.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ describe elb('my-elb') do
it { should belong_to_vpc('my-vpc') }
end
```

### have_tag

```ruby
describe elb('my-elb') do
it { should have_tag('Name').value('my-elb') }
it { should have_tag('my-tag-key').value('my-tag-value') }
end
```
12 changes: 12 additions & 0 deletions doc/resource_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ end
### have_custom_response_error_code

```ruby
describe cloudfront_distribution('123456789zyxw.cloudfront.net') do
it do
should have_custom_response_error_code(400)
.error_caching_min_ttl(60)
Expand All @@ -350,6 +351,7 @@ end
should have_custom_response_error_code(500)
.error_caching_min_ttl(60)
end
end
```


Expand Down Expand Up @@ -1274,6 +1276,15 @@ end
```


### have_tag

```ruby
describe elb('my-elb') do
it { should have_tag('Name').value('my-elb') }
it { should have_tag('my-tag-key').value('my-tag-value') }
end
```

### belong_to_vpc

```ruby
Expand All @@ -1282,6 +1293,7 @@ describe elb('my-elb') do
end
```


### its(:health_check_target), its(:health_check_interval), its(:health_check_timeout), its(:health_check_unhealthy_threshold), its(:health_check_healthy_threshold), its(:load_balancer_name), its(:dns_name), its(:canonical_hosted_zone_name), its(:canonical_hosted_zone_name_id), its(:backend_server_descriptions), its(:availability_zones), its(:subnets), its(:vpc_id), its(:security_groups), its(:created_time), its(:scheme)
## <a name="iam_group">iam_group</a>

Expand Down
3 changes: 3 additions & 0 deletions lib/awspec/generator/spec/elb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def elb_spec_template
<% lb[:listener_descriptions].each do |desc| %>
it { should have_listener(protocol: '<%= desc.listener.protocol %>', port: <%= desc.listener.load_balancer_port %>, instance_protocol: '<%= desc.listener.instance_protocol %>', instance_port: <%= desc.listener.instance_port %>) }
<% end %>
<% select_all_elb_tags(lb.load_balancer_name).each do |tag| %>
it { should have_tag('<%= tag.key %>').value('<%= tag.value %>') }
<% end %>
end
EOF
template
Expand Down
7 changes: 7 additions & 0 deletions lib/awspec/helper/finder/elb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def select_elb_by_vpc_id(vpc_id)
lb.vpc_id == vpc_id
end
end

def select_all_elb_tags(id)
res = elb_client.describe_tags({
load_balancer_names: [id]
})
res.tag_descriptions.single_resource(id).tags
end
end
end
end
17 changes: 17 additions & 0 deletions lib/awspec/stub/elb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@
vpc_id: 'vpc-ab123cde'
}
]
},
describe_tags: {
tag_descriptions: [
{
load_balancer_name: 'my-elb',
tags: [
{
key: 'Name',
value: 'my-elb'
},
{
key: 'my-tag-key',
value: 'my-tag-value'
}
]
}
]
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/awspec/type/elb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,12 @@ def has_listener?(protocol:, port:, instance_protocol:, instance_port:)
listener.instance_protocol == instance_protocol && listener.instance_port == instance_port
end
end

def has_tag?(tag_key, tag_value)
tag_set = select_all_elb_tags(@id)
tag_set.find do |tag|
tag.key == tag_key && tag.value == tag_value
end
end
end
end
2 changes: 2 additions & 0 deletions spec/generator/spec/elb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
its(:health_check_unhealthy_threshold) { should eq 10 }
its(:health_check_healthy_threshold) { should eq 2 }
it { should have_listener(protocol: 'HTTPS', port: 443, instance_protocol: 'HTTP', instance_port: 80) }
it { should have_tag('Name').value('my-elb') }
it { should have_tag('my-tag-key').value('my-tag-value') }
end
EOF
expect(elb.generate_by_vpc_id('my-vpc').to_s.gsub(/\n/, "\n")).to eq spec
Expand Down
2 changes: 2 additions & 0 deletions spec/type/elb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
it { should have_subnet('my-subnet') }
it { should have_listener(protocol: 'HTTPS', port: 443, instance_protocol: 'HTTP', instance_port: 80) }
it { should belong_to_vpc('my-vpc') }
it { should have_tag('Name').value('my-elb') }
it { should have_tag('my-tag-key').value('my-tag-value') }
end

0 comments on commit a2db5ab

Please sign in to comment.