Skip to content

Commit

Permalink
Update spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Nov 12, 2018
1 parent 52e65ae commit 11961dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
37 changes: 22 additions & 15 deletions examples/basic_candlepin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@
# Create certificates then install candlepin
#

Exec {
path => ['/usr/bin'],
cwd => '/etc/candlepin/certs/',
}
$keydir = '/etc/candlepin/certs'
$keystore = "${keydir}/keystore"
$keystore_password = 'secret'
$ca_key = "${keydir}/candlepin-ca.key"
$ca_cert = "${keydir}/candlepin-ca.crt"

file { '/etc/candlepin/':
ensure => directory,
}
file { '/etc/candlepin/certs/':
ensure => directory,
exec { "/bin/mkdir -p ${keydir}":
creates => $keydir,
} ->
exec { 'Create CA key':
command => 'openssl genrsa -out candlepin-ca.key 2048',
creates => '/etc/candlepin/certs/candlepin-ca.key',
command => "/usr/bin/openssl genrsa -out '${ca_key}' 2048",
creates => $ca_key,
notify => Service['tomcat'],
} ->
exec { 'Create CA certficate':
command => "/usr/bin/openssl req -new -x509 -key '${ca_key}' -out '${ca_cert}' -nodes -x509 -subj '/C=US/ST=North Carolina/L=Raleigh/O=CustomKatelloCA/CN=${facts['fqdn']}'",
creates => $ca_cert,
notify => Service['tomcat'],
} ->
exec { 'Create CA certficates':
command => 'openssl req -new -x509 -key candlepin-ca.key -out candlepin-ca.crt -nodes -x509 -subj "/C=US/ST=North Carolina/L=Raleigh/O=CustomKatelloCA/CN=www.candlepin.example.com"',
creates => '/etc/candlepin/certs/candlepin-ca.crt',
exec { 'Create keystore':
command => "/usr/bin/openssl pkcs12 -export -in '${ca_cert}' -inkey '${ca_key}' -out '${keystore}' -name tomcat -CAfile '${ca_cert}' -caname root -password 'pass:${keystore_password}'",
creates => $keystore,
notify => Service['tomcat'],
} ->
class { 'candlepin':
manage_repo => true,
manage_repo => true,
ca_key => $ca_key,
ca_cert => $ca_cert,
keystore_file => $keystore,
keystore_password => $keystore_password,
}
16 changes: 10 additions & 6 deletions spec/classes/candlepin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# install
it { is_expected.to contain_class('candlepin::install') }
it { is_expected.to contain_package('candlepin').with_ensure('present') }
it { is_expected.to contain_package('wget').with_ensure('present') }
it { is_expected.not_to contain_package('wget') }

# config
it { is_expected.to contain_class('candlepin::config') }
Expand Down Expand Up @@ -53,7 +53,7 @@
# database
it { is_expected.not_to contain_class('candlepin::database::mysql') }
it { is_expected.to contain_class('candlepin::database::postgresql') }
it { is_expected.to contain_exec('cpdb').that_subscribes_to('Package[candlepin]').that_comes_before(['Exec[cpinit]', 'Service[tomcat]']) }
it { is_expected.to contain_exec('cpdb').that_subscribes_to('Package[candlepin]').that_comes_before('Service[tomcat]') }
it { is_expected.to contain_postgresql__server__db('candlepin') }
it { is_expected.to contain_postgresql__server__role('candlepin').that_comes_before('Postgresql::Server::Database[candlepin]') }

Expand Down Expand Up @@ -82,7 +82,7 @@
# service
it { is_expected.to contain_class('candlepin::service') }
it { is_expected.to contain_service('tomcat') }
it { is_expected.to contain_exec('cpinit') }
it { is_expected.not_to contain_exec('cpinit') }
it { is_expected.to contain_service('tomcat').with_ensure('running') }
end

Expand Down Expand Up @@ -254,12 +254,16 @@

context 'with run_init false' do
let :params do
{run_init: false}
{run_init: true}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_service('tomcat') }
it { is_expected.not_to contain_exec('cpinit') }
it do
is_expected.to contain_exec('cpinit')
.that_requires(['Package[wget]', 'Service[tomcat]'])
.that_subscribes_to(['Concat[/etc/candlepin/candlepin.conf]', 'File[/etc/tomcat/server.xml]'])
end
end

describe 'notify' do
Expand All @@ -279,7 +283,7 @@

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('notification').that_notifies('Service[tomcat]') }
it { is_expected.to contain_exec('dependency').that_requires(['Service[tomcat]', 'Exec[cpinit]']) }
it { is_expected.to contain_exec('dependency').that_requires('Service[tomcat]') }
end
end
end
Expand Down

0 comments on commit 11961dc

Please sign in to comment.