Skip to content
This repository was archived by the owner on Jun 11, 2019. It is now read-only.

Add spec tests #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -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}"
34 changes: 24 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
default => 'present',
}

validate_absolute_path($java_home_base)

validate_string($version)

$headless_suffix = $java::bool_headless ? {
true => '-headless',
default => '',
Expand Down
6 changes: 3 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

case $install {

package: {
'package': {

$headless_suffix = $bool_headless ? {
true => '-headless',
Expand Down Expand Up @@ -86,7 +86,7 @@
/(?i:Solaris)/ => $::operatingsystemmajrelease ? {
'10' => "CSWjdk${version}",
'11' => "jdk-${version}",
'5' => "jdk",
'5' => 'jdk',
},
default => fail("OperatingSystem ${::operatingsystem} not supported"),
}
Expand All @@ -108,7 +108,7 @@

}

source: {
'source': {
if (!$install_source) {
fail('Required arguement: install_source')
}
Expand Down
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
60 changes: 60 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -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