<commit_before>require 'spec_helper'
require 'plattforms'

describe('icinga2::feature::command', :type => :class) do
  # reference plattform for Linux
  let(:facts) { IcingaPuppet.plattforms['RedHat 7'] }
  let(:pre_condition) { [
    "class { 'icinga2': features => [], }"
  ] }

  context 'with ensure => present on all supported plattforms' do
    let(:params) { {:ensure => 'present'} }
    it do
      should contain_icinga2__feature('command').with({
        'ensure' => 'present',
      })
    end
  end

  context 'with enable => absent on  on all supported plattforms' do
    let(:params) { {:ensure => 'absent'} }
    it do
      should contain_icinga2__feature('command').with({
        'ensure' => 'absent',
      })
    end
  end

  context 'with command_path => /foo/bar on Linux' do
    let(:params) { {:command_path => '/foo/bar'} }
    it do
      should contain_file('/etc/icinga2/features-available/command.conf')
        .with_content(/command_path = "\/foo\/bar"/)
    end
  end

  context 'with command_path => C:/foo/bar on Windows' do
    let(:facts) { IcingaPuppet.plattforms['Windows 2012 R2'] }
    let(:params) { {:command_path => 'C:/foo/bar'} }
    it do
      should contain_file('C:/ProgramData/icinga2/etc/icinga2/features-available/command.conf')
        .with_content(/command_path = "C:\/foo\/bar"/)
    end
  end

  context 'with command_path => foo/bar (not a valid value)' do
    let(:params) { {:command_path => 'foo/bar'} }
    it do
      expect {
        should contain_icinga2__feature('command')
      }.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/)
    end
  end

end<commit_msg>rework unit tests<commit_after>require 'spec_helper'

describe('icinga2::feature::command', :type => :class) do
  let(:pre_condition) { [
    "class { 'icinga2': features => [], }"
  ] }

  on_supported_os.each do |os, facts|
    let :facts do
      facts
    end

    context "#{os} with ensure => present" do
      let(:params) { {:ensure => 'present'} }

      it { is_expected.to contain_icinga2__feature('command').with({'ensure' => 'present'}) }
    end


    context "#{os} with ensure => absent" do
      let(:params) { {:ensure => 'absent'} }

      it { is_expected.to contain_icinga2__feature('command').with({'ensure' => 'absent'}) }
    end


    context "#{os} with command_path => /foo/bar" do
      let(:params) { {:command_path => '/foo/bar'} }

      it {
        is_expected.to contain_file('/etc/icinga2/features-available/command.conf')
          .with_content(/command_path = "\/foo\/bar"/)
      }
    end


    context "#{os} with command_path => foo/bar (not an absolute path)" do
      let(:params) { {:command_path => 'foo/bar'} }

      it do
        expect {
          is_expected.to contain_icinga2__feature('command')
        }.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/)
      end
    end
  end


  context 'Windows 2012 R2 with ensure => present' do
    let(:facts) { {
      :kernel => 'Windows',
      :architecture => 'x86_64',
      :osfamily => 'Windows',
      :operatingsystem => 'Windows',
      :operatingsystemmajrelease => '2012 R2'
    } }
    let(:params) { {:ensure => 'present'} }

    it { is_expected.to contain_icinga2__feature('command').with({'ensure' => 'present'}) }
  end


  context 'Windows 2012 R2 with ensure => absent' do
    let(:facts) { {
      :kernel => 'Windows',
      :architecture => 'x86_64',
      :osfamily => 'Windows',
      :operatingsystem => 'Windows',
      :operatingsystemmajrelease => '2012 R2'
    } }
    let(:params) { {:ensure => 'absent'} }

    it { is_expected.to contain_icinga2__feature('command').with({'ensure' => 'absent'}) }
  end


  context 'Windows 2012 R2 with command_path => c:/foo/bar' do
    let(:facts) { {
      :kernel => 'Windows',
      :architecture => 'x86_64',
      :osfamily => 'Windows',
      :operatingsystem => 'Windows',
      :operatingsystemmajrelease => '2012 R2'
    } }
    let(:params) { {:command_path => 'c:/foo/bar'} }

    it {
      is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/features-available/command.conf')
        .with_content(/command_path = "c:\/foo\/bar"/)
    }
  end


  context 'Windows 2012 R2 with path => foo/bar (not an absolute path)' do
    let(:facts) { {
      :kernel => 'Windows',
      :architecture => 'x86_64',
      :osfamily => 'Windows',
      :operatingsystem => 'Windows',
      :operatingsystemmajrelease => '2012 R2'
    } }
    let(:params) { {:command_path => 'foo/bar'} }

    it do
      expect {
        is_expected.to contain_icinga2__feature('command')
      }.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/)
    end
  end
end
{'fraction_non_alphanumeric': 0.16153028692879914, 'fraction_numerical': 0.017215727948990435, 'mean_word_length': 2.866885784716516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 59, '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': '2334452', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1540, 'n_words': 348}