Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #79 from cyberious/modules_4221
Browse files Browse the repository at this point in the history
MODULES-4221 - Allow boolean values to be passed
  • Loading branch information
bmjen authored Dec 13, 2016
2 parents 1c2e8c2 + 2a06bc5 commit 4e4498e
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 59 deletions.
42 changes: 20 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
101 changes: 67 additions & 34 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,53 +1,86 @@
#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')
gem 'fast_gettext', '1.1.0', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.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
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/puppet/type/git_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/defines/git_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 15 additions & 1 deletion spec/unit/puppet/type/git_config/git_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -46,4 +60,4 @@

end

end
end

0 comments on commit 4e4498e

Please sign in to comment.