Skip to content

Commit

Permalink
Merge pull request #76 from k1LoW/support-wildcard-record
Browse files Browse the repository at this point in the history
route53_hosted_zone support `*` and `\052` as wildcard record
  • Loading branch information
k1LoW committed Nov 25, 2015
2 parents 278ac39 + ca314fc commit 7e41969
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/awspec/generator/spec/route53_hosted_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ def generate_by_domain_name(id)
end

def generate_linespec(record_set)
name = record_set.name.sub(/\\052/, '*') # wildcard support
if !record_set.resource_records.empty?
template = <<-'EOF'
it { should have_record_set('<%= record_set.name %>').<%= type %>('<%= v %>').ttl(<%= record_set.ttl %>) }
it { should have_record_set('<%= name %>').<%= type %>('<%= v %>').ttl(<%= record_set.ttl %>) }
EOF
v = record_set.resource_records.map { |r| r.value }.join("\n")
type = record_set.type.downcase
Expand All @@ -29,7 +30,7 @@ def generate_linespec(record_set)
dns_name = record_set.alias_target.dns_name
hosted_zone_id = record_set.alias_target.hosted_zone_id
template = <<-'EOF'
it { should have_record_set('<%= record_set.name %>').alias('<%= dns_name %>', '<%= hosted_zone_id %>') }
it { should have_record_set('<%= name %>').alias('<%= dns_name %>', '<%= hosted_zone_id %>') }
EOF
return ERB.new(template, nil, '-').result(binding)
end
Expand Down
12 changes: 11 additions & 1 deletion lib/awspec/stub/route53_hosted_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
id: '/hostedzone/Z1A2BCDEF34GH5',
name: 'example.com.',
caller_reference: '',
resource_record_set_count: 5
resource_record_set_count: 6
}
],
marker: '',
Expand All @@ -26,6 +26,16 @@
}
]
},
{
name: '\052.example.com.',
type: 'CNAME',
ttl: 3600,
resource_records: [
{
value: 'example.com'
}
]
},
{
name: 'example.com.',
type: 'MX',
Expand Down
1 change: 1 addition & 0 deletions lib/awspec/type/route53_hosted_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def initialize(id)
end

def has_record_set?(name, type, value, options = {})
name.sub!(/\*/, '\\\052') # wildcard support
ret = @resource_record_sets.find do |record_set|
next if record_set.type != type.upcase
options[:ttl] = record_set.ttl unless options[:ttl]
Expand Down
3 changes: 2 additions & 1 deletion spec/generator/spec/route53_hosted_zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
spec = <<-'EOF'
describe route53_hosted_zone('example.com.') do
it { should exist }
its(:resource_record_set_count) { should eq 5 }
its(:resource_record_set_count) { should eq 6 }
it { should have_record_set('example.com.').a('123.456.7.890').ttl(3600) }
it { should have_record_set('*.example.com.').cname('example.com').ttl(3600) }
it { should have_record_set('example.com.').mx('10 mail.example.com').ttl(3600) }
it { should have_record_set('mail.example.com.').a('123.456.7.890').ttl(3600) }
it { should have_record_set('example.com.').ns('ns-123.awsdns-45.net.
Expand Down
12 changes: 10 additions & 2 deletions spec/type/route53_hosted_zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

describe route53_hosted_zone('example.com.') do
it { should exist }
its(:resource_record_set_count) { should eq 5 }
its(:resource_record_set_count) { should eq 6 }
it { should have_record_set('example.com.').a('123.456.7.890') }
it { should have_record_set('*.example.com.').cname('example.com') }
it { should have_record_set('example.com.').mx('10 mail.example.com') }
it { should have_record_set('mail.example.com.').a('123.456.7.890').ttl(3600) }
ns = 'ns-123.awsdns-45.net.
Expand All @@ -15,7 +16,14 @@
it { should have_record_set('s3.example.com.').alias('s3-website-us-east-1.amazonaws.com.', 'Z2ABCDEFGHIJKL') }
end

describe route53_hosted_zone('example.com.') do
context 'route53_hosted_zone support wildcard format' do
it { should have_record_set('\052.example.com.').cname('example.com') }
it { should have_record_set('*.example.com.').cname('example.com') }
end
end

describe route53_hosted_zone('Z1A2BCDEF34GH5') do
it { should exist }
its(:resource_record_set_count) { should eq 5 }
its(:resource_record_set_count) { should eq 6 }
end

0 comments on commit 7e41969

Please sign in to comment.