<commit_before>require 'spec_helper'

on_supported_os.each do |os, f|
  describe 'ntp' do
    let(:facts) { { is_virtual: false } }

    let(:conf_path) do
      if os =~ %r{solaris}
        '/etc/inet/ntp.conf'
      else
        '/etc/ntp.conf'
      end
    end

    context "on #{os}" do
      let(:facts) do
        f.merge(super())
      end

      it { is_expected.to compile.with_all_deps }

      it { is_expected.to contain_class('ntp::install') }
      it { is_expected.to contain_class('ntp::config') }
      it { is_expected.to contain_class('ntp::service') }

      describe 'ntp::config' do
        it { is_expected.to contain_file(conf_path).with_owner('0') }
        it { is_expected.to contain_file(conf_path).with_group('0') }
        it { is_expected.to contain_file(conf_path).with_mode('0644') }

        if f[:os]['family'] == 'RedHat'
          it { is_expected.to contain_file('/etc/ntp/step-tickers').with_owner('0') }
          it { is_expected.to contain_file('/etc/ntp/step-tickers').with_group('0') }
          it { is_expected.to contain_file('/etc/ntp/step-tickers').with_mode('0644') }
        end

        if f[:os]['family'] == 'Suse' && f[:os]['release']['major'] == '12'
          it { is_expected.to contain_file('/var/run/ntp/servers-netconfig').with_ensure_absent }
        end

        describe 'allows template to be overridden with erb template' do
          let(:params) { { config_template: 'my_ntp/ntp.conf.erb' } }

          it { is_expected.to contain_file(conf_path).with_content(%r{erbserver1}) }
        end

        describe 'allows template to be overridden with epp template' do
          let(:params) { { config_epp: 'my_ntp/ntp.conf.epp' } }

          it { is_expected.to contain_file(conf_path).with_content(%r{eppserver1}) }
        end

        describe 'broadcastclient' do
          context 'when set to true' do
            let(:params) do
              {
                broadcastclient: true,
              }
            end

            it 'contains broadcastclient setting' do
              is_expected.to contain_file(conf_path).with('content' => %r{^broadcastclient\n})
            end
          end
          context 'when set to false' do
            let(:params) do
              {
                broadcastclient: false,
              }
            end

            it 'does not contain broadcastclient setting' do
              is_expected.not_to contain_file(conf_path).with('content' => %r{^broadcastclient\n})
            end
          end
        end

        describe 'burst' do
          context 'when set to true' do
            let(:params) do
              {
                burst: true,
              }
            end

            it do
              is_expected.to contain_file(conf_path).with('content' => %r{ burst\n})
            end
          end

          context 'when set to false' do
            let(:params) do
              {
                burst: false,
              }
            end

            it do
              is_expected.not_to contain_file(conf_path).with('content' => %r{ burst\n})
            end
          end
        end

        context 'config_dir' do
          context 'when set to custom dir' do
            let(:params) do
              {
                keys_enable: true,
                config_dir: '/tmp/foo',
                keys_file: '/tmp/foo/ntp.keys',
              }
            end

            it 'contains custom config directory' do
              is_expected.to contain_file('/tmp/foo').with(
                'ensure' => 'directory', 'owner' => '0', 'group' => '0', 'mode' => '0775', 'recurse' => 'false',
              )
            end
          end
        end

        context 'config_file_mode' do
          context 'when set to custom mode' do
            let(:params) do
              {
                config_file_mode: '0777',
              }
            end

            it 'contains file mode of 0777' do
              is_expected.to contain_file(conf_path).with_mode('0777')
            end
          end
        end

        context 'default pool servers' do
          case f[:os]['family']
          when 'RedHat'
            it 'uses the centos ntp servers' do
              is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.centos.pool.ntp.org})
            end
            it do
              is_expected.to contain_file('/etc/ntp/step-tickers').with('content' => %r{\d.centos.pool.ntp.org})
            end
          when 'Debian'
            it 'uses the debian ntp servers' do
              is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.debian.pool.ntp.org iburst\n})
            end
          when 'Suse'
            it 'uses the opensuse ntp servers' do
              is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.opensuse.pool.ntp.org})
            end
          when 'FreeBSD'
            it 'uses the freebsd ntp servers' do
              is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.freebsd.pool.ntp.org iburst maxpoll 9})
            end
          when 'Solaris'
            it 'uses the generic NTP pool servers' do
              is_expected.to contain_file('/etc/inet/ntp.conf').with('content' => %r{server \d.pool.ntp.org})
            end
          else
            it {
              expect { catalogue }.to raise_error(
                %r{The ntp module is not supported on an unsupported based system.},
              )
            }
          end
        end

        describe 'disable_auth' do
          context 'when set to true' do
            let(:params) do
              {
                disable_auth: true,
              }
            end

            it 'contains disable auth setting' do
              is_expected.to contain_file(conf_path).with('content' => %r{^disable auth\n})
            end
          end
          context 'when set to false' do
            let(:params) do
              {
                disable_auth: false,
              }
            end

            it 'does not contain disable auth setting' do<commit_msg>forced facter 3.9 to ensure AIX testing occurs<commit_after>require 'spec_helper'

on_supported_os(facterversion: '3.9.0').each do |os, f|
  describe 'ntp' do
    let(:facts) { { is_virtual: false } }

    let(:conf_path) do
      if os =~ %r{solaris}
        '/etc/inet/ntp.conf'
      else
        '/etc/ntp.conf'
      end
    end

    context "on #{os}" do
      let(:facts) do
        f.merge(super())
      end

      it { is_expected.to compile.with_all_deps }

      it { is_expected.to contain_class('ntp::install') }
      it { is_expected.to contain_class('ntp::config') }
      it { is_expected.to contain_class('ntp::service') }

      describe 'ntp::config' do
        it { is_expected.to contain_file(conf_path).with_owner('0') }
        it { is_expected.to contain_file(conf_path).with_group('0') }
        it { is_expected.to contain_file(conf_path).with_mode('0644') }

        if f[:os]['family'] == 'RedHat'
          it { is_expected.to contain_file('/etc/ntp/step-tickers').with_owner('0') }
          it { is_expected.to contain_file('/etc/ntp/step-tickers').with_group('0') }
          it { is_expected.to contain_file('/etc/ntp/step-tickers').with_mode('0644') }
        end

        if f[:os]['family'] == 'Suse' && f[:os]['release']['major'] == '12'
          it { is_expected.to contain_file('/var/run/ntp/servers-netconfig').with_ensure_absent }
        end

        describe 'allows template to be overridden with erb template' do
          let(:params) { { config_template: 'my_ntp/ntp.conf.erb' } }

          it { is_expected.to contain_file(conf_path).with_content(%r{erbserver1}) }
        end

        describe 'allows template to be overridden with epp template' do
          let(:params) { { config_epp: 'my_ntp/ntp.conf.epp' } }

          it { is_expected.to contain_file(conf_path).with_content(%r{eppserver1}) }
        end

        describe 'broadcastclient' do
          context 'when set to true' do
            let(:params) do
              {
                broadcastclient: true,
              }
            end

            it 'contains broadcastclient setting' do
              is_expected.to contain_file(conf_path).with('content' => %r{^broadcastclient\n})
            end
          end
          context 'when set to false' do
            let(:params) do
              {
                broadcastclient: false,
              }
            end

            it 'does not contain broadcastclient setting' do
              is_expected.not_to contain_file(conf_path).with('content' => %r{^broadcastclient\n})
            end
          end
        end

        describe 'burst' do
          context 'when set to true' do
            let(:params) do
              {
                burst: true,
              }
            end

            it do
              is_expected.to contain_file(conf_path).with('content' => %r{ burst\n})
            end
          end

          context 'when set to false' do
            let(:params) do
              {
                burst: false,
              }
            end

            it do
              is_expected.not_to contain_file(conf_path).with('content' => %r{ burst\n})
            end
          end
        end

        context 'config_dir' do
          context 'when set to custom dir' do
            let(:params) do
              {
                keys_enable: true,
                config_dir: '/tmp/foo',
                keys_file: '/tmp/foo/ntp.keys',
              }
            end

            it 'contains custom config directory' do
              is_expected.to contain_file('/tmp/foo').with(
                'ensure' => 'directory', 'owner' => '0', 'group' => '0', 'mode' => '0775', 'recurse' => 'false',
              )
            end
          end
        end

        context 'config_file_mode' do
          context 'when set to custom mode' do
            let(:params) do
              {
                config_file_mode: '0777',
              }
            end

            it 'contains file mode of 0777' do
              is_expected.to contain_file(conf_path).with_mode('0777')
            end
          end
        end

        context 'default pool servers' do
          case f[:os]['family']
          when 'RedHat'
            it 'uses the centos ntp servers' do
              is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.centos.pool.ntp.org})
            end
            it do
              is_expected.to contain_file('/etc/ntp/step-tickers').with('content' => %r{\d.centos.pool.ntp.org})
            end
          when 'Debian'
            it 'uses the debian ntp servers' do
              is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.debian.pool.ntp.org iburst\n})
            end
          when 'Suse'
            it 'uses the opensuse ntp servers' do
              is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.opensuse.pool.ntp.org})
            end
          when 'FreeBSD'
            it 'uses the freebsd ntp servers' do
              is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.freebsd.pool.ntp.org iburst maxpoll 9})
            end
          when 'Solaris'
            it 'uses the generic NTP pool servers' do
              is_expected.to contain_file('/etc/inet/ntp.conf').with('content' => %r{server \d.pool.ntp.org})
            end
          when 'AIX'
            it 'uses the generic NTP pool servers on AIX' do
              is_expected.to contain_file('/etc/ntp.conf').with('content' => %r{server \d.pool.ntp.org})
            end
          else
            it {
              expect { catalogue }.to raise_error(
                %r{The ntp module is not supported on an unsupported based system.},
              )
            }
          end
        end

        describe 'disable_auth' do
          context 'when set to true' do
            let(:params) do
              {
                disable_auth: true,
              }
            end

            it 'contains disable auth setting' do
              is_expected.to contain_file(conf_path).with('content' => %r{^disable auth\n})
            end
          end
          context 'when set to false' do
            let(:params) do
              {
                disable_auth: false,
              }
            end

            it 'does not contain disable auth setting' do
{'fraction_non_alphanumeric': 0.11212266411116435, 'fraction_numerical': 0.005989458552946814, 'mean_word_length': 1.5222557905337362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '4299349', 'n_tokens_mistral': 3731, 'n_tokens_neox': 3601, 'n_words': 862}