<commit_before>require 'spec_helper'
describe 'dhcp', :type => :class do
  let(:default_params) do
    {
      'dnsdomain'           => ['sampledomain.com','1.1.1.in-addr.arpa'],
      'nameservers'         => ['1.1.1.1'],
      'dhcp_conf_header'    => 'INTERNAL_TEMPLATE',
      'dhcp_conf_ddns'      => 'INTERNAL_TEMPLATE',
      'dhcp_conf_pxe'       => 'INTERNAL_TEMPLATE',
      'dhcp_conf_extra'     => 'INTERNAL_TEMPLATE',
      'dhcp_conf_fragments' => {},
      'logfacility'         => 'daemon',
      'default_lease_time'  => '3600',
      'max_lease_time'      => '86400',
    }
  end

  context 'on a RedHat OS' do
    let :facts do
      {
        :osfamily               => 'RedHat',
        :operatingsystem        => 'RedHat',
        :operatingsystemrelease => '6',
        :concat_basedir         => '/dne',
      }
    end
    let :params do
       default_params
    end
    context 'input validation' do
      ['dnsdomain','nameservers','ntpservers'].each do |arrays|
        context "when #{arrays} is not an array" do
          let :params do
            super().merge(
              arrays => 'BOGON'
            )
          end
          it {is_expected.not_to compile}
        end
      end
    end
    context 'coverage tests' do
      let :params do
        default_params.merge({
          :interface => 'eth0',
        })
       end
      ['dhcp'].each do |dhclasses|
        it {should contain_class(dhclasses)}
      end
      ['/etc/dhcp/dhcpd.pools','/etc/dhcp/dhcpd.hosts'].each do |concats|
        it {should contain_concat(concats)}
      end
      ['dhcp-conf-pxe','dhcp-conf-extra'].each do |frags|
        it {should contain_concat__fragment(frags)}
      end
      ['/etc/dhcp/dhcpd.conf','/etc/dhcp/dhcpd.pools', '/etc/dhcp/dhcpd.ignoredsubnets'].each do |file|
        it {should contain_concat(file)}
      end
      it { is_expected.to compile.with_all_deps }
    end

    context 'header' do
      let :params do
        default_params.merge({
          :interfaces => ['eth0'],
        })
      end

      it 'defines dhcp header contents' do
        verify_concat_fragment_exact_contents(subject, 'dhcp-conf-header', [
          'authoritative;',
          'default-lease-time 3600;',
          'max-lease-time 86400;',
          'log-facility daemon;',
          'option domain-name "sampledomain.com";',
          'option domain-name-servers 1.1.1.1;',
          'option fqdn.no-client-update on;  # set the "O" and "S" flag bits',
          'option fqdn.rcode2 255;',
          'option pxegrub code 150 = text;',
        ])
      end

      context 'omapi_port => 7911' do
        let :params do
          default_params.merge({
            :interfaces => ['eth0'],
            :omapi_port => 7911,
          })
        end

        it 'defines dhcp header contents' do
          verify_concat_fragment_contents(subject, 'dhcp-conf-header', [
            'omapi-port 7911;',
          ])
        end
      end
    end

    context 'ntp' do
      let :params do
        default_params.merge({
          :interfaces => ['eth0'],
        })
      end

      it 'sets ntp-servers to none' do
        should contain_concat__fragment('dhcp-conf-ntp').with_content(/^option ntp-servers none;$/)
      end

      context 'ntpservers defined' do
        let :params do
          default_params.merge({
            :interfaces => ['eth0'],
            :ntpservers => ['time.sample.com'],
          })
        end

        it 'sets ntp-servers' do
          should contain_concat__fragment('dhcp-conf-ntp').with_content(/^option ntp-servers time.sample.com;$/)
        end<commit_msg>simplify concat::fragment checking<commit_after>require 'spec_helper'
describe 'dhcp', :type => :class do
  let(:default_params) do
    {
      'dnsdomain'           => ['sampledomain.com','1.1.1.in-addr.arpa'],
      'nameservers'         => ['1.1.1.1'],
      'dhcp_conf_header'    => 'INTERNAL_TEMPLATE',
      'dhcp_conf_ddns'      => 'INTERNAL_TEMPLATE',
      'dhcp_conf_pxe'       => 'INTERNAL_TEMPLATE',
      'dhcp_conf_extra'     => 'INTERNAL_TEMPLATE',
      'dhcp_conf_fragments' => {},
      'logfacility'         => 'daemon',
      'default_lease_time'  => '3600',
      'max_lease_time'      => '86400',
    }
  end

  context 'on a RedHat OS' do
    let :facts do
      {
        :osfamily               => 'RedHat',
        :operatingsystem        => 'RedHat',
        :operatingsystemrelease => '6',
        :concat_basedir         => '/dne',
      }
    end
    let :params do
       default_params
    end
    context 'input validation' do
      ['dnsdomain','nameservers','ntpservers'].each do |arrays|
        context "when #{arrays} is not an array" do
          let :params do
            super().merge(
              arrays => 'BOGON'
            )
          end
          it {is_expected.not_to compile}
        end
      end
    end
    context 'coverage tests' do
      let :params do
        default_params.merge({
          :interface => 'eth0',
        })
       end
      ['dhcp'].each do |dhclasses|
        it {should contain_class(dhclasses)}
      end
      ['/etc/dhcp/dhcpd.pools','/etc/dhcp/dhcpd.hosts'].each do |concats|
        it {should contain_concat(concats)}
      end
      ['dhcp-conf-pxe','dhcp-conf-extra'].each do |frags|
        it {should contain_concat__fragment(frags)}
      end
      ['/etc/dhcp/dhcpd.conf','/etc/dhcp/dhcpd.pools', '/etc/dhcp/dhcpd.ignoredsubnets'].each do |file|
        it {should contain_concat(file)}
      end
      it { is_expected.to compile.with_all_deps }
    end

    context 'header' do
      let :params do
        default_params.merge({
          :interfaces => ['eth0'],
        })
      end

      it 'defines dhcp header contents' do
        subject.should contain_concat__fragment('dhcp-conf-header')
      end

      context 'omapi_port => 7911' do
        let :params do
          default_params.merge({
            :interfaces => ['eth0'],
            :omapi_port => 7911,
          })
        end

        it 'defines dhcp header contents' do
          subject.should contain_concat__fragment('dhcp-conf-header')
        end
      end
    end

    context 'ntp' do
      let :params do
        default_params.merge({
          :interfaces => ['eth0'],
        })
      end

      it 'sets ntp-servers to none' do
        should contain_concat__fragment('dhcp-conf-ntp').with_content(/^option ntp-servers none;$/)
      end

      context 'ntpservers defined' do
        let :params do
          default_params.merge({
            :interfaces => ['eth0'],
            :ntpservers => ['time.sample.com'],
          })
        end

        it 'sets ntp-servers' do
          should contain_concat__fragment('dhcp-conf-ntp').with_content(/^option ntp-servers time.sample.com;$/)
        end
{'fraction_non_alphanumeric': 0.12848751835535976, 'fraction_numerical': 0.012334801762114538, 'mean_word_length': 1.8593618807724601, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7525774', 'n_tokens_mistral': 2243, 'n_tokens_neox': 2185, 'n_words': 454}