Add some acceptance tests for functions.
This commit is contained in:
parent
746a4cc67a
commit
afb78e2b25
14 changed files with 335 additions and 0 deletions
27
spec/acceptance/abs_spec.rb
Normal file
27
spec/acceptance/abs_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'abs function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should accept a string' do
|
||||
pp = <<-EOS
|
||||
$input = '-34.56'
|
||||
$output = abs($input)
|
||||
notify { $output: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: 34.56/)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should accept a float' do
|
||||
pp = <<-EOS
|
||||
$input = -34.56
|
||||
$output = abs($input)
|
||||
notify { $output: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: 34.56/)
|
||||
end
|
||||
end
|
||||
end
|
46
spec/acceptance/any2array_spec.rb
Normal file
46
spec/acceptance/any2array_spec.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should create an empty array' do
|
||||
pp = <<-EOS
|
||||
$input = ''
|
||||
$output = any2array($input)
|
||||
validate_array($output)
|
||||
notify { "Output: ${output}": }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: Output: /)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should leave arrays modified' do
|
||||
pp = <<-EOS
|
||||
$input = ['test', 'array']
|
||||
$output = any2array($input)
|
||||
validate_array($output)
|
||||
notify { "Output: ${output}": }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: Output: testarray/)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should turn a hash into an array' do
|
||||
pp = <<-EOS
|
||||
$input = {'test' => 'array'}
|
||||
$output = any2array($input)
|
||||
|
||||
validate_array($output)
|
||||
# Check each element of the array is a plain string.
|
||||
validate_string($output[0])
|
||||
validate_string($output[1])
|
||||
notify { "Output: ${output}": }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: Output: testarray/)
|
||||
end
|
||||
end
|
||||
end
|
15
spec/acceptance/base64_spec.rb
Normal file
15
spec/acceptance/base64_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'base64 function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should encode then decode a string' do
|
||||
pp = <<-EOS
|
||||
$encodestring = base64('encode', 'thestring')
|
||||
$decodestring = base64('decode', $encodestring)
|
||||
notify { $decodestring: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/thestring/)
|
||||
end
|
||||
end
|
||||
end
|
31
spec/acceptance/bool2num_spec.rb
Normal file
31
spec/acceptance/bool2num_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
['false', 'f', '0', 'n', 'no'].each do |bool|
|
||||
it 'should convert a given boolean, #{bool}, to 0' do
|
||||
pp = <<-EOS
|
||||
$input = #{bool}
|
||||
$output = bool2num($input)
|
||||
notify { $output: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: 0/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
['true', 't', '1', 'y', 'yes'].each do |bool|
|
||||
it 'should convert a given boolean, #{bool}, to 1' do
|
||||
pp = <<-EOS
|
||||
$input = #{bool}
|
||||
$output = bool2num($input)
|
||||
notify { $output: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: 1/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
30
spec/acceptance/capitalize_spec.rb
Normal file
30
spec/acceptance/capitalize_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'capitalize function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should capitalize the first letter of a string' do
|
||||
pp = <<-EOS
|
||||
$input = 'this is a string'
|
||||
$output = capitalize($input)
|
||||
notify { $output: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: This is a string/)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should capitalize the first letter of an array of strings' do
|
||||
pp = <<-EOS
|
||||
$input = ['this', 'is', 'a', 'string']
|
||||
$output = capitalize($input)
|
||||
notify { $output: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: This/)
|
||||
expect(r.stdout).to match(/Notice: Is/)
|
||||
expect(r.stdout).to match(/Notice: A/)
|
||||
expect(r.stdout).to match(/Notice: String/)
|
||||
end
|
||||
end
|
||||
end
|
18
spec/acceptance/chomp_spec.rb
Normal file
18
spec/acceptance/chomp_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'chomp function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should eat the newline' do
|
||||
pp = <<-EOS
|
||||
$input = "test\n"
|
||||
if size($input) != 5 {
|
||||
fail("Size of ${input} is not 5.")
|
||||
}
|
||||
$output = chomp($input)
|
||||
if size($output) != 4 {
|
||||
fail("Size of ${input} is not 4.")
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
42
spec/acceptance/chop_spec.rb
Normal file
42
spec/acceptance/chop_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'chop function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should eat the last character' do
|
||||
pp = <<-EOS
|
||||
$input = "test"
|
||||
if size($input) != 4 {
|
||||
fail("Size of ${input} is not 4.")
|
||||
}
|
||||
$output = chop($input)
|
||||
if size($output) != 3 {
|
||||
fail("Size of ${input} is not 3.")
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should eat the last two characters of \r\n' do
|
||||
pp = <<-EOS
|
||||
$input = "test\r\n"
|
||||
if size($input) != 6 {
|
||||
fail("Size of ${input} is not 6.")
|
||||
}
|
||||
$output = chop($input)
|
||||
if size($output) != 4 {
|
||||
fail("Size of ${input} is not 4.")
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should not fail on empty strings' do
|
||||
pp = <<-EOS
|
||||
$input = ""
|
||||
$output = chop($input)
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
15
spec/acceptance/concat_spec.rb
Normal file
15
spec/acceptance/concat_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should concat one array to another' do
|
||||
pp = <<-EOS
|
||||
$output = concat(['1','2','3'],['4','5','6'])
|
||||
validate_array($output)
|
||||
if size($output) != 6 {
|
||||
fail("${output} should have 6 elements.")
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
27
spec/acceptance/count_spec.rb
Normal file
27
spec/acceptance/count_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'count function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should count elements in an array' do
|
||||
pp = <<-EOS
|
||||
$input = [1,2,3,4]
|
||||
$output = count($input)
|
||||
notify { $output: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: 4/)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should count elements in an array that match a second argument' do
|
||||
pp = <<-EOS
|
||||
$input = [1,1,1,2]
|
||||
$output = count($input, 1)
|
||||
notify { $output: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: 3/)
|
||||
end
|
||||
end
|
||||
end
|
17
spec/acceptance/deep_merge_spec.rb
Normal file
17
spec/acceptance/deep_merge_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'deep_merge function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should deep merge two hashes' do
|
||||
pp = <<-EOS
|
||||
$hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }
|
||||
$hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } }
|
||||
$merged_hash = deep_merge($hash1, $hash2)
|
||||
|
||||
if $merged_hash != { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } {
|
||||
fail("Hash was incorrectly merged.")
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
19
spec/acceptance/defined_with_params_spec.rb
Normal file
19
spec/acceptance/defined_with_params_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'defined_with_params function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should successfully notify' do
|
||||
pp = <<-EOS
|
||||
user { 'dan':
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
if defined_with_params(User[dan], {'ensure' => 'present' }) {
|
||||
notify { 'User defined with ensure=>present': }
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: User defined with ensure=>present/)
|
||||
end
|
||||
end
|
||||
end
|
16
spec/acceptance/delete_at_spec.rb
Normal file
16
spec/acceptance/delete_at_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'delete_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should delete elements of the array' do
|
||||
pp = <<-EOS
|
||||
$output = delete_at(['a','b','c','b'], 1)
|
||||
if $output == ['a','c','b'] {
|
||||
notify { 'output correct': }
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: output correct/)
|
||||
end
|
||||
end
|
||||
end
|
16
spec/acceptance/delete_spec.rb
Normal file
16
spec/acceptance/delete_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'delete function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should delete elements of the array' do
|
||||
pp = <<-EOS
|
||||
$output = delete(['a','b','c','b'], 'b')
|
||||
if $output == ['a','c'] {
|
||||
notify { 'output correct': }
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: output correct/)
|
||||
end
|
||||
end
|
||||
end
|
16
spec/acceptance/delete_undef_values_spec.rb
Normal file
16
spec/acceptance/delete_undef_values_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'delete_undef_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
||||
it 'should delete elements of the array' do
|
||||
pp = <<-EOS
|
||||
$output = delete_undef_values({a=>'A', b=>'', c=>undef, d => false})
|
||||
if $output == { a => 'A', b => '', d => false } {
|
||||
notify { 'output correct': }
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/Notice: output correct/)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue