Skip to content

Commit fcbc4b5

Browse files
committed
First set of tests
1 parent afb78e2 commit fcbc4b5

11 files changed

+522
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'validate_array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'validates a single argument' do
6+
pp = <<-EOS
7+
$one = ['a', 'b']
8+
validate_array($one)
9+
EOS
10+
11+
apply_manifest(pp, :catch_failures => true)
12+
end
13+
it 'validates an multiple arguments' do
14+
pp = <<-EOS
15+
$one = ['a', 'b']
16+
$two = [['c'], 'd']
17+
validate_array($one,$two)
18+
EOS
19+
20+
apply_manifest(pp, :catch_failures => true)
21+
end
22+
it 'validates a non-array' do
23+
{
24+
%{validate_array({'a' => 'hash' })} => "Hash",
25+
%{validate_array('string')} => "String",
26+
%{validate_array(false)} => "FalseClass",
27+
%{validate_array(undef)} => "String"
28+
}.each do |pp,type|
29+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
30+
end
31+
end
32+
end
33+
describe 'failure' do
34+
it 'handles improper number of arguments'
35+
end
36+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'validate_augeas function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'prep' do
5+
it 'installs augeas for tests'
6+
end
7+
describe 'success' do
8+
it 'validates a single argument' do
9+
pp = <<-EOS
10+
$one = { 'a' => 1 }
11+
validate_hash($one)
12+
EOS
13+
14+
apply_manifest(pp, :catch_failures => true)
15+
end
16+
it 'validates an multiple arguments' do
17+
pp = <<-EOS
18+
$one = { 'a' => 1 }
19+
$two = { 'b' => 2 }
20+
validate_hash($one,$two)
21+
EOS
22+
23+
apply_manifest(pp, :catch_failures => true)
24+
end
25+
it 'validates a non-hash' do
26+
{
27+
%{validate_hash('{ "not" => "hash" }')} => "String",
28+
%{validate_hash('string')} => "String",
29+
%{validate_hash(["array"])} => "Array",
30+
%{validate_hash(undef)} => "String",
31+
}.each do |pp,type|
32+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
33+
end
34+
end
35+
end
36+
describe 'failure' do
37+
it 'handles improper number of arguments'
38+
end
39+
end

spec/acceptance/validate_bool_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'validate_bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'validates a single argument' do
6+
pp = <<-EOS
7+
$one = true
8+
validate_bool($one)
9+
EOS
10+
11+
apply_manifest(pp, :catch_failures => true)
12+
end
13+
it 'validates an multiple arguments' do
14+
pp = <<-EOS
15+
$one = true
16+
$two = false
17+
validate_bool($one,$two)
18+
EOS
19+
20+
apply_manifest(pp, :catch_failures => true)
21+
end
22+
it 'validates a non-bool' do
23+
{
24+
%{validate_bool('true')} => "String",
25+
%{validate_bool('false')} => "String",
26+
%{validate_bool([true])} => "Array",
27+
%{validate_bool(undef)} => "String",
28+
}.each do |pp,type|
29+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
30+
end
31+
end
32+
end
33+
describe 'failure' do
34+
it 'handles improper number of arguments'
35+
end
36+
end

spec/acceptance/validate_cmd_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'validate_cmd function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'validates a true command' do
6+
pp = <<-EOS
7+
$one = 'foo'
8+
if $::osfamily == 'windows' {
9+
$two = 'echo' #shell built-in
10+
} else {
11+
$two = '/bin/echo'
12+
}
13+
validate_cmd($one,$two)
14+
EOS
15+
16+
apply_manifest(pp, :catch_failures => true)
17+
end
18+
it 'validates a fail command' do
19+
pp = <<-EOS
20+
$one = 'foo'
21+
if $::osfamily == 'windows' {
22+
$two = 'C:/aoeu'
23+
} else {
24+
$two = '/bin/aoeu'
25+
}
26+
validate_cmd($one,$two)
27+
EOS
28+
29+
apply_manifest(pp, :expect_failures => true)
30+
end
31+
it 'validates a fail command with a custom error message' do
32+
pp = <<-EOS
33+
$one = 'foo'
34+
if $::osfamily == 'windows' {
35+
$two = 'C:/aoeu'
36+
} else {
37+
$two = '/bin/aoeu'
38+
}
39+
validate_cmd($one,$two,"aoeu is dvorak)
40+
EOS
41+
42+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/aoeu is dvorak/)
43+
end
44+
end
45+
describe 'failure' do
46+
it 'handles improper number of arguments'
47+
it 'handles improper argument types'
48+
end
49+
end

spec/acceptance/validate_hash_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'validate_hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'validates a single argument' do
6+
pp = <<-EOS
7+
$one = { 'a' => 1 }
8+
validate_hash($one)
9+
EOS
10+
11+
apply_manifest(pp, :catch_failures => true)
12+
end
13+
it 'validates an multiple arguments' do
14+
pp = <<-EOS
15+
$one = { 'a' => 1 }
16+
$two = { 'b' => 2 }
17+
validate_hash($one,$two)
18+
EOS
19+
20+
apply_manifest(pp, :catch_failures => true)
21+
end
22+
it 'validates a non-hash' do
23+
{
24+
%{validate_hash('{ "not" => "hash" }')} => "String",
25+
%{validate_hash('string')} => "String",
26+
%{validate_hash(["array"])} => "Array",
27+
%{validate_hash(undef)} => "String",
28+
}.each do |pp,type|
29+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
30+
end
31+
end
32+
end
33+
describe 'failure' do
34+
it 'handles improper number of arguments'
35+
end
36+
end

spec/acceptance/validate_re_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'validate_re function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'validates a string' do
6+
pp = <<-EOS
7+
$one = 'one'
8+
$two = '^one$'
9+
validate_re($one,$two)
10+
EOS
11+
12+
apply_manifest(pp, :catch_failures => true)
13+
end
14+
it 'validates an array' do
15+
pp = <<-EOS
16+
$one = 'one'
17+
$two = ['^one$', '^two']
18+
validate_re($one,$two)
19+
EOS
20+
21+
apply_manifest(pp, :catch_failures => true)
22+
end
23+
it 'validates a failed array' do
24+
pp = <<-EOS
25+
$one = 'one'
26+
$two = ['^two$', '^three']
27+
validate_re($one,$two)
28+
EOS
29+
30+
apply_manifest(pp, :expect_failures => true)
31+
end
32+
it 'validates a failed array with a custom error message' do
33+
pp = <<-EOS
34+
$one = '3.4.3'
35+
$two = '^2.7'
36+
validate_re($one,$two,"The $puppetversion fact does not match 2.7")
37+
EOS
38+
39+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/does not match/)
40+
end
41+
end
42+
describe 'failure' do
43+
it 'handles improper number of arguments'
44+
it 'handles improper argument types'
45+
end
46+
end
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'validate_slength function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'validates a single string max' do
6+
pp = <<-EOS
7+
$one = 'discombobulate'
8+
$two = 17
9+
validate_slength($one,$two)
10+
EOS
11+
12+
apply_manifest(pp, :catch_failures => true)
13+
end
14+
it 'validates multiple string maxes' do
15+
pp = <<-EOS
16+
$one = ['discombobulate', 'moo']
17+
$two = 17
18+
validate_slength($one,$two)
19+
EOS
20+
21+
apply_manifest(pp, :catch_failures => true)
22+
end
23+
it 'validates min/max of strings in array' do
24+
pp = <<-EOS
25+
$one = ['discombobulate', 'moo']
26+
$two = 17
27+
$three = 3
28+
validate_slength($one,$two,$three)
29+
EOS
30+
31+
apply_manifest(pp, :catch_failures => true)
32+
end
33+
it 'validates a single string max of incorrect length' do
34+
pp = <<-EOS
35+
$one = 'discombobulate'
36+
$two = 1
37+
validate_slength($one,$two)
38+
EOS
39+
40+
apply_manifest(pp, :expect_failures => true)
41+
end
42+
it 'validates multiple string maxes of incorrect length' do
43+
pp = <<-EOS
44+
$one = ['discombobulate', 'moo']
45+
$two = 3
46+
validate_slength($one,$two)
47+
EOS
48+
49+
apply_manifest(pp, :expect_failures => true)
50+
end
51+
it 'validates multiple strings min/maxes of incorrect length' do
52+
pp = <<-EOS
53+
$one = ['discombobulate', 'moo']
54+
$two = 17
55+
$three = 10
56+
validate_slength($one,$two,$three)
57+
EOS
58+
59+
apply_manifest(pp, :expect_failures => true)
60+
end
61+
end
62+
describe 'failure' do
63+
it 'handles improper number of arguments'
64+
it 'handles improper first argument type'
65+
it 'handles non-strings in array of first argument'
66+
it 'handles improper second argument type'
67+
it 'handles improper third argument type'
68+
it 'handles negative ranges'
69+
it 'handles improper ranges'
70+
end
71+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'validate_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'success' do
5+
it 'validates a single argument' do
6+
pp = <<-EOS
7+
$one = 'string'
8+
validate_string($one)
9+
EOS
10+
11+
apply_manifest(pp, :catch_failures => true)
12+
end
13+
it 'validates an multiple arguments' do
14+
pp = <<-EOS
15+
$one = 'string'
16+
$two = 'also string'
17+
validate_string($one,$two)
18+
EOS
19+
20+
apply_manifest(pp, :catch_failures => true)
21+
end
22+
it 'validates a non-string' do
23+
{
24+
%{validate_string({ 'a' => 'hash' })} => "Hash",
25+
%{validate_string(['array'])} => "Array",
26+
%{validate_string(false)} => "FalseClass",
27+
}.each do |pp,type|
28+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
29+
end
30+
end
31+
end
32+
describe 'failure' do
33+
it 'handles improper number of arguments'
34+
end
35+
end

0 commit comments

Comments
 (0)