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
ef37d24b
Commit
ef37d24b
authored
May 23, 2013
by
Raphaël Pinson
Browse files
Add spec for postfix::hash and refactor it
parent
2ff84825
Changes
2
Hide whitespace changes
Inline
Side-by-side
manifests/hash.pp
View file @
ef37d24b
...
...
@@ -26,50 +26,36 @@
# }
# }
#
define
postfix::hash
(
$ensure
=
'present'
,
$source
=
false
,
$content
=
false
)
{
define
postfix::hash
(
$ensure
=
'present'
,
$source
=
undef
,
$content
=
undef
,
)
{
include
::postfix::params
# selinux labels differ from one distribution to another
case
$::operatingsystem
{
validate_absolute_path
(
$name
)
validate_string
(
$source
)
validate_string
(
$content
)
validate_string
(
$ensure
)
validate_re
(
$ensure
,
[
'present'
,
'absent'
],
"
\$
ensure must be either 'present' or 'absent', got '
${ensure}
'"
)
RedHat
,
CentOS
:
{
case
$::lsbmajdistrelease
{
'4'
:
{
$postfix_seltype
=
'etc_t'
}
'5'
,
'6'
:
{
$postfix_seltype
=
'postfix_etc_t'
}
default
:
{
$postfix_seltype
=
undef
}
}
}
default
:
{
$postfix_seltype
=
undef
}
if
$source
and
$content
{
fail
"You must provide either 'source' or 'content', not both"
}
File
{
mode
=>
'0600'
,
owner
=>
root
,
group
=>
root
,
seltype
=>
$postfix
_
seltype
,
seltype
=>
$postfix
::params::
seltype
,
}
if
$source
!=
false
{
file
{
$name
:
ensure
=>
$ensure
,
source
=>
$source
,
require
=>
Package
[
'postfix'
],
}
}
else
{
if
$content
!=
false
{
file
{
$name
:
ensure
=>
$ensure
,
content
=>
$content
,
require
=>
Package
[
'postfix'
],
}
}
else
{
file
{
$name
:
ensure
=>
$ensure
,
require
=>
Package
[
'postfix'
],
}
}
file
{
$name
:
ensure
=>
$ensure
,
source
=>
$source
,
content
=>
$content
,
require
=>
Package
[
'postfix'
],
}
file
{
"
${name}
.db"
:
...
...
spec/defines/postfix_hash_spec.rb
0 → 100644
View file @
ef37d24b
require
'spec_helper'
describe
'postfix::hash'
do
let
(
:title
)
{
'/tmp/foo'
}
let
(
:facts
)
{
{
:osfamily
=>
'Debian'
,
}
}
context
'when passing wrong type for ensure'
do
let
(
:params
)
{
{
:ensure
=>
[
'present'
],
}
}
it
'should fail'
do
expect
{
should
contain_file
(
'/tmp/foo'
)
}.
to
raise_error
(
Puppet
::
Error
,
/\["present"\] is not a string/
)
end
end
context
'when passing wrong value for ensure'
do
let
(
:params
)
{
{
:ensure
=>
'running'
,
}
}
it
'should fail'
do
expect
{
should
contain_file
(
'/tmp/foo'
)
}.
to
raise_error
(
Puppet
::
Error
,
/must be either 'present' or 'absent'/
)
end
end
context
'when passing wrong value for title'
do
let
(
:title
)
{
'foo'
}
it
'should fail'
do
expect
{
should
contain_file
(
'/tmp/foo'
)
}.
to
raise_error
(
Puppet
::
Error
,
/"foo" is not an absolute path/
)
end
end
context
'when passing both source and content'
do
let
(
:params
)
{
{
:source
=>
'/tmp/bar'
,
:content
=>
'bar'
,
}
}
it
'should fail'
do
expect
{
should
contain_file
(
'/tmp/foo'
)
}.
to
raise_error
(
Puppet
::
Error
,
/You must provide either 'source' or 'content'/
)
end
end
context
'when passing source'
do
let
(
:params
)
{
{
:source
=>
'/tmp/bar'
,
}
}
it
{
should
contain_file
(
'/tmp/foo'
).
with
(
:ensure
=>
'present'
,
:source
=>
'/tmp/bar'
).
without
(
:content
)
}
it
{
should
contain_file
(
'/tmp/foo.db'
).
with_ensure
(
'present'
)
}
it
{
should
contain_exec
(
'generate /tmp/foo.db'
)
}
end
context
'when passing content'
do
let
(
:params
)
{
{
:content
=>
'bar'
,
}
}
it
{
should
contain_file
(
'/tmp/foo'
).
with
(
:ensure
=>
'present'
,
:content
=>
'bar'
).
without
(
:source
)
}
it
{
should
contain_file
(
'/tmp/foo.db'
).
with_ensure
(
'present'
)
}
it
{
should
contain_exec
(
'generate /tmp/foo.db'
)
}
end
context
'when not passing source or content'
do
it
{
should
contain_file
(
'/tmp/foo'
).
with
(
:ensure
=>
'present'
).
without
(
:source
).
without
(
:content
)
}
it
{
should
contain_file
(
'/tmp/foo.db'
).
with_ensure
(
'present'
)
}
it
{
should
contain_exec
(
'generate /tmp/foo.db'
)
}
end
context
'when ensuring absence'
do
let
(
:params
)
{
{
:ensure
=>
'absent'
,
}
}
it
{
should
contain_file
(
'/tmp/foo'
).
with_ensure
(
'absent'
)
}
it
{
should
contain_file
(
'/tmp/foo.db'
).
with_ensure
(
'absent'
)
}
it
{
should
contain_exec
(
'generate /tmp/foo.db'
)
}
end
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment