diff --git a/.travis.yml b/.travis.yml index 87d702c..36a381a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,22 @@ --- sudo: false language: ruby +cache: bundler bundler_args: --without system_tests -script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" +before_install: rm Gemfile.lock || true +script: bundle exec rake validate lint spec matrix: fast_finish: true include: - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.4.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" - - rvm: 2.1.5 - env: PUPPET_GEM_VERSION="~> 3.0" - - rvm: 2.1.5 - env: PUPPET_GEM_VERSION="~> 3.6.0" - - rvm: 2.1.5 - env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" + - rvm: 2.1.6 + env: PUPPET_GEM_VERSION='~> 4.0' COVERAGE=yes STRICT_VARIABLES=yes + - rvm: 2.1.6 + env: PUPPET_GEM_VERSION='https://github.com/puppetlabs/puppet.git#stable + - rvm: 2.1.5 + env: PUPPET_GEM_VERSION='~> 3.0' FUTURE_PARSER=yes + - rvm: 2.1.5 + env: PUPPET_GEM_VERSION='~> 3.0' + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION='~> 3.0' notifications: email: false diff --git a/Gemfile b/Gemfile index 189b7c5..df38e07 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,41 @@ -source 'https://rubygems.org' - -puppetversion = ENV.key?('PUPPET_GEM_VERSION') ? "#{ENV['PUPPET_GEM_VERSION']}" : ['>= 3.3'] -facterversion = ENV.key?('FACTER_GEM_VERSION') ? "#{ENV['FACTER_GEM_VERSION']}" : ['>= 1.7'] -gem 'puppet', puppetversion -gem 'puppetlabs_spec_helper', '>= 0.1.0' -gem 'puppet-lint', '>= 0.3.2' -gem 'facter', facterversion -gem 'rspec', '< 3.2.0' +source ENV['GEM_SOURCE'] || "https://rubygems.org" + +def location_for(place, version = nil) + if place =~ /^((?:git|https?)[:@][^#]*)#(.*)/ + [version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, version, { :require => false }].compact + end +end + +gem 'puppetlabs_spec_helper', '>= 0.1.0', :require => false +gem 'puppet-lint', '>= 0.3.2', :require => false +gem 'rspec-puppet', '>= 2.3.2', :require => false +gem 'rspec-puppet-facts', :require => false +gem 'metadata-json-lint', :require => false +# rubi <1.9 versus rake 11.0.0 workaround +gem 'rake', '< 11.0.0', :require => false if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0') +gem 'json', '< 2.0.0', :require => false if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0') +gem 'json_pure', '<= 2.0.1', :require => false if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0') + +gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION']) + +# Only explicitly specify Facter/Hiera if a version has been specified. +# Otherwise it can lead to strange bundler behavior. If you are seeing weird +# gem resolution behavior, try setting `DEBUG_RESOLVER` environment variable +# to `1` and then run bundle install. +gem 'facter', *location_for(ENV['FACTER_GEM_VERSION']) if ENV['FACTER_GEM_VERSION'] +gem 'hiera', *location_for(ENV['HIERA_GEM_VERSION']) if ENV['HIERA_GEM_VERSION'] + + +# Evaluate Gemfile.local if it exists +if File.exists? "#{__FILE__}.local" + eval(File.read("#{__FILE__}.local"), binding) +end + +# Evaluate ~/.gemfile if it exists +if File.exists?(File.join(Dir.home, '.gemfile')) + eval(File.read(File.join(Dir.home, '.gemfile')), binding) +end diff --git a/Rakefile b/Rakefile index 505cb2d..211feeb 100644 --- a/Rakefile +++ b/Rakefile @@ -9,13 +9,12 @@ PuppetLint.configuration.send('disable_class_inherits_from_params_class') PuppetLint.configuration.send('disable_class_parameter_defaults') PuppetLint.configuration.send('disable_documentation') PuppetLint.configuration.send('disable_single_quote_string_with_variables') -PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] +PuppetLint.configuration.send('disable_variable_is_lowercase') +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp", "vendor/**/*.pp"] desc "Validate manifests, templates, and ruby files in lib." task :validate do - Dir['manifests/**/*.pp'].each do |manifest| - sh "puppet parser validate --noop #{manifest}" - end + sh "puppet parser validate --noop #{Dir['manifests/**/*.pp'].join(" ")}" Dir['lib/**/*.rb'].each do |lib_file| sh "ruby -c #{lib_file}" end diff --git a/manifests/install.pp b/manifests/install.pp index 6e9fd45..afffbc4 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -37,11 +37,27 @@ before => Anchor['mongodb::install::end'] } - package { 'mongodb-package': + + case $::osfamily { + 'Debian': { + package { 'mongodb-package': ensure => $package_ensure, name => $::mongodb::repos::apt::package_name, require => $mongodb_10gen_package_require, before => [Anchor['mongodb::install::end']] + } + } + 'RedHat': { + package { 'mongodb-package': + ensure => $package_ensure, + name => $::mongodb::package_name, + require => $mongodb_10gen_package_require, + before => [Anchor['mongodb::install::end']] + } + } + default: { + fail("Unsupported OS ${::osfamily}") } + } } diff --git a/manifests/repos/yum.pp b/manifests/repos/yum.pp index d5e9100..3d43b45 100644 --- a/manifests/repos/yum.pp +++ b/manifests/repos/yum.pp @@ -8,11 +8,10 @@ # class mongodb::repos::yum { - yumrepo { 'mongodb_yum_repo': - descr => '10gen MongoDB Repo', - baseurl => 'http://downloads-distro.mongodb.org/repo/redhat/os/$basearch', - enabled => 1, - gpgcheck => 0; - } - + yumrepo { 'mongodb_yum_repo': + enabled => 1, + descr => '10gen MongoDB Repo', + baseurl => 'http://downloads-distro.mongodb.org/repo/redhat/os/$basearch', + gpgcheck => 0; + } } diff --git a/spec/classes/mongodb_spec.rb b/spec/classes/mongodb_spec.rb index d3cae76..a4454ce 100644 --- a/spec/classes/mongodb_spec.rb +++ b/spec/classes/mongodb_spec.rb @@ -1,20 +1,29 @@ require 'spec_helper' -describe 'mongodb' do +describe 'mongodb', :type => 'class' do context 'Unsupported OS' do - let(:facts) {{ :osfamily => 'unsupported' }} - it { expect { should contain_class('mongodb')}.to raise_error(Puppet::Error, /Unsupported OS/ )} + let(:facts) {{ :osfamily => 'unsupported', :operatingsystem => 'UnknownOS' }} + it { is_expected.to raise_error(Puppet::Error,/Unsupported OS/ )} end - context 'with defaults for all parameters on RedHat' do - let(:facts) {{ :osfamily => 'RedHat' }} - it { should contain_class('mongodb') } - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + let :pre_condition do + 'include ::mongodb' + end - context 'with defaults for all parameters on Debian' do - let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'ubuntu' }} - it { should contain_class('mongodb') } + case facts[:osfamily] + when 'Debian' then + it { should contain_class('mongodb') } + when 'RedHat' then + it { should contain_class('mongodb') } + else + it { is_expected.to raise_error(Puppet::Error,/Unsupported OS/ )} + end + end end - end diff --git a/spec/defines/mongod_spec.rb b/spec/defines/mongod_spec.rb index 44689f5..9809e2b 100644 --- a/spec/defines/mongod_spec.rb +++ b/spec/defines/mongod_spec.rb @@ -6,6 +6,9 @@ context 'with defaults for all parameters on RedHat' do let(:facts) {{ :osfamily => 'RedHat' }} + let :pre_condition do + 'include ::mongodb::params' + end it { should contain_mongodb__mongod('testdb') } context 'with deactivate_transparent_hugepage set' do let(:params) {{ :mongod_deactivate_transparent_hugepage => true }} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3d92005..95c3db2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,11 @@ -require 'puppetlabs_spec_helper/module_spec_helper' \ No newline at end of file +if ENV['COVERAGE'] == 'yes' + RSpec.configure do |c| + c.after(:suite) do + RSpec::Puppet::Coverage.report! + end + end +end + +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts