Commit 2ff84825 authored by Raphaël Pinson's avatar Raphaël Pinson
Browse files

Add spec for postfix::config

parent f3d4c00e
......@@ -29,6 +29,11 @@
#
define postfix::config ($value, $ensure = present) {
validate_string($value)
validate_string($ensure)
validate_re($ensure, ['present', 'absent'],
"\$ensure must be either 'present' or 'absent', got '${ensure}'")
Augeas {
incl => '/etc/postfix/main.cf',
lens => 'Postfix_Main.lns',
......
require 'spec_helper'
describe 'postfix::config' do
let (:title) { 'foo' }
let (:facts) { {
:osfamily => 'Debian',
} }
context 'when not passing value' do
it 'should fail' do
expect {
should contain_augeas("set postfix 'foo'")
}.to raise_error(Puppet::Error, /Must pass value to Postfix::Config/)
end
end
context 'when passing wrong type for value' do
let (:params) { {
:value => ['bar'],
} }
it 'should fail' do
expect {
should contain_augeas("set postfix 'foo'")
}.to raise_error(Puppet::Error, /\["bar"\] is not a string/)
end
end
context 'when passing wrong type for ensure' do
let (:params) { {
:value => 'bar',
:ensure => ['present'],
} }
it 'should fail' do
expect {
should contain_augeas("set postfix 'foo'")
}.to raise_error(Puppet::Error, /\["present"\] is not a string/)
end
end
context 'when passing wrong value for ensure' do
let (:params) { {
:value => 'bar',
:ensure => 'running',
} }
it 'should fail' do
expect {
should contain_augeas("set postfix 'foo'")
}.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/)
end
end
context 'when ensuring presence' do
let (:params) { {
:value => 'bar',
:ensure => 'present',
} }
it { should contain_augeas("set postfix 'foo' to 'bar'").with(
:incl => '/etc/postfix/main.cf',
:lens => 'Postfix_Main.lns',
:changes => "set foo 'bar'"
) }
end
context 'when ensuring absence' do
let (:params) { {
:value => 'bar',
:ensure => 'absent',
} }
it { should contain_augeas("rm postfix 'foo'").with(
:incl => '/etc/postfix/main.cf',
:lens => 'Postfix_Main.lns',
:changes => "rm 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