From 04033f17e1b1ec5c93aa3428868647dbe1032606 Mon Sep 17 00:00:00 2001
From: k1LoW <k1lowxb@gmail.com>
Date: Wed, 25 Nov 2015 10:05:28 +0900
Subject: [PATCH 1/2] [WIP]Support `\052` and `*` as wildcard record


From ca314fc2b75676dca7726d5a2f3c3e6d5fb015b8 Mon Sep 17 00:00:00 2001
From: k1LoW <k1lowxb@gmail.com>
Date: Wed, 25 Nov 2015 10:30:49 +0900
Subject: [PATCH 2/2] route53_hosted_zone support `*` and `\052` as wildcard
 record

---
 lib/awspec/generator/spec/route53_hosted_zone.rb |  5 +++--
 lib/awspec/stub/route53_hosted_zone.rb           | 12 +++++++++++-
 lib/awspec/type/route53_hosted_zone.rb           |  1 +
 spec/generator/spec/route53_hosted_zone_spec.rb  |  3 ++-
 spec/type/route53_hosted_zone_spec.rb            | 12 ++++++++++--
 5 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/lib/awspec/generator/spec/route53_hosted_zone.rb b/lib/awspec/generator/spec/route53_hosted_zone.rb
index ecc8d5cc9..2fab5834c 100644
--- a/lib/awspec/generator/spec/route53_hosted_zone.rb
+++ b/lib/awspec/generator/spec/route53_hosted_zone.rb
@@ -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
@@ -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
diff --git a/lib/awspec/stub/route53_hosted_zone.rb b/lib/awspec/stub/route53_hosted_zone.rb
index 32352d362..4cc819606 100644
--- a/lib/awspec/stub/route53_hosted_zone.rb
+++ b/lib/awspec/stub/route53_hosted_zone.rb
@@ -6,7 +6,7 @@
           id: '/hostedzone/Z1A2BCDEF34GH5',
           name: 'example.com.',
           caller_reference: '',
-          resource_record_set_count: 5
+          resource_record_set_count: 6
         }
       ],
       marker: '',
@@ -26,6 +26,16 @@
             }
           ]
         },
+        {
+          name: '\052.example.com.',
+          type: 'CNAME',
+          ttl: 3600,
+          resource_records: [
+            {
+              value: 'example.com'
+            }
+          ]
+        },
         {
           name: 'example.com.',
           type: 'MX',
diff --git a/lib/awspec/type/route53_hosted_zone.rb b/lib/awspec/type/route53_hosted_zone.rb
index a0ed4fdb9..841865d5b 100644
--- a/lib/awspec/type/route53_hosted_zone.rb
+++ b/lib/awspec/type/route53_hosted_zone.rb
@@ -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]
diff --git a/spec/generator/spec/route53_hosted_zone_spec.rb b/spec/generator/spec/route53_hosted_zone_spec.rb
index cd7f37700..bd40806fc 100644
--- a/spec/generator/spec/route53_hosted_zone_spec.rb
+++ b/spec/generator/spec/route53_hosted_zone_spec.rb
@@ -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.
diff --git a/spec/type/route53_hosted_zone_spec.rb b/spec/type/route53_hosted_zone_spec.rb
index 49826869c..b295b6f66 100644
--- a/spec/type/route53_hosted_zone_spec.rb
+++ b/spec/type/route53_hosted_zone_spec.rb
@@ -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.
@@ -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