Commit e81564f0 authored by Mickaël Canévet's avatar Mickaël Canévet
Browse files

Manage unit tests with rspec-puppet-facts

parent 745509f3
...@@ -48,7 +48,8 @@ ...@@ -48,7 +48,8 @@
"operatingsystem": "RedHat", "operatingsystem": "RedHat",
"operatingsystemrelease": [ "operatingsystemrelease": [
"5", "5",
"6" "6",
"7"
] ]
} }
], ],
......
require 'spec_helper' require 'spec_helper'
describe 'postfix::augeas' do describe 'postfix::augeas' do
let (:facts) { {
:augeasversion => '1.2.0',
:lsbdistcodename => 'wheezy',
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:rubyversion => '1.9.3',
:path => '/foo/bar',
} }
let :pre_condition do let :pre_condition do
"include ::augeas" "include ::augeas"
end end
it { is_expected.to contain_augeas__lens('postfix_transport').with( on_supported_os.each do |os, facts|
:ensure => 'present', context "on #{os}" do
:lens_source => 'puppet:///modules/postfix/lenses/postfix_transport.aug', let(:facts) do
:test_source => 'puppet:///modules/postfix/lenses/test_postfix_transport.aug', facts.merge({
:stock_since => '1.0.0' :augeasversion => '1.2.0',
) } })
it { is_expected.to contain_augeas__lens('postfix_virtual').with( end
:ensure => 'present',
:lens_source => 'puppet:///modules/postfix/lenses/postfix_virtual.aug', it { is_expected.to compile.with_all_deps }
:test_source => 'puppet:///modules/postfix/lenses/test_postfix_virtual.aug',
:stock_since => '1.0.0' it { is_expected.to contain_augeas__lens('postfix_transport').with({
) } :ensure => 'present',
:lens_source => 'puppet:///modules/postfix/lenses/postfix_transport.aug',
:test_source => 'puppet:///modules/postfix/lenses/test_postfix_transport.aug',
:stock_since => '1.0.0',
} ) }
it { is_expected.to contain_augeas__lens('postfix_virtual').with({
:ensure => 'present',
:lens_source => 'puppet:///modules/postfix/lenses/postfix_virtual.aug',
:test_source => 'puppet:///modules/postfix/lenses/test_postfix_virtual.aug',
:stock_since => '1.0.0',
}) }
end
end
end end
require 'spec_helper' require 'spec_helper'
describe 'postfix::mailman' do describe 'postfix::mailman' do
let :pre_condition do
"include ::postfix"
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
it { is_expected.to compile.with_all_deps }
end
end
end end
require 'spec_helper' require 'spec_helper'
describe 'postfix::mta' do describe 'postfix::mta' do
let (:facts) { {
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:path => '/foo/bar',
} }
let :pre_condition do let :pre_condition do
"class { 'postfix': "class { 'postfix':
mydestination => 'bar', mydestination => 'bar',
...@@ -14,7 +9,16 @@ describe 'postfix::mta' do ...@@ -14,7 +9,16 @@ describe 'postfix::mta' do
}" }"
end end
it { is_expected.to contain_postfix__config('mydestination').with_value('bar') } on_supported_os.each do |os, facts|
it { is_expected.to contain_postfix__config('mynetworks').with_value('127.0.0.1/8, [::1]/128 ![::2]/128') } context "on #{os}" do
it { is_expected.to contain_postfix__config('relayhost').with_value('foo') } let(:facts) do
facts
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_postfix__config('mydestination').with_value('bar') }
it { is_expected.to contain_postfix__config('mynetworks').with_value('127.0.0.1/8, [::1]/128 ![::2]/128') }
it { is_expected.to contain_postfix__config('relayhost').with_value('foo') }
end
end
end end
require 'spec_helper' require 'spec_helper'
describe 'postfix::satellite' do describe 'postfix::satellite' do
let (:node) { 'foo.example.com' }
let (:facts) { {
:augeasversion => '1.2.0',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:rubyversion => '1.9.3',
:path => '/foo/bar',
} }
let :pre_condition do let :pre_condition do
" class { 'augeas': } " class { 'augeas': }
class { 'postfix': class { 'postfix':
...@@ -17,9 +9,21 @@ describe 'postfix::satellite' do ...@@ -17,9 +9,21 @@ describe 'postfix::satellite' do
mynetworks => 'baz', mynetworks => 'baz',
}" }"
end end
it { is_expected.to contain_class('postfix::mta') }
it { is_expected.to contain_postfix__virtual('@foo.example.com').with( on_supported_os.each do |os, facts|
:ensure => 'present', context "on #{os}" do
:destination => 'root' let(:facts) do
) } facts.merge({
:augeasversion => '1.2.0',
})
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('postfix::mta') }
it { is_expected.to contain_postfix__virtual('@foo.example.com').with(
:ensure => 'present',
:destination => 'root'
) }
end
end
end end
This diff is collapsed.
...@@ -2,93 +2,98 @@ require 'spec_helper' ...@@ -2,93 +2,98 @@ require 'spec_helper'
describe 'postfix::config' do describe 'postfix::config' do
let (:title) { 'foo' } let (:title) { 'foo' }
let (:facts) { {
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
} }
let :pre_condition do let :pre_condition do
"class { 'postfix': }" "class { 'postfix': }"
end end
context 'when not passing value' do on_supported_os.each do |os, facts|
it 'should fail' do context "on #{os}" do
expect { let(:facts) do
is_expected.to contain_augeas("set postfix 'foo'") facts
}.to raise_error(Puppet::Error, /value can not be empty/) end
end
end
context 'when passing wrong type for value' do context 'when not passing value' do
let (:params) { { it 'should fail' do
:value => ['bar'], expect {
} } is_expected.to contain_augeas("set postfix 'foo'")
it 'should fail' do }.to raise_error(Puppet::Error, /value can not be empty/)
expect { end
is_expected.to contain_augeas("set postfix 'foo'") end
}.to raise_error(Puppet::Error, /\["bar"\] is not a string/)
end
end
context 'when passing wrong type for ensure' do context 'when passing wrong type for value' do
let (:params) { { let (:params) { {
:value => 'bar', :value => ['bar'],
:ensure => ['present'], } }
} } it 'should fail' do
it 'should fail' do expect {
expect { is_expected.to contain_augeas("set postfix 'foo'")
is_expected.to contain_augeas("set postfix 'foo'") }.to raise_error(Puppet::Error, /\["bar"\] is not a string/)
}.to raise_error(Puppet::Error, /\["present"\] is not a string/) end
end end
end
context 'when passing wrong value for ensure' do context 'when passing wrong type for ensure' do
let (:params) { { let (:params) { {
:value => 'bar', :value => 'bar',
:ensure => 'running', :ensure => ['present'],
} } } }
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_augeas("set postfix 'foo'") is_expected.to contain_augeas("set postfix 'foo'")
}.to raise_error(Puppet::Error, /must be either 'present', 'absent' or 'blank'/) }.to raise_error(Puppet::Error, /\["present"\] is not a string/)
end end
end end
context 'when ensuring presence' do context 'when passing wrong value for ensure' do
let (:params) { { let (:params) { {
:value => 'bar', :value => 'bar',
:ensure => 'present', :ensure => 'running',
} } } }
it 'should fail' do
expect {
is_expected.to contain_augeas("set postfix 'foo'")
}.to raise_error(Puppet::Error, /must be either 'present', 'absent' or 'blank'/)
end
end
it { is_expected.to contain_augeas("manage postfix 'foo'").with( context 'when ensuring presence' do
:incl => '/etc/postfix/main.cf', let (:params) { {
:lens => 'Postfix_Main.lns', :value => 'bar',
:changes => "set foo 'bar'" :ensure => 'present',
) } } }
end
context 'when ensuring absence' do it { is_expected.to contain_augeas("manage postfix 'foo'").with(
let (:params) { { :incl => '/etc/postfix/main.cf',
:value => 'bar', :lens => 'Postfix_Main.lns',
:ensure => 'absent', :changes => "set foo 'bar'"
} } ) }
end
it { is_expected.to contain_augeas("manage postfix 'foo'").with( context 'when ensuring absence' do
:incl => '/etc/postfix/main.cf', let (:params) { {
:lens => 'Postfix_Main.lns', :value => 'bar',
:changes => "rm foo" :ensure => 'absent',
) } } }
end
it { is_expected.to contain_augeas("manage postfix 'foo'").with(
:incl => '/etc/postfix/main.cf',
:lens => 'Postfix_Main.lns',
:changes => "rm foo"
) }
end
context 'when ensuring blank' do context 'when ensuring blank' do
let (:params) { { let (:params) { {
:value => 'bar', :value => 'bar',
:ensure => 'blank', :ensure => 'blank',
} } } }
it { is_expected.to contain_augeas("manage postfix 'foo'").with( it { is_expected.to contain_augeas("manage postfix 'foo'").with(
:incl => '/etc/postfix/main.cf', :incl => '/etc/postfix/main.cf',
:lens => 'Postfix_Main.lns', :lens => 'Postfix_Main.lns',
:changes => "clear foo" :changes => "clear foo"
) } ) }
end
end
end end
end end
...@@ -2,103 +2,107 @@ require 'spec_helper' ...@@ -2,103 +2,107 @@ require 'spec_helper'
describe 'postfix::hash' do describe 'postfix::hash' do
let (:title) { '/tmp/foo' } let (:title) { '/tmp/foo' }
let (:facts) { {
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:path => '/foo/bar',
} }
let :pre_condition do let :pre_condition do
"class { '::postfix': }" "class { '::postfix': }"
end end
context 'when passing wrong type for ensure' do on_supported_os.each do |os, facts|
let (:params) { { context "on #{os}" do
:ensure => ['present'], let(:facts) do
} } facts
it 'should fail' do end
expect {
is_expected.to contain_file('/tmp/foo')
}.to raise_error(Puppet::Error, /\["present"\] is not a string/)
end
end
context 'when passing wrong value for ensure' do context 'when passing wrong type for ensure' do
let (:params) { { let (:params) { {
:ensure => 'running', :ensure => ['present'],
} } } }
it 'should fail' do it 'should fail' do
expect { expect {
is_expected.to contain_file('/tmp/foo') is_expected.to contain_file('/tmp/foo')
}.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/) }.to raise_error(Puppet::Error, /\["present"\] is not a string/)
end end
end end
context 'when passing wrong value for title' do context 'when passing wrong value for ensure' do
let (:title) { 'foo' } let (:params) { {
it 'should fail' do :ensure => 'running',
expect { } }
is_expected.to contain_file('/tmp/foo') it 'should fail' do
}.to raise_error(Puppet::Error, /"foo" is not an absolute path/) expect {
end is_expected.to contain_file('/tmp/foo')
end }.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/)
end
end
context 'when passing both source and content' do context 'when passing wrong value for title' do
let (:params) { { let (:title) { 'foo' }
:source => '/tmp/bar', it 'should fail' do
:content => 'bar', expect {
} } is_expected.to contain_file('/tmp/foo')
}.to raise_error(Puppet::Error, /"foo" is not an absolute path/)
end
end
it 'should fail' do context 'when passing both source and content' do
expect { let (:params) { {
is_expected.to contain_file('/tmp/foo') :source => '/tmp/bar',
}.to raise_error(Puppet::Error, /You must provide either 'source' or 'content'/) :content => 'bar',
end } }
end
context 'when passing source' do it 'should fail' do
let (:params) { { expect {
:source => '/tmp/bar', is_expected.to contain_file('/tmp/foo')
} } }.to raise_error(Puppet::Error, /You must provide either 'source' or 'content'/)
end
end
it { is_expected.to contain_file('/tmp/foo').with( context 'when passing source' do
:ensure => 'present', let (:params) { {
:source => '/tmp/bar' :source => '/tmp/bar',
).without(:content) } }
}
it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
it { is_expected.to contain_exec('generate /tmp/foo.db') }
end
context 'when passing content' do it { is_expected.to contain_file('/tmp/foo').with(
let (:params) { { :ensure => 'present',
:content => 'bar', :source => '/tmp/bar'
} } ).without(:content)
}
it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
it { is_expected.to contain_exec('generate /tmp/foo.db') }
end
it { is_expected.to contain_file('/tmp/foo').with( context 'when passing content' do
:ensure => 'present', let (:params) { {
:content => 'bar' :content => 'bar',
).without(:source) } }
}
it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
it { is_expected.to contain_exec('generate /tmp/foo.db') }
end
context 'when not passing source or content' do it { is_expected.to contain_file('/tmp/foo').with(
it { is_expected.to contain_file('/tmp/foo').with( :ensure => 'present',
:ensure => 'present' :content => 'bar'
).without(:source).without(:content) ).without(:source)
} }
it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') } it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
it { is_expected.to contain_exec('generate /tmp/foo.db') } it { is_expected.to contain_exec('generate /tmp/foo.db') }
end end
context 'when not passing source or content' do
it { is_expected.to contain_file('/tmp/foo').with(
:ensure => 'present'
).without(:source).without(:content)
}
it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
it { is_expected.to contain_exec('generate /tmp/foo.db') }
end
context 'when ensuring absence' do context 'when ensuring absence' do
let (:params) { { let (:params) { {
:ensure => 'absent', :ensure => 'absent',
} } } }
it { is_expected.to contain_file('/tmp/foo').with_ensure('absent') } it { is_expected.to contain_file('/tmp/foo').with_ensure('absent') }
it { is_expected.to contain_file('/tmp/foo.db').with_ensure('absent') } it { is_expected.to contain_file('/tmp/foo.db').with_ensure('absent') }
it { is_expected.to contain_exec('generate /tmp/foo.db') } it { is_expected.to contain_exec('generate /tmp/foo.db') }
end
end
end end
end end
...@@ -2,139 +2,144 @@ require 'spec_helper' ...@@ -2,139 +2,144 @@ require 'spec_helper'
describe 'postfix::transport' do describe 'postfix::transport' do
let (:title) { 'foo' } let (:title) { 'foo' }
let (:facts) { {
:augeasversion => '1.2.0',
:osfamily => 'Debian',
:rubyversion => '1.9.3',
:path => '/foo/bar',
} }
let :pre_condition do
"class { 'augeas': }"
end
context 'when sending wrong type for destination' do
let (:params) { {
:destination => ['bar'],
} }
it 'should fail' do
expect {
is_expected.to contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /\["bar"\] is not a string/)
end
end
context 'when sending wrong type for nexthop' do
let (:params) { {
:destination => 'bar',
:nexthop => ['baz'],
} }
it 'should fail' do
expect {
is_expected.to contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /\["baz"\] is not a string/)
end
end
context 'when sending wrong type for file' do
let (:params) { {
:destination => 'bar',
:file => ['baz'],
} }
it 'should fail' do
expect {
is_expected.to contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /\["baz"\] is not a string/)
end
end
context 'when sending wrong value for file' do