diff --git a/spec/classes/munin_master_spec.rb b/spec/classes/munin_master_spec.rb index f8728e5..11550d8 100644 --- a/spec/classes/munin_master_spec.rb +++ b/spec/classes/munin_master_spec.rb @@ -1,155 +1,161 @@ require 'spec_helper' describe 'munin::master' do - [ :CentOS, :Debian, :RedHat, :Ubuntu ].each do |sc| - context "Check for supported operatingsystem #{sc}" do - include_context sc - it { should compile } - it { should contain_class('munin::master') } - it { - should contain_package('munin') - should contain_file('/etc/munin/munin.conf') - should contain_file('/etc/munin/munin-conf.d') - .with_ensure('directory') - } - end - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end - [ :SmartOS ].each do |sc| - context "Check for supported operatingsystem #{sc}" do - include_context sc - it { should compile } - it { should contain_class('munin::master') } - it { - should contain_package('munin') - should contain_file('/opt/local/etc/munin/munin.conf') - should contain_file('/opt/local/etc/munin/munin-conf.d') - .with_ensure('directory') - } - end - end + case facts[:osfamily] + when 'Solaris' + conf_dir = '/opt/local/etc/munin' + when 'FreeBSD' + conf_dir = '/usr/local/etc/munin' + else + conf_dir = '/etc/munin' + end - context 'with default params' do - it { - should contain_file('/etc/munin/munin.conf') - .with_content(/graph_strategy\s+cgi/) - .with_content(/html_strategy\s+cgi/) - } - end + it { should compile.with_all_deps } - context 'with html_strategy => cron' do - let (:params) { { :html_strategy => 'cron' } } - it { - should contain_file('/etc/munin/munin.conf') - .with_content(/html_strategy\s+cron/) - } - end + it { should contain_package('munin') } - context 'with graph_strategy => cron' do - let (:params) { { :graph_strategy => 'cron' } } - it { - should contain_file('/etc/munin/munin.conf') - .with_content(/graph_strategy\s+cron/) - } - end + 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 - context 'with dbdir => /var/lib/munin' do - let (:params) { { :dbdir => '/var/lib/munin' } } - it { - should contain_file('/etc/munin/munin.conf') - .with_content(/dbdir\s+\/var\/lib\/munin/) - } - end + it do + should contain_file("#{conf_dir}/munin-conf.d") + .with_ensure('directory') + end + end - context 'with htmldir => /var/www/munin' do - let (:params) { { :htmldir => '/var/www/munin' } } - it { - should contain_file('/etc/munin/munin.conf') - .with_content(/htmldir\s+\/var\/www\/munin/) - } - 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 logdir => /var/log/munin' do - let (:params) { { :dbdir => '/var/log/munin' } } - it { - should contain_file('/etc/munin/munin.conf') - .with_content(/dbdir\s+\/var\/log\/munin/) - } - 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 rudir => /var/run/munin' do - let (:params) { { :dbdir => '/var/run/munin' } } - it { - should contain_file('/etc/munin/munin.conf') - .with_content(/dbdir\s+\/var\/run\/munin/) - } - 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 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 } - it { - should contain_file('/etc/munin/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 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 extra_config' do - token = '1b7febce-bb2d-4c18-b889-84c73538a900' - let(:params) do - { :extra_config => [ token ] } - end - it { should compile } - it do - should contain_file('/etc/munin/munin.conf') - .with_content(/#{token}/) - end - 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 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 + 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 - ['test.example.com', 'invalid/hostname.example.com'].each do |param| - context "with host_name => #{param}" do - let(:params) do - { :host_name => param } + 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 - if param =~ /invalid/ - it { should raise_error(Puppet::Error, /valid domain name/) } - else - it { should compile } + + + 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 - end - end - %w( enabled disabled mine unclaimed invalid ).each do |param| - context "with collect_nodes => #{param}" do - let(:params) do - { :collect_nodes => param } + 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 - if param == 'invalid' - it { should raise_error(Puppet::Error, /validate_re/) } - else - it { should compile } + + ['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 - 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 9e8d0db..2ce33e4 100644 --- a/spec/classes/munin_node_spec.rb +++ b/spec/classes/munin_node_spec.rb @@ -1,79 +1,82 @@ require 'spec_helper' describe 'munin::node' do - [ :CentOS, :Debian, :RedHat, :Ubuntu ].each do |sc| - context "Check for supported operatingsystem #{sc}" do - include_context sc - it { should compile } - it { should contain_class('munin::node') } - it { - should contain_package('munin-node') - should contain_service('munin-node') - should contain_file('/etc/munin/munin-node.conf') - } - end - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + it { should compile.with_all_deps } + + it { should contain_package('munin-node') } + + case facts[:osfamily] + when 'Solaris' + munin_node_service = 'smf:/munin-node' + munin_node_conf = '/opt/local/etc/munin/munin-node.conf' + when 'FreeBSD' + munin_node_conf = '/usr/local/etc/munin/munin-node.conf' + munin_node_service = 'munin-node' + else + munin_node_service = 'munin-node' + munin_node_conf = '/etc/munin/munin-node.conf' + end + + it { should contain_service(munin_node_service) } + it { should contain_file(munin_node_conf) } + + + context 'acl with ipv4 and ipv6 addresses' 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('/etc/munin/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 host_name unset' do + it { should compile.with_all_deps } + it do + should contain_file('/etc/munin/munin-node.conf') + .with_content(/host_name\s+foo.example.com/) + end + end + + context 'with host_name set' do + let(:params) do + { host_name: 'something.example.com' } + end + it { should compile.with_all_deps } + it do + should contain_file('/etc/munin/munin-node.conf') + .with_content(/host_name\s+something.example.com/) + end + end - [ :SmartOS ].each do |sc| - context "Check for supported operatingsystem #{sc}" do - include_context sc - it { should compile } - it { should contain_class('munin::node') } - it { - should contain_package('munin-node') - should contain_service('smf:/munin-node') - should contain_file('/opt/local/etc/munin/munin-node.conf') - } end end context 'unsupported' do include_context :unsupported it { expect { should contain_class('munin::node') }.to raise_error(Puppet::Error, /Unsupported osfamily/) } end - context 'acl with ipv4 and ipv6 addresses' do - include_context :Debian - 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 do - should contain_file('/etc/munin/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 host_name unset' do - include_context :Debian - it do - should contain_file('/etc/munin/munin-node.conf') - .with_content(/host_name\s+testnode.example.com/) - end - end - - context 'with host_name set' do - include_context :Debian - let(:params) do - { host_name: 'something.example.com' } - end - it do - should contain_file('/etc/munin/munin-node.conf') - .with_content(/host_name\s+something.example.com/) - end - end - end diff --git a/spec/defines/munin_plugin_spec.rb b/spec/defines/munin_plugin_spec.rb index 9d9cd6a..d51b99f 100644 --- a/spec/defines/munin_plugin_spec.rb +++ b/spec/defines/munin_plugin_spec.rb @@ -1,108 +1,131 @@ require 'spec_helper' describe 'munin::plugin', :type => 'define' do let(:title) { 'testplugin' } - context 'with no parameters' do - include_context :Debian - it { - expect { - should contain_file('/etc/munin/plugins/testplugin') - }.to raise_error("expected that the catalogue would contain File[/etc/munin/plugins/testplugin]") + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + + case facts[:osfamily] + when 'Solaris' + conf_dir = '/opt/local/etc/munin' + when 'FreeBSD' + conf_dir = '/usr/local/etc/munin' + else + conf_dir = '/etc/munin' + end + + 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('/usr/share/munin/plugins/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('/usr/share/munin/plugins/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 - should contain_file('/etc/munin/plugin-conf.d/testplugin.conf').with_ensure('absent') - } - end - - context 'with ensure=link parameter' do - include_context :Debian - let(:params) { { :ensure => 'link' } } - it { - should contain_file('/etc/munin/plugins/testplugin').with_ensure('link').with_target('/usr/share/munin/plugins/testplugin') - - should contain_file('/etc/munin/plugin-conf.d/testplugin.conf').with_ensure('absent') - } - end - - context 'with ensure=link and target parameters' do - include_context :Debian - let (:title) { 'test_foo' } - let (:params) { - { :ensure => 'link', - :target => 'test_' } - } - - it { - should contain_file('/etc/munin/plugins/test_foo').with_ensure('link').with_target('/usr/share/munin/plugins/test_') - - should contain_file('/etc/munin/plugin-conf.d/test_foo.conf').with_ensure('absent') - } - end - - context 'with ensure=present and source parameters' do - include_context :SmartOS - let(:params) { - { :ensure => 'present', - :source => 'puppet:///modules/munin/plugins/testplugin' } - } - - it { - - expect { - should contain_file('/opt/local/etc/munin/plugins/testplugin').with_ensure('present').with_source('puppet:///modules/munin/plugins/testplugin') - } - should contain_file('/opt/local/etc/munin/plugin-conf.d/testplugin.conf').with_ensure('absent') - } - end - - context 'with ensure=present, source and config parameters' do - include_context :Debian - let(:params) { - { :ensure => 'present', - :source => 'puppet:///modules/munin/plugins/testplugin', - :config => [ 'something wonderful' ], - } - } - - it { - should contain_file('/etc/munin/plugins/testplugin').with_ensure('present').with_source('puppet:///modules/munin/plugins/testplugin') - - should contain_file('/etc/munin/plugin-conf.d/testplugin.conf').with_ensure('present').with_content(/something wonderful/) - } - end - - context 'only configuration' do - include_context :Debian - let (:params) { - { :config => ['env.rootdn cn=admin,dc=example,dc=org'], - :config_label => 'slapd_*', - } - } - - it { - - should contain_file('/etc/munin/plugin-conf.d/testplugin.conf').with_ensure('present').with_content(/env.rootdn/) - - expect { - should contain_file('/etc/munin/plugins/testplugin') - }.to raise_error("expected that the catalogue would contain File[/etc/munin/plugins/testplugin]") - - } - end - - context 'with absolute target' do - include_context :Debian - - let(:params) do - { ensure: 'link', - target: '/full/path/to/testplugin' } - end - - it do - should contain_file('/etc/munin/plugins/testplugin') - .with_ensure('link') - .with_target('/full/path/to/testplugin') 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 f9a01b8..7abd610 100644 --- a/spec/defines/regression_13_munin_plugin_config_name_spec.rb +++ b/spec/defines/regression_13_munin_plugin_config_name_spec.rb @@ -1,30 +1,37 @@ require 'spec_helper' describe 'munin::plugin' do - - include_context :Debian let(:title) { 'testplugin' } - context 'with config_label unset, label should be set to title' do - let(:params) do - { config: ['env.foo bar'] } - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end - it do - should contain_file('/etc/munin/plugin-conf.d/testplugin.conf') - .with_content(/^\[testplugin\]$/) - end - end + 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('/etc/munin/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('/etc/munin/plugin-conf.d/testplugin.conf') + .with_content(/^\[foo_\]$/) + 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('/etc/munin/plugin-conf.d/testplugin.conf') - .with_content(/^\[foo_\]$/) - end + end # on os end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6a26505..11bd0a4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,35 +1,7 @@ require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' include RspecPuppetFacts -RSpec.configure do |c| - c.default_facts = { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :fqdn => 'testnode.example.com', - } -end - - shared_context :unsupported do let(:facts) { { :osfamily => 'Unsupported', } } end - -shared_context :Debian do -end - -shared_context :Ubuntu do - let(:facts) { { :operatingsystem => 'Ubuntu', } } -end - -shared_context :CentOS do - let(:facts) { { :operatingsystem => 'CentOS', :osfamily => 'RedHat', } } -end - -shared_context :RedHat do - let(:facts) { { :osfamily => 'RedHat', } } -end - -shared_context :SmartOS do - let(:facts) { { :operatingsystem => 'SmartOS', :osfamily => 'Solaris', } } -end