Skip to content

Commit

Permalink
First set of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hunner committed Apr 3, 2014
1 parent afb78e2 commit fcbc4b5
Show file tree
Hide file tree
Showing 11 changed files with 522 additions and 0 deletions.
36 changes: 36 additions & 0 deletions spec/acceptance/validate_array_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 39 additions & 0 deletions spec/acceptance/validate_augeas_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 36 additions & 0 deletions spec/acceptance/validate_bool_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 49 additions & 0 deletions spec/acceptance/validate_cmd_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 36 additions & 0 deletions spec/acceptance/validate_hash_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 46 additions & 0 deletions spec/acceptance/validate_re_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 71 additions & 0 deletions spec/acceptance/validate_slength_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 35 additions & 0 deletions spec/acceptance/validate_string_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit fcbc4b5

Please sign in to comment.