From c129b66d570d37a5c0ef0e499b0f046ca4657c66 Mon Sep 17 00:00:00 2001 From: vagrant Date: Tue, 26 Apr 2016 12:08:31 -0700 Subject: [PATCH 1/9] Add spec tests --- .fixtures.yml | 17 ++++++----- Gemfile | 34 +++++++++++++++------- manifests/init.pp | 4 +++ metadata.json | 4 +-- spec/classes/init_spec.rb | 60 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 19 deletions(-) create mode 100644 spec/classes/init_spec.rb diff --git a/.fixtures.yml b/.fixtures.yml index 7fa5bb4..4cc9072 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,10 +1,13 @@ fixtures: repositories: - "puppi": "git://github.com/example42/puppi.git" - "monitor": "git://github.com/example42/puppet-monitor.git" - "firewall": "git://github.com/example42/puppet-firewall.git" - "iptables": "git://github.com/example42/puppet-iptables.git" - "concat": "git://github.com/example42/puppet-concat.git" + concat: + repo: 'https://github.com/puppetlabs/puppetlabs-concat.git' + ref: '2.1.0' + puppi: + repo: 'https://github.com/example42/puppi.git' + ref: 'v2.1.13' + stdlib: + repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' + ref: '4.6.0' symlinks: - "java": "#{source_dir}" - + java: "#{source_dir}" diff --git a/Gemfile b/Gemfile index be1c34c..9d19ada 100644 --- a/Gemfile +++ b/Gemfile @@ -1,18 +1,32 @@ source 'https://rubygems.org' -puppetversion = ENV['PUPPET_VERSION'] +if puppetversion = ENV['PUPPET_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end -is_ruby18 = RUBY_VERSION.start_with? '1.8' +gem 'metadata-json-lint' +gem 'puppetlabs_spec_helper', '>= 1.1.1' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' +gem 'puppet-lint', :git => 'https://github.com/rodjek/puppet-lint.git' +gem 'puppet-lint-absolute_classname-check' +gem 'puppet-lint-alias-check' +gem 'puppet-lint-file_ensure-check' +gem 'puppet-lint-file_source_rights-check' +gem 'puppet-lint-leading_zero-check' +gem 'puppet-lint-spaceship_operator_without_tag-check' +gem 'puppet-lint-trailing_comma-check' +gem 'puppet-lint-unquoted_string-check' +gem 'puppet-lint-variable_contains_upcase' -if is_ruby18 - gem 'rspec', "~> 3.1.0", :require => false - gem 'rake', '~> 10.5.0', :require => false +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9' + # rake >=11 does not support ruby 1.8.7 + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' end -gem 'puppet', puppetversion, :require => false -gem 'puppet-lint' -gem 'puppetlabs_spec_helper', '>= 0.1.0' -gem 'rspec-puppet' -gem 'metadata-json-lint' group :development do gem 'puppet-blacksmith' diff --git a/manifests/init.pp b/manifests/init.pp index 2de6b57..f252327 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -29,6 +29,10 @@ default => 'present', } + validate_absolute_path($java_home_base) + + validate_string($version) + $headless_suffix = $java::bool_headless ? { true => '-headless', default => '', diff --git a/metadata.json b/metadata.json index e16e237..222385d 100644 --- a/metadata.json +++ b/metadata.json @@ -59,11 +59,11 @@ }, { "name": "example42/puppi", - "version_requirement": ">= 2.0.0" + "version_requirement": ">= 2.0.0 < 3.0.0" }, { "name": "puppetlabs/concat", - "version_requirement": ">= 1.0.0" + "version_requirement": ">= 1.0.0 < 2.0.0" } ] } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..2cdf5ba --- /dev/null +++ b/spec/classes/init_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + + describe 'java' do + let(:facts) do + { :osfamily => 'Debian', + :operatingsystemmajrelease => '6', + } + end + + context 'with defaults for all parameters' do + it { should contain_class('java') } + + it { should compile.with_all_deps } + end + + describe 'variable type and content validations' do + let(:validation_params) do + { + #:param => 'value', + } + end + + validations = { + 'absolute_path' => { + :name => ['java_home_base'], + :valid => ['/usr/lib/jvm'], + :invalid => ['invalid',3,2.42,['array'],a={'ha'=>'sh'}], + :message => 'is not an absolute path', + }, + 'version' => { + :name => ['version'] , + :valid => ['6'], + :invalid => [['array'],a={'ha'=>'sh'}, true], + :message => 'is not a string', + }, + } + + validations.sort.each do |type, var| + var[:name].each do |var_name| + var[:valid].each do |valid| + context "with #{var_name} (#{type}) set to valid #{valid} (as #{valid.class})" do + let(:params) { validation_params.merge({ :"#{var_name}" => valid, }) } + it { should compile } + end + end + + var[:invalid].each do |invalid| + context "with #{var_name} (#{type}) set to invalid #{invalid} (as #{invalid.class})" do + let(:params) { validation_params.merge({ :"#{var_name}" => invalid, }) } + it 'should fail' do + expect do + should contain_class(subject) + end.to raise_error(Puppet::Error, /#{var[:message]}/) + end + end + end + end # var[:name].each + end # validations.sort.each + end # describe +end From e57eab7a6d462f825dc4d67ddd1446c6b72bd028 Mon Sep 17 00:00:00 2001 From: krishnadonepudi Date: Tue, 26 Apr 2016 14:00:55 -0700 Subject: [PATCH 2/9] Comply with community style plugins --- manifests/install.pp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index f4bdf3f..e9d8693 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -58,7 +58,7 @@ case $install { - package: { + 'package': { $headless_suffix = $bool_headless ? { true => '-headless', @@ -86,7 +86,7 @@ /(?i:Solaris)/ => $::operatingsystemmajrelease ? { '10' => "CSWjdk${version}", '11' => "jdk-${version}", - '5' => "jdk", + '5' => 'jdk', }, default => fail("OperatingSystem ${::operatingsystem} not supported"), } @@ -108,7 +108,7 @@ } - source: { + 'source': { if (!$install_source) { fail('Required arguement: install_source') } From d03ba706d4407f63e67a3231602276a52c84618a Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Fri, 29 Apr 2016 14:39:42 -0400 Subject: [PATCH 3/9] removing requiring rubygems as it is unnecessary --- Rakefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Rakefile b/Rakefile index 1a8a8a0..87c22c5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,3 @@ -require 'rubygems' require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint' PuppetLint.configuration.send("disable_80chars") From 55438380bdfa3adbe4e0b7d06ef19e51bc89c27e Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Fri, 29 Apr 2016 14:41:11 -0400 Subject: [PATCH 4/9] Use standard puppet-lint configuration --- Rakefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 87c22c5..f6da6e7 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,7 @@ require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint' +require 'puppet-lint/tasks/puppet-lint' PuppetLint.configuration.send("disable_80chars") +PuppetLint.configuration.send("disable_140chars") PuppetLint.configuration.send('disable_class_parameter_defaults') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] From 641758ab11d163dd9024e0f49d86faee8b7cd0c1 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Fri, 29 Apr 2016 14:46:25 -0400 Subject: [PATCH 5/9] Depend on stdlib >= 4.6.0 --- metadata.json | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/metadata.json b/metadata.json index 222385d..ba2de55 100644 --- a/metadata.json +++ b/metadata.json @@ -4,8 +4,6 @@ "summary": "Puppet module to manage Java", "license": "Apache-2.0", "author": "Alessandro Franceschi, Martin Alfke", - "checksums": { - }, "source": "https://github.com/example42/puppet-java", "project_page": "https://github.com/example42/puppet-java", "issues_url": "https://github.com/example42/puppet-java/issues", @@ -43,27 +41,12 @@ } ], "requirements": [ - { - "name": "pe", - "version_requirement": ">= 3.0.0 < 5.0.0" - }, - { - "name": "puppet", - "version_requirement": ">= 3.0.0 < 5.0.0" - } + { "name": "pe", "version_requirement": ">= 3.0.0 < 5.0.0" }, + { "name": "puppet", "version_requirement": ">= 3.0.0 < 5.0.0" } ], "dependencies": [ - { - "name": "puppetlabs/stdlib", - "version_requirement": ">= 3.2.0 < 5.0.0" - }, - { - "name": "example42/puppi", - "version_requirement": ">= 2.0.0 < 3.0.0" - }, - { - "name": "puppetlabs/concat", - "version_requirement": ">= 1.0.0 < 2.0.0" - } + { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.6.0 < 5.0.0" }, + { "name": "example42/puppi", "version_requirement": ">= 2.0.0 < 3.0.0" }, + { "name": "puppetlabs/concat", "version_requirement": ">= 1.0.0 < 2.0.0" } ] } From 093db60e74443b56bf140af70e8fe3d618da6049 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Fri, 29 Apr 2016 14:50:22 -0400 Subject: [PATCH 6/9] Support Ruby v2.0.0 and improve scope of testing --- .travis.yml | 70 ++++++++++++++++++++++++++++++++++++++--------------- Gemfile | 2 +- README.md | 25 ++++++++++++++----- 3 files changed, 70 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9f85bab..6fb0ec0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,61 @@ +--- language: ruby + bundler_args: --without development + rvm: - 1.8.7 - 1.9.3 - - 2.1.4 -script: - - "bundle exec rake lint spec SPEC_OPTS='--format documentation'" + - 2.0.0 + - 2.1.0 + env: - - PUPPET_VERSION="~> 2.7.0" - - PUPPET_VERSION="~> 3.0.0" - - PUPPET_VERSION="~> 3.1.0" - - PUPPET_VERSION="~> 3.8.0" - - PUPPET_VERSION="~> 4.2" + matrix: + - PUPPET_GEM_VERSION="~> 3.1.0" + - PUPPET_GEM_VERSION="~> 3.2.0" + - PUPPET_GEM_VERSION="~> 3.3.0" + - PUPPET_GEM_VERSION="~> 3.4.0" + - PUPPET_GEM_VERSION="~> 3.5.0" + - PUPPET_GEM_VERSION="~> 3.6.0" + - PUPPET_GEM_VERSION="~> 3.7.0" + - PUPPET_GEM_VERSION="~> 3.8.0" + - PUPPET_GEM_VERSION="~> 3" FUTURE_PARSER="yes" + - PUPPET_GEM_VERSION="~> 4.0.0" + - PUPPET_GEM_VERSION="~> 4.1.0" + - PUPPET_GEM_VERSION="~> 4.2.0" + - PUPPET_GEM_VERSION="~> 4.3.0" + - PUPPET_GEM_VERSION="~> 4.4.0" + - PUPPET_GEM_VERSION="~> 4" + +sudo: false + +script: 'bundle exec rake metadata_lint && bundle exec rake validate && bundle exec rake lint && SPEC_OPTS="--format documentation" bundle exec rake spec' + matrix: + fast_finish: true exclude: + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.1.0" + - rvm: 2.1.0 + env: PUPPET_GEM_VERSION="~> 3.1.0" + - rvm: 2.1.0 + env: PUPPET_GEM_VERSION="~> 3.2.0" + - rvm: 2.1.0 + env: PUPPET_GEM_VERSION="~> 3.3.0" + - rvm: 2.1.0 + env: PUPPET_GEM_VERSION="~> 3.4.0" - rvm: 1.8.7 - env: PUPPET_VERSION="~> 4.2" - - rvm: 1.9.3 - env: PUPPET_VERSION="~> 2.7.0" - - rvm: 2.1.4 - env: PUPPET_VERSION="~> 2.7.0" - - rvm: 2.1.4 - env: PUPPET_VERSION="~> 3.0.0" - - rvm: 2.1.4 - env: PUPPET_VERSION="~> 3.1.0" + env: PUPPET_GEM_VERSION="~> 4.0.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 4.1.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 4.2.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 4.3.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 4.4.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 4" -sudo: false notifications: - email: - - al@lab42.it + email: false diff --git a/Gemfile b/Gemfile index 9d19ada..b5c5871 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -if puppetversion = ENV['PUPPET_VERSION'] +if puppetversion = ENV['PUPPET_GEM_VERSION'] gem 'puppet', puppetversion, :require => false else gem 'puppet', :require => false diff --git a/README.md b/README.md index 6c6ddad..e21859f 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,25 @@ ####Table of Contents 1. [Overview](#overview) -2. [Setup](#setup) -3. [Usage](#usage) +1. [Compatibility](#compatibility) +1. [Setup](#setup) +1. [Usage](#usage) ##Overview This module installs java (JDK + JRE) versions +##Compatibility +Puppet v3 (with and without the future parser) and Puppet v4 with Ruby versions +1.8.7, 1.9.3, 2.0.0 and 2.1.0 where supported by Puppet. + +* Debian 6 +* EL 6 +* Solaris 10 +* Solaris 11 +* Ubuntu 14.04 + ##Setup ###Setup Requirements @@ -23,10 +34,12 @@ This module installs java (JDK + JRE) versions The main class is used only. - class { 'java': - jdk => false, # default - whether to install the jdk or the jre only - version => '6', # Java version to install - } +```puppet +class { 'java': + jdk => false, # default - whether to install the jdk or the jre only + version => '6', # Java version to install +} +``` ##Development From 08f77167bc29ab4bdfb346009fa28ed0134ecc18 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Fri, 29 Apr 2016 15:08:09 -0400 Subject: [PATCH 7/9] Comply with style --- manifests/install.pp | 22 +++++++++------------- manifests/params.pp | 6 +++--- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index e9d8693..2bf1ef6 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -21,7 +21,7 @@ # [*package*] # Name of the package to install (when install='package'). If not default it's # automatically defined for the operatingsystem -# Default: '' +# Default: undef # # [*package_source*] # Source from where to retrieve the defined package. Use a url. @@ -44,8 +44,8 @@ $version = '7', $headless = true, $install = 'package', - $install_source = '', - $package = '', + $install_source = undef, + $package = undef, $package_source = undef, $package_responsefile = undef, $package_provider = undef, @@ -59,13 +59,12 @@ case $install { 'package': { - $headless_suffix = $bool_headless ? { true => '-headless', default => '', } $real_package = $package ? { - '' => $bool_jdk ? { + undef => $bool_jdk ? { false => $::operatingsystem ? { /(?i:RedHat|Centos|Fedora|Scientific|Amazon|Linux)/ => "java-1.${version}.0-openjdk", /(?i:Ubuntu|Debian|Mint)/ => "openjdk-${version}-jre${headless_suffix}", @@ -78,7 +77,7 @@ }, default => fail("OperatingSystem ${::operatingsystem} not supported"), }, - true => $::operatingsystem ? { + true => $::operatingsystem ? { /(?i:RedHat|Centos|Fedora|Scientific|Amazon|Linux)/ => "java-1.${version}.0-openjdk-devel", /(?i:Ubuntu|Debian|Mint)/ => "openjdk-${version}-jdk", /(?i:SLES)/ => "java-1_${version}_0-ibm", @@ -88,7 +87,7 @@ '11' => "jdk-${version}", '5' => 'jdk', }, - default => fail("OperatingSystem ${::operatingsystem} not supported"), + default => fail("OperatingSystem ${::operatingsystem} not supported"), } }, default => $package, @@ -105,9 +104,7 @@ responsefile => $package_responsefile, provider => $package_provider, } - } - 'source': { if (!$install_source) { fail('Required arguement: install_source') @@ -130,10 +127,9 @@ target => $created_dir, require => Puppi::Netinstall["netinstall_java_${name}"], } - } - - default: { } - + default: { + fail("java::install::${name}::install is <${install}> and must be 'package' or 'source'.") + } } } diff --git a/manifests/params.pp b/manifests/params.pp index 3da1fc3..c730c6f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -34,11 +34,11 @@ # Real package names are computed in java class - $package = '' - $package_jdk = '' + $package = undef + $package_jdk = undef # General Settings - $my_class = '' + $my_class = undef $absent = false $puppi = false $puppi_helper = 'standard' From 6fac2b279b619ddd9990561662535c98c35284cd Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Fri, 29 Apr 2016 15:50:58 -0400 Subject: [PATCH 8/9] improve type validation --- manifests/init.pp | 49 ++++++++++++----------- manifests/install.pp | 4 +- manifests/params.pp | 7 ---- spec/classes/init_spec.rb | 83 +++++++++++++++++++++++---------------- 4 files changed, 76 insertions(+), 67 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index f252327..9876a63 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -19,71 +19,73 @@ $bool_jdk=any2bool($jdk) $bool_debug=any2bool($debug) + if $package != undef { validate_string($package) } + if $package_jdk != undef { validate_string($package_jdk) } + ### Definition of some variables used in the module - $manage_package = $java::bool_absent ? { + $manage_package = $bool_absent ? { true => 'absent', false => 'present', } - $manage_file = $java::bool_absent ? { + $manage_file = $bool_absent ? { true => 'absent', default => 'present', } validate_absolute_path($java_home_base) - validate_string($version) - $headless_suffix = $java::bool_headless ? { + $headless_suffix = $bool_headless ? { true => '-headless', default => '', } $real_package = $package ? { - '' => $::operatingsystem ? { + '' => $::operatingsystem ? { /(?i:Ubuntu|Debian|Mint)/ => "openjdk-${version}-jre${headless_suffix}", /(?i:SLES)/ => "java-1_${version}_0-ibm", /(?i:OpenSuSE)/ => "java-1_${version}_0-openjdk", - /(?i:Solaris)/ => $::operatingsystemmajrelease ? { - '10' => "CSWjre${version}", - '11' => "jre-${version}", - '5' => "jre-${version}", + /(?i:Solaris)/ => $::operatingsystemmajrelease ? { + '10' => "CSWjre${version}", + '11' => "jre-${version}", + '5' => "jre-${version}", }, - default => "java-1.${version}.0-openjdk", + default => "java-1.${version}.0-openjdk", }, default => $package, } $real_package_jdk = $package_jdk ? { - '' => $::operatingsystem ? { + '' => $::operatingsystem ? { /(?i:Ubuntu|Debian|Mint)/ => "openjdk-${version}-jdk", /(?i:SLES)/ => "java-1_${version}_0-ibm", /(?i:OpenSuSE)/ => "java-1_${version}_0-openjdk-devel", - /(?i:Solaris)/ => $::operatingsystemmajrelease ? { - '10' => "CSWjdk${version}", - '11' => "jdk-${version}", - '5' => "jdk-${version}", + /(?i:Solaris)/ => $::operatingsystemmajrelease ? { + '10' => "CSWjdk${version}", + '11' => "jdk-${version}", + '5' => "jdk-${version}", }, - default => "java-1.${version}.0-openjdk-devel", + default => "java-1.${version}.0-openjdk-devel", }, default => $package_jdk, } ### Managed resources package { 'java': - ensure => $java::manage_package, - name => $java::real_package, + ensure => $manage_package, + name => $real_package, } - if $java::bool_jdk == true { + if $bool_jdk == true { package { 'java-jdk': - ensure => $java::manage_package, - name => $java::real_package_jdk, + ensure => $manage_package, + name => $real_package_jdk, } } ### Debugging, if enabled ( debug => true ) - if $java::bool_debug == true { + if $bool_debug == true { file { 'debug_java': - ensure => $java::manage_file, + ensure => $manage_file, path => "${settings::vardir}/debug-java", mode => '0640', owner => 'root', @@ -96,5 +98,4 @@ if $java::my_class { include $java::my_class } - } diff --git a/manifests/install.pp b/manifests/install.pp index 2bf1ef6..beb4f03 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -64,7 +64,7 @@ default => '', } $real_package = $package ? { - undef => $bool_jdk ? { + '' => $bool_jdk ? { false => $::operatingsystem ? { /(?i:RedHat|Centos|Fedora|Scientific|Amazon|Linux)/ => "java-1.${version}.0-openjdk", /(?i:Ubuntu|Debian|Mint)/ => "openjdk-${version}-jre${headless_suffix}", @@ -73,7 +73,7 @@ /(?i:Solaris)/ => $::operatingsystemmajrelease ? { '10' => "CSWjre${version}", '11' => "jre-${version}", - '5' => undef, + '5' => '', }, default => fail("OperatingSystem ${::operatingsystem} not supported"), }, diff --git a/manifests/params.pp b/manifests/params.pp index c730c6f..e45726c 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -32,16 +32,9 @@ default => '/usr/lib/jvm', } - - # Real package names are computed in java class - $package = undef - $package_jdk = undef - # General Settings - $my_class = undef $absent = false $puppi = false $puppi_helper = 'standard' $debug = false - } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 2cdf5ba..b70b073 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -13,48 +13,63 @@ it { should compile.with_all_deps } end - describe 'variable type and content validations' do - let(:validation_params) do + + describe 'variable type and content validations' do + # set needed custom facts and variables + let(:facts) do + { + :operatingsystem => 'Ubuntu', + :operatingsystemrelease => '14.04', + } + end + let(:mandatory_params) do { #:param => 'value', } - end + end + + validations = { + 'absolute_path' => { + :name => %w(java_home_base), + :valid => ['/absolute/filepath', '/absolute/directory/', %w(/array /with_paths)], + :invalid => ['../invalid', 3, 2.42, %w(array), { 'ha' => 'sh' }, true, false, nil], + :message => 'is not an absolute path', + }, + 'string' => { + :name => %w(package package_jdk version), + :valid => ['string'], + :invalid => [%w(array), { 'ha' => 'sh' }, 3, 2.42, true, false], + :params => { :jdk => true }, + :message => 'is not a string', + }, + 'bool_stringified' => { + :name => %w(jdk headless absent debug), + #:valid => [true, false, 'true', 'false'], + :valid => [true, false], + :invalid => ['invalid', %w(array), { 'ha' => 'sh' }, 3, 2.42, nil], + :message => '(Unknown type of boolean|str2bool\(\): Requires either string to work with)', + }, + } + + validations.sort.each do |type, var| + var[:name].each do |var_name| + var[:params] = {} if var[:params].nil? + var[:valid].each do |valid| + context "when #{var_name} (#{type}) is set to valid #{valid} (as #{valid.class})" do + let(:params) { [mandatory_params, var[:params], { :"#{var_name}" => valid, }].reduce(:merge) } + it { should compile } + end + end - validations = { - 'absolute_path' => { - :name => ['java_home_base'], - :valid => ['/usr/lib/jvm'], - :invalid => ['invalid',3,2.42,['array'],a={'ha'=>'sh'}], - :message => 'is not an absolute path', - }, - 'version' => { - :name => ['version'] , - :valid => ['6'], - :invalid => [['array'],a={'ha'=>'sh'}, true], - :message => 'is not a string', - }, - } - - validations.sort.each do |type, var| - var[:name].each do |var_name| - var[:valid].each do |valid| - context "with #{var_name} (#{type}) set to valid #{valid} (as #{valid.class})" do - let(:params) { validation_params.merge({ :"#{var_name}" => valid, }) } - it { should compile } - end - end - - var[:invalid].each do |invalid| - context "with #{var_name} (#{type}) set to invalid #{invalid} (as #{invalid.class})" do - let(:params) { validation_params.merge({ :"#{var_name}" => invalid, }) } + var[:invalid].each do |invalid| + context "when #{var_name} (#{type}) is set to invalid #{invalid} (as #{invalid.class})" do + let(:params) { [mandatory_params, var[:params], { :"#{var_name}" => invalid, }].reduce(:merge) } it 'should fail' do - expect do - should contain_class(subject) - end.to raise_error(Puppet::Error, /#{var[:message]}/) + expect { should contain_class(subject) }.to raise_error(Puppet::Error, /#{var[:message]}/) end end end end # var[:name].each end # validations.sort.each - end # describe + end # describe 'variable type and content validations' end From 5e075dc816ce2e6016a5c92e76b0551be44f0b11 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Fri, 29 Apr 2016 15:55:29 -0400 Subject: [PATCH 9/9] revert '' changes in install --- manifests/install.pp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index beb4f03..d9bdcfd 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -16,12 +16,12 @@ # Installation method ('package' or 'source'). Default 'package'. # # [*install_source*] -# Source URL (when install='source'). Not default. +# Source URL (when install='source'). Default: '' # # [*package*] # Name of the package to install (when install='package'). If not default it's # automatically defined for the operatingsystem -# Default: undef +# Default: '' # # [*package_source*] # Source from where to retrieve the defined package. Use a url. @@ -44,8 +44,8 @@ $version = '7', $headless = true, $install = 'package', - $install_source = undef, - $package = undef, + $install_source = '', + $package = '', $package_source = undef, $package_responsefile = undef, $package_provider = undef,