Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Puppet Camptocamp Postfix
Commits
e81564f0
Commit
e81564f0
authored
Mar 25, 2015
by
Mickaël Canévet
Browse files
Manage unit tests with rspec-puppet-facts
parent
745509f3
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
metadata.json
View file @
e81564f0
...
...
@@ -48,7 +48,8 @@
"operatingsystem"
:
"RedHat"
,
"operatingsystemrelease"
:
[
"5"
,
"6"
"6"
,
"7"
]
}
],
...
...
spec/classes/postfix_augeas_spec.rb
View file @
e81564f0
require
'spec_helper'
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
"include ::augeas"
end
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'
)
}
on_supported_os
.
each
do
|
os
,
facts
|
context
"on
#{
os
}
"
do
let
(
:facts
)
do
facts
.
merge
({
:augeasversion
=>
'1.2.0'
,
})
end
it
{
is_expected
.
to
compile
.
with_all_deps
}
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
spec/classes/postfix_mailman_spec.rb
View file @
e81564f0
require
'spec_helper'
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
spec/classes/postfix_mta_spec.rb
View file @
e81564f0
require
'spec_helper'
describe
'postfix::mta'
do
let
(
:facts
)
{
{
:lsbdistcodename
=>
'wheezy'
,
:osfamily
=>
'Debian'
,
:path
=>
'/foo/bar'
,
}
}
let
:pre_condition
do
"class { 'postfix':
mydestination => 'bar',
...
...
@@ -14,7 +9,16 @@ describe 'postfix::mta' do
}"
end
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'
)
}
on_supported_os
.
each
do
|
os
,
facts
|
context
"on
#{
os
}
"
do
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
spec/classes/postfix_satellite_spec.rb
View file @
e81564f0
require
'spec_helper'
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
" class { 'augeas': }
class { 'postfix':
...
...
@@ -17,9 +9,21 @@ describe 'postfix::satellite' do
mynetworks => 'baz',
}"
end
it
{
is_expected
.
to
contain_class
(
'postfix::mta'
)
}
it
{
is_expected
.
to
contain_postfix__virtual
(
'@foo.example.com'
).
with
(
:ensure
=>
'present'
,
:destination
=>
'root'
)
}
on_supported_os
.
each
do
|
os
,
facts
|
context
"on
#{
os
}
"
do
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
spec/classes/postfix_spec.rb
View file @
e81564f0
This diff is collapsed.
Click to expand it.
spec/defines/postfix_config_spec.rb
View file @
e81564f0
...
...
@@ -2,93 +2,98 @@ require 'spec_helper'
describe
'postfix::config'
do
let
(
:title
)
{
'foo'
}
let
(
:facts
)
{
{
:lsbdistcodename
=>
'wheezy'
,
:osfamily
=>
'Debian'
,
}
}
let
:pre_condition
do
"class { 'postfix': }"
end
context
'when not passing value'
do
it
'should fail'
do
expect
{
is_expected
.
to
contain_augeas
(
"set postfix 'foo'"
)
}.
to
raise_error
(
Puppet
::
Error
,
/value can not be empty/
)
end
end
on_supported_os
.
each
do
|
os
,
facts
|
context
"on
#{
os
}
"
do
let
(
:facts
)
do
facts
end
context
'when passing wrong type for value'
do
let
(
:params
)
{
{
:value
=>
[
'bar'
],
}
}
it
'should fail'
do
expect
{
is_expected
.
to
contain_augeas
(
"set postfix 'foo'"
)
}.
to
raise_error
(
Puppet
::
Error
,
/\["bar"\] is not a string/
)
end
end
context
'when not passing value'
do
it
'should fail'
do
expect
{
is_expected
.
to
contain_augeas
(
"set postfix 'foo'"
)
}.
to
raise_error
(
Puppet
::
Error
,
/value can not be empty/
)
end
end
context
'when passing wrong type for ensure'
do
let
(
:params
)
{
{
:value
=>
'bar'
,
:ensure
=>
[
'present'
],
}
}
it
'should fail'
do
expect
{
is_expected
.
to
contain_augeas
(
"set postfix 'foo'"
)
}.
to
raise_error
(
Puppet
::
Error
,
/\["present"\] is not a string/
)
end
end
context
'when passing wrong type for value'
do
let
(
:params
)
{
{
:value
=>
[
'bar'
],
}
}
it
'should fail'
do
expect
{
is_expected
.
to
contain_augeas
(
"set postfix 'foo'"
)
}.
to
raise_error
(
Puppet
::
Error
,
/\["bar"\] is not a string/
)
end
end
context
'when passing wrong
valu
e for ensure'
do
let
(
:params
)
{
{
:value
=>
'bar'
,
: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
context
'when passing wrong
typ
e for ensure'
do
let
(
:params
)
{
{
:value
=>
'bar'
,
:ensure
=>
[
'present'
]
,
}
}
it
'should fail'
do
expect
{
is_expected
.
to
contain_augeas
(
"set postfix 'foo'"
)
}.
to
raise_error
(
Puppet
::
Error
,
/
\["present"\] is not a string
/
)
end
end
context
'when ensuring presence'
do
let
(
:params
)
{
{
:value
=>
'bar'
,
:ensure
=>
'present'
,
}
}
context
'when passing wrong value for ensure'
do
let
(
:params
)
{
{
:value
=>
'bar'
,
: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
(
:incl
=>
'/etc/postfix/main.cf'
,
:lens
=>
'Postfix_Main.lns'
,
:changes
=>
"set foo 'bar'"
)
}
end
context
'when ensuring presence'
do
let
(
:params
)
{
{
:value
=>
'bar'
,
:ensure
=>
'present'
,
}
}
context
'when ensuring absence'
do
let
(
:params
)
{
{
:value
=>
'bar'
,
:ensure
=>
'absent'
,
}
}
it
{
is_expected
.
to
contain_augeas
(
"manage postfix 'foo'"
).
with
(
:incl
=>
'/etc/postfix/main.cf'
,
:lens
=>
'Postfix_Main.lns'
,
:changes
=>
"set foo 'bar'"
)
}
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 absence'
do
let
(
:params
)
{
{
:value
=>
'bar'
,
:ensure
=>
'absent'
,
}
}
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
let
(
:params
)
{
{
:value
=>
'bar'
,
:ensure
=>
'blank'
,
}
}
context
'when ensuring blank'
do
let
(
:params
)
{
{
:value
=>
'bar'
,
:ensure
=>
'blank'
,
}
}
it
{
is_expected
.
to
contain_augeas
(
"manage postfix 'foo'"
).
with
(
:incl
=>
'/etc/postfix/main.cf'
,
:lens
=>
'Postfix_Main.lns'
,
:changes
=>
"clear foo"
)
}
it
{
is_expected
.
to
contain_augeas
(
"manage postfix 'foo'"
).
with
(
:incl
=>
'/etc/postfix/main.cf'
,
:lens
=>
'Postfix_Main.lns'
,
:changes
=>
"clear foo"
)
}
end
end
end
end
spec/defines/postfix_hash_spec.rb
View file @
e81564f0
...
...
@@ -2,103 +2,107 @@ require 'spec_helper'
describe
'postfix::hash'
do
let
(
:title
)
{
'/tmp/foo'
}
let
(
:facts
)
{
{
:lsbdistcodename
=>
'wheezy'
,
:osfamily
=>
'Debian'
,
:path
=>
'/foo/bar'
,
}
}
let
:pre_condition
do
"class { '::postfix': }"
end
context
'when passing wrong type for ensure'
do
let
(
:params
)
{
{
:ensure
=>
[
'present'
],
}
}
it
'should fail'
do
expect
{
is_expected
.
to
contain_file
(
'/tmp/foo'
)
}.
to
raise_error
(
Puppet
::
Error
,
/\["present"\] is not a string/
)
end
end
on_supported_os
.
each
do
|
os
,
facts
|
context
"on
#{
os
}
"
do
let
(
:facts
)
do
facts
end
context
'when passing wrong
valu
e for ensure'
do
let
(
:params
)
{
{
:ensure
=>
'running'
,
}
}
it
'should fail'
do
expect
{
is_expected
.
to
contain_file
(
'/tmp/foo'
)
}.
to
raise_error
(
Puppet
::
Error
,
/
must be either 'present' or 'absent'
/
)
end
end
context
'when passing wrong
typ
e for ensure'
do
let
(
:params
)
{
{
:ensure
=>
[
'present'
]
,
}
}
it
'should fail'
do
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 title'
do
let
(
:title
)
{
'foo'
}
it
'should fail'
do
expect
{
is_expected
.
to
contain_file
(
'/tmp/foo'
)
}.
to
raise_error
(
Puppet
::
Error
,
/"foo" is not an absolute path/
)
end
end
context
'when passing wrong value for ensure'
do
let
(
:params
)
{
{
:ensure
=>
'running'
,
}
}
it
'should fail'
do
expect
{
is_expected
.
to
contain_file
(
'/tmp/foo'
)
}.
to
raise_error
(
Puppet
::
Error
,
/must be either 'present' or 'absent'/
)
end
end
context
'when passing both source and content'
do
let
(
:params
)
{
{
:source
=>
'/tmp/bar'
,
:content
=>
'bar'
,
}
}
context
'when passing wrong value for title'
do
let
(
:title
)
{
'foo'
}
it
'should fail'
do
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
expect
{
is_expected
.
to
contain_file
(
'/tmp/foo'
)
}.
to
raise_error
(
Puppet
::
Error
,
/You must provide either 'source' or 'content'/
)
end
end
context
'when passing both source and content'
do
let
(
:params
)
{
{
:source
=>
'/tmp/bar'
,
:content
=>
'bar'
,
}
}
context
'when passing source'
do
let
(
:params
)
{
{
:source
=>
'/tmp/bar'
,
}
}
it
'should fail'
do
expect
{
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
(
:ensure
=>
'present'
,
: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 source'
do
let
(
:params
)
{
{
:source
=>
'/tmp/bar'
,
}
}
context
'when passing content'
do
let
(
:params
)
{
{
:content
=>
'bar'
,
}
}
it
{
is_expected
.
to
contain_file
(
'/tmp/foo'
).
with
(
:ensure
=>
'present'
,
: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
(
:ensure
=>
'present'
,
: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 passing content'
do
let
(
:params
)
{
{
:content
=>
'bar'
,
}
}
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
it
{
is_expected
.
to
contain_file
(
'/tmp/foo'
).
with
(
:ensure
=>
'present'
,
: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
(
: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
let
(
:params
)
{
{
:ensure
=>
'absent'
,
}
}
context
'when ensuring absence'
do
let
(
:params
)
{
{
: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_exec
(
'generate /tmp/foo.db'
)
}
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_exec
(
'generate /tmp/foo.db'
)
}
end
end
end
end
spec/defines/postfix_transport_spec.rb
View file @
e81564f0
...
...
@@ -2,139 +2,144 @@ require 'spec_helper'
describe
'postfix::transport'
do
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
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 an absolute path/
)
end
end
context
'when sending wrong type for ensure'
do
let
(
:params
)
{
{
:destination
=>
'bar'
,
:ensure
=>
[
'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
let
:pre_condition
do
"class { '::augeas': }"
end
context
'when sending wrong value for ensure'
do
let
(
:params
)
{
{
:destination
=>
'bar'
,