|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe('icinga2::feature::syslog', :type => :class) do |
| 4 | + let(:pre_condition) { [ |
| 5 | + "class { 'icinga2': features => [], }" |
| 6 | + ] } |
| 7 | + |
| 8 | + on_supported_os.each do |os, facts| |
| 9 | + let :facts do |
| 10 | + facts |
| 11 | + end |
| 12 | + |
| 13 | + |
| 14 | + context "#{os} with ensure => present" do |
| 15 | + let(:params) { {:ensure => 'present'} } |
| 16 | + |
| 17 | + it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'present'}) } |
| 18 | + |
| 19 | + it { is_expected.to contain_icinga2__object('icinga2::object::SyslogLogger::syslog') |
| 20 | + .with({ 'target' => '/etc/icinga2/features-available/syslog.conf' }) |
| 21 | + .that_notifies('Class[icinga2::service]') } |
| 22 | + end |
| 23 | + |
| 24 | + |
| 25 | + context "#{os} with ensure => absent" do |
| 26 | + let(:params) { {:ensure => 'absent'} } |
| 27 | + |
| 28 | + it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'absent'}) } |
| 29 | + |
| 30 | + it { is_expected.to contain_icinga2__object('icinga2::object::SyslogLogger::syslog') |
| 31 | + .with({ 'target' => '/etc/icinga2/features-available/syslog.conf' }) } |
| 32 | + end |
| 33 | + |
| 34 | + |
| 35 | + context "#{os} with all defaults" do |
| 36 | + it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'present'}) } |
| 37 | + |
| 38 | + it { is_expected.to contain_concat__fragment('icinga2::object::SyslogLogger::syslog') |
| 39 | + .with({ 'target' => '/etc/icinga2/features-available/syslog.conf' }) |
| 40 | + .with_content(/severity = "warning"/) } |
| 41 | + end |
| 42 | + |
| 43 | + |
| 44 | + context "#{os} with severity => notice" do |
| 45 | + let(:params) { {:severity => 'notice'} } |
| 46 | + |
| 47 | + it { is_expected.to contain_concat__fragment('icinga2::object::SyslogLogger::syslog') |
| 48 | + .with({ 'target' => '/etc/icinga2/features-available/syslog.conf' }) |
| 49 | + .with_content(/severity = "notice"/) } |
| 50 | + end |
| 51 | + |
| 52 | + |
| 53 | + context "#{os} with severity => foo (not a valid value)" do |
| 54 | + let(:params) { {:severity => 'foo'} } |
| 55 | + |
| 56 | + it { is_expected.to raise_error(Puppet::Error, /"foo" does not match/) } |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + |
| 61 | + context 'Windows 2012 R2 with ensure => present' do |
| 62 | + let(:facts) { { |
| 63 | + :kernel => 'Windows', |
| 64 | + :architecture => 'x86_64', |
| 65 | + :osfamily => 'Windows', |
| 66 | + :operatingsystem => 'Windows', |
| 67 | + :operatingsystemmajrelease => '2012 R2' |
| 68 | + } } |
| 69 | + let(:params) { {:ensure => 'present'} } |
| 70 | + |
| 71 | + it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'present'}) } |
| 72 | + |
| 73 | + it { is_expected.to contain_icinga2__object('icinga2::object::SyslogLogger::syslog') |
| 74 | + .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/syslog.conf' }) |
| 75 | + .that_notifies('Class[icinga2::service]') } |
| 76 | + end |
| 77 | + |
| 78 | + |
| 79 | + context 'Windows 2012 R2 with ensure => absent' do |
| 80 | + let(:facts) { { |
| 81 | + :kernel => 'Windows', |
| 82 | + :architecture => 'x86_64', |
| 83 | + :osfamily => 'Windows', |
| 84 | + :operatingsystem => 'Windows', |
| 85 | + :operatingsystemmajrelease => '2012 R2' |
| 86 | + } } |
| 87 | + let(:params) { {:ensure => 'absent'} } |
| 88 | + |
| 89 | + it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'absent'}) } |
| 90 | + |
| 91 | + it { is_expected.to contain_icinga2__object('icinga2::object::SyslogLogger::syslog') |
| 92 | + .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/syslog.conf' }) } |
| 93 | + end |
| 94 | + |
| 95 | + |
| 96 | + context "Windows 2012 R2 with all defaults" do |
| 97 | + let(:facts) { { |
| 98 | + :kernel => 'Windows', |
| 99 | + :architecture => 'x86_64', |
| 100 | + :osfamily => 'Windows', |
| 101 | + :operatingsystem => 'Windows', |
| 102 | + :operatingsystemmajrelease => '2012 R2' |
| 103 | + } } |
| 104 | + it { is_expected.to contain_icinga2__feature('syslog').with({'ensure' => 'present'}) } |
| 105 | + |
| 106 | + it { is_expected.to contain_concat__fragment('icinga2::object::SyslogLogger::syslog') |
| 107 | + .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/syslog.conf' }) |
| 108 | + .with_content(/severity = "warning"/) } |
| 109 | + end |
| 110 | + |
| 111 | + |
| 112 | + context 'Windows 2012 R2 with severity => notice' do |
| 113 | + let(:facts) { { |
| 114 | + :kernel => 'Windows', |
| 115 | + :architecture => 'x86_64', |
| 116 | + :osfamily => 'Windows', |
| 117 | + :operatingsystem => 'Windows', |
| 118 | + :operatingsystemmajrelease => '2012 R2' |
| 119 | + } } |
| 120 | + let(:params) { {:severity => 'notice'} } |
| 121 | + |
| 122 | + it { is_expected.to contain_concat__fragment('icinga2::object::SyslogLogger::syslog') |
| 123 | + .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/syslog.conf' }) |
| 124 | + .with_content(/severity = "notice"/) } |
| 125 | + end |
| 126 | + |
| 127 | + |
| 128 | + context 'Windows 2012 R2 with severity => foo (not a valid value)' do |
| 129 | + let(:facts) { { |
| 130 | + :kernel => 'Windows', |
| 131 | + :architecture => 'x86_64', |
| 132 | + :osfamily => 'Windows', |
| 133 | + :operatingsystem => 'Windows', |
| 134 | + :operatingsystemmajrelease => '2012 R2' |
| 135 | + } } |
| 136 | + let(:params) { {:severity => 'foo'} } |
| 137 | + |
| 138 | + it { is_expected.to raise_error(Puppet::Error, /"foo" does not match/) } |
| 139 | + end |
| 140 | +end |
0 commit comments