Commit 803c088f authored by Raphaël Pinson's avatar Raphaël Pinson
Browse files

Add spec for postfix::transport

parent 68f789a4
......@@ -39,6 +39,12 @@ define postfix::transport (
) {
include postfix::augeas
validate_string($destination)
validate_string($nexthop)
validate_string($file)
validate_absolute_path($file)
validate_string($ensure)
case $ensure {
'present': {
if ($destination) {
......@@ -65,7 +71,7 @@ define postfix::transport (
}
default: {
fail("Wrong ensure value: ${ensure}")
fail "\$ensure must be either 'present' or 'absent', got '${ensure}'"
}
}
......
require 'spec_helper'
describe 'postfix::transport' do
let (:title) { 'foo' }
let (:facts) { {
:osfamily => 'Debian',
} }
context 'when sending wrong type for destination' do
let (:params) { {
:destination => ['bar'],
} }
it 'should fail' do
expect {
should 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 {
should 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 {
should 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
let (:params) { {
:destination => 'bar',
:file => 'baz',
} }
it 'should fail' do
expect {
should contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /"baz" is not an absolute path/)
end
end
context 'when sending wrong type for ensure' do
let (:params) { {
:destination => 'bar',
:ensure => ['baz'],
} }
it 'should fail' do
expect {
should contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /\["baz"\] is not a string/)
end
end
context 'when sending wrong value for ensure' do
let (:params) { {
:destination => 'bar',
:ensure => 'running',
} }
it 'should fail' do
expect {
should contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /\$ensure must be either/)
end
end
context 'when using default values' do
it { should include_class('postfix::augeas') }
it { should contain_augeas('Postfix transport - foo').with(
:incl => '/etc/postfix/transport',
:lens => 'Postfix_Transport.lns',
:changes => [
"set pattern[. = 'foo'] 'foo'",
"clear pattern[. = 'foo']/transport",
"clear pattern[. = 'foo']/nexthop",
])
}
end
context 'when overriding default values' do
let (:params) { {
:destination => 'bar',
:nexthop => 'baz',
:file => '/tmp/transport',
:ensure => 'present',
} }
it { should include_class('postfix::augeas') }
it { should contain_augeas('Postfix transport - foo').with(
:incl => '/tmp/transport',
:lens => 'Postfix_Transport.lns',
:changes => [
"set pattern[. = 'foo'] 'foo'",
"set pattern[. = 'foo']/transport 'bar'",
"set pattern[. = 'foo']/nexthop 'baz'",
])
}
end
context 'when ensuring absence' do
let (:params) { {
:destination => 'bar',
:ensure => 'absent',
} }
it { should include_class('postfix::augeas') }
it { should contain_augeas('Postfix transport - foo').with(
:incl => '/etc/postfix/transport',
:lens => 'Postfix_Transport.lns',
:changes => [
"rm pattern[. = 'foo']",
])
}
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment