<commit_before>shared_examples 'RedHat' do
  let(:facts) {{ :osfamily => "RedHat", :operatingsystemmajrelease => '6' }}

  describe "when using default class parameters" do
    let(:params) {{ }}

    it { should create_class('timezone') }
    it { should contain_class('timezone::params') }

    it do
      should contain_package('tzdata').with({
        :ensure => 'present',
        :before => 'File[/etc/localtime]',
      })
    end


    it { should contain_file('/etc/sysconfig/clock').with_ensure('file') }
    it { should contain_file('/etc/sysconfig/clock').with_content(/^ZONE="Etc\/UTC"$/) }
    it { should contain_exec('update_timezone').with_command('tzdata-update') }

    it do
      should contain_file('/etc/localtime').with({
        :ensure => 'file',
        :source => 'file:///usr/share/zoneinfo/Etc/UTC',
      })
    end

    context 'when timezone => "Europe/Berlin"' do
      let(:params) {{ :timezone => "Europe/Berlin" }}

      it { should contain_file('/etc/sysconfig/clock').with_content(/^ZONE="Europe\/Berlin"$/) }
      it { should contain_file('/etc/localtime').with_source('file:///usr/share/zoneinfo/Europe/Berlin') }
    end

    context 'when autoupgrade => true' do
      let(:params) {{ :autoupgrade => true }}
      it { should contain_package('tzdata').with_ensure('latest') }
    end

    context 'when ensure => absent' do
      let(:params) {{ :ensure => 'absent' }}
      it { should contain_package('tzdata').with_ensure('present') }
      it { should contain_file('/etc/sysconfig/clock').with_ensure('absent') }
      it { should contain_file('/etc/localtime').with_ensure('absent') }
    end

    context 'when RHEL 7' do
      let(:facts) {{ :osfamily => "RedHat", :operatingsystemmajrelease => '7' }}
      it { should_not contain_file('/etc/sysconfig/clock').with_ensure('file') }
      it { should contain_exec('update_timezone').with_command('timedatectl set-timezone  Etc/UTC') }
    end

    include_examples 'validate parameters'
  end
end<commit_msg>refacter redhat unit test.<commit_after>shared_examples 'RedHat' do
  let(:facts) {{ :osfamily => "RedHat" }}

  describe "when using default class parameters" do
    let(:params) {{ }}

    it { should create_class('timezone') }
    it { should contain_class('timezone::params') }

    it do
      should contain_package('tzdata').with({
        :ensure => 'present',
        :before => 'File[/etc/localtime]',
      })
    end

    context 'when autoupgrade => true' do
      let(:params) {{ :autoupgrade => true }}
      it { should contain_package('tzdata').with_ensure('latest') }
    end

    context 'when ensure => absent' do
      let(:params) {{ :ensure => 'absent' }}
      it { should contain_package('tzdata').with_ensure('present') }
      it { should contain_file('/etc/sysconfig/clock').with_ensure('absent') }
      it { should contain_file('/etc/localtime').with_ensure('absent') }
    end

    include_examples 'validate parameters'
  end

  context 'when RHEL 6' do
    let(:facts) {{ :osfamily => "RedHat", :operatingsystemmajrelease => '6' }}
    it { should contain_file('/etc/sysconfig/clock').with_ensure('file') }
    it { should contain_file('/etc/sysconfig/clock').with_content(/^ZONE="Etc\/UTC"$/) }
    it { should contain_exec('update_timezone').with_command('tzdata-update') }

    it do
      should contain_file('/etc/localtime').with({
        :ensure => 'file',
        :source => 'file:///usr/share/zoneinfo/Etc/UTC',
      })
    end

    context 'when timezone => "Europe/Berlin"' do
      let(:params) {{ :timezone => "Europe/Berlin" }}

      it { should contain_file('/etc/sysconfig/clock').with_content(/^ZONE="Europe\/Berlin"$/) }
      it { should contain_file('/etc/localtime').with_source('file:///usr/share/zoneinfo/Europe/Berlin') }
    end
  end

  context 'when RHEL 7' do
    let(:facts) {{ :osfamily => "RedHat", :operatingsystemmajrelease => '7' }}
    it { should_not contain_file('/etc/sysconfig/clock').with_ensure('file') }
    it { should contain_exec('update_timezone').with_command('timedatectl set-timezone  Etc/UTC') }

    context 'when timezone => "Europe/Berlin"' do
      let(:params) {{ :timezone => "Europe/Berlin" }}

      it { should contain_exec('update_timezone').with_command('timedatectl set-timezone  Europe/Berlin') }
    end
  end
end
{'fraction_non_alphanumeric': 0.16786127167630058, 'fraction_numerical': 0.0016184971098265897, 'mean_word_length': 3.432377049180328, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, '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': '1965716', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1356, 'n_words': 261}