Skip to content

Commit

Permalink
Merge pull request #54 from tykeal/improve_tests
Browse files Browse the repository at this point in the history
Improve tests
  • Loading branch information
pranav committed Oct 1, 2015
2 parents 3003db0 + 2da78c0 commit 182803f
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 22 deletions.
20 changes: 19 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]

desc "Validate manifests, templates, and ruby files"
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end

task :default => [:validate, :spec, :lint]
4 changes: 2 additions & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@

$nexus_properties_file = "${nexus_root}/${nexus_home_dir}/conf/nexus.properties"

file_line{ 'nexus-appliction-host':
file_line{ 'nexus-application-host':
path => $nexus_properties_file,
match => '^application-host',
line => "application-host=${nexus_host}"
}

file_line{ 'nexus-appliction-port':
file_line{ 'nexus-application-port':
path => $nexus_properties_file,
match => '^application-port',
line => "application-port=${nexus_port}"
Expand Down
14 changes: 7 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@
}

user { $nexus_user:
ensure => present,
comment => 'Nexus User',
gid => $nexus_group,
home => $nexus_root,
shell => '/bin/sh', # required to start application via script.
system => true,
require => Group['nexus']
ensure => present,
comment => 'Nexus User',
gid => $nexus_group,
home => $nexus_root,
shell => '/bin/sh', # required to start application via script.
system => true,
require => Group[$nexus_group]
}
}

Expand Down
12 changes: 6 additions & 6 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
$nexus_script = "${nexus_home}/bin/nexus"

file_line{ 'nexus_NEXUS_HOME':
path => $nexus_script,
match => '^#?NEXUS_HOME=',
line => "NEXUS_HOME=${nexus_home}",
path => $nexus_script,
match => '^#?NEXUS_HOME=',
line => "NEXUS_HOME=${nexus_home}",
}

file_line{ 'nexus_RUN_AS_USER':
path => $nexus_script,
match => '^#?RUN_AS_USER=',
line => "RUN_AS_USER=\${run_as_user:-${nexus_user}}",
path => $nexus_script,
match => '^#?RUN_AS_USER=',
line => "RUN_AS_USER=\${run_as_user:-${nexus_user}}",
}

file{ '/etc/init.d/nexus':
Expand Down
53 changes: 53 additions & 0 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'spec_helper'

describe 'nexus::config', :type => :class do
let(:params) {
{
'nexus_root' => '/foo',
'nexus_home_dir' => '/bar',
'nexus_host' => '1.1.1.1',
'nexus_port' => '8888',
'nexus_context' => '/baz',
'nexus_work_dir' => '/foom',
}
}

context 'no params set' do
let(:params) {{}}

it 'should fail' do
expect { should compile }.to raise_error(RSpec::Expectations::ExpectationNotMetError,
/Must pass /)
end
end

context 'with test values' do
it { should contain_class('nexus::config') }

it { should contain_file_line('nexus-application-host').with(
'path' => '/foo//bar/conf/nexus.properties',
'match' => '^application-host',
'line' => 'application-host=1.1.1.1',
) }

it { should contain_file_line('nexus-application-port').with(
'path' => '/foo//bar/conf/nexus.properties',
'match' => '^application-port',
'line' => 'application-port=8888',
) }

it { should contain_file_line('nexus-webapp-context-path').with(
'path' => '/foo//bar/conf/nexus.properties',
'match' => '^nexus-webapp-context-path',
'line' => 'nexus-webapp-context-path=/baz',
) }

it { should contain_file_line('nexus-work').with(
'path' => '/foo//bar/conf/nexus.properties',
'match' => '^nexus-work',
'line' => 'nexus-work=/foom',
) }
end
end

# vim: sw=2 ts=2 sts=2 et :
40 changes: 37 additions & 3 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,32 @@
end

context 'with a version set' do
it { should create_class('nexus::package') }
it { should create_class('nexus::config') }
it { should create_class('nexus::service') }
it { should contain_class('nexus') }
it { should contain_class('nexus::params') }

it { should contain_group('nexus').with(
'ensure' => 'present',
) }

it { should contain_user('nexus').with(
'ensure' => 'present',
'comment' => 'Nexus User',
'gid' => 'nexus',
'home' => '/srv',
'shell' => '/bin/sh',
'system' => true,
'require' => 'Group[nexus]',
) }

it { should contain_anchor('nexus::begin') }
it { should contain_class('nexus::package').that_requires(
'Anchor[nexus::begin]' ) }
it { should contain_class('nexus::config').that_requires(
'Class[nexus::package]' ).that_notifies('Class[nexus::service]') }
it { should contain_class('nexus::service').that_subscribes_to(
'Class[nexus::config]' ) }
it { should contain_anchor('nexus::end').that_requires(
'Class[nexus::service]' ) }

it 'should handle deploy_pro' do
params.merge!(
Expand All @@ -33,6 +56,17 @@
'download_site' => 'http://download.sonatype.com/nexus/professional-bundle',
)
end

it 'should not have a user or group if nexus_manage_user is false' do
params.merge!(
{
'nexus_manage_user' => false,
}
)

should_not contain_group('nexus')
should_not contain_user('nexus')
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/classes/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
'require' => 'Exec[nexus-untar]',
) }

it 'should handle deploy_true' do
it 'should handle deploy_pro' do
params.merge!(
{
'deploy_pro' => true,
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/params_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'spec_helper'

describe 'nexus::params', :type => :class do

context 'with default params' do
it { should contain_class('nexus::params') }
end
end

# vim: sw=2 ts=2 sts=2 et :
40 changes: 39 additions & 1 deletion spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,45 @@
end
end

it { should contain_service('nexus') }
context 'with test values' do
it { should contain_class('nexus::service') }

it { should contain_file_line('nexus_NEXUS_HOME').with(
'path' => '/srv/nexus/bin/nexus',
'match' => '^#?NEXUS_HOME=',
'line' => 'NEXUS_HOME=/srv/nexus',
) }

it { should contain_file_line('nexus_RUN_AS_USER').with(
'path' => '/srv/nexus/bin/nexus',
'match' => '^#?RUN_AS_USER=',
'line' => 'RUN_AS_USER=${run_as_user:-nexus}',
) }

it { should contain_file('/etc/init.d/nexus').with(
'ensure' => 'present',
'owner' => 'root',
'group' => 'root',
'mode' => '0755',
'source' => 'file:///srv/nexus/bin/nexus',
'require' => ['File_line[nexus_NEXUS_HOME]', 'File_line[nexus_RUN_AS_USER]'],
'notify' => 'Service[nexus]',
) }

it { should contain_service('nexus').with(
'ensure' => 'running',
'enable' => true,
'status' => 'env run_as_user=root /etc/init.d/nexus status',
) }

it 'should have the correct status line when version >= 2.8.0' do
params.merge!({'version' => '2.8.0'})

should contain_service('nexus').with(
'status' => 'env run_as_user=nexus /etc/init.d/nexus status',
)
end
end
end

# vim: sw=2 ts=2 sts=2 et :
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
require 'puppetlabs_spec_helper/module_spec_helper'
require 'puppetlabs_spec_helper/module_spec_helper'

at_exit { RSpec::Puppet::Coverage.report! }

0 comments on commit 182803f

Please sign in to comment.