Skip to content

Commit

Permalink
Refactor some of the rspec-puppet examples for jenkins::slave to be m…
Browse files Browse the repository at this point in the history
…ore concise

This reduces some duplication, but also makes sure we have the exact same
branch coverage with the shared_context for both sets of platforms supported by
puppet-jenkins
  • Loading branch information
R. Tyler Croy committed Apr 24, 2014
1 parent 91af030 commit 19e0bb3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
2 changes: 0 additions & 2 deletions manifests/slave.pp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@
if $slave_home {
$fsroot_flag = "-fsroot ${slave_home}"
}
else {$fsroot_flag = ''}


# choose the correct init functions
case $::osfamily {
Expand Down
47 changes: 24 additions & 23 deletions spec/classes/jenkins_slave_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,47 @@

describe 'jenkins::slave' do

describe 'RedHat' do
let(:facts) { { :osfamily => 'RedHat', :operatingsystem => 'CentOS' } }

describe 'default' do
it { should contain_exec('get_swarm_client') }
it { should contain_file('/etc/init.d/jenkins-slave') }
it { should contain_service('jenkins-slave') }
it { should contain_user('jenkins-slave_user').with_uid(nil) }
it { should contain_file('/etc/init.d/jenkins-slave').with_content(/-fsroot \/home\/jenkins-slave/) }
end
shared_context 'a jenkins::slave catalog' do
it { should contain_exec('get_swarm_client') }
it { should contain_file('/etc/init.d/jenkins-slave') }
it { should contain_service('jenkins-slave') }
it { should contain_user('jenkins-slave_user').with_uid(nil) }
# Let the different platform blocks define `slave_runtime_file` separately below
it { should contain_file(slave_runtime_file).with_content(/-fsroot \/home\/jenkins-slave/) }

describe 'with ssl verification disabled' do
let(:params) { { :disable_ssl_verification => true } }
it { should contain_file('/etc/init.d/jenkins-slave').with_content(/-disableSslVerification/) }
it { should contain_file(slave_runtime_file).with_content(/-disableSslVerification/) }
end

describe 'slave_uid' do
let(:params) { { :slave_uid => '123' } }
it { should contain_user('jenkins-slave_user').with_uid(123) }
end

describe 'with a non-default $slave_home' do
let(:home) { '/home/rspec-runner' }
let(:params) { {:slave_home => home } }
it { should contain_file(slave_runtime_file).with_content(/-fsroot #{home}/) }
end
end

describe 'RedHat' do
let(:facts) { { :osfamily => 'RedHat', :operatingsystem => 'CentOS' } }
let(:slave_runtime_file) { '/etc/init.d/jenkins-slave' }

it_behaves_like 'a jenkins::slave catalog'
end

describe 'Debian' do
let(:facts) { { :osfamily => 'Debian', :lsbdistid => 'debian', :lsbdistcodename => 'natty', :operatingsystem => 'Debian' } }
describe 'default' do
it { should contain_exec('get_swarm_client') }
it { should contain_file('/etc/init.d/jenkins-slave') }
it { should contain_service('jenkins-slave') }
it { should contain_user('jenkins-slave_user').with_uid(nil) }
it { should contain_file('/etc/default/jenkins-slave').with_content(/-fsroot \/home\/jenkins-slave/) }
end
describe 'with ssl verification disabled' do
let(:params) { { :disable_ssl_verification => true } }
it { should contain_file('/etc/default/jenkins-slave').with_content(/-disableSslVerification/) }
end
let(:slave_runtime_file) { '/etc/default/jenkins-slave' }

it_behaves_like 'a jenkins::slave catalog'
end

describe 'Unknown' do
let(:facts) { { :ostype => 'Unknown' } }
it { expect { should raise_error(Puppet::Error) } }
end

end

0 comments on commit 19e0bb3

Please sign in to comment.