From dd16c46b2b42305dfe1b9b8f86bbcef3979142f6 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 13 Dec 2016 11:04:48 -0800 Subject: [PATCH 1/5] MODULES-4221 - Allow boolean values to be passed - Currently have to quote all boolean values in order to pass validation of empty? this fix adds a check to ensure the value type responds to empty? --- lib/puppet/type/git_config.rb | 4 +++- spec/defines/git_config_spec.rb | 20 +++++++++++++++++++ .../puppet/type/git_config/git_config_spec.rb | 16 ++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/puppet/type/git_config.rb b/lib/puppet/type/git_config.rb index 55c330e..242dc07 100644 --- a/lib/puppet/type/git_config.rb +++ b/lib/puppet/type/git_config.rb @@ -28,7 +28,9 @@ DOC validate do - fail('it is required to pass "value"') if self[:value].nil? || self[:value].empty? || self[:value] == :absent + if self[:value].nil? || (self[:value].respond_to?(:empty?) && self[:value].empty?) || self[:value] == :absent + fail('it is required to pass "value"') + end warning('Parameter `section` is deprecated, supply the full option name (e.g. "user.email") in the `key` parameter') if self[:section] && !self[:section].empty? end diff --git a/spec/defines/git_config_spec.rb b/spec/defines/git_config_spec.rb index 4149fc7..177f29c 100644 --- a/spec/defines/git_config_spec.rb +++ b/spec/defines/git_config_spec.rb @@ -34,4 +34,24 @@ have_git_config_resource_count(1) end end + context 'allow boolean values' do + let(:title) { 'core.preloadindex' } + let(:params) { + { + :value => true, + :scope => 'system', + } + } + it { + is_expected.to compile + } + it { + is_expected.to contain_git_config(title).with( + { + 'value' => params[:value], + 'scope' => params[:scope], + } + ) + } + end end diff --git a/spec/unit/puppet/type/git_config/git_config_spec.rb b/spec/unit/puppet/type/git_config/git_config_spec.rb index 0fd2685..8a70786 100644 --- a/spec/unit/puppet/type/git_config/git_config_spec.rb +++ b/spec/unit/puppet/type/git_config/git_config_spec.rb @@ -18,6 +18,20 @@ @class.key_attributes.should == [:name] end + describe "should fail when value is empty string" do + let(:params) { + { + name: 'core.preloadindex', + value: '' + } + } + it { + expect{ + Puppet::Type.type(:git_config).new(params) + }.to raise_error(Puppet::ResourceError, /it is required to pass "value"/) + } + end + describe "when validating attributes" do params = [ @@ -46,4 +60,4 @@ end -end \ No newline at end of file +end From 83cae677432a787b9b435a713f736022f9304767 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 13 Dec 2016 11:42:12 -0800 Subject: [PATCH 2/5] Copy gemfile from apt as there are many things that should have been caught with modulesync - A lot of ruby dependent issues need to be resolved include rake and fast_gettext --- Gemfile | 100 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 34 deletions(-) diff --git a/Gemfile b/Gemfile index b9665d6..f6a332a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,53 +1,85 @@ +#This file is generated by ModuleSync, do not edit. + source ENV['GEM_SOURCE'] || "https://rubygems.org" -def location_for(place, fake_version = nil) - if place =~ /^(git:[^#]*)#(.*)/ +# Determines what type of gem is requested based on place_or_version. +def gem_type(place_or_version) + if place_or_version =~ /^git:/ + :git + elsif place_or_version =~ /^file:/ + :file + else + :gem + end +end + +# Find a location or specific version for a gem. place_or_version can be a +# version, which is most often used. It can also be git, which is specified as +# `git://somewhere.git#branch`. You can also use a file source location, which +# is specified as `file://some/location/on/disk`. +def location_for(place_or_version, fake_version = nil) + if place_or_version =~ /^(git[:@][^#]*)#(.*)/ [fake_version, { :git => $1, :branch => $2, :require => false }].compact - elsif place =~ /^file:\/\/(.*)/ + elsif place_or_version =~ /^file:\/\/(.*)/ ['>= 0', { :path => File.expand_path($1), :require => false }] else - [place, { :require => false }] + [place_or_version, { :require => false }] end end -is_ruby18 = RUBY_VERSION.start_with? '1.8' +# Used for gem conditionals +supports_windows = false -group :development, :test do - gem 'rake', :require => false - if is_ruby18 - gem 'rspec', "~> 3.1.0", :require => false - end - gem 'rspec-puppet', :require => false - gem 'puppetlabs_spec_helper', :require => false - gem 'puppet-lint', :require => false - gem 'pry', :require => false - gem 'simplecov', :require => false - gem 'metadata-json-lint', :require => false +group :development do + gem 'puppet-lint', :require => false + gem 'metadata-json-lint', :require => false, :platforms => 'ruby' + gem 'puppet_facts', :require => false + gem 'puppet-blacksmith', '>= 3.4.0', :require => false, :platforms => 'ruby' + gem 'puppetlabs_spec_helper', '>= 1.2.1', :require => false + gem 'rspec-puppet', '>= 2.3.2', :require => false + gem 'rspec-puppet-facts', :require => false, :platforms => 'ruby' + gem 'mocha', '< 1.2.0', :require => false + gem 'simplecov', :require => false, :platforms => 'ruby' + gem 'parallel_tests', '< 2.10.0', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') + gem 'parallel_tests', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0') + gem 'rubocop', '0.41.2', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') + gem 'rubocop', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0') + gem 'rubocop-rspec', '~> 1.6', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0') + gem 'pry', :require => false + gem 'json_pure', '<= 2.0.1', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') end -beaker_version = ENV['BEAKER_VERSION'] group :system_tests do - gem 'serverspec', :require => false - if beaker_version - gem 'beaker', *location_for(beaker_version) - else - gem 'beaker', :require => false - end - gem 'beaker-rspec', :require => false + gem 'beaker', *location_for(ENV['BEAKER_VERSION'] || '~> 2.20') if supports_windows + gem 'beaker', *location_for(ENV['BEAKER_VERSION']) if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0') and ! supports_windows + gem 'beaker', *location_for(ENV['BEAKER_VERSION'] || '< 3') if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.3.0') and ! supports_windows + gem 'beaker-pe', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0') + gem 'beaker-rspec', *location_for(ENV['BEAKER_RSPEC_VERSION'] || '>= 3.4') if ! supports_windows + gem 'beaker-rspec', *location_for(ENV['BEAKER_RSPEC_VERSION'] || '~> 5.1') if supports_windows + gem 'beaker-puppet_install_helper', :require => false + gem 'master_manipulator', :require => false + gem 'beaker-hostgenerator', *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION']) + gem 'beaker-abs', *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1') end -facter_version = ENV['FACTER_GEM_VERSION'] -if facter_version - gem 'facter', *location_for(facter_version) -else - gem 'facter', :require => false +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 -puppet_version = ENV['PUPPET_GEM_VERSION'] -if puppet_version - gem 'puppet', *location_for(puppet_version) -else - gem 'puppet', :require => false +# Evaluate ~/.gemfile if it exists +if File.exists?(File.join(Dir.home, '.gemfile')) + eval(File.read(File.join(Dir.home, '.gemfile')), binding) end # vim:ft=ruby From 79b7820100143985783e3cfeabe4e461f9b7f895 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 13 Dec 2016 11:45:55 -0800 Subject: [PATCH 3/5] Copy trimmed down, non docker .travis.yml config from apt --- .travis.yml | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index ca0091d..f02a626 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,29 @@ +#This file is generated by ModuleSync, do not edit. --- +sudo: false language: ruby - -bundler_args: '--without development system_tests' - +cache: bundler +script: "bundle exec rake validate lint spec" +#Inserting below due to the following issue: https://github.com/travis-ci/travis-ci/issues/3531#issuecomment-88311203 before_install: - - 'gem update --system' - - 'gem update bundler' - -script: "SPEC_OPTS='--format documentation' bundle exec rake validate lint spec" - + - gem update bundler matrix: fast_finish: true include: - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 1.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 2.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 1.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 2.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 1.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 2.0" - rvm: 2.3.1 - env: PUPPET_GEM_VERSION="~> 4" FACTER_GEM_VERSION="~> 2.0" - + bundler_args: --without system_tests + env: PUPPET_GEM_VERSION="~> 4.0" + - rvm: 2.1.9 + bundler_args: --without system_tests + env: PUPPET_GEM_VERSION="~> 4.0" + - rvm: 2.1.5 + bundler_args: --without system_tests + env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" + - rvm: 2.1.5 + bundler_args: --without system_tests + env: PUPPET_GEM_VERSION="~> 3.0" + - rvm: 1.9.3 + bundler_args: --without system_tests + env: PUPPET_GEM_VERSION="~> 3.0" notifications: email: false From 1e70bb38be6a48d2fbb75e1b33f8accfa40cbcbf Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 13 Dec 2016 12:39:55 -0800 Subject: [PATCH 4/5] Pin fast_gettext for ruby < 2.1.0 --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index f6a332a..893c169 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,7 @@ group :development do gem 'rubocop-rspec', '~> 1.6', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0') gem 'pry', :require => false gem 'json_pure', '<= 2.0.1', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') + gem 'fast_gettext', '1.1.0', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') end group :system_tests do From 2a06bc590964abd6d8813aa2102cfacae2a02424 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 13 Dec 2016 12:49:09 -0800 Subject: [PATCH 5/5] Ignore vendor path for any puppet code when running lint --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index f2f0456..3c8b131 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ require 'puppet-lint/tasks/puppet-lint' PuppetLint.configuration.send('disable_80chars') PuppetLint.configuration.send('disable_140chars') PuppetLint.configuration.relative = true -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