diff --git a/Rakefile b/Rakefile index f9c730a..2e0ac6f 100644 --- a/Rakefile +++ b/Rakefile @@ -1 +1,19 @@ -require 'puppetlabs_spec_helper/rake_tasks' \ No newline at end of file +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] diff --git a/manifests/config.pp b/manifests/config.pp index 8be35a3..0e19aeb 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -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}" diff --git a/manifests/init.pp b/manifests/init.pp index cd8b926..e814484 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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] } } diff --git a/manifests/service.pp b/manifests/service.pp index 8b5cb33..eb18587 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -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': diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb new file mode 100644 index 0000000..3d59bab --- /dev/null +++ b/spec/classes/config_spec.rb @@ -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 : diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 1fe2951..0f63803 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -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!( @@ -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 diff --git a/spec/classes/package_spec.rb b/spec/classes/package_spec.rb index 41eb453..63b72e2 100644 --- a/spec/classes/package_spec.rb +++ b/spec/classes/package_spec.rb @@ -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, diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb new file mode 100644 index 0000000..07a5414 --- /dev/null +++ b/spec/classes/params_spec.rb @@ -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 : diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index fadb5d0..f390328 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -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 : diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3d92005..245555f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,3 @@ -require 'puppetlabs_spec_helper/module_spec_helper' \ No newline at end of file +require 'puppetlabs_spec_helper/module_spec_helper' + +at_exit { RSpec::Puppet::Coverage.report! }