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

Commit 4924ded

Browse files
vagrantkrishnadonepudi
authored andcommitted
Add spec tests
1 parent 56224cf commit 4924ded

File tree

5 files changed

+101
-19
lines changed

5 files changed

+101
-19
lines changed

.fixtures.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
fixtures:
22
repositories:
3-
"puppi": "git://github.com/example42/puppi.git"
4-
"monitor": "git://github.com/example42/puppet-monitor.git"
5-
"firewall": "git://github.com/example42/puppet-firewall.git"
6-
"iptables": "git://github.com/example42/puppet-iptables.git"
7-
"concat": "git://github.com/example42/puppet-concat.git"
3+
concat:
4+
repo: 'https://github.com/puppetlabs/puppetlabs-concat.git'
5+
ref: '2.1.0'
6+
puppi:
7+
repo: 'https://github.com/example42/puppi.git'
8+
ref: 'v2.1.13'
9+
stdlib:
10+
repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git'
11+
ref: '4.6.0'
812
symlinks:
9-
"java": "#{source_dir}"
10-
13+
java: "#{source_dir}"

Gemfile

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
source 'https://rubygems.org'
22

3-
puppetversion = ENV['PUPPET_VERSION']
3+
if puppetversion = ENV['PUPPET_VERSION']
4+
gem 'puppet', puppetversion, :require => false
5+
else
6+
gem 'puppet', :require => false
7+
end
48

5-
is_ruby18 = RUBY_VERSION.start_with? '1.8'
9+
gem 'metadata-json-lint'
10+
gem 'puppetlabs_spec_helper', '>= 1.1.1'
11+
gem 'facter', '>= 1.7.0'
12+
gem 'rspec-puppet'
13+
gem 'puppet-lint', :git => 'https://github.com/rodjek/puppet-lint.git'
14+
gem 'puppet-lint-absolute_classname-check'
15+
gem 'puppet-lint-alias-check'
16+
gem 'puppet-lint-empty_string-check'
17+
gem 'puppet-lint-file_ensure-check'
18+
gem 'puppet-lint-file_source_rights-check'
19+
gem 'puppet-lint-leading_zero-check'
20+
gem 'puppet-lint-spaceship_operator_without_tag-check'
21+
gem 'puppet-lint-trailing_comma-check'
22+
gem 'puppet-lint-unquoted_string-check'
23+
gem 'puppet-lint-variable_contains_upcase'
624

7-
if is_ruby18
8-
gem 'rspec', "~> 3.1.0", :require => false
9-
gem 'rake', '~> 10.5.0', :require => false
25+
# rspec must be v2 for ruby 1.8.7
26+
if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
27+
# rake >=11 does not support ruby 1.8.7
28+
gem 'rspec', '~> 2.0'
29+
gem 'rake', '~> 10.0'
1030
end
11-
gem 'puppet', puppetversion, :require => false
12-
gem 'puppet-lint'
13-
gem 'puppetlabs_spec_helper', '>= 0.1.0'
14-
gem 'rspec-puppet'
15-
gem 'metadata-json-lint'
1631

1732
group :development do
1833
gem 'puppet-blacksmith'

manifests/init.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
default => 'present',
3030
}
3131

32+
validate_absolute_path($java_home_base)
33+
34+
validate_string($version)
35+
3236
$headless_suffix = $java::bool_headless ? {
3337
true => '-headless',
3438
default => '',

metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
},
6060
{
6161
"name": "example42/puppi",
62-
"version_requirement": ">= 2.0.0"
62+
"version_requirement": ">= 2.0.0 < 3.0.0"
6363
},
6464
{
6565
"name": "puppetlabs/concat",
66-
"version_requirement": ">= 1.0.0"
66+
"version_requirement": ">= 1.0.0 < 2.0.0"
6767
}
6868
]
6969
}

spec/classes/init_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
require 'spec_helper'
2+
3+
describe 'java' do
4+
let(:facts) do
5+
{ :osfamily => 'Debian',
6+
:operatingsystemmajrelease => '6',
7+
}
8+
end
9+
10+
context 'with defaults for all parameters' do
11+
it { should contain_class('java') }
12+
13+
it { should compile.with_all_deps }
14+
end
15+
16+
describe 'variable type and content validations' do
17+
let(:validation_params) do
18+
{
19+
#:param => 'value',
20+
}
21+
end
22+
23+
validations = {
24+
'absolute_path' => {
25+
:name => ['java_home_base'],
26+
:valid => ['/usr/lib/jvm'],
27+
:invalid => ['invalid',3,2.42,['array'],a={'ha'=>'sh'}],
28+
:message => 'is not an absolute path',
29+
},
30+
'version' => {
31+
:name => ['version'] ,
32+
:valid => ['6',6],
33+
:invalid => [['array'],a={'ha'=>'sh'}, true],
34+
:message => 'is not a string',
35+
},
36+
}
37+
38+
validations.sort.each do |type, var|
39+
var[:name].each do |var_name|
40+
var[:valid].each do |valid|
41+
context "with #{var_name} (#{type}) set to valid #{valid} (as #{valid.class})" do
42+
let(:params) { validation_params.merge({ :"#{var_name}" => valid, }) }
43+
it { should compile }
44+
end
45+
end
46+
47+
var[:invalid].each do |invalid|
48+
context "with #{var_name} (#{type}) set to invalid #{invalid} (as #{invalid.class})" do
49+
let(:params) { validation_params.merge({ :"#{var_name}" => invalid, }) }
50+
it 'should fail' do
51+
expect do
52+
should contain_class(subject)
53+
end.to raise_error(Puppet::Error, /#{var[:message]}/)
54+
end
55+
end
56+
end
57+
end # var[:name].each
58+
end # validations.sort.each
59+
end # describe
60+
end

0 commit comments

Comments
 (0)