diff --git a/spec/classes/munin_master_spec.rb b/spec/classes/munin_master_spec.rb index 520eca5..a56cb64 100644 --- a/spec/classes/munin_master_spec.rb +++ b/spec/classes/munin_master_spec.rb @@ -1,159 +1,167 @@ require 'spec_helper' _conf_dir = {} _conf_dir.default = '/etc/munin' _conf_dir['Solaris'] = '/opt/local/etc/munin' _conf_dir['FreeBSD'] = '/usr/local/etc/munin' describe 'munin::master' do on_supported_os.each do |os, facts| + + # Avoid testing on distributions similar to RedHat and Debian + next if /^(ubuntu|centos|scientific|oraclelinux)-/.match(os) + + # No need to test all os versions as long as os version is not + # used in the params class + next if /^(debian-[67]|redhat-[56]|freebsd-9)-/.match(os) + context "on #{os}" do let(:facts) do facts end conf_dir = _conf_dir[facts[:osfamily]] it { should compile.with_all_deps } it { should contain_package('munin') } context 'with default params' do it do should contain_file("#{conf_dir}/munin.conf") .with_content(/graph_strategy\s+cgi/) .with_content(/html_strategy\s+cgi/) end it do should contain_file("#{conf_dir}/munin-conf.d") .with_ensure('directory') end end context 'with html_strategy => cron' do let (:params) { { :html_strategy => 'cron' } } it { should compile.with_all_deps } it { should contain_file("#{conf_dir}/munin.conf") .with_content(/html_strategy\s+cron/) } end context 'with graph_strategy => cron' do let (:params) { { :graph_strategy => 'cron' } } it { should compile.with_all_deps } it { should contain_file("#{conf_dir}/munin.conf") .with_content(/graph_strategy\s+cron/) } end context 'with dbdir => /var/lib/munin' do let (:params) { { :dbdir => '/var/lib/munin' } } it { should compile.with_all_deps } it { should contain_file("#{conf_dir}/munin.conf") .with_content(/dbdir\s+\/var\/lib\/munin/) } end context 'with htmldir => /var/www/munin' do let (:params) { { :htmldir => '/var/www/munin' } } it { should compile.with_all_deps } it { should contain_file("#{conf_dir}/munin.conf") .with_content(/htmldir\s+\/var\/www\/munin/) } end context 'with logdir => /var/log/munin' do let (:params) { { :dbdir => '/var/log/munin' } } it { should compile.with_all_deps } it { should contain_file("#{conf_dir}/munin.conf") .with_content(/dbdir\s+\/var\/log\/munin/) } end context 'with rundir => /var/run/munin' do let (:params) { { :dbdir => '/var/run/munin' } } it { should compile.with_all_deps } it { should contain_file("#{conf_dir}/munin.conf") .with_content(/dbdir\s+\/var\/run\/munin/) } end context 'with tls => enabled' do let(:params) { { :tls => 'enabled', :tls_certificate => '/path/to/certificate.pem', :tls_private_key => '/path/to/key.pem', :tls_verify_certificate => 'yes', } } it { should compile.with_all_deps } it { should contain_file("#{conf_dir}/munin.conf") .with_content(/tls = enabled/) .with_content(/tls_certificate = \/path\/to\/certificate\.pem/) .with_content(/tls_private_key = \/path\/to\/key\.pem/) .with_content(/tls_verify_certificate = yes/) } end context 'with extra_config' do token = '1b7febce-bb2d-4c18-b889-84c73538a900' let(:params) do { :extra_config => [ token ] } end it { should compile.with_all_deps } it do should contain_file("#{conf_dir}/munin.conf") .with_content(/#{token}/) end end context 'with extra_config set to a string' do token = '1b7febce-bb2d-4c18-b889-84c73538a900' let(:params) do { :extra_config => token } end it { should raise_error(Puppet::Error, /is not an Array/) } end ['test.example.com', 'invalid/hostname.example.com'].each do |param| context "with host_name => #{param}" do let(:params) do { :host_name => param } end if param =~ /invalid/ it { should raise_error(Puppet::Error, /valid domain name/) } else it { should compile.with_all_deps } end end end %w( enabled disabled mine unclaimed invalid ).each do |param| context "with collect_nodes => #{param}" do let(:params) do { :collect_nodes => param } end if param == 'invalid' it { should raise_error(Puppet::Error, /validate_re/) } else it { should compile.with_all_deps } end end end end # on os end end diff --git a/spec/classes/munin_node_spec.rb b/spec/classes/munin_node_spec.rb index 9e1048b..667feb2 100644 --- a/spec/classes/munin_node_spec.rb +++ b/spec/classes/munin_node_spec.rb @@ -1,189 +1,197 @@ require 'spec_helper' _conf_dir = {} _conf_dir.default = '/etc/munin' _conf_dir['DragonFly'] = '/usr/local/etc/munin' _conf_dir['FreeBSD'] = '/usr/local/etc/munin' _conf_dir['Solaris'] = '/opt/local/etc/munin' describe 'munin::node' do on_supported_os.each do |os, facts| + + # Avoid testing on distributions similar to RedHat and Debian + next if /^(ubuntu|centos|scientific|oraclelinux)-/.match(os) + + # No need to test all os versions as long as os version is not + # used in the params class + next if /^(debian-[67]|redhat-[56]|freebsd-9)-/.match(os) + context "on #{os}" do let(:facts) do facts end it { should compile.with_all_deps } it { should contain_package('munin-node') } munin_confdir = _conf_dir[facts[:osfamily]] munin_node_conf = "#{munin_confdir}/munin-node.conf" munin_plugin_dir = "#{munin_confdir}/plugins" munin_plugin_conf_dir = "#{munin_confdir}/plugin-conf.d" case facts[:osfamily] when 'Solaris' munin_node_service = 'smf:/munin-node' else munin_node_service = 'munin-node' end case facts[:osfamily] when 'Solaris' log_dir = '/var/opt/log/munin' when 'RedHat' log_dir = '/var/log/munin-node' else log_dir = '/var/log/munin' end it { should contain_service(munin_node_service) } it { should contain_file(munin_node_conf) } context 'with no parameters' do it { should compile.with_all_deps } it do should contain_service(munin_node_service) .without_ensure() end it do should contain_file(munin_node_conf) .with_content(/host_name\s+foo.example.com/) .with_content(/log_file\s+#{log_dir}\/munin-node.log/) end end context 'with parameter allow' do let(:params) do { allow: ['2001:db8:1::', '2001:db8:2::/64', '192.0.2.129', '192.0.2.0/25', '192\.0\.2'] } end it { should compile.with_all_deps } it do should contain_file(munin_node_conf) .with_content(/^cidr_allow 192.0.2.0\/25$/) .with_content(/^cidr_allow 2001:db8:2::\/64$/) .with_content(/^allow \^192\\.0\\.2\\.129\$$/) .with_content(/^allow 192\\.0\\.2$/) .with_content(/^allow \^2001:db8:1::\$$/) end end context 'with parameter host_name' do let(:params) do { host_name: 'something.example.com' } end it { should compile.with_all_deps } it do should contain_file(munin_node_conf) .with_content(/host_name\s+something.example.com/) end end context 'with parameter service_ensure' do let(:params) do { service_ensure: 'running' } end it { should compile.with_all_deps } it do should contain_service('munin-node') .with_ensure('running') end end context 'logging to syslog' do context 'defaults' do let(:params) do { log_destination: 'syslog' } end it{ should compile.with_all_deps } it do should contain_file(munin_node_conf) .with_content(/log_file\s+Sys::Syslog/) end end context 'with syslog options' do let(:params) do { log_destination: 'syslog', syslog_ident: 'munin-granbusk', syslog_facility: 'local1', } end it{ should compile.with_all_deps } it do should contain_file(munin_node_conf) .with_content(/log_file\s+Sys::Syslog/) .with_content(/syslog_ident\s+"munin-granbusk"/) .with_content(/syslog_facility\s+local1/) end end context 'with syslog_facility set to wrong value ' do let(:params) do { log_destination: 'syslog', syslog_facility: 'wrong', } end it { expect { should compile.with_all_deps }.to raise_error(/validate_re/) } end end context 'purge_configs' do context 'set' do let(:params) { { purge_configs: true } } it { should compile.with_all_deps } it do should contain_file(munin_plugin_dir) .with_ensure('directory') .with_recurse(true) .with_purge(true) end it do should contain_file(munin_plugin_conf_dir) .with_ensure('directory') .with_recurse(true) .with_purge(true) end end context 'unset' do it { should compile.with_all_deps } it { should_not contain_file(munin_plugin_dir) } it { should_not contain_file(munin_plugin_conf_dir) } end end context 'timeout' do context 'set' do let(:params) { { timeout: 123 } } it { should compile.with_all_deps } it do should contain_file(munin_node_conf) .with_content(/^timeout 123/) end end context 'unset' do it { should compile.with_all_deps } it do should contain_file(munin_node_conf) .without_content(/^timeout/) end end end end end context 'unsupported' do include_context :unsupported it { expect { should contain_class('munin::node') }.to raise_error(Puppet::Error, /Unsupported osfamily/) } end end diff --git a/spec/defines/munin_plugin_spec.rb b/spec/defines/munin_plugin_spec.rb index a9ec3e1..dbf36da 100644 --- a/spec/defines/munin_plugin_spec.rb +++ b/spec/defines/munin_plugin_spec.rb @@ -1,135 +1,143 @@ require 'spec_helper' _conf_dir = {} _conf_dir.default = '/etc/munin' _conf_dir['Solaris'] = '/opt/local/etc/munin' _conf_dir['FreeBSD'] = '/usr/local/etc/munin' _share_dir = {} _share_dir.default = '/usr/share/munin' _share_dir['Solaris'] = '/opt/local/share/munin' _share_dir['FreeBSD'] = '/usr/local/share/munin' describe 'munin::plugin', :type => 'define' do let(:title) { 'testplugin' } on_supported_os.each do |os, facts| + + # Avoid testing on distributions similar to RedHat and Debian + next if /^(ubuntu|centos|scientific|oraclelinux)-/.match(os) + + # No need to test all os versions as long as os version is not + # used in the params class + next if /^(debian-[67]|redhat-[56]|freebsd-9)-/.match(os) + context "on #{os}" do let(:facts) do facts end conf_dir = _conf_dir[facts[:osfamily]] plugin_share_dir = "#{_share_dir[facts[:osfamily]]}/plugins" context 'with no parameters' do it do expect { should contain_file("#{conf_dir}/plugins/testplugin") } .to raise_error("expected that the catalogue would contain File[#{conf_dir}/plugins/testplugin]") end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('absent') end end context 'with ensure=link parameter' do let(:params) { { :ensure => 'link' } } it do should contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('link') .with_target("#{plugin_share_dir}/testplugin") end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('absent') end end context 'with ensure=link and target parameters' do let (:title) { 'test_foo' } let (:params) do { :ensure => 'link', :target => 'test_' } end it do should contain_file("#{conf_dir}/plugins/test_foo") .with_ensure('link') .with_target("#{plugin_share_dir}/test_") end it do should contain_file("#{conf_dir}/plugin-conf.d/test_foo.conf") .with_ensure('absent') end end context 'with ensure=present and source parameters' do let(:params) do { :ensure => 'present', :source => 'puppet:///modules/munin/plugins/testplugin' } end it do should contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('present') .with_source('puppet:///modules/munin/plugins/testplugin') end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('absent') end end context 'with ensure=present, source and config parameters' do let(:params) do { :ensure => 'present', :source => 'puppet:///modules/munin/plugins/testplugin', :config => [ 'something wonderful' ], } end it do should contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('present') .with_source('puppet:///modules/munin/plugins/testplugin') end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('present') .with_content(/something wonderful/) end end context 'only configuration' do let (:params) do { :config => ['env.rootdn cn=admin,dc=example,dc=org'], :config_label => 'slapd_*', } end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_ensure('present') .with_content(/env.rootdn/) end it do expect { should contain_file("#{conf_dir}/plugins/testplugin") } .to raise_error("expected that the catalogue would contain File[#{conf_dir}/plugins/testplugin]") end end context 'with absolute target' do let(:params) do { ensure: 'link', target: '/full/path/to/testplugin' } end it do should contain_file("#{conf_dir}/plugins/testplugin") .with_ensure('link') .with_target('/full/path/to/testplugin') end end end end end diff --git a/spec/defines/regression_13_munin_plugin_config_name_spec.rb b/spec/defines/regression_13_munin_plugin_config_name_spec.rb index 8bc6dd3..862327c 100644 --- a/spec/defines/regression_13_munin_plugin_config_name_spec.rb +++ b/spec/defines/regression_13_munin_plugin_config_name_spec.rb @@ -1,44 +1,52 @@ require 'spec_helper' _conf_dir = {} _conf_dir.default = '/etc/munin' _conf_dir['Solaris'] = '/opt/local/etc/munin' _conf_dir['FreeBSD'] = '/usr/local/etc/munin' describe 'munin::plugin' do let(:title) { 'testplugin' } on_supported_os.each do |os, facts| + + # Avoid testing on distributions similar to RedHat and Debian + next if /^(ubuntu|centos|scientific|oraclelinux)-/.match(os) + + # No need to test all os versions as long as os version is not + # used in the params class + next if /^(debian-[67]|redhat-[56]|freebsd-9)-/.match(os) + context "on #{os}" do let(:facts) do facts end conf_dir = _conf_dir[facts[:osfamily]] context 'with config_label unset, label should be set to title' do let(:params) do { config: ['env.foo bar'] } end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_content(/^\[testplugin\]$/) end end context 'with config_label set, label should be set to config_label' do let(:params) do { config: ['env.foo bar'], config_label: 'foo_' } end it do should contain_file("#{conf_dir}/plugin-conf.d/testplugin.conf") .with_content(/^\[foo_\]$/) end end end # on os end end