<commit_before>require 'spec_helper'

describe 'logrotate::conf' do
  _, facts = on_supported_os.first
  let(:facts) { facts }

  shared_examples 'error raised' do |param, _|
    context "=> 'foo'" do
      let(:params) { { param.to_sym => 'foo' } }

      it {
        expect do
          is_expected.to contain_file('/etc/logrotate.conf')
        end.to raise_error Puppet::PreformattedError
      }
    end
  end

  shared_examples 'error match' do |param, _|
    context "=> 'foo'" do
      let(:params) { { param.to_sym => 'foo' } }

      it {
        expect do
          is_expected.to contain_file('/etc/logrotate.conf')
        end.to raise_error Puppet::PreformattedError
      }
    end
  end

  shared_examples 'boolean flag' do |param, optional = true|
    it_behaves_like 'error raised', param, 'Boolean'
    context "#{param} => false" do
      let(:params) { { param.to_sym => false } }

      it {
        is_expected.to contain_file('/etc/logrotate.conf').
          with_content(%r{^no(t|)#{param}$})
      }
    end
    context "#{param} => true" do
      let(:params) { { param.to_sym => true } }

      it {
        is_expected.to contain_file('/etc/logrotate.conf').
          with_content(%r{^#{param}$})
      }
    end

    if optional
      context "#{param} missing by default" do
        it {
          is_expected.to contain_file('/etc/logrotate.conf').
            without_content(%r{^(no(t|)|)#{param}$})
        }
      end
    end
  end

  shared_examples 'logrotate::size' do |param|
    context param do
      %w[100 100k 10M 1G].each do |value|
        context "=> #{value}" do
          let(:params) { { param.to_sym => value } }

          it {
            is_expected.to contain_file('/etc/logrotate.conf').
              with_content(%r{^#{param} #{value}$})
          }
        end
      end

      context "=> 'foo'" do
        let(:params) { { param.to_sym => 'foo' } }

        it_behaves_like 'error match', param, 'Integer or Pattern'
      end
    end
  end

  shared_examples 'integer' do |param, params = {}|
    context param do
      it_behaves_like 'error raised', param, 'Integer'
      [1, 10, 20].each do |value|
        context "#{param} => #{value}" do
          let(:params) { params.merge(param.to_sym => value) }

          it {
            is_expected.to contain_file('/etc/logrotate.conf').
              with_content(%r{^#{param} #{value}})
          }
        end
      end
    end
  end

  context '=> /etc/logrotate.conf' do
    let(:title) { '/etc/logrotate.conf' }

    context 'ensure => absent' do
      let(:params) { { ensure: 'absent' } }

      it { is_expected.to contain_file('/etc/logrotate.conf').with_ensure('absent') }
    end

    it {
      is_expected.to contain_class('logrotate')
    }
    it {
      is_expected.to contain_file('/etc/logrotate.conf').with(
        'owner' => 'root',
        'group' => 'root',
        'ensure' => 'present',
        'mode' => '0644'
      ).with_content(%r{\ninclude \/etc\/logrotate.d\n})
    }

    context 'compresscmd => bzip2' do
      let(:params) { { compresscmd: 'bzip2' } }

      it {
        is_expected.to contain_file('/etc/logrotate.conf').
          with_content(%r{^compresscmd bzip2$})
      }
    end

    context 'su_user => root' do
      context 'su_group => root' do
        let(:params) do
          { su_user: 'root',
            su_group: 'root' }
        end
        it {
          is_expected.to contain_file('/etc/logrotate.conf').
            with_content(%r{^su root root$})
        }
      end
    end

    context 'su_user => undef' do
      context 'su_group => root' do
        let(:params) do
          {
            su_user: :undef,
            su_group: 'root'
          }
        end
        it {
          is_expected.to contain_file('/etc/logrotate.conf').
            with_content(%r{^su root root$})
        }
      end
    end

    context 'su_user => root' do
      context 'su_group => undef' do
        let(:params) do
          {
            su_user: 'root',
            su_group: :undef
          }
        end
        it {
          is_expected.to contain_file('/etc/logrotate.conf').
            with_content(%r{^su root root$})
        }
      end
    end

    context 'compressext => .bz2' do
      let(:params) { { compressext: '.bz2' } }

      it {
        is_expected.to contain_file('/etc/logrotate.conf').
          with_content(%r{^compressext .bz2$})
      }
    end

    context 'compressoptions => -9' do<commit_msg>Changed formatting to attempt to pass rubocop tests<commit_after>require 'spec_helper'

describe 'logrotate::conf' do
  _, facts = on_supported_os.first
  let(:facts) { facts }

  shared_examples 'error raised' do |param, _|
    context "=> 'foo'" do
      let(:params) { { param.to_sym => 'foo' } }

      it {
        expect do
          is_expected.to contain_file('/etc/logrotate.conf')
        end.to raise_error Puppet::PreformattedError
      }
    end
  end

  shared_examples 'error match' do |param, _|
    context "=> 'foo'" do
      let(:params) { { param.to_sym => 'foo' } }

      it {
        expect do
          is_expected.to contain_file('/etc/logrotate.conf')
        end.to raise_error Puppet::PreformattedError
      }
    end
  end

  shared_examples 'boolean flag' do |param, optional = true|
    it_behaves_like 'error raised', param, 'Boolean'
    context "#{param} => false" do
      let(:params) { { param.to_sym => false } }

      it {
        is_expected.to contain_file('/etc/logrotate.conf').
          with_content(%r{^no(t|)#{param}$})
      }
    end
    context "#{param} => true" do
      let(:params) { { param.to_sym => true } }

      it {
        is_expected.to contain_file('/etc/logrotate.conf').
          with_content(%r{^#{param}$})
      }
    end

    if optional
      context "#{param} missing by default" do
        it {
          is_expected.to contain_file('/etc/logrotate.conf').
            without_content(%r{^(no(t|)|)#{param}$})
        }
      end
    end
  end

  shared_examples 'logrotate::size' do |param|
    context param do
      %w[100 100k 10M 1G].each do |value|
        context "=> #{value}" do
          let(:params) { { param.to_sym => value } }

          it {
            is_expected.to contain_file('/etc/logrotate.conf').
              with_content(%r{^#{param} #{value}$})
          }
        end
      end

      context "=> 'foo'" do
        let(:params) { { param.to_sym => 'foo' } }

        it_behaves_like 'error match', param, 'Integer or Pattern'
      end
    end
  end

  shared_examples 'integer' do |param, params = {}|
    context param do
      it_behaves_like 'error raised', param, 'Integer'
      [1, 10, 20].each do |value|
        context "#{param} => #{value}" do
          let(:params) { params.merge(param.to_sym => value) }

          it {
            is_expected.to contain_file('/etc/logrotate.conf').
              with_content(%r{^#{param} #{value}})
          }
        end
      end
    end
  end

  context '=> /etc/logrotate.conf' do
    let(:title) { '/etc/logrotate.conf' }

    context 'ensure => absent' do
      let(:params) { { ensure: 'absent' } }

      it { is_expected.to contain_file('/etc/logrotate.conf').with_ensure('absent') }
    end

    it {
      is_expected.to contain_class('logrotate')
    }
    it {
      is_expected.to contain_file('/etc/logrotate.conf').with(
        'owner' => 'root',
        'group' => 'root',
        'ensure' => 'present',
        'mode' => '0644'
      ).with_content(%r{\ninclude \/etc\/logrotate.d\n})
    }

    context 'compresscmd => bzip2' do
      let(:params) { { compresscmd: 'bzip2' } }

      it {
        is_expected.to contain_file('/etc/logrotate.conf').
          with_content(%r{^compresscmd bzip2$})
      }
    end

    context 'su_user => root' do
      context 'su_group => root' do
        let(:params) do
          { su_user: 'root',
            su_group: 'root' }
        end
        it {
          is_expected.to contain_file('/etc/logrotate.conf').
            with_content(%r{^su root root$})
        }
      end
    end

    context 'su_user => undef' do
      context 'su_group => root' do
        let(:params) do
          { su_user: :undef,
            su_group: 'root' }
        end
        it {
          is_expected.to contain_file('/etc/logrotate.conf').
            with_content(%r{^su root root$})
        }
      end
    end

    context 'su_user => root' do
      context 'su_group => undef' do
        let(:params) do
          { su_user: 'root',
            su_group: :undef }
        end
        it {
          is_expected.to contain_file('/etc/logrotate.conf').
            with_content(%r{^su root root$})
        }
      end
    end

    context 'compressext => .bz2' do
      let(:params) { { compressext: '.bz2' } }

      it {
        is_expected.to contain_file('/etc/logrotate.conf').
          with_content(%r{^compressext .bz2$})
      }
    end

    context 'compressoptions => -9' do
{'fraction_non_alphanumeric': 0.14323843416370108, 'fraction_numerical': 0.00556049822064057, 'mean_word_length': 1.9141283214517175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 61, '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': '4408316', 'n_tokens_mistral': 2983, 'n_tokens_neox': 2879, 'n_words': 624}