summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Penney <ashley.penney@puppetlabs.com>2014-04-28 14:55:29 -0400
committerAshley Penney <ashley.penney@puppetlabs.com>2014-04-28 14:55:29 -0400
commitf8bfe46bbfa4a4737cef9a20cfe1bed04aee4bdc (patch)
tree3f9e8ee134c0ed8375d3e80987c0801971f32736
parent0b59dfe64299abd0c7e9a72dd381341cb9a5c260 (diff)
parent90222959b14a10c3519c88f74e244b13b07fd78b (diff)
Merge pull request #243 from hunner/add_beaker
Add beaker tests for functions.
-rw-r--r--Gemfile3
-rw-r--r--spec/acceptance/abs_spec.rb29
-rw-r--r--spec/acceptance/any2array_spec.rb48
-rw-r--r--spec/acceptance/base64_spec.rb17
-rw-r--r--spec/acceptance/bool2num_spec.rb33
-rw-r--r--spec/acceptance/build_csv.rb69
-rw-r--r--spec/acceptance/capitalize_spec.rb32
-rw-r--r--spec/acceptance/chomp_spec.rb20
-rw-r--r--spec/acceptance/chop_spec.rb44
-rw-r--r--spec/acceptance/concat_spec.rb17
-rw-r--r--spec/acceptance/count_spec.rb29
-rw-r--r--spec/acceptance/deep_merge_spec.rb19
-rw-r--r--spec/acceptance/defined_with_params_spec.rb21
-rw-r--r--spec/acceptance/delete_at_spec.rb18
-rw-r--r--spec/acceptance/delete_spec.rb18
-rw-r--r--spec/acceptance/delete_undef_values_spec.rb18
-rw-r--r--spec/acceptance/num2bool_spec.rb75
-rw-r--r--spec/acceptance/parsejson_spec.rb33
-rw-r--r--spec/acceptance/parseyaml_spec.rb34
-rw-r--r--spec/acceptance/pick_spec.rb43
-rw-r--r--spec/acceptance/prefix_spec.rb41
-rw-r--r--spec/acceptance/reject_spec.rb41
-rw-r--r--spec/acceptance/size_spec.rb54
-rw-r--r--spec/acceptance/sort_spec.rb33
-rw-r--r--spec/acceptance/validate_array_spec.rb36
-rw-r--r--spec/acceptance/validate_augeas_spec.rb39
-rw-r--r--spec/acceptance/validate_bool_spec.rb36
-rw-r--r--spec/acceptance/validate_cmd_spec.rb49
-rw-r--r--spec/acceptance/validate_hash_spec.rb36
-rw-r--r--spec/acceptance/validate_re_spec.rb46
-rw-r--r--spec/acceptance/validate_slength_spec.rb71
-rw-r--r--spec/acceptance/validate_string_spec.rb35
-rw-r--r--spec/acceptance/values_at_spec.rb71
-rw-r--r--spec/acceptance/values_spec.rb30
-rw-r--r--spec/acceptance/zip_spec.rb73
-rw-r--r--spec/spec_helper_acceptance.rb2
36 files changed, 1309 insertions, 4 deletions
diff --git a/Gemfile b/Gemfile
index eb5a31c..bbef720 100644
--- a/Gemfile
+++ b/Gemfile
@@ -14,9 +14,6 @@ group :development, :test do
gem 'rake', '~> 10.1.0', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
- gem 'rspec-system', :require => false
- gem 'rspec-system-puppet', :require => false
- gem 'rspec-system-serverspec', :require => false
gem 'serverspec', :require => false
gem 'puppet-lint', :require => false
gem 'pry', :require => false
diff --git a/spec/acceptance/abs_spec.rb b/spec/acceptance/abs_spec.rb
new file mode 100644
index 0000000..eeae89b
--- /dev/null
+++ b/spec/acceptance/abs_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper_acceptance'
+
+describe 'abs function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/any2array_spec.rb b/spec/acceptance/any2array_spec.rb
new file mode 100644
index 0000000..0127303
--- /dev/null
+++ b/spec/acceptance/any2array_spec.rb
@@ -0,0 +1,48 @@
+require 'spec_helper_acceptance'
+
+describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/base64_spec.rb b/spec/acceptance/base64_spec.rb
new file mode 100644
index 0000000..30ba689
--- /dev/null
+++ b/spec/acceptance/base64_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper_acceptance'
+
+describe 'base64 function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/bool2num_spec.rb b/spec/acceptance/bool2num_spec.rb
new file mode 100644
index 0000000..1cbd88d
--- /dev/null
+++ b/spec/acceptance/bool2num_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper_acceptance'
+
+describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/build_csv.rb b/spec/acceptance/build_csv.rb
new file mode 100644
index 0000000..556d1f8
--- /dev/null
+++ b/spec/acceptance/build_csv.rb
@@ -0,0 +1,69 @@
+#!/usr/bin/env ruby
+# vim: set sw=2 sts=2 et tw=80 :
+require 'rspec'
+require 'pry'
+
+#XXX Super ugly hack to keep from starting beaker nodes
+module Kernel
+ # make an alias of the original require
+ alias_method :original_require, :require
+ # rewrite require
+ def require name
+ original_require name if name != 'spec_helper_acceptance'
+ end
+end
+UNSUPPORTED_PLATFORMS = []
+def fact(*args) [] end
+#XXX End hax
+
+# Get a list of functions for test coverage
+function_list = Dir[File.join(File.dirname(__FILE__),"..","..","lib","puppet","parser","functions","*.rb")].collect do |function_rb|
+ File.basename(function_rb,".rb")
+end
+
+## Configure rspec to parse tests
+options = RSpec::Core::ConfigurationOptions.new(['spec/acceptance'])
+configuration = RSpec::configuration
+world = RSpec::world
+options.parse_options
+options.configure(configuration)
+configuration.load_spec_files
+
+## Collect up tests and example groups into a hash
+def get_tests(children)
+ children.inject({}) do |memo,c|
+ memo[c.description] = Hash.new
+ memo[c.description]["groups"] = get_tests(c.children) unless c.children.empty?
+ memo[c.description]["tests"] = c.examples.collect { |e|
+ e.description unless e.pending?
+ }.compact unless c.examples.empty?
+ memo[c.description]["pending_tests"] = c.examples.collect { |e|
+ e.description if e.pending?
+ }.compact unless c.examples.empty?
+ memo
+ end
+end
+
+# Convert tests hash to csv format
+def to_csv(function_list,tests)
+ function_list.collect do |function_name|
+ if v = tests["#{function_name} function"]
+ positive_tests = v["groups"]["success"] ? v["groups"]["success"]["tests"].length : 0
+ negative_tests = v["groups"]["failure"] ? v["groups"]["failure"]["tests"].length : 0
+ pending_tests =
+ (v["groups"]["failure"] ? v["groups"]["success"]["pending_tests"].length : 0) +
+ (v["groups"]["failure"] ? v["groups"]["failure"]["pending_tests"].length : 0)
+ else
+ positive_tests = 0
+ negative_tests = 0
+ pending_tests = 0
+ end
+ sprintf("%-25s, %-9d, %-9d, %-9d", function_name,positive_tests,negative_tests,pending_tests)
+ end.compact
+end
+
+tests = get_tests(world.example_groups)
+csv = to_csv(function_list,tests)
+percentage_tested = "#{tests.count*100/function_list.count}%"
+printf("%-25s, %-9s, %-9s, %-9s\n","#{percentage_tested} have tests.","Positive","Negative","Pending")
+puts csv
diff --git a/spec/acceptance/capitalize_spec.rb b/spec/acceptance/capitalize_spec.rb
new file mode 100644
index 0000000..c04b401
--- /dev/null
+++ b/spec/acceptance/capitalize_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper_acceptance'
+
+describe 'capitalize function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/chomp_spec.rb b/spec/acceptance/chomp_spec.rb
new file mode 100644
index 0000000..c4af9d9
--- /dev/null
+++ b/spec/acceptance/chomp_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper_acceptance'
+
+describe 'chomp function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/chop_spec.rb b/spec/acceptance/chop_spec.rb
new file mode 100644
index 0000000..8774390
--- /dev/null
+++ b/spec/acceptance/chop_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper_acceptance'
+
+describe 'chop function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb
new file mode 100644
index 0000000..24b5955
--- /dev/null
+++ b/spec/acceptance/concat_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper_acceptance'
+
+describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/count_spec.rb b/spec/acceptance/count_spec.rb
new file mode 100644
index 0000000..0a0f5d7
--- /dev/null
+++ b/spec/acceptance/count_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper_acceptance'
+
+describe 'count function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/deep_merge_spec.rb b/spec/acceptance/deep_merge_spec.rb
new file mode 100644
index 0000000..676d23d
--- /dev/null
+++ b/spec/acceptance/deep_merge_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper_acceptance'
+
+describe 'deep_merge function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/defined_with_params_spec.rb b/spec/acceptance/defined_with_params_spec.rb
new file mode 100644
index 0000000..7477453
--- /dev/null
+++ b/spec/acceptance/defined_with_params_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper_acceptance'
+
+describe 'defined_with_params function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/delete_at_spec.rb b/spec/acceptance/delete_at_spec.rb
new file mode 100644
index 0000000..f2c5cfe
--- /dev/null
+++ b/spec/acceptance/delete_at_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper_acceptance'
+
+describe 'delete_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/delete_spec.rb b/spec/acceptance/delete_spec.rb
new file mode 100644
index 0000000..e54d816
--- /dev/null
+++ b/spec/acceptance/delete_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper_acceptance'
+
+describe 'delete function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/delete_undef_values_spec.rb b/spec/acceptance/delete_undef_values_spec.rb
new file mode 100644
index 0000000..c2ac931
--- /dev/null
+++ b/spec/acceptance/delete_undef_values_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper_acceptance'
+
+describe 'delete_undef_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' 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
+end
diff --git a/spec/acceptance/num2bool_spec.rb b/spec/acceptance/num2bool_spec.rb
new file mode 100644
index 0000000..cdfbc70
--- /dev/null
+++ b/spec/acceptance/num2bool_spec.rb
@@ -0,0 +1,75 @@
+require 'spec_helper_acceptance'
+
+describe 'num2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'bools positive numbers and numeric strings as true' do
+ pp = <<-EOS
+ $a = 1
+ $b = "1"
+ $c = "50"
+ $ao = num2bool($a)
+ $bo = num2bool($b)
+ $co = num2bool($c)
+ notice(inline_template('a is <%= @ao.inspect %>'))
+ notice(inline_template('b is <%= @bo.inspect %>'))
+ notice(inline_template('c is <%= @co.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/a is true/)
+ expect(r.stdout).to match(/b is true/)
+ expect(r.stdout).to match(/c is true/)
+ end
+ end
+ it 'bools negative numbers as false' do
+ pp = <<-EOS
+ $a = 0
+ $b = -0.1
+ $c = ["-50","1"]
+ $ao = num2bool($a)
+ $bo = num2bool($b)
+ $co = num2bool($c)
+ notice(inline_template('a is <%= @ao.inspect %>'))
+ notice(inline_template('b is <%= @bo.inspect %>'))
+ notice(inline_template('c is <%= @co.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/a is false/)
+ expect(r.stdout).to match(/b is false/)
+ expect(r.stdout).to match(/c is false/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'fails on words' do
+ pp = <<-EOS
+ $a = "a"
+ $ao = num2bool($a)
+ notice(inline_template('a is <%= @ao.inspect %>'))
+ EOS
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/)
+ end
+
+ it 'fails on numberwords' do
+ pp = <<-EOS
+ $b = "1b"
+ $bo = num2bool($b)
+ notice(inline_template('b is <%= @bo.inspect %>'))
+ EOS
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/)
+
+ end
+
+ it 'fails on non-numeric/strings' do
+ pending "The function will call .to_s.to_i on anything not a Numeric or
+ String, and results in 0. Is this intended?"
+ pp = <<-EOS
+ $c = {"c" => "-50"}
+ $co = num2bool($c)
+ notice(inline_template('c is <%= @co.inspect %>'))
+ EOS
+ expect(apply_manifest(ppc :expect_failures => true).stderr).to match(/Unable to parse/)
+ end
+ end
+end
diff --git a/spec/acceptance/parsejson_spec.rb b/spec/acceptance/parsejson_spec.rb
new file mode 100644
index 0000000..b2ae030
--- /dev/null
+++ b/spec/acceptance/parsejson_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper_acceptance'
+
+describe 'parsejson function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'parses valid json' do
+ pp = <<-EOS
+ $a = '{"hunter": "washere", "tests": "passing"}'
+ $ao = parsejson($a)
+ $tests = $ao['tests']
+ notice(inline_template('tests are <%= @tests.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/tests are "passing"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'raises error on incorrect json' do
+ pp = <<-EOS
+ $a = '{"hunter": "washere", "tests": "passing",}'
+ $ao = parsejson($a)
+ notice(inline_template('a is <%= @ao.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :expect_failures => true) do |r|
+ expect(r.stderr).to match(/expected next name/)
+ end
+ end
+
+ it 'raises error on incorrect number of arguments'
+ end
+end
diff --git a/spec/acceptance/parseyaml_spec.rb b/spec/acceptance/parseyaml_spec.rb
new file mode 100644
index 0000000..01e0988
--- /dev/null
+++ b/spec/acceptance/parseyaml_spec.rb
@@ -0,0 +1,34 @@
+require 'spec_helper_acceptance'
+
+describe 'parseyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'parses valid yaml' do
+ pp = <<-EOS
+ $a = "---\nhunter: washere\ntests: passing\n"
+ $o = parseyaml($a)
+ $tests = $o['tests']
+ notice(inline_template('tests are <%= @tests.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/tests are "passing"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'raises error on incorrect yaml' do
+ pp = <<-EOS
+ $a = "---\nhunter: washere\ntests: passing\n:"
+ $o = parseyaml($a)
+ $tests = $o['tests']
+ notice(inline_template('tests are <%= @tests.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :expect_failures => true) do |r|
+ expect(r.stderr).to match(/syntax error/)
+ end
+ end
+
+ it 'raises error on incorrect number of arguments'
+ end
+end
diff --git a/spec/acceptance/pick_spec.rb b/spec/acceptance/pick_spec.rb
new file mode 100644
index 0000000..8a768a9
--- /dev/null
+++ b/spec/acceptance/pick_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper_acceptance'
+
+describe 'pick function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'picks a default value' do
+ pp = <<-EOS
+ $a = undef
+ $o = pick($a, 'default')
+ notice(inline_template('picked is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/picked is "default"/)
+ end
+ end
+ it 'picks the first set value' do
+ pp = <<-EOS
+ $a = "something"
+ $b = "long"
+ $o = pick($a, $b, 'default')
+ notice(inline_template('picked is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/picked is "something"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'raises error with all undef values' do
+ pp = <<-EOS
+ $a = undef
+ $b = undef
+ $o = pick($a, $b)
+ notice(inline_template('picked is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :expect_failures => true) do |r|
+ expect(r.stderr).to match(/must receive at least one non empty value/)
+ end
+ end
+ end
+end
diff --git a/spec/acceptance/prefix_spec.rb b/spec/acceptance/prefix_spec.rb
new file mode 100644
index 0000000..d7b80a8
--- /dev/null
+++ b/spec/acceptance/prefix_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper_acceptance'
+
+describe 'prefix function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'prefixes array of values' do
+ pp = <<-EOS
+ $o = prefix(['a','b','c'],'p')
+ notice(inline_template('prefix is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/prefix is \["pa", "pb", "pc"\]/)
+ end
+ end
+ it 'prefixs with empty array' do
+ pp = <<-EOS
+ $o = prefix([],'p')
+ notice(inline_template('prefix is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/prefix is \[\]/)
+ end
+ end
+ it 'prefixs array of values with undef' do
+ pp = <<-EOS
+ $o = prefix(['a','b','c'], undef)
+ notice(inline_template('prefix is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/prefix is \["a", "b", "c"\]/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'fails with no arguments'
+ it 'fails when first argument is not array'
+ it 'fails when second argument is not string'
+ end
+end
diff --git a/spec/acceptance/reject_spec.rb b/spec/acceptance/reject_spec.rb
new file mode 100644
index 0000000..5333f36
--- /dev/null
+++ b/spec/acceptance/reject_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper_acceptance'
+
+describe 'reject function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'rejects array of values' do
+ pp = <<-EOS
+ $o = reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
+ notice(inline_template('reject is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/reject is \["bbb", "ccc"\]/)
+ end
+ end
+ it 'rejects with empty array' do
+ pp = <<-EOS
+ $o = reject([],'aaa')
+ notice(inline_template('reject is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/reject is \[\]/)
+ end
+ end
+ it 'rejects array of values with undef' do
+ pp = <<-EOS
+ $o = reject(['aaa','bbb','ccc','aaaddd'], undef)
+ notice(inline_template('reject is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/reject is \["aaa", "bbb", "ccc", "aaaddd"\]/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'fails with no arguments'
+ it 'fails when first argument is not array'
+ it 'fails when second argument is not string'
+ end
+end
diff --git a/spec/acceptance/size_spec.rb b/spec/acceptance/size_spec.rb
new file mode 100644
index 0000000..2aacf0b
--- /dev/null
+++ b/spec/acceptance/size_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper_acceptance'
+
+describe 'size function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'single string size' do
+ pp = <<-EOS
+ $a = 'discombobulate'
+ $o =size($a)
+ notice(inline_template('size is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/size is 14/)
+ end
+ end
+ it 'with empty string' do
+ pp = <<-EOS
+ $a = ''
+ $o =size($a)
+ notice(inline_template('size is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/size is 0/)
+ end
+ end
+ it 'with undef' do
+ pp = <<-EOS
+ $a = undef
+ $o =size($a)
+ notice(inline_template('size is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/size is 0/)
+ end
+ end
+ it 'strings in array' do
+ pp = <<-EOS
+ $a = ['discombobulate', 'moo']
+ $o =size($a)
+ notice(inline_template('size is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/size is 2/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/sort_spec.rb b/spec/acceptance/sort_spec.rb
new file mode 100644
index 0000000..1868a03
--- /dev/null
+++ b/spec/acceptance/sort_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper_acceptance'
+
+describe 'sort function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
+ describe 'success' do
+ it 'sorts arrays' do
+ pp = <<-EOS
+ $a = ["the","public","art","galleries"]
+ # Anagram: Large picture halls, I bet
+ $o =sort($a)
+ notice(inline_template('sort is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/sort is \["art", "galleries", "public", "the"\]/)
+ end
+ end
+ it 'sorts strings' do
+ pp = <<-EOS
+ $a = "blowzy night-frumps vex'd jack q"
+ $o =sort($a)
+ notice(inline_template('sort is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/sort is " '-abcdefghijklmnopqrstuvwxyz"/)
+ end
+ end
+ end
+ describe 'failure' do
+ it 'handles no arguments'
+ it 'handles non strings or arrays'
+ end
+end
diff --git a/spec/acceptance/validate_array_spec.rb b/spec/acceptance/validate_array_spec.rb
new file mode 100644
index 0000000..da9f465
--- /dev/null
+++ b/spec/acceptance/validate_array_spec.rb
@@ -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
diff --git a/spec/acceptance/validate_augeas_spec.rb b/spec/acceptance/validate_augeas_spec.rb
new file mode 100644
index 0000000..8b904f5
--- /dev/null
+++ b/spec/acceptance/validate_augeas_spec.rb
@@ -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
diff --git a/spec/acceptance/validate_bool_spec.rb b/spec/acceptance/validate_bool_spec.rb
new file mode 100644
index 0000000..4e77da2
--- /dev/null
+++ b/spec/acceptance/validate_bool_spec.rb
@@ -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
diff --git a/spec/acceptance/validate_cmd_spec.rb b/spec/acceptance/validate_cmd_spec.rb
new file mode 100644
index 0000000..b4d6575
--- /dev/null
+++ b/spec/acceptance/validate_cmd_spec.rb
@@ -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
diff --git a/spec/acceptance/validate_hash_spec.rb b/spec/acceptance/validate_hash_spec.rb
new file mode 100644
index 0000000..d26c9e7
--- /dev/null
+++ b/spec/acceptance/validate_hash_spec.rb
@@ -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
diff --git a/spec/acceptance/validate_re_spec.rb b/spec/acceptance/validate_re_spec.rb
new file mode 100644
index 0000000..8d7e634
--- /dev/null
+++ b/spec/acceptance/validate_re_spec.rb
@@ -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
diff --git a/spec/acceptance/validate_slength_spec.rb b/spec/acceptance/validate_slength_spec.rb
new file mode 100644
index 0000000..96b2a6f
--- /dev/null
+++ b/spec/acceptance/validate_slength_spec.rb
@@ -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
diff --git a/spec/acceptance/validate_string_spec.rb b/spec/acceptance/validate_string_spec.rb
new file mode 100644
index 0000000..f8658c5
--- /dev/null
+++ b/spec/acceptance/validate_string_spec.rb
@@ -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
diff --git a/spec/acceptance/values_at_spec.rb b/spec/acceptance/values_at_spec.rb
new file mode 100644
index 0000000..fb661dd
--- /dev/null
+++ b/spec/acceptance/values_at_spec.rb
@@ -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
diff --git a/spec/acceptance/values_spec.rb b/spec/acceptance/values_spec.rb
new file mode 100644
index 0000000..0c12702
--- /dev/null
+++ b/spec/acceptance/values_spec.rb
@@ -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
diff --git a/spec/acceptance/zip_spec.rb b/spec/acceptance/zip_spec.rb
new file mode 100644
index 0000000..a551b80
--- /dev/null
+++ b/spec/acceptance/zip_spec.rb
@@ -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
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
index 4cefa75..e9d0be8 100644
--- a/spec/spec_helper_acceptance.rb
+++ b/spec/spec_helper_acceptance.rb
@@ -2,7 +2,7 @@ require 'beaker-rspec'
UNSUPPORTED_PLATFORMS = []
-unless ENV['RS_PROVISION'] == 'no'
+unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
hosts.each do |host|
# Install Puppet
if host.is_pe?