<commit_before>module Awspec::Generator
  module Spec
    class Route53HostedZone
      include Awspec::Helper::Finder
      def generate_by_domain_name(id)
        hosted_zone = find_hosted_zone(id)
        fail 'Not Found Route53 Hosted Zone' unless hosted_zone
        id = hosted_zone[:id]
        res = @route53_client.list_resource_record_sets({
                                                          hosted_zone_id: id
                                                        })
        resource_record_sets = res.resource_record_sets.map do |record_set|
          generate_linespec(record_set)
        end

        content = ERB.new(route53_hosted_zone_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
      end

      def generate_linespec(record_set)
        if !record_set.resource_records.empty?
          template = <<-'EOF'
it { should have_record_set('<%= 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
          return ERB.new(template, nil, '-').result(binding)
        else
          # ALIAS
          dns_name = record_set.alias_target.dns_name
          hosted_zone_id = record_set.alias_target.hosted_zone_id
          # rubocop:disable all
          template = <<-'EOF'
it { should have_record_set('<%= record_set.name %>').alias('<%= dns_name %>', '<%= hosted_zone_id %>').ttl(<%= record_set.ttl %>) }
EOF
          # rubocop:enable all
          return ERB.new(template, nil, '-').result(binding)
        end
      end

      def route53_hosted_zone_spec_template
        template = <<-'EOF'
describe route53_hosted_zone('<%= hosted_zone.name %>') do
  it { should exist }
  its(:resource_record_set_count) { should eq <%= hosted_zone.resource_record_set_count %> }
<% resource_record_sets.each do |line| %>
  <%= line %>
<% end %>
end
EOF
        template
      end
    end
  end
end<commit_msg>Alias has no ttl<commit_after>module Awspec::Generator
  module Spec
    class Route53HostedZone
      include Awspec::Helper::Finder
      def generate_by_domain_name(id)
        hosted_zone = find_hosted_zone(id)
        fail 'Not Found Route53 Hosted Zone' unless hosted_zone
        id = hosted_zone[:id]
        res = @route53_client.list_resource_record_sets({
                                                          hosted_zone_id: id
                                                        })
        resource_record_sets = res.resource_record_sets.map do |record_set|
          generate_linespec(record_set)
        end

        content = ERB.new(route53_hosted_zone_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
      end

      def generate_linespec(record_set)
        if !record_set.resource_records.empty?
          template = <<-'EOF'
it { should have_record_set('<%= 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
          return ERB.new(template, nil, '-').result(binding)
        else
          # ALIAS
          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 %>') }
EOF
          return ERB.new(template, nil, '-').result(binding)
        end
      end

      def route53_hosted_zone_spec_template
        template = <<-'EOF'
describe route53_hosted_zone('<%= hosted_zone.name %>') do
  it { should exist }
  its(:resource_record_set_count) { should eq <%= hosted_zone.resource_record_set_count %> }
<% resource_record_sets.each do |line| %>
  <%= line %>
<% end %>
end
EOF
        template
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12341526520051746, 'fraction_numerical': 0.006209573091849935, 'mean_word_length': 2.3270223752151464, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7052042', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1168, 'n_words': 232}