First set of tests
This commit is contained in:
parent
afb78e2b25
commit
fcbc4b59a6
11 changed files with 522 additions and 0 deletions
36
spec/acceptance/validate_array_spec.rb
Normal file
36
spec/acceptance/validate_array_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'validate_array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'success' do
|
||||
it 'validates a single argument' do
|
||||
pp = <<-EOS
|
||||
$one = ['a', 'b']
|
||||
validate_array($one)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates an multiple arguments' do
|
||||
pp = <<-EOS
|
||||
$one = ['a', 'b']
|
||||
$two = [['c'], 'd']
|
||||
validate_array($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates a non-array' do
|
||||
{
|
||||
%{validate_array({'a' => 'hash' })} => "Hash",
|
||||
%{validate_array('string')} => "String",
|
||||
%{validate_array(false)} => "FalseClass",
|
||||
%{validate_array(undef)} => "String"
|
||||
}.each do |pp,type|
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles improper number of arguments'
|
||||
end
|
||||
end
|
39
spec/acceptance/validate_augeas_spec.rb
Normal file
39
spec/acceptance/validate_augeas_spec.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'validate_augeas function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'prep' do
|
||||
it 'installs augeas for tests'
|
||||
end
|
||||
describe 'success' do
|
||||
it 'validates a single argument' do
|
||||
pp = <<-EOS
|
||||
$one = { 'a' => 1 }
|
||||
validate_hash($one)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates an multiple arguments' do
|
||||
pp = <<-EOS
|
||||
$one = { 'a' => 1 }
|
||||
$two = { 'b' => 2 }
|
||||
validate_hash($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates a non-hash' do
|
||||
{
|
||||
%{validate_hash('{ "not" => "hash" }')} => "String",
|
||||
%{validate_hash('string')} => "String",
|
||||
%{validate_hash(["array"])} => "Array",
|
||||
%{validate_hash(undef)} => "String",
|
||||
}.each do |pp,type|
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles improper number of arguments'
|
||||
end
|
||||
end
|
36
spec/acceptance/validate_bool_spec.rb
Normal file
36
spec/acceptance/validate_bool_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'validate_bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'success' do
|
||||
it 'validates a single argument' do
|
||||
pp = <<-EOS
|
||||
$one = true
|
||||
validate_bool($one)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates an multiple arguments' do
|
||||
pp = <<-EOS
|
||||
$one = true
|
||||
$two = false
|
||||
validate_bool($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates a non-bool' do
|
||||
{
|
||||
%{validate_bool('true')} => "String",
|
||||
%{validate_bool('false')} => "String",
|
||||
%{validate_bool([true])} => "Array",
|
||||
%{validate_bool(undef)} => "String",
|
||||
}.each do |pp,type|
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles improper number of arguments'
|
||||
end
|
||||
end
|
49
spec/acceptance/validate_cmd_spec.rb
Normal file
49
spec/acceptance/validate_cmd_spec.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'validate_cmd function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'success' do
|
||||
it 'validates a true command' do
|
||||
pp = <<-EOS
|
||||
$one = 'foo'
|
||||
if $::osfamily == 'windows' {
|
||||
$two = 'echo' #shell built-in
|
||||
} else {
|
||||
$two = '/bin/echo'
|
||||
}
|
||||
validate_cmd($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates a fail command' do
|
||||
pp = <<-EOS
|
||||
$one = 'foo'
|
||||
if $::osfamily == 'windows' {
|
||||
$two = 'C:/aoeu'
|
||||
} else {
|
||||
$two = '/bin/aoeu'
|
||||
}
|
||||
validate_cmd($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true)
|
||||
end
|
||||
it 'validates a fail command with a custom error message' do
|
||||
pp = <<-EOS
|
||||
$one = 'foo'
|
||||
if $::osfamily == 'windows' {
|
||||
$two = 'C:/aoeu'
|
||||
} else {
|
||||
$two = '/bin/aoeu'
|
||||
}
|
||||
validate_cmd($one,$two,"aoeu is dvorak)
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/aoeu is dvorak/)
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles improper number of arguments'
|
||||
it 'handles improper argument types'
|
||||
end
|
||||
end
|
36
spec/acceptance/validate_hash_spec.rb
Normal file
36
spec/acceptance/validate_hash_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'validate_hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'success' do
|
||||
it 'validates a single argument' do
|
||||
pp = <<-EOS
|
||||
$one = { 'a' => 1 }
|
||||
validate_hash($one)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates an multiple arguments' do
|
||||
pp = <<-EOS
|
||||
$one = { 'a' => 1 }
|
||||
$two = { 'b' => 2 }
|
||||
validate_hash($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates a non-hash' do
|
||||
{
|
||||
%{validate_hash('{ "not" => "hash" }')} => "String",
|
||||
%{validate_hash('string')} => "String",
|
||||
%{validate_hash(["array"])} => "Array",
|
||||
%{validate_hash(undef)} => "String",
|
||||
}.each do |pp,type|
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles improper number of arguments'
|
||||
end
|
||||
end
|
46
spec/acceptance/validate_re_spec.rb
Normal file
46
spec/acceptance/validate_re_spec.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'validate_re function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'success' do
|
||||
it 'validates a string' do
|
||||
pp = <<-EOS
|
||||
$one = 'one'
|
||||
$two = '^one$'
|
||||
validate_re($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates an array' do
|
||||
pp = <<-EOS
|
||||
$one = 'one'
|
||||
$two = ['^one$', '^two']
|
||||
validate_re($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates a failed array' do
|
||||
pp = <<-EOS
|
||||
$one = 'one'
|
||||
$two = ['^two$', '^three']
|
||||
validate_re($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true)
|
||||
end
|
||||
it 'validates a failed array with a custom error message' do
|
||||
pp = <<-EOS
|
||||
$one = '3.4.3'
|
||||
$two = '^2.7'
|
||||
validate_re($one,$two,"The $puppetversion fact does not match 2.7")
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/does not match/)
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles improper number of arguments'
|
||||
it 'handles improper argument types'
|
||||
end
|
||||
end
|
71
spec/acceptance/validate_slength_spec.rb
Normal file
71
spec/acceptance/validate_slength_spec.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'validate_slength function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'success' do
|
||||
it 'validates a single string max' do
|
||||
pp = <<-EOS
|
||||
$one = 'discombobulate'
|
||||
$two = 17
|
||||
validate_slength($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates multiple string maxes' do
|
||||
pp = <<-EOS
|
||||
$one = ['discombobulate', 'moo']
|
||||
$two = 17
|
||||
validate_slength($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates min/max of strings in array' do
|
||||
pp = <<-EOS
|
||||
$one = ['discombobulate', 'moo']
|
||||
$two = 17
|
||||
$three = 3
|
||||
validate_slength($one,$two,$three)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates a single string max of incorrect length' do
|
||||
pp = <<-EOS
|
||||
$one = 'discombobulate'
|
||||
$two = 1
|
||||
validate_slength($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true)
|
||||
end
|
||||
it 'validates multiple string maxes of incorrect length' do
|
||||
pp = <<-EOS
|
||||
$one = ['discombobulate', 'moo']
|
||||
$two = 3
|
||||
validate_slength($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true)
|
||||
end
|
||||
it 'validates multiple strings min/maxes of incorrect length' do
|
||||
pp = <<-EOS
|
||||
$one = ['discombobulate', 'moo']
|
||||
$two = 17
|
||||
$three = 10
|
||||
validate_slength($one,$two,$three)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true)
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles improper number of arguments'
|
||||
it 'handles improper first argument type'
|
||||
it 'handles non-strings in array of first argument'
|
||||
it 'handles improper second argument type'
|
||||
it 'handles improper third argument type'
|
||||
it 'handles negative ranges'
|
||||
it 'handles improper ranges'
|
||||
end
|
||||
end
|
35
spec/acceptance/validate_string_spec.rb
Normal file
35
spec/acceptance/validate_string_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'validate_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'success' do
|
||||
it 'validates a single argument' do
|
||||
pp = <<-EOS
|
||||
$one = 'string'
|
||||
validate_string($one)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates an multiple arguments' do
|
||||
pp = <<-EOS
|
||||
$one = 'string'
|
||||
$two = 'also string'
|
||||
validate_string($one,$two)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
it 'validates a non-string' do
|
||||
{
|
||||
%{validate_string({ 'a' => 'hash' })} => "Hash",
|
||||
%{validate_string(['array'])} => "Array",
|
||||
%{validate_string(false)} => "FalseClass",
|
||||
}.each do |pp,type|
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles improper number of arguments'
|
||||
end
|
||||
end
|
71
spec/acceptance/values_at_spec.rb
Normal file
71
spec/acceptance/values_at_spec.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'values_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'success' do
|
||||
it 'returns a specific value' do
|
||||
pp = <<-EOS
|
||||
$one = ['a','b','c','d','e']
|
||||
$two = 1
|
||||
$output = values_at($one,$two)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b"\]/)
|
||||
end
|
||||
it 'returns a specific negative index value' do
|
||||
pp = <<-EOS
|
||||
$one = ['a','b','c','d','e']
|
||||
$two = "-1"
|
||||
$output = values_at($one,$two)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["e"\]/)
|
||||
end
|
||||
it 'returns a range of values' do
|
||||
pp = <<-EOS
|
||||
$one = ['a','b','c','d','e']
|
||||
$two = "1-3"
|
||||
$output = values_at($one,$two)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b", "c", "d"\]/)
|
||||
end
|
||||
it 'returns a negative specific value and range of values' do
|
||||
pp = <<-EOS
|
||||
$one = ['a','b','c','d','e']
|
||||
$two = ["1-3",0]
|
||||
$output = values_at($one,$two)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b", "c", "d", "a"\]/)
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles improper number of arguments' do
|
||||
pp = <<-EOS
|
||||
$one = ['a','b','c','d','e']
|
||||
$output = values_at($one)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Wrong number of arguments/)
|
||||
end
|
||||
it 'handles non-indicies arguments' do
|
||||
pp = <<-EOS
|
||||
$one = ['a','b','c','d','e']
|
||||
$two = []
|
||||
$output = values_at($one,$two)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/at least one positive index/)
|
||||
end
|
||||
|
||||
it 'detects index ranges smaller than the start range'
|
||||
it 'handles index ranges larger than array'
|
||||
it 'handles non-integer indicies'
|
||||
end
|
||||
end
|
30
spec/acceptance/values_spec.rb
Normal file
30
spec/acceptance/values_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'success' do
|
||||
it 'returns an array of values' do
|
||||
pp = <<-EOS
|
||||
$arg = {
|
||||
'a' => 1,
|
||||
'b' => 2,
|
||||
'c' => 3,
|
||||
}
|
||||
$output = values($arg)
|
||||
notice(inline_template('<%= @output.sort.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "2", "3"\]/)
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles non-hash arguments' do
|
||||
pp = <<-EOS
|
||||
$arg = "foo"
|
||||
$output = values($arg)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Requires hash/)
|
||||
end
|
||||
end
|
||||
end
|
73
spec/acceptance/zip_spec.rb
Normal file
73
spec/acceptance/zip_spec.rb
Normal file
|
@ -0,0 +1,73 @@
|
|||
require 'spec_helper_acceptance'
|
||||
require 'puppet'
|
||||
|
||||
describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
describe 'success' do
|
||||
it 'zips two arrays of numbers together' do
|
||||
pp = <<-EOS
|
||||
$one = [1,2,3,4]
|
||||
$two = [5,6,7,8]
|
||||
$output = zip($one,$two)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/)
|
||||
end
|
||||
it 'zips two arrays of numbers & bools together' do
|
||||
pp = <<-EOS
|
||||
$one = [1,2,"three",4]
|
||||
$two = [true,true,false,false]
|
||||
$output = zip($one,$two)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/)
|
||||
end
|
||||
it 'zips two arrays of numbers together and flattens them' do
|
||||
# XXX This only tests the argument `true`, even though the following are valid:
|
||||
# 1 t y true yes
|
||||
# 0 f n false no
|
||||
# undef undefined
|
||||
pp = <<-EOS
|
||||
$one = [1,2,3,4]
|
||||
$two = [5,6,7,8]
|
||||
$output = zip($one,$two,true)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/)
|
||||
end
|
||||
it 'handles unmatched length' do
|
||||
# XXX Is this expected behavior?
|
||||
pp = <<-EOS
|
||||
$one = [1,2]
|
||||
$two = [5,6,7,8]
|
||||
$output = zip($one,$two)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/)
|
||||
end
|
||||
end
|
||||
describe 'failure' do
|
||||
it 'handles improper number of arguments' do
|
||||
pp = <<-EOS
|
||||
$one = [1,2]
|
||||
$output = zip($one)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Wrong number of arguments/)
|
||||
end
|
||||
it 'handles improper argument types' do
|
||||
pp = <<-EOS
|
||||
$one = "a string"
|
||||
$two = [5,6,7,8]
|
||||
$output = zip($one,$two)
|
||||
notice(inline_template('<%= @output.inspect %>'))
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Requires array/)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue