Skip to content

Commit

Permalink
FIX unit tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gbloquel committed Sep 25, 2016
1 parent 2495174 commit 191211a
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 183 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
*.swp
.bundle
.ruby-version
.ruby-gemset
Gemfile.lock
pkg
spec/fixtures/
.vagrant/
log/
vendor/
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ group :test do
if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
gem 'rspec', '~> 2.0'
end

gem 'safe_yaml', '~> 1.0.4'
gem 'rake'
gem 'puppet-lint'
gem 'rspec-puppet', :git => 'https://github.com/rodjek/rspec-puppet.git'
gem 'puppet-syntax'
gem 'puppetlabs_spec_helper'
gem 'simplecov'
gem 'metadata-json-lint'
gem 'rspec-puppet-facts', :require => false
end

group :development do
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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"]
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp", "vendor/**/*.pp"]

desc "Validate manifests, templates, and ruby files"
task :validate do
Expand Down
11 changes: 5 additions & 6 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$nexus_context = $::nexus::nexus_context,
$nexus_work_dir = $::nexus::nexus_work_dir,
$nexus_data_folder = $::nexus::nexus_data_folder,
$version = $::nexus::version
$version = $::nexus::version,
) {

if $version !~ /\d.*/ or versioncmp($version, '3.0.0') >= 0 {
Expand Down Expand Up @@ -63,11 +63,10 @@

if $nexus_data_folder {
file{ $nexus_data_dir :
ensure => 'link',
target => $nexus_data_folder,
force => true,
notify => Service['nexus']
ensure => 'link',
target => $nexus_data_folder,
force => true,
notify => Service['nexus']
}
}

}
2 changes: 1 addition & 1 deletion manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
$nexus_script = "${nexus_home}/bin/nexus"

if ($::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '8.0') > 0) or
($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '15.04') > 0) {
($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '15.04') > 0) {
file { '/lib/systemd/system/nexus.service':
mode => '0644',
owner => 'root',
Expand Down
16 changes: 9 additions & 7 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
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',
'nexus_root' => '/foo',
'nexus_home_dir' => '/bar',
'nexus_host' => '1.1.1.1',
'nexus_port' => '8888',
'nexus_context' => '/baz',
'nexus_work_dir' => '/foom',
'version' => '2.11.2',
'nexus_data_folder' => '',
}
}

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

it { should contain_file_line('nexus-application-host').with(
Expand Down
118 changes: 63 additions & 55 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -1,71 +1,79 @@
require 'spec_helper'

describe 'nexus', :type => :class do
let(:params) {
{
'version' => '2.11.2'
}
}
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

context 'no params set' do
let(:params) {{}}
let(:params) {
{
'version' => '2.11.2'
}
}

it 'should fail if no version configured' do
expect { should compile }.to raise_error(RSpec::Expectations::ExpectationNotMetError,
/Cannot set version nexus version to "latest" or leave undefined./)
end
end
context 'no params set' do
let(:params) {{}}

context 'with a version set' do
it { should contain_class('nexus') }
it { should contain_class('nexus::params') }
it 'should fail if no version configured' do
expect { should compile }.to raise_error(RSpec::Expectations::ExpectationNotMetError,
/Cannot set version nexus version to "latest" or leave undefined./)
end
end

it { should contain_group('nexus').with(
'ensure' => 'present',
) }
context 'with a version set' do
it { should contain_class('nexus') }
it { should contain_class('nexus::params') }

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_group('nexus').with(
'ensure' => 'present',
) }

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 contain_user('nexus').with(
'ensure' => 'present',
'comment' => 'Nexus User',
'gid' => 'nexus',
'home' => '/srv',
'shell' => '/bin/sh',
'system' => true,
'require' => 'Group[nexus]',
) }

it 'should handle deploy_pro' do
params.merge!(
{
'deploy_pro' => true,
}
)
it { should contain_anchor('nexus::setup') }
it { should contain_class('nexus::package').that_requires(
'Anchor[nexus::setup]' ) }
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::done').that_requires(
'Class[nexus::service]' ) }

should create_class('nexus::package').with(
'deploy_pro' => true,
'download_site' => 'http://download.sonatype.com/nexus/professional-bundle',
)
end
it 'should handle deploy_pro' do
params.merge!(
{
'deploy_pro' => true,
}
)

it 'should not have a user or group if nexus_manage_user is false' do
params.merge!(
{
'nexus_manage_user' => false,
}
)
should create_class('nexus::package').with(
'deploy_pro' => true,
'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')
should_not contain_group('nexus')
should_not contain_user('nexus')
end
end
end
end
end
Expand Down
144 changes: 77 additions & 67 deletions spec/classes/package_spec.rb
Original file line number Diff line number Diff line change
@@ -1,84 +1,94 @@
require 'spec_helper'

describe 'nexus::package', :type => :class do
let(:params) {
{
'deploy_pro' => false,
'download_site' => 'http://download.sonatype.com/nexus/oss',
'nexus_root' => '/srv',
'nexus_home_dir' => 'nexus',
'nexus_user' => 'nexus',
'nexus_group' => 'nexus',
'nexus_work_dir' => '/srv/sonatype-work/nexus',
'nexus_work_dir_manage' => true,
'nexus_work_recurse' => true,
# Assume a good revision as init.pp screens for us
'revision' => '01',
'version' => '2.11.2',
'download_folder' => '/srv',
}
}
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

context 'with default values' do
it { should contain_class('nexus::package') }
let(:params) {
{
'deploy_pro' => false,
'download_site' => 'http://download.sonatype.com/nexus/oss',
'nexus_root' => '/srv',
'nexus_home_dir' => 'nexus',
'nexus_user' => 'nexus',
'nexus_group' => 'nexus',
'nexus_work_dir' => '/srv/sonatype-work/nexus',
'nexus_work_dir_manage' => true,
'nexus_work_recurse' => true,
'nexus_type' => 'bundle',
'nexus_selinux_ignore_defaults' => true,
# Assume a good revision as init.pp screens for us
'revision' => '01',
'version' => '2.11.2',
'download_folder' => '/srv',
}
}

it { should contain_wget__fetch('nexus-2.11.2-01-bundle.tar.gz').with(
'source' => 'http://download.sonatype.com/nexus/oss/nexus-2.11.2-01-bundle.tar.gz',
'destination' => '/srv/nexus-2.11.2-01-bundle.tar.gz',
'before' => 'Exec[nexus-untar]',
) }
context 'with default values' do
it { should contain_class('nexus::package') }

it { should contain_exec('nexus-untar').with(
'command' => 'tar zxf /srv/nexus-2.11.2-01-bundle.tar.gz --directory /srv',
'creates' => '/srv/nexus-2.11.2-01',
'path' => [ '/bin', '/usr/bin' ],
) }
it { should contain_wget__fetch('nexus-2.11.2-01-bundle.tar.gz').with(
'source' => 'http://download.sonatype.com/nexus/oss/nexus-2.11.2-01-bundle.tar.gz',
'destination' => '/srv/nexus-2.11.2-01-bundle.tar.gz',
'before' => 'Exec[nexus-untar]',
) }

it { should contain_file('/srv/nexus-2.11.2-01').with(
'ensure' => 'directory',
'owner' => 'nexus',
'group' => 'nexus',
'recurse' => true,
'require' => 'Exec[nexus-untar]',
) }
it { should contain_exec('nexus-untar').with(
'command' => 'tar zxf /srv/nexus-2.11.2-01-bundle.tar.gz --directory /srv',
'creates' => '/srv/nexus-2.11.2-01',
'path' => [ '/bin', '/usr/bin' ],
) }

it { should contain_file('/srv/sonatype-work/nexus').with(
'ensure' => 'directory',
'owner' => 'nexus',
'group' => 'nexus',
'recurse' => true,
'require' => 'Exec[nexus-untar]',
) }
it { should contain_file('/srv/nexus-2.11.2-01').with(
'ensure' => 'directory',
'owner' => 'nexus',
'group' => 'nexus',
'recurse' => true,
'require' => 'Exec[nexus-untar]',
) }

it { should contain_file('/srv/nexus').with(
'ensure' => 'link',
'target' => '/srv/nexus-2.11.2-01',
'require' => 'Exec[nexus-untar]',
) }
it { should contain_file('/srv/sonatype-work/nexus').with(
'ensure' => 'directory',
'owner' => 'nexus',
'group' => 'nexus',
'recurse' => true,
'require' => 'Exec[nexus-untar]',
) }

it 'should handle deploy_pro' do
params.merge!(
{
'deploy_pro' => true,
'download_site' => 'http://download.sonatype.com/nexus/professional-bundle',
}
)
it { should contain_file('/srv/nexus').with(
'ensure' => 'link',
'target' => '/srv/nexus-2.11.2-01',
'require' => 'Exec[nexus-untar]',
) }

it 'should handle deploy_pro' do
params.merge!(
{
'deploy_pro' => true,
'download_site' => 'http://download.sonatype.com/nexus/professional-bundle',
}
)

should contain_wget__fetch('nexus-professional-2.11.2-01-bundle.tar.gz').with(
'source' => 'http://download.sonatype.com/nexus/professional-bundle/nexus-professional-2.11.2-01-bundle.tar.gz',
'destination' => '/srv/nexus-professional-2.11.2-01-bundle.tar.gz',
)
should contain_wget__fetch('nexus-professional-2.11.2-01-bundle.tar.gz').with(
'source' => 'http://download.sonatype.com/nexus/professional-bundle/nexus-professional-2.11.2-01-bundle.tar.gz',
'destination' => '/srv/nexus-professional-2.11.2-01-bundle.tar.gz',
)

should contain_exec('nexus-untar').with(
'command' => 'tar zxf /srv/nexus-professional-2.11.2-01-bundle.tar.gz --directory /srv',
'creates' => '/srv/nexus-professional-2.11.2-01',
)
should contain_exec('nexus-untar').with(
'command' => 'tar zxf /srv/nexus-professional-2.11.2-01-bundle.tar.gz --directory /srv',
'creates' => '/srv/nexus-professional-2.11.2-01',
)

should contain_file('/srv/nexus-professional-2.11.2-01')
should contain_file('/srv/nexus-professional-2.11.2-01')

should contain_file('/srv/nexus').with(
'target' => '/srv/nexus-professional-2.11.2-01',
)
should contain_file('/srv/nexus').with(
'target' => '/srv/nexus-professional-2.11.2-01',
)
end
end
end
end
end
Expand Down
Loading

0 comments on commit 191211a

Please sign in to comment.