From bb9f7d1726c4e33d41b992a981f1932fdab644a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Wed, 14 Aug 2013 02:23:36 +0200 Subject: small fix to delete_values_spec.rb and README.markdown --- spec/unit/puppet/parser/functions/delete_values_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/delete_values_spec.rb b/spec/unit/puppet/parser/functions/delete_values_spec.rb index e15c366..c62e55f 100644 --- a/spec/unit/puppet/parser/functions/delete_values_spec.rb +++ b/spec/unit/puppet/parser/functions/delete_values_spec.rb @@ -13,7 +13,7 @@ describe "the delete_values function" do end it "should raise a ParseError if there are greater than 2 arguments" do - lambda { scope.function_delete([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError)) + lambda { scope.function_delete_values([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError)) end it "should raise a TypeError if the argument is not a hash" do -- cgit v1.2.3 From 30e994fb6eb91e25a77e60a849f795d60c11af4b Mon Sep 17 00:00:00 2001 From: Leonardo Rodrigues de Mello Date: Fri, 6 Sep 2013 10:53:47 -0300 Subject: enhanced the error message of pick function. When pick function fail return a better error message like the other stdlib functions, indicating that the error is on function pick. This would help people that see the error to identity it is related to a incorrect use of stdlib function pick, instead of having to grep all puppet libraries and manifests source for the old message. I had also changed the spec test. pick function change spec as suggested GH-179 Fix the spec test to use expect {}.to instead of lambda {}.should as explained by Adrienthebo. "Using expect { }.to is preferred over lambda { }.should. In addition it's best practice to do a string match against the error message to ensure that we're catching the right error, instead of any error of the right type." Also fixed a typo on the error message, it was missing one space. pick function stylish fix as suggested on GH179 --- spec/unit/puppet/parser/functions/pick_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/pick_spec.rb b/spec/unit/puppet/parser/functions/pick_spec.rb index 761db6b..d2b275f 100644 --- a/spec/unit/puppet/parser/functions/pick_spec.rb +++ b/spec/unit/puppet/parser/functions/pick_spec.rb @@ -29,6 +29,6 @@ describe "the pick function" do end it 'should error if no values are passed' do - expect { scope.function_pick([]) }.to raise_error(Puppet::Error, /Must provide non empty value./) + expect { scope.function_pick([]) }.to( raise_error(Puppet::ParseError, "pick(): must receive at last one non empty value")) end end -- cgit v1.2.3 From c14cbf31e26b5749623947727ffac64817b5bb5f Mon Sep 17 00:00:00 2001 From: Leonardo Rodrigues de Mello Date: Mon, 9 Sep 2013 10:27:54 -0300 Subject: bug # 20681 delete() function should not remove elements from original list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The setup: list with 3 elements, delete one: $test_list = [‘a’, ‘b’, ‘c’] $test_deleted = delete($test_list, ‘a’) Print out the elements in ‘test_deleted’: notify { ‘group_output2’: withpath => true, name => “$cfeng::test_deleted”, } Notice: /Stage[main]/Syslog/Notify[group_output2]/message: bc Good! Run-on output shows that ‘a’ was deleted Print out the elements in ‘test_list’: notify { ‘group_output1’: withpath => true, name => “$cfeng::test_list”, } Notice: /Stage[main]/Syslog/Notify[group_output1]/message: bc WHAT!? 'a' was deleted from ‘test_list’ as well! Expected abc as output! This behaviour is confirmed for string, hash and array. This is fixed on this commit, I had added two spec tests to cover that cases. bug #20681 spec test for delete() function. I had forgot in the last commit the spec test for hash in the delete function. bug # 20681 delete() function change aproach. Instead of rejecting elements from the original list, we use collection = arguments[0].dup . then latter we could continue to use delete and gsub! on collection without impact on original argument. this is a better solution than the previous one, and works on ruby 1.8.7, 1.9.3 and 2.0.0. The previous solution does not work on ruby 1.8.7. delete function remove typo whitespace. fix typo whitespaces. --- spec/unit/puppet/parser/functions/delete_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/delete_spec.rb b/spec/unit/puppet/parser/functions/delete_spec.rb index 2f29c93..06238f1 100755 --- a/spec/unit/puppet/parser/functions/delete_spec.rb +++ b/spec/unit/puppet/parser/functions/delete_spec.rb @@ -35,4 +35,22 @@ describe "the delete function" do result.should(eq({ 'a' => 1, 'c' => 3 })) end + it "should not change origin array passed as argument" do + origin_array = ['a','b','c','d'] + result = scope.function_delete([origin_array, 'b']) + origin_array.should(eq(['a','b','c','d'])) + end + + it "should not change the origin string passed as argument" do + origin_string = 'foobarbabarz' + result = scope.function_delete([origin_string,'bar']) + origin_string.should(eq('foobarbabarz')) + end + + it "should not change origin hash passed as argument" do + origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } + result = scope.function_delete([origin_hash, 'b']) + origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) + end + end -- cgit v1.2.3 From 51d96088c1d6bde8dae511d6a93bc6775e716f60 Mon Sep 17 00:00:00 2001 From: Leonardo Rodrigues de Mello Date: Mon, 16 Sep 2013 10:33:58 -0300 Subject: (#20681) fix behaviour of delete_values The issue #20681 describe the error of delete() function removing the elements from the origin array/hash/string. This issue affected other delete functions. Because ruby delete and delete_if functions make destructive changes to the origin array/hash. The delete_undef_values removed elements from the origin hash and this is not the desired behaviour. To solve this, we should dup or clone the hash before using the delete or delete_if ruby functions. This fix the problem and add unit tests, so we could enforce this behaviour and prevent regressions. --- spec/unit/puppet/parser/functions/delete_values_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/delete_values_spec.rb b/spec/unit/puppet/parser/functions/delete_values_spec.rb index c62e55f..180cc30 100644 --- a/spec/unit/puppet/parser/functions/delete_values_spec.rb +++ b/spec/unit/puppet/parser/functions/delete_values_spec.rb @@ -27,4 +27,10 @@ describe "the delete_values function" do result.should(eq({ 'a'=>'A', 'B'=>'C' })) end + it "should not change origin hash passed as argument" do + origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } + result = scope.function_delete_values([origin_hash, 2]) + origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) + end + end -- cgit v1.2.3 From b43c044581aa7cc7e38c3b010c0218df583ef51f Mon Sep 17 00:00:00 2001 From: Leonardo Rodrigues de Mello Date: Mon, 16 Sep 2013 10:51:15 -0300 Subject: (#20681) delete_at function unit test against issue The issue #20681 describe the error of delete() function removing the elements from the origin array/hash/string. This issue affected the other delete functions. The delete_at function is not afected by this bug, but it did not had the unit test to check against it. I had added the unit test so we could prevent regressions on the future and also have better test coverage. --- spec/unit/puppet/parser/functions/delete_at_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/delete_at_spec.rb b/spec/unit/puppet/parser/functions/delete_at_spec.rb index d8d9618..cfc0a29 100755 --- a/spec/unit/puppet/parser/functions/delete_at_spec.rb +++ b/spec/unit/puppet/parser/functions/delete_at_spec.rb @@ -16,4 +16,10 @@ describe "the delete_at function" do result = scope.function_delete_at([['a','b','c'],1]) result.should(eq(['a','c'])) end + + it "should not change origin array passed as argument" do + origin_array = ['a','b','c','d'] + result = scope.function_delete_at([origin_array, 1]) + origin_array.should(eq(['a','b','c','d'])) + end end -- cgit v1.2.3 From bcd84f5c3d79c4e83366772da5eb0e82291155a6 Mon Sep 17 00:00:00 2001 From: Leonardo Rodrigues de Mello Date: Tue, 17 Sep 2013 11:10:00 -0300 Subject: (#16498) Added unit test for loadyaml function. As stated on the issue #16498, it would be great to have unit tests for all the functions. Function loadyaml was missing a unit test. This commit added the unit test to loadyaml function. --- spec/unit/puppet/parser/functions/loadyaml_spec.rb | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/unit/puppet/parser/functions/loadyaml_spec.rb (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/loadyaml_spec.rb b/spec/unit/puppet/parser/functions/loadyaml_spec.rb new file mode 100644 index 0000000..fe16318 --- /dev/null +++ b/spec/unit/puppet/parser/functions/loadyaml_spec.rb @@ -0,0 +1,25 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the loadyaml function" do + include PuppetlabsSpec::Files + + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("loadyaml").should == "function_loadyaml" + end + + it "should raise a ParseError if there is less than 1 arguments" do + expect { scope.function_loadyaml([]) }.to raise_error(Puppet::ParseError) + end + + it "should convert YAML file to a data structure" do + yaml_file = tmpfilename ('yamlfile') + File.open(yaml_file, 'w') do |fh| + fh.write("---\n aaa: 1\n bbb: 2\n ccc: 3\n ddd: 4\n") + end + result = scope.function_loadyaml([yaml_file]) + result.should == {"aaa" => 1, "bbb" => 2, "ccc" => 3, "ddd" => 4 } + end +end -- cgit v1.2.3 From 80a8b7bd1fdb3aadd53d112ce9a20b86d8ea9a62 Mon Sep 17 00:00:00 2001 From: Leonardo Rodrigues de Mello Date: Mon, 16 Sep 2013 11:08:13 -0300 Subject: (#20681) fix behaviour of delete_undef_values The issue #20681 describe the error of delete() function removing the elements from the origin array/hash/string. This issue affected other delete functions. Because ruby delete and delete_if functions make destructive changes to the origin array/hash. The delete_undef_values removed elements from the origin array/hash and this is not the desired behaviour. To solve this, we should dup or clone the array/hash before using the delete or delete_if ruby functions. We should also check if args[0] is not nil before using dup, since dup on nil raises exception. This fix the problem and add unit tests, so we could enforce this behaviour and prevent regressions. --- .../unit/puppet/parser/functions/delete_undef_values_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb b/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb index 0536641..404aeda 100644 --- a/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb +++ b/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb @@ -26,4 +26,16 @@ describe "the delete_undef_values function" do result = scope.function_delete_undef_values([{'a'=>'A','b'=>:undef,'c'=>'C','d'=>'undef'}]) result.should(eq({'a'=>'A','c'=>'C','d'=>'undef'})) end + + it "should not change origin array passed as argument" do + origin_array = ['a',:undef,'c','undef'] + result = scope.function_delete_undef_values([origin_array]) + origin_array.should(eq(['a',:undef,'c','undef'])) + end + + it "should not change origin hash passed as argument" do + origin_hash = { 'a' => 1, 'b' => :undef, 'c' => 'undef' } + result = scope.function_delete_undef_values([origin_hash]) + origin_hash.should(eq({ 'a' => 1, 'b' => :undef, 'c' => 'undef' })) + end end -- cgit v1.2.3 From 9e0d8a8e0a83e1659fdb289078fd15862dca028b Mon Sep 17 00:00:00 2001 From: sgzijl Date: Mon, 9 Sep 2013 16:20:36 +0200 Subject: (#22214): close content file before executing checkscript Right now validation seems to be done against zero byte generated temp files. We need to close the file before executing validation against it. --- spec/unit/puppet/parser/functions/validate_cmd_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb index 69ea7f4..c0defbc 100644 --- a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb @@ -78,4 +78,12 @@ describe Puppet::Parser::Functions.function(:validate_cmd) do end end end + + it "can positively validate file content" do + expect { subject.call ["non-empty", "/usr/bin/test -s"] }.to_not raise_error + end + + it "can negatively validate file content" do + expect { subject.call ["", "/usr/bin/test -s"] }.to raise_error Puppet::ParseError, /failed to validate.*test -s/ + end end -- cgit v1.2.3 From 63811b9d599bdc23ae9c69189f7940013fcae87a Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Wed, 18 Sep 2013 21:48:45 -0700 Subject: (maint) Simplify validate_cmd specs --- .../puppet/parser/functions/validate_cmd_spec.rb | 91 ++++++---------------- 1 file changed, 23 insertions(+), 68 deletions(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb index c0defbc..0aa3ba7 100644 --- a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb @@ -3,87 +3,42 @@ require 'spec_helper' describe Puppet::Parser::Functions.function(:validate_cmd) do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - # The subject of these examplres is the method itself. subject do - # This makes sure the function is loaded within each test function_name = Puppet::Parser::Functions.function(:validate_cmd) scope.method(function_name) end - context 'Using Puppet::Parser::Scope.new' do - - describe 'Garbage inputs' do - inputs = [ - [ nil ], - [ [ nil ] ], - [ { 'foo' => 'bar' } ], - [ { } ], - [ '' ], - [ "one", "one", "MSG to User", "4th arg" ], - ] - - inputs.each do |input| - it "validate_cmd(#{input.inspect}) should fail" do - expect { subject.call [input] }.to raise_error Puppet::ParseError - end - end + describe "with an explicit failure message" do + it "prints the failure message on error" do + expect { + subject.call ['', '/bin/false', 'failure message!'] + }.to raise_error Puppet::ParseError, /failure message!/ end + end - describe 'Valid inputs' do - inputs = [ - [ '/full/path/to/something', '/bin/echo' ], - [ '/full/path/to/something', '/bin/cat' ], - ] - - inputs.each do |input| - it "validate_cmd(#{input.inspect}) should not fail" do - expect { subject.call input }.not_to raise_error - end - end + describe "on validation failure" do + it "includes the command error output" do + expect { + subject.call ['', '/bin/touch /cant/touch/this'] + }.to raise_error Puppet::ParseError, /cannot touch/ end - describe "Valid inputs which should raise an exception without a message" do - # The intent here is to make sure valid inputs raise exceptions when they - # don't specify an error message to display. This is the behvior in - # 2.2.x and prior. - inputs = [ - [ "hello", "/bin/false" ], - ] - - inputs.each do |input| - it "validate_cmd(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /validate_cmd.*?failed to validate content with command/ - end - end + it "includes the command return value" do + expect { + subject.call ['', '/cant/run/this'] + }.to raise_error Puppet::ParseError, /returned 1\b/ end + end - describe "Nicer Error Messages" do - # The intent here is to make sure the function returns the 3rd argument - # in the exception thrown - inputs = [ - [ "hello", [ "bye", "later", "adios" ], "MSG to User" ], - [ "greetings", "salutations", "Error, greetings does not match salutations" ], - ] - - inputs.each do |input| - it "validate_cmd(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /#{input[2]}/ - end - end + describe "when performing actual validation" do + it "can positively validate file content" do + expect { subject.call ["non-empty", "/usr/bin/test -s"] }.to_not raise_error end - describe "Test output message" do - it "validate_cmd('whatever', 'kthnksbye') should fail" do - expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.* returned 1/ - end + it "can negatively validate file content" do + expect { + subject.call ["", "/usr/bin/test -s"] + }.to raise_error Puppet::ParseError, /failed to validate.*test -s/ end end - - it "can positively validate file content" do - expect { subject.call ["non-empty", "/usr/bin/test -s"] }.to_not raise_error - end - - it "can negatively validate file content" do - expect { subject.call ["", "/usr/bin/test -s"] }.to raise_error Puppet::ParseError, /failed to validate.*test -s/ - end end -- cgit v1.2.3 From 57a5c0b3e36e1c01016865c264ca3642f64b5034 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Tue, 29 Oct 2013 14:21:03 -0400 Subject: (Main) fix typo in pick error message Update pick error message "at least one non empty value" --- spec/unit/puppet/parser/functions/pick_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 spec/unit/puppet/parser/functions/pick_spec.rb (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/pick_spec.rb b/spec/unit/puppet/parser/functions/pick_spec.rb old mode 100644 new mode 100755 index d2b275f..f53fa80 --- a/spec/unit/puppet/parser/functions/pick_spec.rb +++ b/spec/unit/puppet/parser/functions/pick_spec.rb @@ -29,6 +29,6 @@ describe "the pick function" do end it 'should error if no values are passed' do - expect { scope.function_pick([]) }.to( raise_error(Puppet::ParseError, "pick(): must receive at last one non empty value")) + expect { scope.function_pick([]) }.to( raise_error(Puppet::ParseError, "pick(): must receive at least one non empty value")) end end -- cgit v1.2.3 From 199ca9c78be3ceb7d8d49329ea28ff75e53d979e Mon Sep 17 00:00:00 2001 From: Justin Burnham Date: Tue, 24 Sep 2013 10:57:15 -0700 Subject: (#20200) Add a recursive merge function. Issue #20200 notes that the merge function does not support nested hashes. To prevent unintended side effects with changing merge, add a deep_merge function instead. --- .../puppet/parser/functions/deep_merge_spec.rb | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 spec/unit/puppet/parser/functions/deep_merge_spec.rb (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/deep_merge_spec.rb b/spec/unit/puppet/parser/functions/deep_merge_spec.rb new file mode 100644 index 0000000..fffb7f7 --- /dev/null +++ b/spec/unit/puppet/parser/functions/deep_merge_spec.rb @@ -0,0 +1,77 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:deep_merge) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + describe 'when calling deep_merge from puppet' do + it "should not compile when no arguments are passed" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = '$x = deep_merge()' + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + + it "should not compile when 1 argument is passed" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = "$my_hash={'one' => 1}\n$x = deep_merge($my_hash)" + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + end + + describe 'when calling deep_merge on the scope instance' do + it 'should require all parameters are hashes' do + expect { new_hash = scope.function_deep_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/) + expect { new_hash = scope.function_deep_merge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) + end + + it 'should accept empty strings as puppet undef' do + expect { new_hash = scope.function_deep_merge([{}, ''])}.not_to raise_error(Puppet::ParseError, /unexpected argument type String/) + end + + it 'should be able to deep_merge two hashes' do + new_hash = scope.function_deep_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}]) + new_hash['one'].should == '1' + new_hash['two'].should == '2' + new_hash['three'].should == '2' + end + + it 'should deep_merge multiple hashes' do + hash = scope.function_deep_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) + hash['one'].should == '3' + end + + it 'should accept empty hashes' do + scope.function_deep_merge([{},{},{}]).should == {} + end + + it 'should deep_merge subhashes' do + hash = scope.function_deep_merge([{'one' => 1}, {'two' => 2, 'three' => { 'four' => 4 } }]) + hash['one'].should == 1 + hash['two'].should == 2 + hash['three'].should == { 'four' => 4 } + end + + it 'should append to subhashes' do + hash = scope.function_deep_merge([{'one' => { 'two' => 2 } }, { 'one' => { 'three' => 3 } }]) + hash['one'].should == { 'two' => 2, 'three' => 3 } + end + + it 'should append to subhashes 2' do + hash = scope.function_deep_merge([{'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, {'two' => 'dos', 'three' => { 'five' => 5 } }]) + hash['one'].should == 1 + hash['two'].should == 'dos' + hash['three'].should == { 'four' => 4, 'five' => 5 } + end + + it 'should append to subhashes 3' do + hash = scope.function_deep_merge([{ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } }]) + hash['key1'].should == { 'a' => 1, 'b' => 99 } + hash['key2'].should == { 'c' => 3 } + end + end +end -- cgit v1.2.3 From a1978698ef0909c0954812176316a7f28b0db986 Mon Sep 17 00:00:00 2001 From: Tomas Doran Date: Tue, 19 Nov 2013 18:42:19 +0000 Subject: Fix the tests on osx --- spec/unit/puppet/parser/functions/validate_cmd_spec.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb index 0aa3ba7..a86cb01 100644 --- a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb @@ -1,5 +1,8 @@ require 'spec_helper' +TESTEXE = File.exists?('/usr/bin/test') ? '/usr/bin/test' : '/bin/test' +TOUCHEXE = File.exists?('/usr/bin/touch') ? '/usr/bin/touch' : '/bin/touch' + describe Puppet::Parser::Functions.function(:validate_cmd) do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } @@ -19,8 +22,8 @@ describe Puppet::Parser::Functions.function(:validate_cmd) do describe "on validation failure" do it "includes the command error output" do expect { - subject.call ['', '/bin/touch /cant/touch/this'] - }.to raise_error Puppet::ParseError, /cannot touch/ + subject.call ['', "#{TOUCHEXE} /cant/touch/this"] + }.to raise_error Puppet::ParseError, /(cannot touch|o such file or)/ end it "includes the command return value" do @@ -32,12 +35,12 @@ describe Puppet::Parser::Functions.function(:validate_cmd) do describe "when performing actual validation" do it "can positively validate file content" do - expect { subject.call ["non-empty", "/usr/bin/test -s"] }.to_not raise_error + expect { subject.call ["non-empty", "#{TESTEXE} -s"] }.to_not raise_error end it "can negatively validate file content" do expect { - subject.call ["", "/usr/bin/test -s"] + subject.call ["", "#{TESTEXE} -s"] }.to raise_error Puppet::ParseError, /failed to validate.*test -s/ end end -- cgit v1.2.3 From 4241eb4806c64fb406caef998383bd455a802c83 Mon Sep 17 00:00:00 2001 From: Tristan Smith Date: Wed, 20 Nov 2013 18:30:46 -0800 Subject: calling rspec directly makes this not pass ruby -c. adjusting to be in line with the rest. --- spec/unit/puppet/parser/functions/is_function_available.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/is_function_available.rb b/spec/unit/puppet/parser/functions/is_function_available.rb index bd40c51..d5669a7 100644 --- a/spec/unit/puppet/parser/functions/is_function_available.rb +++ b/spec/unit/puppet/parser/functions/is_function_available.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env rspec +#!/usr/bin/env ruby -S rspec require 'spec_helper' describe "the is_function_available function" do -- cgit v1.2.3 From 1077881873024a5d2f53d3b4c4159ee49ae38c7a Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Mon, 9 Dec 2013 11:45:50 -0700 Subject: (#23381) add is_bool() function --- spec/unit/puppet/parser/functions/is_bool_spec.rb | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 spec/unit/puppet/parser/functions/is_bool_spec.rb (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/is_bool_spec.rb b/spec/unit/puppet/parser/functions/is_bool_spec.rb new file mode 100644 index 0000000..c94e83a --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_bool_spec.rb @@ -0,0 +1,44 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the is_bool function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("is_bool").should == "function_is_bool" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_is_bool([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if passed a TrueClass" do + result = scope.function_is_bool([true]) + result.should(eq(true)) + end + + it "should return true if passed a FalseClass" do + result = scope.function_is_bool([false]) + result.should(eq(true)) + end + + it "should return false if passed the string 'true'" do + result = scope.function_is_bool(['true']) + result.should(eq(false)) + end + + it "should return false if passed the string 'false'" do + result = scope.function_is_bool(['false']) + result.should(eq(false)) + end + + it "should return false if passed an array" do + result = scope.function_is_bool([["a","b"]]) + result.should(eq(false)) + end + + it "should return false if passed a hash" do + result = scope.function_is_bool([{"a" => "b"}]) + result.should(eq(false)) + end +end -- cgit v1.2.3 From 7085472e69569abf67862dfdd4263e8754afb89b Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Fri, 20 Dec 2013 14:59:51 -0800 Subject: (maint) Improve test coverage for prefix and suffix --- spec/unit/puppet/parser/functions/prefix_spec.rb | 19 ++++++++++++++----- spec/unit/puppet/parser/functions/suffix_spec.rb | 18 +++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/prefix_spec.rb b/spec/unit/puppet/parser/functions/prefix_spec.rb index 5cf592b..6e8ddc5 100644 --- a/spec/unit/puppet/parser/functions/prefix_spec.rb +++ b/spec/unit/puppet/parser/functions/prefix_spec.rb @@ -4,15 +4,24 @@ require 'spec_helper' describe "the prefix function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - Puppet::Parser::Functions.function("prefix").should == "function_prefix" + it "raises a ParseError if there is less than 1 arguments" do + expect { scope.function_prefix([]) }.to raise_error(Puppet::ParseError, /number of arguments/) end - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_prefix([]) }.should( raise_error(Puppet::ParseError)) + it "raises an error if the first argument is not an array" do + expect { + scope.function_prefix([Object.new]) + }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/) end - it "should return a prefixed array" do + + it "raises an error if the second argument is not a string" do + expect { + scope.function_prefix([['first', 'second'], 42]) + }.to raise_error(Puppet::ParseError, /expected second argument to be a String/) + end + + it "returns a prefixed array" do result = scope.function_prefix([['a','b','c'], 'p']) result.should(eq(['pa','pb','pc'])) end diff --git a/spec/unit/puppet/parser/functions/suffix_spec.rb b/spec/unit/puppet/parser/functions/suffix_spec.rb index c28f719..89ba3b8 100644 --- a/spec/unit/puppet/parser/functions/suffix_spec.rb +++ b/spec/unit/puppet/parser/functions/suffix_spec.rb @@ -4,15 +4,23 @@ require 'spec_helper' describe "the suffix function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - Puppet::Parser::Functions.function("suffix").should == "function_suffix" + it "raises a ParseError if there is less than 1 arguments" do + expect { scope.function_suffix([]) }.to raise_error(Puppet::ParseError, /number of arguments/) end - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_suffix([]) }.should( raise_error(Puppet::ParseError)) + it "raises an error if the first argument is not an array" do + expect { + scope.function_suffix([Object.new]) + }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/) end - it "should return a suffixed array" do + it "raises an error if the second argument is not a string" do + expect { + scope.function_suffix([['first', 'second'], 42]) + }.to raise_error(Puppet::ParseError, /expected second argument to be a String/) + end + + it "returns a suffixed array" do result = scope.function_suffix([['a','b','c'], 'p']) result.should(eq(['ap','bp','cp'])) end -- cgit v1.2.3 From 264dc9bbdee8f04b78f8193d62d17b2ba096d671 Mon Sep 17 00:00:00 2001 From: Simon Effenberg Date: Fri, 20 Dec 2013 00:13:39 +0100 Subject: (PUP-1195) Fix is_numeric/is_integer when checking non-string parameters I expect a function called "is_numeric" or "is_integer" to check if a variable is an integer or a number even if the variable passed by isn't a string nor a number at all. Otherwise we should call them is_string_a_number and is_string_an_integer and we have then to remove the check for .is_a?(Number) and .is_a?(FixNum) now checking also if it is a hex or octal number improved/corrected checking for integer * checking against Integer instead of Fixnum so that also Bignum is matching * now .is_a? Integer is done first so this is quiet fast Now many types of numerics are recognized. 1. Float/Integer values (signed or unsigned, with exponent or without) 2. octal and hex check 3. except hex numbers and the "0." in a float lower than 1 can be prefixed with a '0'. whitespaces shouldn't be allowed as prefix/suffix string representation of numbers should not contain any type of whitespace.. the user is responsible to clean a string before checking it.. fix documentation and added more checks tried to be 99.9% backward compatible * for now the decission is post poned if hex and octal numbers should be allowed or not (is_numeric) * native Bignum is now also a valid integer class fix problem with old 1.8 ruby and Hash.to_s/Array.to_s In ruby < 1.9 array and hashes would be recognized as numeric if they have a special format: 1.8: [1,2,3,4].to_s = "1234" {1=>2}.to_s = "12" 1.9: [1,2,3,4].to_s = "[1, 2, 3, 4]" {1=>2}.to_s = "{1=>2}" --- .../puppet/parser/functions/is_integer_spec.rb | 35 ++++++++++ .../puppet/parser/functions/is_numeric_spec.rb | 80 ++++++++++++++++++++++ 2 files changed, 115 insertions(+) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/is_integer_spec.rb b/spec/unit/puppet/parser/functions/is_integer_spec.rb index 4335795..24141cc 100644 --- a/spec/unit/puppet/parser/functions/is_integer_spec.rb +++ b/spec/unit/puppet/parser/functions/is_integer_spec.rb @@ -17,6 +17,11 @@ describe "the is_integer function" do result.should(eq(true)) end + it "should return true if a negative integer" do + result = scope.function_is_integer(["-7"]) + result.should(eq(true)) + end + it "should return false if a float" do result = scope.function_is_integer(["3.2"]) result.should(eq(false)) @@ -31,4 +36,34 @@ describe "the is_integer function" do result = scope.function_is_integer([3*2]) result.should(eq(true)) end + + it "should return false if an array" do + result = scope.function_is_numeric([["asdf"]]) + result.should(eq(false)) + end + + it "should return false if a hash" do + result = scope.function_is_numeric([{"asdf" => false}]) + result.should(eq(false)) + end + + it "should return false if a boolean" do + result = scope.function_is_numeric([true]) + result.should(eq(false)) + end + + it "should return false if a whitespace is in the string" do + result = scope.function_is_numeric([" -1324"]) + result.should(eq(false)) + end + + it "should return false if it is zero prefixed" do + result = scope.function_is_numeric(["0001234"]) + result.should(eq(false)) + end + + it "should return false if it is wrapped inside an array" do + result = scope.function_is_numeric([[1234]]) + result.should(eq(false)) + end end diff --git a/spec/unit/puppet/parser/functions/is_numeric_spec.rb b/spec/unit/puppet/parser/functions/is_numeric_spec.rb index d7440fb..1df1497 100644 --- a/spec/unit/puppet/parser/functions/is_numeric_spec.rb +++ b/spec/unit/puppet/parser/functions/is_numeric_spec.rb @@ -36,4 +36,84 @@ describe "the is_numeric function" do result = scope.function_is_numeric(["asdf"]) result.should(eq(false)) end + + it "should return false if an array" do + result = scope.function_is_numeric([["asdf"]]) + result.should(eq(false)) + end + + it "should return false if an array of integers" do + result = scope.function_is_numeric([[1,2,3,4]]) + result.should(eq(false)) + end + + it "should return false if a hash" do + result = scope.function_is_numeric([{"asdf" => false}]) + result.should(eq(false)) + end + + it "should return false if a hash with numbers in it" do + result = scope.function_is_numeric([{1 => 2}]) + result.should(eq(false)) + end + + it "should return false if a boolean" do + result = scope.function_is_numeric([true]) + result.should(eq(false)) + end + + it "should return true if a negative float with exponent" do + result = scope.function_is_numeric(["-342.2315e-12"]) + result.should(eq(true)) + end + + it "should return false if a negative integer with whitespaces before/after the dash" do + result = scope.function_is_numeric([" - 751"]) + result.should(eq(false)) + end + +# it "should return true if a hexadecimal" do +# result = scope.function_is_numeric(["0x52F8c"]) +# result.should(eq(true)) +# end +# +# it "should return true if a hexadecimal with uppercase 0X prefix" do +# result = scope.function_is_numeric(["0X52F8c"]) +# result.should(eq(true)) +# end +# +# it "should return false if a hexadecimal without a prefix" do +# result = scope.function_is_numeric(["52F8c"]) +# result.should(eq(false)) +# end +# +# it "should return true if a octal" do +# result = scope.function_is_numeric(["0751"]) +# result.should(eq(true)) +# end +# +# it "should return true if a negative hexadecimal" do +# result = scope.function_is_numeric(["-0x52F8c"]) +# result.should(eq(true)) +# end +# +# it "should return true if a negative octal" do +# result = scope.function_is_numeric(["-0751"]) +# result.should(eq(true)) +# end +# +# it "should return false if a negative octal with whitespaces before/after the dash" do +# result = scope.function_is_numeric([" - 0751"]) +# result.should(eq(false)) +# end +# +# it "should return false if a bad hexadecimal" do +# result = scope.function_is_numeric(["0x23d7g"]) +# result.should(eq(false)) +# end +# +# it "should return false if a bad octal" do +# result = scope.function_is_numeric(["0287"]) +# result.should(eq(false)) +# end end -- cgit v1.2.3 From 52fcef573f206630df007caf2979fb4c404e3dbc Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 23 Jan 2014 15:22:27 +0100 Subject: (PUP-638) Add a pick_default() function that always returns a value. This version of pick() does not error out, instead always returning at least the last argument, even if that too has no "real" value. --- .../puppet/parser/functions/pick_default_spec.rb | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 spec/unit/puppet/parser/functions/pick_default_spec.rb (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/pick_default_spec.rb b/spec/unit/puppet/parser/functions/pick_default_spec.rb new file mode 100644 index 0000000..c9235b5 --- /dev/null +++ b/spec/unit/puppet/parser/functions/pick_default_spec.rb @@ -0,0 +1,58 @@ +#!/usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the pick_default function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("pick_default").should == "function_pick_default" + end + + it 'should return the correct value' do + scope.function_pick_default(['first', 'second']).should == 'first' + end + + it 'should return the correct value if the first value is empty' do + scope.function_pick_default(['', 'second']).should == 'second' + end + + it 'should skip empty string values' do + scope.function_pick_default(['', 'first']).should == 'first' + end + + it 'should skip :undef values' do + scope.function_pick_default([:undef, 'first']).should == 'first' + end + + it 'should skip :undefined values' do + scope.function_pick_default([:undefined, 'first']).should == 'first' + end + + it 'should return the empty string if it is the last possibility' do + scope.function_pick_default([:undef, :undefined, '']).should == '' + end + + it 'should return :undef if it is the last possibility' do + scope.function_pick_default(['', :undefined, :undef]).should == :undef + end + + it 'should return :undefined if it is the last possibility' do + scope.function_pick_default([:undef, '', :undefined]).should == :undefined + end + + it 'should return the empty string if it is the only possibility' do + scope.function_pick_default(['']).should == '' + end + + it 'should return :undef if it is the only possibility' do + scope.function_pick_default([:undef]).should == :undef + end + + it 'should return :undefined if it is the only possibility' do + scope.function_pick_default([:undefined]).should == :undefined + end + + it 'should error if no values are passed' do + expect { scope.function_pick_default([]) }.to raise_error(Puppet::Error, /Must receive at least one argument./) + end +end -- cgit v1.2.3 From a972e0645b31cf1eb89874cb08b403bdc0fad3a4 Mon Sep 17 00:00:00 2001 From: Sharif Nassar Date: Wed, 5 Feb 2014 15:01:45 -0800 Subject: Remove trailing whitespace --- spec/unit/puppet/parser/functions/delete_at_spec.rb | 4 ++-- spec/unit/puppet/parser/functions/delete_spec.rb | 6 +++--- spec/unit/puppet/parser/functions/delete_undef_values_spec.rb | 10 +++++----- spec/unit/puppet/parser/functions/delete_values_spec.rb | 6 +++--- spec/unit/puppet/parser/functions/str2bool_spec.rb | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/delete_at_spec.rb b/spec/unit/puppet/parser/functions/delete_at_spec.rb index cfc0a29..593cf45 100755 --- a/spec/unit/puppet/parser/functions/delete_at_spec.rb +++ b/spec/unit/puppet/parser/functions/delete_at_spec.rb @@ -17,9 +17,9 @@ describe "the delete_at function" do result.should(eq(['a','c'])) end - it "should not change origin array passed as argument" do + it "should not change origin array passed as argument" do origin_array = ['a','b','c','d'] result = scope.function_delete_at([origin_array, 1]) origin_array.should(eq(['a','b','c','d'])) - end + end end diff --git a/spec/unit/puppet/parser/functions/delete_spec.rb b/spec/unit/puppet/parser/functions/delete_spec.rb index 06238f1..1508a63 100755 --- a/spec/unit/puppet/parser/functions/delete_spec.rb +++ b/spec/unit/puppet/parser/functions/delete_spec.rb @@ -35,7 +35,7 @@ describe "the delete function" do result.should(eq({ 'a' => 1, 'c' => 3 })) end - it "should not change origin array passed as argument" do + it "should not change origin array passed as argument" do origin_array = ['a','b','c','d'] result = scope.function_delete([origin_array, 'b']) origin_array.should(eq(['a','b','c','d'])) @@ -47,8 +47,8 @@ describe "the delete function" do origin_string.should(eq('foobarbabarz')) end - it "should not change origin hash passed as argument" do - origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } + it "should not change origin hash passed as argument" do + origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } result = scope.function_delete([origin_hash, 'b']) origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) end diff --git a/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb b/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb index 404aeda..b341d88 100644 --- a/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb +++ b/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb @@ -27,15 +27,15 @@ describe "the delete_undef_values function" do result.should(eq({'a'=>'A','c'=>'C','d'=>'undef'})) end - it "should not change origin array passed as argument" do + it "should not change origin array passed as argument" do origin_array = ['a',:undef,'c','undef'] result = scope.function_delete_undef_values([origin_array]) origin_array.should(eq(['a',:undef,'c','undef'])) - end + end - it "should not change origin hash passed as argument" do - origin_hash = { 'a' => 1, 'b' => :undef, 'c' => 'undef' } + it "should not change origin hash passed as argument" do + origin_hash = { 'a' => 1, 'b' => :undef, 'c' => 'undef' } result = scope.function_delete_undef_values([origin_hash]) origin_hash.should(eq({ 'a' => 1, 'b' => :undef, 'c' => 'undef' })) - end + end end diff --git a/spec/unit/puppet/parser/functions/delete_values_spec.rb b/spec/unit/puppet/parser/functions/delete_values_spec.rb index 180cc30..8d7f231 100644 --- a/spec/unit/puppet/parser/functions/delete_values_spec.rb +++ b/spec/unit/puppet/parser/functions/delete_values_spec.rb @@ -27,10 +27,10 @@ describe "the delete_values function" do result.should(eq({ 'a'=>'A', 'B'=>'C' })) end - it "should not change origin hash passed as argument" do - origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } + it "should not change origin hash passed as argument" do + origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } result = scope.function_delete_values([origin_hash, 2]) origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) - end + end end diff --git a/spec/unit/puppet/parser/functions/str2bool_spec.rb b/spec/unit/puppet/parser/functions/str2bool_spec.rb index ef6350f..73c09c7 100644 --- a/spec/unit/puppet/parser/functions/str2bool_spec.rb +++ b/spec/unit/puppet/parser/functions/str2bool_spec.rb @@ -21,7 +21,7 @@ describe "the str2bool function" do result = scope.function_str2bool(["undef"]) result.should(eq(false)) end - + it "should return the boolean it was called with" do result = scope.function_str2bool([true]) result.should(eq(true)) -- cgit v1.2.3 From c12e9afc97f4356bc20554d32861889680c5fdc1 Mon Sep 17 00:00:00 2001 From: Justin Burnham Date: Mon, 17 Feb 2014 11:46:55 -0800 Subject: PUP-1724 Don't modify the paramaters to deep_merge Instead of modifying the first paramater of deep_merge due to the use of the merge! function, instead use merge to return a copy of the merged object. This allows one to continue to use the original first parameter after the call to deep_merge. --- .../puppet/parser/functions/deep_merge_spec.rb | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/deep_merge_spec.rb b/spec/unit/puppet/parser/functions/deep_merge_spec.rb index fffb7f7..9623fd6 100644 --- a/spec/unit/puppet/parser/functions/deep_merge_spec.rb +++ b/spec/unit/puppet/parser/functions/deep_merge_spec.rb @@ -73,5 +73,33 @@ describe Puppet::Parser::Functions.function(:deep_merge) do hash['key1'].should == { 'a' => 1, 'b' => 99 } hash['key2'].should == { 'c' => 3 } end + + it 'should not change the original hashes' do + hash1 = {'one' => { 'two' => 2 } } + hash2 = { 'one' => { 'three' => 3 } } + hash = scope.function_deep_merge([hash1, hash2]) + hash1.should == {'one' => { 'two' => 2 } } + hash2.should == { 'one' => { 'three' => 3 } } + hash['one'].should == { 'two' => 2, 'three' => 3 } + end + + it 'should not change the original hashes 2' do + hash1 = {'one' => { 'two' => [1,2] } } + hash2 = { 'one' => { 'three' => 3 } } + hash = scope.function_deep_merge([hash1, hash2]) + hash1.should == {'one' => { 'two' => [1,2] } } + hash2.should == { 'one' => { 'three' => 3 } } + hash['one'].should == { 'two' => [1,2], 'three' => 3 } + end + + it 'should not change the original hashes 3' do + hash1 = {'one' => { 'two' => [1,2, {'two' => 2} ] } } + hash2 = { 'one' => { 'three' => 3 } } + hash = scope.function_deep_merge([hash1, hash2]) + hash1.should == {'one' => { 'two' => [1,2, {'two' => 2}] } } + hash2.should == { 'one' => { 'three' => 3 } } + hash['one'].should == { 'two' => [1,2, {'two' => 2} ], 'three' => 3 } + hash['one']['two'].should == [1,2, {'two' => 2}] + end end end -- cgit v1.2.3 From 35bf5fd8c93d5052ecf5284ed3194a92cab838d5 Mon Sep 17 00:00:00 2001 From: Martin Foot Date: Fri, 21 Feb 2014 14:32:32 +0000 Subject: Allow concat to take non-array second parameters Also improve and extend concat tests to lock down functionality --- spec/unit/puppet/parser/functions/concat_spec.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/concat_spec.rb b/spec/unit/puppet/parser/functions/concat_spec.rb index 123188b..6e67620 100644 --- a/spec/unit/puppet/parser/functions/concat_spec.rb +++ b/spec/unit/puppet/parser/functions/concat_spec.rb @@ -4,12 +4,27 @@ require 'spec_helper' describe "the concat function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_concat([]) }.should( raise_error(Puppet::ParseError)) + it "should raise a ParseError if the client does not provide two arguments" do + lambda { scope.function_concat([]) }.should(raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if the first parameter is not an array" do + lambda { scope.function_concat([1, []])}.should(raise_error(Puppet::ParseError)) end it "should be able to concat an array" do result = scope.function_concat([['1','2','3'],['4','5','6']]) result.should(eq(['1','2','3','4','5','6'])) end + + it "should be able to concat a primitive to an array" do + result = scope.function_concat([['1','2','3'],'4']) + result.should(eq(['1','2','3','4'])) + end + + it "should not accidentally flatten nested arrays" do + result = scope.function_concat([['1','2','3'],[['4','5'],'6']]) + result.should(eq(['1','2','3',['4','5'],'6'])) + end + end -- cgit v1.2.3 From 3854e076ccb75d1bcb1ddd29f5976b194d857765 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 5 Mar 2014 15:43:58 -0500 Subject: Numerous changes to update testing gems. This work updates a number of Gems to the latest versions (rspec, rspec-puppet), and updates and tweaks a bunch of tests to work with the updated gems. --- spec/unit/puppet/parser/functions/deep_merge_spec.rb | 2 +- spec/unit/puppet/parser/functions/merge_spec.rb | 2 +- spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/deep_merge_spec.rb b/spec/unit/puppet/parser/functions/deep_merge_spec.rb index fffb7f7..1d2c183 100644 --- a/spec/unit/puppet/parser/functions/deep_merge_spec.rb +++ b/spec/unit/puppet/parser/functions/deep_merge_spec.rb @@ -30,7 +30,7 @@ describe Puppet::Parser::Functions.function(:deep_merge) do end it 'should accept empty strings as puppet undef' do - expect { new_hash = scope.function_deep_merge([{}, ''])}.not_to raise_error(Puppet::ParseError, /unexpected argument type String/) + expect { new_hash = scope.function_deep_merge([{}, ''])}.not_to raise_error end it 'should be able to deep_merge two hashes' do diff --git a/spec/unit/puppet/parser/functions/merge_spec.rb b/spec/unit/puppet/parser/functions/merge_spec.rb index 8a170bb..15a5d94 100644 --- a/spec/unit/puppet/parser/functions/merge_spec.rb +++ b/spec/unit/puppet/parser/functions/merge_spec.rb @@ -30,7 +30,7 @@ describe Puppet::Parser::Functions.function(:merge) do end it 'should accept empty strings as puppet undef' do - expect { new_hash = scope.function_merge([{}, ''])}.not_to raise_error(Puppet::ParseError, /unexpected argument type String/) + expect { new_hash = scope.function_merge([{}, ''])}.not_to raise_error end it 'should be able to merge two hashes' do diff --git a/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb b/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb index 08aaf78..1c9cce2 100644 --- a/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb @@ -35,7 +35,7 @@ describe Puppet::Parser::Functions.function(:validate_absolute_path) do end valid_paths.each do |path| it "validate_absolute_path(#{path.inspect}) should not fail" do - expect { subject.call [path] }.not_to raise_error Puppet::ParseError + expect { subject.call [path] }.not_to raise_error end end end @@ -43,7 +43,7 @@ describe Puppet::Parser::Functions.function(:validate_absolute_path) do context "Puppet without mocking" do valid_paths.each do |path| it "validate_absolute_path(#{path.inspect}) should not fail" do - expect { subject.call [path] }.not_to raise_error Puppet::ParseError + expect { subject.call [path] }.not_to raise_error end end end -- cgit v1.2.3 From 09f892023c726eabaa85a308c2dbffd8e8b71fbd Mon Sep 17 00:00:00 2001 From: Andrea Veri Date: Wed, 7 May 2014 11:49:25 +0200 Subject: Add the missing shebangs and fix the wrong ones for rpmlint to stop complaining loudly --- spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb | 1 + spec/unit/puppet/parser/functions/validate_augeas_spec.rb | 1 + spec/unit/puppet/parser/functions/validate_bool_spec.rb | 2 +- spec/unit/puppet/parser/functions/validate_cmd_spec.rb | 1 + spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb | 2 +- spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb | 2 +- spec/unit/puppet/parser/functions/validate_re_spec.rb | 1 + 7 files changed, 7 insertions(+), 3 deletions(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb b/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb index 1c9cce2..342ae84 100644 --- a/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' describe Puppet::Parser::Functions.function(:validate_absolute_path) do diff --git a/spec/unit/puppet/parser/functions/validate_augeas_spec.rb b/spec/unit/puppet/parser/functions/validate_augeas_spec.rb index ab5c140..c695ba2 100644 --- a/spec/unit/puppet/parser/functions/validate_augeas_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_augeas_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' describe Puppet::Parser::Functions.function(:validate_augeas), :if => Puppet.features.augeas? do diff --git a/spec/unit/puppet/parser/functions/validate_bool_spec.rb b/spec/unit/puppet/parser/functions/validate_bool_spec.rb index 261fb23..a352d3b 100644 --- a/spec/unit/puppet/parser/functions/validate_bool_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_bool_spec.rb @@ -1,4 +1,4 @@ -#! /usr/bin/env/ruby -S rspec +#! /usr/bin/env ruby -S rspec require 'spec_helper' diff --git a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb index a86cb01..a6e68df 100644 --- a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' TESTEXE = File.exists?('/usr/bin/test') ? '/usr/bin/test' : '/bin/test' diff --git a/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb b/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb index 85536d3..45401a4 100644 --- a/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb @@ -1,4 +1,4 @@ -#! /usr/bin/env/ruby -S rspec +#! /usr/bin/env ruby -S rspec require "spec_helper" diff --git a/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb b/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb index 1fe5304..a839d90 100644 --- a/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb @@ -1,4 +1,4 @@ -#! /usr/bin/env/ruby -S rspec +#! /usr/bin/env ruby -S rspec require "spec_helper" diff --git a/spec/unit/puppet/parser/functions/validate_re_spec.rb b/spec/unit/puppet/parser/functions/validate_re_spec.rb index d189efb..d29988b 100644 --- a/spec/unit/puppet/parser/functions/validate_re_spec.rb +++ b/spec/unit/puppet/parser/functions/validate_re_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' describe Puppet::Parser::Functions.function(:validate_re) do -- cgit v1.2.3 From 78982c923812042046becad16a3c4d03b6cf3063 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Wed, 7 May 2014 10:09:21 -0700 Subject: Move the 4 misplaced tests --- .../parser/functions/defined_with_params_spec.rb | 37 +++++++ .../parser/functions/ensure_packages_spec.rb | 81 +++++++++++++++ .../parser/functions/ensure_resource_spec.rb | 113 +++++++++++++++++++++ spec/unit/puppet/parser/functions/getparam_spec.rb | 76 ++++++++++++++ 4 files changed, 307 insertions(+) create mode 100644 spec/unit/puppet/parser/functions/defined_with_params_spec.rb create mode 100644 spec/unit/puppet/parser/functions/ensure_packages_spec.rb create mode 100644 spec/unit/puppet/parser/functions/ensure_resource_spec.rb create mode 100644 spec/unit/puppet/parser/functions/getparam_spec.rb (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/defined_with_params_spec.rb b/spec/unit/puppet/parser/functions/defined_with_params_spec.rb new file mode 100644 index 0000000..28dbab3 --- /dev/null +++ b/spec/unit/puppet/parser/functions/defined_with_params_spec.rb @@ -0,0 +1,37 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +require 'rspec-puppet' +describe 'defined_with_params' do + describe 'when a resource is not specified' do + it { should run.with_params().and_raise_error(ArgumentError) } + end + describe 'when compared against a resource with no attributes' do + let :pre_condition do + 'user { "dan": }' + end + it do + should run.with_params('User[dan]', {}).and_return(true) + should run.with_params('User[bob]', {}).and_return(false) + should run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) + end + end + + describe 'when compared against a resource with attributes' do + let :pre_condition do + 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}' + end + it do + should run.with_params('User[dan]', {}).and_return(true) + should run.with_params('User[dan]', '').and_return(true) + should run.with_params('User[dan]', {'ensure' => 'present'} + ).and_return(true) + should run.with_params('User[dan]', + {'ensure' => 'present', 'managehome' => false} + ).and_return(true) + should run.with_params('User[dan]', + {'ensure' => 'absent', 'managehome' => false} + ).and_return(false) + end + end +end diff --git a/spec/unit/puppet/parser/functions/ensure_packages_spec.rb b/spec/unit/puppet/parser/functions/ensure_packages_spec.rb new file mode 100644 index 0000000..436be10 --- /dev/null +++ b/spec/unit/puppet/parser/functions/ensure_packages_spec.rb @@ -0,0 +1,81 @@ +#! /usr/bin/env ruby + +require 'spec_helper' +require 'rspec-puppet' +require 'puppet_spec/compiler' + +describe 'ensure_packages' do + include PuppetSpec::Compiler + + before :each do + Puppet::Parser::Functions.autoloader.loadall + Puppet::Parser::Functions.function(:ensure_packages) + Puppet::Parser::Functions.function(:ensure_resource) + Puppet::Parser::Functions.function(:defined_with_params) + Puppet::Parser::Functions.function(:create_resources) + end + + let :node do Puppet::Node.new('localhost') end + let :compiler do Puppet::Parser::Compiler.new(node) end + let :scope do + if Puppet.version.to_f >= 3.0 + Puppet::Parser::Scope.new(compiler) + else + newscope = Puppet::Parser::Scope.new + newscope.compiler = compiler + newscope.source = Puppet::Resource::Type.new(:node, :localhost) + newscope + end + end + + describe 'argument handling' do + it 'fails with no arguments' do + expect { + scope.function_ensure_packages([]) + }.to raise_error(Puppet::ParseError, /0 for 1 or 2/) + end + + it 'accepts an array of values' do + scope.function_ensure_packages([['foo']]) + end + + it 'accepts a single package name as a string' do + scope.function_ensure_packages(['foo']) + end + end + + context 'given a catalog with puppet package => absent' do + let :catalog do + compile_to_catalog(<<-EOS + ensure_packages(['facter']) + package { puppet: ensure => absent } + EOS + ) + end + + it 'has no effect on Package[puppet]' do + expect(catalog.resource(:package, 'puppet')['ensure']).to eq('absent') + end + end + + context 'given a clean catalog' do + let :catalog do + compile_to_catalog('ensure_packages(["facter"])') + end + + it 'declares package resources with ensure => present' do + expect(catalog.resource(:package, 'facter')['ensure']).to eq('present') + end + end + + context 'given a clean catalog and specified defaults' do + let :catalog do + compile_to_catalog('ensure_packages(["facter"], {"provider" => "gem"})') + end + + it 'declares package resources with ensure => present' do + expect(catalog.resource(:package, 'facter')['ensure']).to eq('present') + expect(catalog.resource(:package, 'facter')['provider']).to eq('gem') + end + end +end diff --git a/spec/unit/puppet/parser/functions/ensure_resource_spec.rb b/spec/unit/puppet/parser/functions/ensure_resource_spec.rb new file mode 100644 index 0000000..33bcac0 --- /dev/null +++ b/spec/unit/puppet/parser/functions/ensure_resource_spec.rb @@ -0,0 +1,113 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' +require 'rspec-puppet' +require 'puppet_spec/compiler' + +describe 'ensure_resource' do + include PuppetSpec::Compiler + + before :all do + Puppet::Parser::Functions.autoloader.loadall + Puppet::Parser::Functions.function(:ensure_packages) + end + + let :node do Puppet::Node.new('localhost') end + let :compiler do Puppet::Parser::Compiler.new(node) end + let :scope do Puppet::Parser::Scope.new(compiler) end + + describe 'when a type or title is not specified' do + it { expect { scope.function_ensure_resource([]) }.to raise_error } + it { expect { scope.function_ensure_resource(['type']) }.to raise_error } + end + + describe 'when compared against a resource with no attributes' do + let :catalog do + compile_to_catalog(<<-EOS + user { "dan": } + ensure_resource('user', 'dan', {}) + EOS + ) + end + + it 'should contain the the ensured resources' do + expect(catalog.resource(:user, 'dan').to_s).to eq('User[dan]') + end + end + + describe 'works when compared against a resource with non-conflicting attributes' do + [ + "ensure_resource('User', 'dan', {})", + "ensure_resource('User', 'dan', '')", + "ensure_resource('User', 'dan', {'ensure' => 'present'})", + "ensure_resource('User', 'dan', {'ensure' => 'present', 'managehome' => false})" + ].each do |ensure_resource| + pp = <<-EOS + user { "dan": ensure => present, shell => "/bin/csh", managehome => false} + #{ensure_resource} + EOS + + it { expect { compile_to_catalog(pp) }.to_not raise_error } + end + end + + describe 'fails when compared against a resource with conflicting attributes' do + pp = <<-EOS + user { "dan": ensure => present, shell => "/bin/csh", managehome => false} + ensure_resource('User', 'dan', {'ensure' => 'absent', 'managehome' => false}) + EOS + + it { expect { compile_to_catalog(pp) }.to raise_error } + end + + describe 'when an array of new resources are passed in' do + let :catalog do + compile_to_catalog("ensure_resource('User', ['dan', 'alex'], {})") + end + + it 'should contain the ensured resources' do + expect(catalog.resource('User[dan]').to_s).to eq('User[dan]') + expect(catalog.resource('User[alex]').to_s).to eq('User[alex]') + end + end + + describe 'when an array of existing resources is compared against existing resources' do + pp = <<-EOS + user { 'dan': ensure => present; 'alex': ensure => present } + ensure_resource('User', ['dan', 'alex'], {}) + EOS + + let :catalog do + compile_to_catalog(pp) + end + + it 'should return the existing resources' do + expect(catalog.resource('User[dan]').to_s).to eq('User[dan]') + expect(catalog.resource('User[alex]').to_s).to eq('User[alex]') + end + end + + describe 'works when compared against existing resources with attributes' do + [ + "ensure_resource('User', ['dan', 'alex'], {})", + "ensure_resource('User', ['dan', 'alex'], '')", + "ensure_resource('User', ['dan', 'alex'], {'ensure' => 'present'})", + ].each do |ensure_resource| + pp = <<-EOS + user { 'dan': ensure => present; 'alex': ensure => present } + #{ensure_resource} + EOS + + it { expect { compile_to_catalog(pp) }.to_not raise_error } + end + end + + describe 'fails when compared against existing resources with conflicting attributes' do + pp = <<-EOS + user { 'dan': ensure => present; 'alex': ensure => present } + ensure_resource('User', ['dan', 'alex'], {'ensure' => 'absent'}) + EOS + + it { expect { compile_to_catalog(pp) }.to raise_error } + end + +end diff --git a/spec/unit/puppet/parser/functions/getparam_spec.rb b/spec/unit/puppet/parser/functions/getparam_spec.rb new file mode 100644 index 0000000..bf024af --- /dev/null +++ b/spec/unit/puppet/parser/functions/getparam_spec.rb @@ -0,0 +1,76 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' +require 'rspec-puppet' +require 'puppet_spec/compiler' + +describe 'getparam' do + include PuppetSpec::Compiler + + before :each do + Puppet::Parser::Functions.autoloader.loadall + Puppet::Parser::Functions.function(:getparam) + end + + let :node do Puppet::Node.new('localhost') end + let :compiler do Puppet::Parser::Compiler.new(node) end + if Puppet.version.to_f >= 3.0 + let :scope do Puppet::Parser::Scope.new(compiler) end + else + let :scope do + newscope = Puppet::Parser::Scope.new + newscope.compiler = compiler + newscope.source = Puppet::Resource::Type.new(:node, :localhost) + newscope + end + end + + it "should exist" do + Puppet::Parser::Functions.function("getparam").should == "function_getparam" + end + + describe 'when a resource is not specified' do + it { expect { scope.function_getparam([]) }.to raise_error } + it { expect { scope.function_getparam(['User[dan]']) }.to raise_error } + it { expect { scope.function_getparam(['User[dan]']) }.to raise_error } + it { expect { scope.function_getparam(['User[dan]', {}]) }.to raise_error } + # This seems to be OK because we just check for a string. + it { expect { scope.function_getparam(['User[dan]', '']) }.to_not raise_error } + end + + describe 'when compared against a resource with no params' do + let :catalog do + compile_to_catalog(<<-EOS + user { "dan": } + EOS + ) + end + + it do + expect(scope.function_getparam(['User[dan]', 'shell'])).to eq('') + end + end + + describe 'when compared against a resource with params' do + let :catalog do + compile_to_catalog(<<-EOS + user { 'dan': ensure => present, shell => '/bin/sh', managehome => false} + $test = getparam(User[dan], 'shell') + EOS + ) + end + + it do + resource = Puppet::Parser::Resource.new(:user, 'dan', {:scope => scope}) + resource.set_parameter('ensure', 'present') + resource.set_parameter('shell', '/bin/sh') + resource.set_parameter('managehome', false) + compiler.add_resource(scope, resource) + + expect(scope.function_getparam(['User[dan]', 'shell'])).to eq('/bin/sh') + expect(scope.function_getparam(['User[dan]', ''])).to eq('') + expect(scope.function_getparam(['User[dan]', 'ensure'])).to eq('present') + # TODO: Expected this to be false, figure out why we're getting '' back. + expect(scope.function_getparam(['User[dan]', 'managehome'])).to eq('') + end + end +end -- cgit v1.2.3 From c66a2e4f49d6c9ebcbff718f3ec119049fb4c514 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Wed, 7 May 2014 10:09:32 -0700 Subject: Add mode +x to spec .rb files --- spec/unit/puppet/parser/functions/any2array_spec.rb | 0 spec/unit/puppet/parser/functions/concat_spec.rb | 0 spec/unit/puppet/parser/functions/count_spec.rb | 0 spec/unit/puppet/parser/functions/deep_merge_spec.rb | 0 spec/unit/puppet/parser/functions/defined_with_params_spec.rb | 0 spec/unit/puppet/parser/functions/delete_undef_values_spec.rb | 0 spec/unit/puppet/parser/functions/delete_values_spec.rb | 0 spec/unit/puppet/parser/functions/difference_spec.rb | 0 spec/unit/puppet/parser/functions/ensure_packages_spec.rb | 0 spec/unit/puppet/parser/functions/ensure_resource_spec.rb | 0 spec/unit/puppet/parser/functions/floor_spec.rb | 0 spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb | 0 spec/unit/puppet/parser/functions/get_module_path_spec.rb | 0 spec/unit/puppet/parser/functions/getparam_spec.rb | 0 spec/unit/puppet/parser/functions/getvar_spec.rb | 0 spec/unit/puppet/parser/functions/has_key_spec.rb | 0 spec/unit/puppet/parser/functions/hash_spec.rb | 0 spec/unit/puppet/parser/functions/intersection_spec.rb | 0 spec/unit/puppet/parser/functions/is_array_spec.rb | 0 spec/unit/puppet/parser/functions/is_bool_spec.rb | 0 spec/unit/puppet/parser/functions/is_domain_name_spec.rb | 0 spec/unit/puppet/parser/functions/is_float_spec.rb | 0 spec/unit/puppet/parser/functions/is_function_available.rb | 0 spec/unit/puppet/parser/functions/is_hash_spec.rb | 0 spec/unit/puppet/parser/functions/is_integer_spec.rb | 0 spec/unit/puppet/parser/functions/is_ip_address_spec.rb | 0 spec/unit/puppet/parser/functions/is_mac_address_spec.rb | 0 spec/unit/puppet/parser/functions/is_numeric_spec.rb | 0 spec/unit/puppet/parser/functions/is_string_spec.rb | 0 spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb | 0 spec/unit/puppet/parser/functions/join_spec.rb | 0 spec/unit/puppet/parser/functions/keys_spec.rb | 0 spec/unit/puppet/parser/functions/loadyaml_spec.rb | 0 spec/unit/puppet/parser/functions/lstrip_spec.rb | 0 spec/unit/puppet/parser/functions/member_spec.rb | 0 spec/unit/puppet/parser/functions/merge_spec.rb | 0 spec/unit/puppet/parser/functions/num2bool_spec.rb | 0 spec/unit/puppet/parser/functions/parsejson_spec.rb | 0 spec/unit/puppet/parser/functions/parseyaml_spec.rb | 0 spec/unit/puppet/parser/functions/pick_default_spec.rb | 0 spec/unit/puppet/parser/functions/prefix_spec.rb | 0 spec/unit/puppet/parser/functions/range_spec.rb | 0 spec/unit/puppet/parser/functions/reverse_spec.rb | 0 spec/unit/puppet/parser/functions/rstrip_spec.rb | 0 spec/unit/puppet/parser/functions/shuffle_spec.rb | 0 spec/unit/puppet/parser/functions/size_spec.rb | 0 spec/unit/puppet/parser/functions/sort_spec.rb | 0 spec/unit/puppet/parser/functions/squeeze_spec.rb | 0 spec/unit/puppet/parser/functions/str2bool_spec.rb | 0 spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb | 0 spec/unit/puppet/parser/functions/strftime_spec.rb | 0 spec/unit/puppet/parser/functions/strip_spec.rb | 0 spec/unit/puppet/parser/functions/suffix_spec.rb | 0 spec/unit/puppet/parser/functions/swapcase_spec.rb | 0 spec/unit/puppet/parser/functions/time_spec.rb | 0 spec/unit/puppet/parser/functions/type_spec.rb | 0 spec/unit/puppet/parser/functions/union_spec.rb | 0 spec/unit/puppet/parser/functions/unique_spec.rb | 0 spec/unit/puppet/parser/functions/upcase_spec.rb | 0 spec/unit/puppet/parser/functions/uriescape_spec.rb | 0 spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb | 0 spec/unit/puppet/parser/functions/validate_array_spec.rb | 0 spec/unit/puppet/parser/functions/validate_augeas_spec.rb | 0 spec/unit/puppet/parser/functions/validate_bool_spec.rb | 0 spec/unit/puppet/parser/functions/validate_cmd_spec.rb | 0 spec/unit/puppet/parser/functions/validate_hash_spec.rb | 0 spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb | 0 spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb | 0 spec/unit/puppet/parser/functions/validate_re_spec.rb | 0 spec/unit/puppet/parser/functions/validate_string_spec.rb | 0 spec/unit/puppet/parser/functions/values_at_spec.rb | 0 spec/unit/puppet/parser/functions/values_spec.rb | 0 spec/unit/puppet/parser/functions/zip_spec.rb | 0 73 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 spec/unit/puppet/parser/functions/any2array_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/concat_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/count_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/deep_merge_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/defined_with_params_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/delete_undef_values_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/delete_values_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/difference_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/ensure_packages_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/ensure_resource_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/floor_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/get_module_path_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/getparam_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/getvar_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/has_key_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/hash_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/intersection_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_array_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_bool_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_domain_name_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_float_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_function_available.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_hash_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_integer_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_ip_address_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_mac_address_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_numeric_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/is_string_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/join_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/keys_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/loadyaml_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/lstrip_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/member_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/merge_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/num2bool_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/parsejson_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/parseyaml_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/pick_default_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/prefix_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/range_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/reverse_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/rstrip_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/shuffle_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/size_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/sort_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/squeeze_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/str2bool_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/strftime_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/strip_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/suffix_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/swapcase_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/time_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/type_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/union_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/unique_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/upcase_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/uriescape_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/validate_array_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/validate_augeas_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/validate_bool_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/validate_cmd_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/validate_hash_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/validate_re_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/validate_string_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/values_at_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/values_spec.rb mode change 100644 => 100755 spec/unit/puppet/parser/functions/zip_spec.rb (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/any2array_spec.rb b/spec/unit/puppet/parser/functions/any2array_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/concat_spec.rb b/spec/unit/puppet/parser/functions/concat_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/count_spec.rb b/spec/unit/puppet/parser/functions/count_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/deep_merge_spec.rb b/spec/unit/puppet/parser/functions/deep_merge_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/defined_with_params_spec.rb b/spec/unit/puppet/parser/functions/defined_with_params_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb b/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/delete_values_spec.rb b/spec/unit/puppet/parser/functions/delete_values_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/difference_spec.rb b/spec/unit/puppet/parser/functions/difference_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/ensure_packages_spec.rb b/spec/unit/puppet/parser/functions/ensure_packages_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/ensure_resource_spec.rb b/spec/unit/puppet/parser/functions/ensure_resource_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/floor_spec.rb b/spec/unit/puppet/parser/functions/floor_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb b/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/get_module_path_spec.rb b/spec/unit/puppet/parser/functions/get_module_path_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/getparam_spec.rb b/spec/unit/puppet/parser/functions/getparam_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/getvar_spec.rb b/spec/unit/puppet/parser/functions/getvar_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/has_key_spec.rb b/spec/unit/puppet/parser/functions/has_key_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/hash_spec.rb b/spec/unit/puppet/parser/functions/hash_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/intersection_spec.rb b/spec/unit/puppet/parser/functions/intersection_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_array_spec.rb b/spec/unit/puppet/parser/functions/is_array_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_bool_spec.rb b/spec/unit/puppet/parser/functions/is_bool_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_domain_name_spec.rb b/spec/unit/puppet/parser/functions/is_domain_name_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_float_spec.rb b/spec/unit/puppet/parser/functions/is_float_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_function_available.rb b/spec/unit/puppet/parser/functions/is_function_available.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_hash_spec.rb b/spec/unit/puppet/parser/functions/is_hash_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_integer_spec.rb b/spec/unit/puppet/parser/functions/is_integer_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_ip_address_spec.rb b/spec/unit/puppet/parser/functions/is_ip_address_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_mac_address_spec.rb b/spec/unit/puppet/parser/functions/is_mac_address_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_numeric_spec.rb b/spec/unit/puppet/parser/functions/is_numeric_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/is_string_spec.rb b/spec/unit/puppet/parser/functions/is_string_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb b/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/join_spec.rb b/spec/unit/puppet/parser/functions/join_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/keys_spec.rb b/spec/unit/puppet/parser/functions/keys_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/loadyaml_spec.rb b/spec/unit/puppet/parser/functions/loadyaml_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/lstrip_spec.rb b/spec/unit/puppet/parser/functions/lstrip_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/member_spec.rb b/spec/unit/puppet/parser/functions/member_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/merge_spec.rb b/spec/unit/puppet/parser/functions/merge_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/num2bool_spec.rb b/spec/unit/puppet/parser/functions/num2bool_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/parsejson_spec.rb b/spec/unit/puppet/parser/functions/parsejson_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/parseyaml_spec.rb b/spec/unit/puppet/parser/functions/parseyaml_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/pick_default_spec.rb b/spec/unit/puppet/parser/functions/pick_default_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/prefix_spec.rb b/spec/unit/puppet/parser/functions/prefix_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/range_spec.rb b/spec/unit/puppet/parser/functions/range_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/reverse_spec.rb b/spec/unit/puppet/parser/functions/reverse_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/rstrip_spec.rb b/spec/unit/puppet/parser/functions/rstrip_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/shuffle_spec.rb b/spec/unit/puppet/parser/functions/shuffle_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/size_spec.rb b/spec/unit/puppet/parser/functions/size_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/sort_spec.rb b/spec/unit/puppet/parser/functions/sort_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/squeeze_spec.rb b/spec/unit/puppet/parser/functions/squeeze_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/str2bool_spec.rb b/spec/unit/puppet/parser/functions/str2bool_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb b/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/strftime_spec.rb b/spec/unit/puppet/parser/functions/strftime_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/strip_spec.rb b/spec/unit/puppet/parser/functions/strip_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/suffix_spec.rb b/spec/unit/puppet/parser/functions/suffix_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/swapcase_spec.rb b/spec/unit/puppet/parser/functions/swapcase_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/time_spec.rb b/spec/unit/puppet/parser/functions/time_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/type_spec.rb b/spec/unit/puppet/parser/functions/type_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/union_spec.rb b/spec/unit/puppet/parser/functions/union_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/unique_spec.rb b/spec/unit/puppet/parser/functions/unique_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/upcase_spec.rb b/spec/unit/puppet/parser/functions/upcase_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/uriescape_spec.rb b/spec/unit/puppet/parser/functions/uriescape_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb b/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/validate_array_spec.rb b/spec/unit/puppet/parser/functions/validate_array_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/validate_augeas_spec.rb b/spec/unit/puppet/parser/functions/validate_augeas_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/validate_bool_spec.rb b/spec/unit/puppet/parser/functions/validate_bool_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/validate_hash_spec.rb b/spec/unit/puppet/parser/functions/validate_hash_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb b/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb b/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/validate_re_spec.rb b/spec/unit/puppet/parser/functions/validate_re_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/validate_string_spec.rb b/spec/unit/puppet/parser/functions/validate_string_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/values_at_spec.rb b/spec/unit/puppet/parser/functions/values_at_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/values_spec.rb b/spec/unit/puppet/parser/functions/values_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/parser/functions/zip_spec.rb b/spec/unit/puppet/parser/functions/zip_spec.rb old mode 100644 new mode 100755 -- cgit v1.2.3 From 96e43e69d8496926ad4951534e75b204bb279f22 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 8 May 2014 10:47:24 -0700 Subject: Move unit tests to spec/functions rspec-puppet matchers are defined for tests which exist in spec/functions, but the function unit tests lived in spec/unit/puppet/parser/functions. This moves them to the correct place for using rspec-puppet --- spec/unit/puppet/parser/functions/abs_spec.rb | 25 ----- .../unit/puppet/parser/functions/any2array_spec.rb | 55 ---------- spec/unit/puppet/parser/functions/base64_spec.rb | 34 ------ spec/unit/puppet/parser/functions/bool2num_spec.rb | 24 ----- .../puppet/parser/functions/capitalize_spec.rb | 19 ---- spec/unit/puppet/parser/functions/chomp_spec.rb | 19 ---- spec/unit/puppet/parser/functions/chop_spec.rb | 19 ---- spec/unit/puppet/parser/functions/concat_spec.rb | 30 ------ spec/unit/puppet/parser/functions/count_spec.rb | 31 ------ .../puppet/parser/functions/deep_merge_spec.rb | 105 ------------------ .../parser/functions/defined_with_params_spec.rb | 37 ------- .../unit/puppet/parser/functions/delete_at_spec.rb | 25 ----- spec/unit/puppet/parser/functions/delete_spec.rb | 56 ---------- .../parser/functions/delete_undef_values_spec.rb | 41 ------- .../puppet/parser/functions/delete_values_spec.rb | 36 ------- .../puppet/parser/functions/difference_spec.rb | 19 ---- spec/unit/puppet/parser/functions/dirname_spec.rb | 24 ----- spec/unit/puppet/parser/functions/downcase_spec.rb | 24 ----- spec/unit/puppet/parser/functions/empty_spec.rb | 23 ---- .../parser/functions/ensure_packages_spec.rb | 81 -------------- .../parser/functions/ensure_resource_spec.rb | 113 ------------------- spec/unit/puppet/parser/functions/flatten_spec.rb | 27 ----- spec/unit/puppet/parser/functions/floor_spec.rb | 39 ------- .../puppet/parser/functions/fqdn_rotate_spec.rb | 33 ------ .../parser/functions/get_module_path_spec.rb | 46 -------- spec/unit/puppet/parser/functions/getparam_spec.rb | 76 ------------- spec/unit/puppet/parser/functions/getvar_spec.rb | 37 ------- spec/unit/puppet/parser/functions/grep_spec.rb | 19 ---- .../parser/functions/has_interface_with_spec.rb | 64 ----------- .../puppet/parser/functions/has_ip_address_spec.rb | 39 ------- .../puppet/parser/functions/has_ip_network_spec.rb | 36 ------- spec/unit/puppet/parser/functions/has_key_spec.rb | 42 -------- spec/unit/puppet/parser/functions/hash_spec.rb | 19 ---- .../puppet/parser/functions/intersection_spec.rb | 19 ---- spec/unit/puppet/parser/functions/is_array_spec.rb | 29 ----- spec/unit/puppet/parser/functions/is_bool_spec.rb | 44 -------- .../puppet/parser/functions/is_domain_name_spec.rb | 64 ----------- spec/unit/puppet/parser/functions/is_float_spec.rb | 33 ------ .../parser/functions/is_function_available.rb | 31 ------ spec/unit/puppet/parser/functions/is_hash_spec.rb | 29 ----- .../puppet/parser/functions/is_integer_spec.rb | 69 ------------ .../puppet/parser/functions/is_ip_address_spec.rb | 39 ------- .../puppet/parser/functions/is_mac_address_spec.rb | 29 ----- .../puppet/parser/functions/is_numeric_spec.rb | 119 --------------------- .../unit/puppet/parser/functions/is_string_spec.rb | 34 ------ .../parser/functions/join_keys_to_values_spec.rb | 40 ------- spec/unit/puppet/parser/functions/join_spec.rb | 19 ---- spec/unit/puppet/parser/functions/keys_spec.rb | 21 ---- spec/unit/puppet/parser/functions/loadyaml_spec.rb | 25 ----- spec/unit/puppet/parser/functions/lstrip_spec.rb | 19 ---- spec/unit/puppet/parser/functions/max_spec.rb | 27 ----- spec/unit/puppet/parser/functions/member_spec.rb | 24 ----- spec/unit/puppet/parser/functions/merge_spec.rb | 52 --------- spec/unit/puppet/parser/functions/min_spec.rb | 27 ----- spec/unit/puppet/parser/functions/num2bool_spec.rb | 67 ------------ .../unit/puppet/parser/functions/parsejson_spec.rb | 22 ---- .../unit/puppet/parser/functions/parseyaml_spec.rb | 24 ----- .../puppet/parser/functions/pick_default_spec.rb | 58 ---------- spec/unit/puppet/parser/functions/pick_spec.rb | 34 ------ spec/unit/puppet/parser/functions/prefix_spec.rb | 28 ----- spec/unit/puppet/parser/functions/range_spec.rb | 70 ------------ spec/unit/puppet/parser/functions/reject_spec.rb | 20 ---- spec/unit/puppet/parser/functions/reverse_spec.rb | 19 ---- spec/unit/puppet/parser/functions/rstrip_spec.rb | 24 ----- spec/unit/puppet/parser/functions/shuffle_spec.rb | 24 ----- spec/unit/puppet/parser/functions/size_spec.rb | 24 ----- spec/unit/puppet/parser/functions/sort_spec.rb | 24 ----- spec/unit/puppet/parser/functions/squeeze_spec.rb | 24 ----- spec/unit/puppet/parser/functions/str2bool_spec.rb | 31 ------ .../parser/functions/str2saltedsha512_spec.rb | 45 -------- spec/unit/puppet/parser/functions/strftime_spec.rb | 29 ----- spec/unit/puppet/parser/functions/strip_spec.rb | 18 ---- spec/unit/puppet/parser/functions/suffix_spec.rb | 27 ----- spec/unit/puppet/parser/functions/swapcase_spec.rb | 19 ---- spec/unit/puppet/parser/functions/time_spec.rb | 29 ----- spec/unit/puppet/parser/functions/to_bytes_spec.rb | 58 ---------- spec/unit/puppet/parser/functions/type_spec.rb | 43 -------- spec/unit/puppet/parser/functions/union_spec.rb | 19 ---- spec/unit/puppet/parser/functions/unique_spec.rb | 24 ----- spec/unit/puppet/parser/functions/upcase_spec.rb | 24 ----- .../unit/puppet/parser/functions/uriescape_spec.rb | 24 ----- .../functions/validate_absolute_path_spec.rb | 84 --------------- .../puppet/parser/functions/validate_array_spec.rb | 38 ------- .../parser/functions/validate_augeas_spec.rb | 103 ------------------ .../puppet/parser/functions/validate_bool_spec.rb | 51 --------- .../puppet/parser/functions/validate_cmd_spec.rb | 48 --------- .../puppet/parser/functions/validate_hash_spec.rb | 43 -------- .../parser/functions/validate_ipv4_address_spec.rb | 64 ----------- .../parser/functions/validate_ipv6_address_spec.rb | 67 ------------ .../puppet/parser/functions/validate_re_spec.rb | 77 ------------- .../parser/functions/validate_slength_spec.rb | 67 ------------ .../parser/functions/validate_string_spec.rb | 60 ----------- .../unit/puppet/parser/functions/values_at_spec.rb | 38 ------- spec/unit/puppet/parser/functions/values_spec.rb | 31 ------ spec/unit/puppet/parser/functions/zip_spec.rb | 15 --- 95 files changed, 3748 deletions(-) delete mode 100755 spec/unit/puppet/parser/functions/abs_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/any2array_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/base64_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/bool2num_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/capitalize_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/chomp_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/chop_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/concat_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/count_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/deep_merge_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/defined_with_params_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/delete_at_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/delete_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/delete_undef_values_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/delete_values_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/difference_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/dirname_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/downcase_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/empty_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/ensure_packages_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/ensure_resource_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/flatten_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/floor_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/get_module_path_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/getparam_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/getvar_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/grep_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/has_interface_with_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/has_ip_address_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/has_ip_network_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/has_key_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/hash_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/intersection_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/is_array_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/is_bool_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/is_domain_name_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/is_float_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/is_function_available.rb delete mode 100755 spec/unit/puppet/parser/functions/is_hash_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/is_integer_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/is_ip_address_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/is_mac_address_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/is_numeric_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/is_string_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/join_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/keys_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/loadyaml_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/lstrip_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/max_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/member_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/merge_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/min_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/num2bool_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/parsejson_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/parseyaml_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/pick_default_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/pick_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/prefix_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/range_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/reject_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/reverse_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/rstrip_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/shuffle_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/size_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/sort_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/squeeze_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/str2bool_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/strftime_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/strip_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/suffix_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/swapcase_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/time_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/to_bytes_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/type_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/union_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/unique_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/upcase_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/uriescape_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_array_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_augeas_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_bool_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_cmd_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_hash_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_re_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_slength_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/validate_string_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/values_at_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/values_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/zip_spec.rb (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/abs_spec.rb b/spec/unit/puppet/parser/functions/abs_spec.rb deleted file mode 100755 index c0b4297..0000000 --- a/spec/unit/puppet/parser/functions/abs_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe "the abs function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("abs").should == "function_abs" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should convert a negative number into a positive" do - result = scope.function_abs(["-34"]) - result.should(eq(34)) - end - - it "should do nothing with a positive number" do - result = scope.function_abs(["5678"]) - result.should(eq(5678)) - end -end diff --git a/spec/unit/puppet/parser/functions/any2array_spec.rb b/spec/unit/puppet/parser/functions/any2array_spec.rb deleted file mode 100755 index b266e84..0000000 --- a/spec/unit/puppet/parser/functions/any2array_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the any2array function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("any2array").should == "function_any2array" - end - - it "should return an empty array if there is less than 1 argument" do - result = scope.function_any2array([]) - result.should(eq([])) - end - - it "should convert boolean true to [ true ] " do - result = scope.function_any2array([true]) - result.should(eq([true])) - end - - it "should convert one object to [object]" do - result = scope.function_any2array(['one']) - result.should(eq(['one'])) - end - - it "should convert multiple objects to [objects]" do - result = scope.function_any2array(['one', 'two']) - result.should(eq(['one', 'two'])) - end - - it "should return empty array it was called with" do - result = scope.function_any2array([[]]) - result.should(eq([])) - end - - it "should return one-member array it was called with" do - result = scope.function_any2array([['string']]) - result.should(eq(['string'])) - end - - it "should return multi-member array it was called with" do - result = scope.function_any2array([['one', 'two']]) - result.should(eq(['one', 'two'])) - end - - it "should return members of a hash it was called with" do - result = scope.function_any2array([{ 'key' => 'value' }]) - result.should(eq(['key', 'value'])) - end - - it "should return an empty array if it was called with an empty hash" do - result = scope.function_any2array([{ }]) - result.should(eq([])) - end -end diff --git a/spec/unit/puppet/parser/functions/base64_spec.rb b/spec/unit/puppet/parser/functions/base64_spec.rb deleted file mode 100755 index 5faa5e6..0000000 --- a/spec/unit/puppet/parser/functions/base64_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe "the base64 function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("base64").should == "function_base64" - end - - it "should raise a ParseError if there are other than 2 arguments" do - expect { scope.function_base64([]) }.to(raise_error(Puppet::ParseError)) - expect { scope.function_base64(["asdf"]) }.to(raise_error(Puppet::ParseError)) - expect { scope.function_base64(["asdf","moo","cow"]) }.to(raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if argument 1 isn't 'encode' or 'decode'" do - expect { scope.function_base64(["bees","astring"]) }.to(raise_error(Puppet::ParseError, /first argument must be one of/)) - end - - it "should raise a ParseError if argument 2 isn't a string" do - expect { scope.function_base64(["encode",["2"]]) }.to(raise_error(Puppet::ParseError, /second argument must be a string/)) - end - - it "should encode a encoded string" do - result = scope.function_base64(["encode",'thestring']) - result.should =~ /\AdGhlc3RyaW5n\n\Z/ - end - it "should decode a base64 encoded string" do - result = scope.function_base64(["decode",'dGhlc3RyaW5n']) - result.should == 'thestring' - end -end diff --git a/spec/unit/puppet/parser/functions/bool2num_spec.rb b/spec/unit/puppet/parser/functions/bool2num_spec.rb deleted file mode 100755 index 518ac85..0000000 --- a/spec/unit/puppet/parser/functions/bool2num_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the bool2num function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("bool2num").should == "function_bool2num" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should convert true to 1" do - result = scope.function_bool2num([true]) - result.should(eq(1)) - end - - it "should convert false to 0" do - result = scope.function_bool2num([false]) - result.should(eq(0)) - end -end diff --git a/spec/unit/puppet/parser/functions/capitalize_spec.rb b/spec/unit/puppet/parser/functions/capitalize_spec.rb deleted file mode 100755 index 69c9758..0000000 --- a/spec/unit/puppet/parser/functions/capitalize_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the capitalize function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("capitalize").should == "function_capitalize" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should capitalize the beginning of a string" do - result = scope.function_capitalize(["abc"]) - result.should(eq("Abc")) - end -end diff --git a/spec/unit/puppet/parser/functions/chomp_spec.rb b/spec/unit/puppet/parser/functions/chomp_spec.rb deleted file mode 100755 index e425365..0000000 --- a/spec/unit/puppet/parser/functions/chomp_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the chomp function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("chomp").should == "function_chomp" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_chomp([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should chomp the end of a string" do - result = scope.function_chomp(["abc\n"]) - result.should(eq("abc")) - end -end diff --git a/spec/unit/puppet/parser/functions/chop_spec.rb b/spec/unit/puppet/parser/functions/chop_spec.rb deleted file mode 100755 index 9e466de..0000000 --- a/spec/unit/puppet/parser/functions/chop_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the chop function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("chop").should == "function_chop" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_chop([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should chop the end of a string" do - result = scope.function_chop(["asdf\n"]) - result.should(eq("asdf")) - end -end diff --git a/spec/unit/puppet/parser/functions/concat_spec.rb b/spec/unit/puppet/parser/functions/concat_spec.rb deleted file mode 100755 index 6e67620..0000000 --- a/spec/unit/puppet/parser/functions/concat_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the concat function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should raise a ParseError if the client does not provide two arguments" do - lambda { scope.function_concat([]) }.should(raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if the first parameter is not an array" do - lambda { scope.function_concat([1, []])}.should(raise_error(Puppet::ParseError)) - end - - it "should be able to concat an array" do - result = scope.function_concat([['1','2','3'],['4','5','6']]) - result.should(eq(['1','2','3','4','5','6'])) - end - - it "should be able to concat a primitive to an array" do - result = scope.function_concat([['1','2','3'],'4']) - result.should(eq(['1','2','3','4'])) - end - - it "should not accidentally flatten nested arrays" do - result = scope.function_concat([['1','2','3'],[['4','5'],'6']]) - result.should(eq(['1','2','3',['4','5'],'6'])) - end - -end diff --git a/spec/unit/puppet/parser/functions/count_spec.rb b/spec/unit/puppet/parser/functions/count_spec.rb deleted file mode 100755 index 2453815..0000000 --- a/spec/unit/puppet/parser/functions/count_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe "the count function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("count").should == "function_count" - end - - it "should raise a ArgumentError if there is more than 2 arguments" do - lambda { scope.function_count(['foo', 'bar', 'baz']) }.should( raise_error(ArgumentError)) - end - - it "should be able to count arrays" do - scope.function_count([["1","2","3"]]).should(eq(3)) - end - - it "should be able to count matching elements in arrays" do - scope.function_count([["1", "2", "2"], "2"]).should(eq(2)) - end - - it "should not count nil or empty strings" do - scope.function_count([["foo","bar",nil,""]]).should(eq(2)) - end - - it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do - expect(scope.function_count([["foo",:undef,:undef]])).to eq(1) - end -end diff --git a/spec/unit/puppet/parser/functions/deep_merge_spec.rb b/spec/unit/puppet/parser/functions/deep_merge_spec.rb deleted file mode 100755 index f134701..0000000 --- a/spec/unit/puppet/parser/functions/deep_merge_spec.rb +++ /dev/null @@ -1,105 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:deep_merge) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling deep_merge from puppet' do - it "should not compile when no arguments are passed" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$x = deep_merge()' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should not compile when 1 argument is passed" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = "$my_hash={'one' => 1}\n$x = deep_merge($my_hash)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - end - - describe 'when calling deep_merge on the scope instance' do - it 'should require all parameters are hashes' do - expect { new_hash = scope.function_deep_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/) - expect { new_hash = scope.function_deep_merge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) - end - - it 'should accept empty strings as puppet undef' do - expect { new_hash = scope.function_deep_merge([{}, ''])}.not_to raise_error - end - - it 'should be able to deep_merge two hashes' do - new_hash = scope.function_deep_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}]) - new_hash['one'].should == '1' - new_hash['two'].should == '2' - new_hash['three'].should == '2' - end - - it 'should deep_merge multiple hashes' do - hash = scope.function_deep_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) - hash['one'].should == '3' - end - - it 'should accept empty hashes' do - scope.function_deep_merge([{},{},{}]).should == {} - end - - it 'should deep_merge subhashes' do - hash = scope.function_deep_merge([{'one' => 1}, {'two' => 2, 'three' => { 'four' => 4 } }]) - hash['one'].should == 1 - hash['two'].should == 2 - hash['three'].should == { 'four' => 4 } - end - - it 'should append to subhashes' do - hash = scope.function_deep_merge([{'one' => { 'two' => 2 } }, { 'one' => { 'three' => 3 } }]) - hash['one'].should == { 'two' => 2, 'three' => 3 } - end - - it 'should append to subhashes 2' do - hash = scope.function_deep_merge([{'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, {'two' => 'dos', 'three' => { 'five' => 5 } }]) - hash['one'].should == 1 - hash['two'].should == 'dos' - hash['three'].should == { 'four' => 4, 'five' => 5 } - end - - it 'should append to subhashes 3' do - hash = scope.function_deep_merge([{ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } }]) - hash['key1'].should == { 'a' => 1, 'b' => 99 } - hash['key2'].should == { 'c' => 3 } - end - - it 'should not change the original hashes' do - hash1 = {'one' => { 'two' => 2 } } - hash2 = { 'one' => { 'three' => 3 } } - hash = scope.function_deep_merge([hash1, hash2]) - hash1.should == {'one' => { 'two' => 2 } } - hash2.should == { 'one' => { 'three' => 3 } } - hash['one'].should == { 'two' => 2, 'three' => 3 } - end - - it 'should not change the original hashes 2' do - hash1 = {'one' => { 'two' => [1,2] } } - hash2 = { 'one' => { 'three' => 3 } } - hash = scope.function_deep_merge([hash1, hash2]) - hash1.should == {'one' => { 'two' => [1,2] } } - hash2.should == { 'one' => { 'three' => 3 } } - hash['one'].should == { 'two' => [1,2], 'three' => 3 } - end - - it 'should not change the original hashes 3' do - hash1 = {'one' => { 'two' => [1,2, {'two' => 2} ] } } - hash2 = { 'one' => { 'three' => 3 } } - hash = scope.function_deep_merge([hash1, hash2]) - hash1.should == {'one' => { 'two' => [1,2, {'two' => 2}] } } - hash2.should == { 'one' => { 'three' => 3 } } - hash['one'].should == { 'two' => [1,2, {'two' => 2} ], 'three' => 3 } - hash['one']['two'].should == [1,2, {'two' => 2}] - end - end -end diff --git a/spec/unit/puppet/parser/functions/defined_with_params_spec.rb b/spec/unit/puppet/parser/functions/defined_with_params_spec.rb deleted file mode 100755 index 28dbab3..0000000 --- a/spec/unit/puppet/parser/functions/defined_with_params_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -require 'rspec-puppet' -describe 'defined_with_params' do - describe 'when a resource is not specified' do - it { should run.with_params().and_raise_error(ArgumentError) } - end - describe 'when compared against a resource with no attributes' do - let :pre_condition do - 'user { "dan": }' - end - it do - should run.with_params('User[dan]', {}).and_return(true) - should run.with_params('User[bob]', {}).and_return(false) - should run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) - end - end - - describe 'when compared against a resource with attributes' do - let :pre_condition do - 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}' - end - it do - should run.with_params('User[dan]', {}).and_return(true) - should run.with_params('User[dan]', '').and_return(true) - should run.with_params('User[dan]', {'ensure' => 'present'} - ).and_return(true) - should run.with_params('User[dan]', - {'ensure' => 'present', 'managehome' => false} - ).and_return(true) - should run.with_params('User[dan]', - {'ensure' => 'absent', 'managehome' => false} - ).and_return(false) - end - end -end diff --git a/spec/unit/puppet/parser/functions/delete_at_spec.rb b/spec/unit/puppet/parser/functions/delete_at_spec.rb deleted file mode 100755 index 593cf45..0000000 --- a/spec/unit/puppet/parser/functions/delete_at_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the delete_at function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("delete_at").should == "function_delete_at" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should delete an item at specified location from an array" do - result = scope.function_delete_at([['a','b','c'],1]) - result.should(eq(['a','c'])) - end - - it "should not change origin array passed as argument" do - origin_array = ['a','b','c','d'] - result = scope.function_delete_at([origin_array, 1]) - origin_array.should(eq(['a','b','c','d'])) - end -end diff --git a/spec/unit/puppet/parser/functions/delete_spec.rb b/spec/unit/puppet/parser/functions/delete_spec.rb deleted file mode 100755 index 1508a63..0000000 --- a/spec/unit/puppet/parser/functions/delete_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the delete function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("delete").should == "function_delete" - end - - it "should raise a ParseError if there are fewer than 2 arguments" do - lambda { scope.function_delete([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there are greater than 2 arguments" do - lambda { scope.function_delete([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a TypeError if a number is passed as the first argument" do - lambda { scope.function_delete([1, 'bar']) }.should( raise_error(TypeError)) - end - - it "should delete all instances of an element from an array" do - result = scope.function_delete([['a','b','c','b'],'b']) - result.should(eq(['a','c'])) - end - - it "should delete all instances of a substring from a string" do - result = scope.function_delete(['foobarbabarz','bar']) - result.should(eq('foobaz')) - end - - it "should delete a key from a hash" do - result = scope.function_delete([{ 'a' => 1, 'b' => 2, 'c' => 3 },'b']) - result.should(eq({ 'a' => 1, 'c' => 3 })) - end - - it "should not change origin array passed as argument" do - origin_array = ['a','b','c','d'] - result = scope.function_delete([origin_array, 'b']) - origin_array.should(eq(['a','b','c','d'])) - end - - it "should not change the origin string passed as argument" do - origin_string = 'foobarbabarz' - result = scope.function_delete([origin_string,'bar']) - origin_string.should(eq('foobarbabarz')) - end - - it "should not change origin hash passed as argument" do - origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } - result = scope.function_delete([origin_hash, 'b']) - origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) - end - -end diff --git a/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb b/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb deleted file mode 100755 index b341d88..0000000 --- a/spec/unit/puppet/parser/functions/delete_undef_values_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the delete_undef_values function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("delete_undef_values").should == "function_delete_undef_values" - end - - it "should raise a ParseError if there is less than 1 argument" do - lambda { scope.function_delete_undef_values([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if the argument is not Array nor Hash" do - lambda { scope.function_delete_undef_values(['']) }.should( raise_error(Puppet::ParseError)) - lambda { scope.function_delete_undef_values([nil]) }.should( raise_error(Puppet::ParseError)) - end - - it "should delete all undef items from Array and only these" do - result = scope.function_delete_undef_values([['a',:undef,'c','undef']]) - result.should(eq(['a','c','undef'])) - end - - it "should delete all undef items from Hash and only these" do - result = scope.function_delete_undef_values([{'a'=>'A','b'=>:undef,'c'=>'C','d'=>'undef'}]) - result.should(eq({'a'=>'A','c'=>'C','d'=>'undef'})) - end - - it "should not change origin array passed as argument" do - origin_array = ['a',:undef,'c','undef'] - result = scope.function_delete_undef_values([origin_array]) - origin_array.should(eq(['a',:undef,'c','undef'])) - end - - it "should not change origin hash passed as argument" do - origin_hash = { 'a' => 1, 'b' => :undef, 'c' => 'undef' } - result = scope.function_delete_undef_values([origin_hash]) - origin_hash.should(eq({ 'a' => 1, 'b' => :undef, 'c' => 'undef' })) - end -end diff --git a/spec/unit/puppet/parser/functions/delete_values_spec.rb b/spec/unit/puppet/parser/functions/delete_values_spec.rb deleted file mode 100755 index 8d7f231..0000000 --- a/spec/unit/puppet/parser/functions/delete_values_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the delete_values function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("delete_values").should == "function_delete_values" - end - - it "should raise a ParseError if there are fewer than 2 arguments" do - lambda { scope.function_delete_values([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there are greater than 2 arguments" do - lambda { scope.function_delete_values([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a TypeError if the argument is not a hash" do - lambda { scope.function_delete_values([1,'bar']) }.should( raise_error(TypeError)) - lambda { scope.function_delete_values(['foo','bar']) }.should( raise_error(TypeError)) - lambda { scope.function_delete_values([[],'bar']) }.should( raise_error(TypeError)) - end - - it "should delete all instances of a value from a hash" do - result = scope.function_delete_values([{ 'a'=>'A', 'b'=>'B', 'B'=>'C', 'd'=>'B' },'B']) - result.should(eq({ 'a'=>'A', 'B'=>'C' })) - end - - it "should not change origin hash passed as argument" do - origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } - result = scope.function_delete_values([origin_hash, 2]) - origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) - end - -end diff --git a/spec/unit/puppet/parser/functions/difference_spec.rb b/spec/unit/puppet/parser/functions/difference_spec.rb deleted file mode 100755 index 9feff09..0000000 --- a/spec/unit/puppet/parser/functions/difference_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the difference function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("difference").should == "function_difference" - end - - it "should raise a ParseError if there are fewer than 2 arguments" do - lambda { scope.function_difference([]) }.should( raise_error(Puppet::ParseError) ) - end - - it "should return the difference between two arrays" do - result = scope.function_difference([["a","b","c"],["b","c","d"]]) - result.should(eq(["a"])) - end -end diff --git a/spec/unit/puppet/parser/functions/dirname_spec.rb b/spec/unit/puppet/parser/functions/dirname_spec.rb deleted file mode 100755 index fb3b4fe..0000000 --- a/spec/unit/puppet/parser/functions/dirname_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the dirname function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("dirname").should == "function_dirname" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_dirname([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return dirname for an absolute path" do - result = scope.function_dirname(['/path/to/a/file.ext']) - result.should(eq('/path/to/a')) - end - - it "should return dirname for a relative path" do - result = scope.function_dirname(['path/to/a/file.ext']) - result.should(eq('path/to/a')) - end -end diff --git a/spec/unit/puppet/parser/functions/downcase_spec.rb b/spec/unit/puppet/parser/functions/downcase_spec.rb deleted file mode 100755 index acef1f0..0000000 --- a/spec/unit/puppet/parser/functions/downcase_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the downcase function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("downcase").should == "function_downcase" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_downcase([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should downcase a string" do - result = scope.function_downcase(["ASFD"]) - result.should(eq("asfd")) - end - - it "should do nothing to a string that is already downcase" do - result = scope.function_downcase(["asdf asdf"]) - result.should(eq("asdf asdf")) - end -end diff --git a/spec/unit/puppet/parser/functions/empty_spec.rb b/spec/unit/puppet/parser/functions/empty_spec.rb deleted file mode 100755 index 7745875..0000000 --- a/spec/unit/puppet/parser/functions/empty_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the empty function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - Puppet::Parser::Functions.function("empty").should == "function_empty" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_empty([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return a true for an empty string" do - result = scope.function_empty(['']) - result.should(eq(true)) - end - - it "should return a false for a non-empty string" do - result = scope.function_empty(['asdf']) - result.should(eq(false)) - end -end diff --git a/spec/unit/puppet/parser/functions/ensure_packages_spec.rb b/spec/unit/puppet/parser/functions/ensure_packages_spec.rb deleted file mode 100755 index 436be10..0000000 --- a/spec/unit/puppet/parser/functions/ensure_packages_spec.rb +++ /dev/null @@ -1,81 +0,0 @@ -#! /usr/bin/env ruby - -require 'spec_helper' -require 'rspec-puppet' -require 'puppet_spec/compiler' - -describe 'ensure_packages' do - include PuppetSpec::Compiler - - before :each do - Puppet::Parser::Functions.autoloader.loadall - Puppet::Parser::Functions.function(:ensure_packages) - Puppet::Parser::Functions.function(:ensure_resource) - Puppet::Parser::Functions.function(:defined_with_params) - Puppet::Parser::Functions.function(:create_resources) - end - - let :node do Puppet::Node.new('localhost') end - let :compiler do Puppet::Parser::Compiler.new(node) end - let :scope do - if Puppet.version.to_f >= 3.0 - Puppet::Parser::Scope.new(compiler) - else - newscope = Puppet::Parser::Scope.new - newscope.compiler = compiler - newscope.source = Puppet::Resource::Type.new(:node, :localhost) - newscope - end - end - - describe 'argument handling' do - it 'fails with no arguments' do - expect { - scope.function_ensure_packages([]) - }.to raise_error(Puppet::ParseError, /0 for 1 or 2/) - end - - it 'accepts an array of values' do - scope.function_ensure_packages([['foo']]) - end - - it 'accepts a single package name as a string' do - scope.function_ensure_packages(['foo']) - end - end - - context 'given a catalog with puppet package => absent' do - let :catalog do - compile_to_catalog(<<-EOS - ensure_packages(['facter']) - package { puppet: ensure => absent } - EOS - ) - end - - it 'has no effect on Package[puppet]' do - expect(catalog.resource(:package, 'puppet')['ensure']).to eq('absent') - end - end - - context 'given a clean catalog' do - let :catalog do - compile_to_catalog('ensure_packages(["facter"])') - end - - it 'declares package resources with ensure => present' do - expect(catalog.resource(:package, 'facter')['ensure']).to eq('present') - end - end - - context 'given a clean catalog and specified defaults' do - let :catalog do - compile_to_catalog('ensure_packages(["facter"], {"provider" => "gem"})') - end - - it 'declares package resources with ensure => present' do - expect(catalog.resource(:package, 'facter')['ensure']).to eq('present') - expect(catalog.resource(:package, 'facter')['provider']).to eq('gem') - end - end -end diff --git a/spec/unit/puppet/parser/functions/ensure_resource_spec.rb b/spec/unit/puppet/parser/functions/ensure_resource_spec.rb deleted file mode 100755 index 33bcac0..0000000 --- a/spec/unit/puppet/parser/functions/ensure_resource_spec.rb +++ /dev/null @@ -1,113 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' -require 'rspec-puppet' -require 'puppet_spec/compiler' - -describe 'ensure_resource' do - include PuppetSpec::Compiler - - before :all do - Puppet::Parser::Functions.autoloader.loadall - Puppet::Parser::Functions.function(:ensure_packages) - end - - let :node do Puppet::Node.new('localhost') end - let :compiler do Puppet::Parser::Compiler.new(node) end - let :scope do Puppet::Parser::Scope.new(compiler) end - - describe 'when a type or title is not specified' do - it { expect { scope.function_ensure_resource([]) }.to raise_error } - it { expect { scope.function_ensure_resource(['type']) }.to raise_error } - end - - describe 'when compared against a resource with no attributes' do - let :catalog do - compile_to_catalog(<<-EOS - user { "dan": } - ensure_resource('user', 'dan', {}) - EOS - ) - end - - it 'should contain the the ensured resources' do - expect(catalog.resource(:user, 'dan').to_s).to eq('User[dan]') - end - end - - describe 'works when compared against a resource with non-conflicting attributes' do - [ - "ensure_resource('User', 'dan', {})", - "ensure_resource('User', 'dan', '')", - "ensure_resource('User', 'dan', {'ensure' => 'present'})", - "ensure_resource('User', 'dan', {'ensure' => 'present', 'managehome' => false})" - ].each do |ensure_resource| - pp = <<-EOS - user { "dan": ensure => present, shell => "/bin/csh", managehome => false} - #{ensure_resource} - EOS - - it { expect { compile_to_catalog(pp) }.to_not raise_error } - end - end - - describe 'fails when compared against a resource with conflicting attributes' do - pp = <<-EOS - user { "dan": ensure => present, shell => "/bin/csh", managehome => false} - ensure_resource('User', 'dan', {'ensure' => 'absent', 'managehome' => false}) - EOS - - it { expect { compile_to_catalog(pp) }.to raise_error } - end - - describe 'when an array of new resources are passed in' do - let :catalog do - compile_to_catalog("ensure_resource('User', ['dan', 'alex'], {})") - end - - it 'should contain the ensured resources' do - expect(catalog.resource('User[dan]').to_s).to eq('User[dan]') - expect(catalog.resource('User[alex]').to_s).to eq('User[alex]') - end - end - - describe 'when an array of existing resources is compared against existing resources' do - pp = <<-EOS - user { 'dan': ensure => present; 'alex': ensure => present } - ensure_resource('User', ['dan', 'alex'], {}) - EOS - - let :catalog do - compile_to_catalog(pp) - end - - it 'should return the existing resources' do - expect(catalog.resource('User[dan]').to_s).to eq('User[dan]') - expect(catalog.resource('User[alex]').to_s).to eq('User[alex]') - end - end - - describe 'works when compared against existing resources with attributes' do - [ - "ensure_resource('User', ['dan', 'alex'], {})", - "ensure_resource('User', ['dan', 'alex'], '')", - "ensure_resource('User', ['dan', 'alex'], {'ensure' => 'present'})", - ].each do |ensure_resource| - pp = <<-EOS - user { 'dan': ensure => present; 'alex': ensure => present } - #{ensure_resource} - EOS - - it { expect { compile_to_catalog(pp) }.to_not raise_error } - end - end - - describe 'fails when compared against existing resources with conflicting attributes' do - pp = <<-EOS - user { 'dan': ensure => present; 'alex': ensure => present } - ensure_resource('User', ['dan', 'alex'], {'ensure' => 'absent'}) - EOS - - it { expect { compile_to_catalog(pp) }.to raise_error } - end - -end diff --git a/spec/unit/puppet/parser/functions/flatten_spec.rb b/spec/unit/puppet/parser/functions/flatten_spec.rb deleted file mode 100755 index dba7a6b..0000000 --- a/spec/unit/puppet/parser/functions/flatten_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the flatten function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - Puppet::Parser::Functions.function("flatten").should == "function_flatten" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there is more than 1 argument" do - lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError)) - end - - it "should flatten a complex data structure" do - result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]]) - result.should(eq(["a","b","c","d","e","f","g"])) - end - - it "should do nothing to a structure that is already flat" do - result = scope.function_flatten([["a","b","c","d"]]) - result.should(eq(["a","b","c","d"])) - end -end diff --git a/spec/unit/puppet/parser/functions/floor_spec.rb b/spec/unit/puppet/parser/functions/floor_spec.rb deleted file mode 100755 index dbc8c77..0000000 --- a/spec/unit/puppet/parser/functions/floor_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe "the floor function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("floor").should == "function_floor" - end - - it "should raise a ParseError if there is less than 1 argument" do - lambda { scope.function_floor([]) }.should( raise_error(Puppet::ParseError, /Wrong number of arguments/)) - end - - it "should should raise a ParseError if input isn't numeric (eg. String)" do - lambda { scope.function_floor(["foo"]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/)) - end - - it "should should raise a ParseError if input isn't numeric (eg. Boolean)" do - lambda { scope.function_floor([true]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/)) - end - - it "should return an integer when a numeric type is passed" do - result = scope.function_floor([12.4]) - result.is_a?(Integer).should(eq(true)) - end - - it "should return the input when an integer is passed" do - result = scope.function_floor([7]) - result.should(eq(7)) - end - - it "should return the largest integer less than or equal to the input" do - result = scope.function_floor([3.8]) - result.should(eq(3)) - end -end - diff --git a/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb b/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb deleted file mode 100755 index 2577723..0000000 --- a/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the fqdn_rotate function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("fqdn_rotate").should == "function_fqdn_rotate" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_fqdn_rotate([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should rotate a string and the result should be the same size" do - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") - result = scope.function_fqdn_rotate(["asdf"]) - result.size.should(eq(4)) - end - - it "should rotate a string to give the same results for one host" do - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice - scope.function_fqdn_rotate(["abcdefg"]).should eql(scope.function_fqdn_rotate(["abcdefg"])) - end - - it "should rotate a string to give different values on different hosts" do - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") - val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"]) - scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2") - val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"]) - val1.should_not eql(val2) - end -end diff --git a/spec/unit/puppet/parser/functions/get_module_path_spec.rb b/spec/unit/puppet/parser/functions/get_module_path_spec.rb deleted file mode 100755 index 486bef6..0000000 --- a/spec/unit/puppet/parser/functions/get_module_path_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:get_module_path) do - Internals = PuppetlabsSpec::PuppetInternals - class StubModule - attr_reader :path - def initialize(path) - @path = path - end - end - - def scope(environment = "production") - Internals.scope(:compiler => Internals.compiler(:node => Internals.node(:environment => environment))) - end - - it 'should only allow one argument' do - expect { scope.function_get_module_path([]) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) - expect { scope.function_get_module_path(['1','2','3']) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) - end - it 'should raise an exception when the module cannot be found' do - expect { scope.function_get_module_path(['foo']) }.to raise_error(Puppet::ParseError, /Could not find module/) - end - describe 'when locating a module' do - let(:modulepath) { "/tmp/does_not_exist" } - let(:path_of_module_foo) { StubModule.new("/tmp/does_not_exist/foo") } - - before(:each) { Puppet[:modulepath] = modulepath } - - it 'should be able to find module paths from the modulepath setting' do - Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo) - scope.function_get_module_path(['foo']).should == path_of_module_foo.path - end - it 'should be able to find module paths when the modulepath is a list' do - Puppet[:modulepath] = modulepath + ":/tmp" - Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo) - scope.function_get_module_path(['foo']).should == path_of_module_foo.path - end - it 'should respect the environment' do - pending("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/ - Puppet.settings[:environment] = 'danstestenv' - Puppet::Module.expects(:find).with('foo', 'danstestenv').returns(path_of_module_foo) - scope('danstestenv').function_get_module_path(['foo']).should == path_of_module_foo.path - end - end -end diff --git a/spec/unit/puppet/parser/functions/getparam_spec.rb b/spec/unit/puppet/parser/functions/getparam_spec.rb deleted file mode 100755 index bf024af..0000000 --- a/spec/unit/puppet/parser/functions/getparam_spec.rb +++ /dev/null @@ -1,76 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' -require 'rspec-puppet' -require 'puppet_spec/compiler' - -describe 'getparam' do - include PuppetSpec::Compiler - - before :each do - Puppet::Parser::Functions.autoloader.loadall - Puppet::Parser::Functions.function(:getparam) - end - - let :node do Puppet::Node.new('localhost') end - let :compiler do Puppet::Parser::Compiler.new(node) end - if Puppet.version.to_f >= 3.0 - let :scope do Puppet::Parser::Scope.new(compiler) end - else - let :scope do - newscope = Puppet::Parser::Scope.new - newscope.compiler = compiler - newscope.source = Puppet::Resource::Type.new(:node, :localhost) - newscope - end - end - - it "should exist" do - Puppet::Parser::Functions.function("getparam").should == "function_getparam" - end - - describe 'when a resource is not specified' do - it { expect { scope.function_getparam([]) }.to raise_error } - it { expect { scope.function_getparam(['User[dan]']) }.to raise_error } - it { expect { scope.function_getparam(['User[dan]']) }.to raise_error } - it { expect { scope.function_getparam(['User[dan]', {}]) }.to raise_error } - # This seems to be OK because we just check for a string. - it { expect { scope.function_getparam(['User[dan]', '']) }.to_not raise_error } - end - - describe 'when compared against a resource with no params' do - let :catalog do - compile_to_catalog(<<-EOS - user { "dan": } - EOS - ) - end - - it do - expect(scope.function_getparam(['User[dan]', 'shell'])).to eq('') - end - end - - describe 'when compared against a resource with params' do - let :catalog do - compile_to_catalog(<<-EOS - user { 'dan': ensure => present, shell => '/bin/sh', managehome => false} - $test = getparam(User[dan], 'shell') - EOS - ) - end - - it do - resource = Puppet::Parser::Resource.new(:user, 'dan', {:scope => scope}) - resource.set_parameter('ensure', 'present') - resource.set_parameter('shell', '/bin/sh') - resource.set_parameter('managehome', false) - compiler.add_resource(scope, resource) - - expect(scope.function_getparam(['User[dan]', 'shell'])).to eq('/bin/sh') - expect(scope.function_getparam(['User[dan]', ''])).to eq('') - expect(scope.function_getparam(['User[dan]', 'ensure'])).to eq('present') - # TODO: Expected this to be false, figure out why we're getting '' back. - expect(scope.function_getparam(['User[dan]', 'managehome'])).to eq('') - end - end -end diff --git a/spec/unit/puppet/parser/functions/getvar_spec.rb b/spec/unit/puppet/parser/functions/getvar_spec.rb deleted file mode 100755 index 5ff834e..0000000 --- a/spec/unit/puppet/parser/functions/getvar_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:getvar) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - describe 'when calling getvar from puppet' do - - it "should not compile when no arguments are passed" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$foo = getvar()' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should not compile when too many arguments are passed" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$foo = getvar("foo::bar", "baz")' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should lookup variables in other namespaces" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = <<-'ENDofPUPPETcode' - class site::data { $foo = 'baz' } - include site::data - $foo = getvar("site::data::foo") - if $foo != 'baz' { - fail('getvar did not return what we expect') - } - ENDofPUPPETcode - scope.compiler.compile - end - end -end diff --git a/spec/unit/puppet/parser/functions/grep_spec.rb b/spec/unit/puppet/parser/functions/grep_spec.rb deleted file mode 100755 index a93b842..0000000 --- a/spec/unit/puppet/parser/functions/grep_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the grep function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("grep").should == "function_grep" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_grep([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should grep contents from an array" do - result = scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"]) - result.should(eq(["aaabbb","bbbccc"])) - end -end diff --git a/spec/unit/puppet/parser/functions/has_interface_with_spec.rb b/spec/unit/puppet/parser/functions/has_interface_with_spec.rb deleted file mode 100755 index c5264e4..0000000 --- a/spec/unit/puppet/parser/functions/has_interface_with_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env ruby -S rspec -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:has_interface_with) do - - let(:scope) do - PuppetlabsSpec::PuppetInternals.scope - end - - # The subject of these examples is the method itself. - subject do - function_name = Puppet::Parser::Functions.function(:has_interface_with) - scope.method(function_name) - end - - # We need to mock out the Facts so we can specify how we expect this function - # to behave on different platforms. - context "On Mac OS X Systems" do - before :each do - scope.stubs(:lookupvar).with("interfaces").returns('lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0') - end - it 'should have loopback (lo0)' do - subject.call(['lo0']).should be_true - end - it 'should not have loopback (lo)' do - subject.call(['lo']).should be_false - end - end - context "On Linux Systems" do - before :each do - scope.stubs(:lookupvar).with("interfaces").returns('eth0,lo') - scope.stubs(:lookupvar).with("ipaddress").returns('10.0.0.1') - scope.stubs(:lookupvar).with("ipaddress_lo").returns('127.0.0.1') - scope.stubs(:lookupvar).with("ipaddress_eth0").returns('10.0.0.1') - scope.stubs(:lookupvar).with('muppet').returns('kermit') - scope.stubs(:lookupvar).with('muppet_lo').returns('mspiggy') - scope.stubs(:lookupvar).with('muppet_eth0').returns('kermit') - end - it 'should have loopback (lo)' do - subject.call(['lo']).should be_true - end - it 'should not have loopback (lo0)' do - subject.call(['lo0']).should be_false - end - it 'should have ipaddress with 127.0.0.1' do - subject.call(['ipaddress', '127.0.0.1']).should be_true - end - it 'should have ipaddress with 10.0.0.1' do - subject.call(['ipaddress', '10.0.0.1']).should be_true - end - it 'should not have ipaddress with 10.0.0.2' do - subject.call(['ipaddress', '10.0.0.2']).should be_false - end - it 'should have muppet named kermit' do - subject.call(['muppet', 'kermit']).should be_true - end - it 'should have muppet named mspiggy' do - subject.call(['muppet', 'mspiggy']).should be_true - end - it 'should not have muppet named bigbird' do - subject.call(['muppet', 'bigbird']).should be_false - end - end -end diff --git a/spec/unit/puppet/parser/functions/has_ip_address_spec.rb b/spec/unit/puppet/parser/functions/has_ip_address_spec.rb deleted file mode 100755 index 5a68460..0000000 --- a/spec/unit/puppet/parser/functions/has_ip_address_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env ruby -S rspec -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:has_ip_address) do - - let(:scope) do - PuppetlabsSpec::PuppetInternals.scope - end - - subject do - function_name = Puppet::Parser::Functions.function(:has_ip_address) - scope.method(function_name) - end - - context "On Linux Systems" do - before :each do - scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo') - scope.stubs(:lookupvar).with('ipaddress').returns('10.0.2.15') - scope.stubs(:lookupvar).with('ipaddress_eth0').returns('10.0.2.15') - scope.stubs(:lookupvar).with('ipaddress_lo').returns('127.0.0.1') - end - - it 'should have primary address (10.0.2.15)' do - subject.call(['10.0.2.15']).should be_true - end - - it 'should have lookupback address (127.0.0.1)' do - subject.call(['127.0.0.1']).should be_true - end - - it 'should not have other address' do - subject.call(['192.1681.1.1']).should be_false - end - - it 'should not have "mspiggy" on an interface' do - subject.call(['mspiggy']).should be_false - end - end -end diff --git a/spec/unit/puppet/parser/functions/has_ip_network_spec.rb b/spec/unit/puppet/parser/functions/has_ip_network_spec.rb deleted file mode 100755 index c3a289e..0000000 --- a/spec/unit/puppet/parser/functions/has_ip_network_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env ruby -S rspec -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:has_ip_network) do - - let(:scope) do - PuppetlabsSpec::PuppetInternals.scope - end - - subject do - function_name = Puppet::Parser::Functions.function(:has_ip_network) - scope.method(function_name) - end - - context "On Linux Systems" do - before :each do - scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo') - scope.stubs(:lookupvar).with('network').returns(:undefined) - scope.stubs(:lookupvar).with('network_eth0').returns('10.0.2.0') - scope.stubs(:lookupvar).with('network_lo').returns('127.0.0.1') - end - - it 'should have primary network (10.0.2.0)' do - subject.call(['10.0.2.0']).should be_true - end - - it 'should have loopback network (127.0.0.0)' do - subject.call(['127.0.0.1']).should be_true - end - - it 'should not have other network' do - subject.call(['192.168.1.0']).should be_false - end - end -end - diff --git a/spec/unit/puppet/parser/functions/has_key_spec.rb b/spec/unit/puppet/parser/functions/has_key_spec.rb deleted file mode 100755 index 490daea..0000000 --- a/spec/unit/puppet/parser/functions/has_key_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:has_key) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling has_key from puppet' do - it "should not compile when no arguments are passed" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$x = has_key()' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should not compile when 1 argument is passed" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = "$x = has_key('foo')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should require the first value to be a Hash" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = "$x = has_key('foo', 'bar')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /expects the first argument to be a hash/) - end - end - - describe 'when calling the function has_key from a scope instance' do - it 'should detect existing keys' do - scope.function_has_key([{'one' => 1}, 'one']).should be_true - end - - it 'should detect existing keys' do - scope.function_has_key([{'one' => 1}, 'two']).should be_false - end - end -end diff --git a/spec/unit/puppet/parser/functions/hash_spec.rb b/spec/unit/puppet/parser/functions/hash_spec.rb deleted file mode 100755 index 7c91be9..0000000 --- a/spec/unit/puppet/parser/functions/hash_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the hash function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("hash").should == "function_hash" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_hash([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should convert an array to a hash" do - result = scope.function_hash([['a',1,'b',2,'c',3]]) - result.should(eq({'a'=>1,'b'=>2,'c'=>3})) - end -end diff --git a/spec/unit/puppet/parser/functions/intersection_spec.rb b/spec/unit/puppet/parser/functions/intersection_spec.rb deleted file mode 100755 index fd44f7f..0000000 --- a/spec/unit/puppet/parser/functions/intersection_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the intersection function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("intersection").should == "function_intersection" - end - - it "should raise a ParseError if there are fewer than 2 arguments" do - lambda { scope.function_intersection([]) }.should( raise_error(Puppet::ParseError) ) - end - - it "should return the intersection of two arrays" do - result = scope.function_intersection([["a","b","c"],["b","c","d"]]) - result.should(eq(["b","c"])) - end -end diff --git a/spec/unit/puppet/parser/functions/is_array_spec.rb b/spec/unit/puppet/parser/functions/is_array_spec.rb deleted file mode 100755 index e7f4bcd..0000000 --- a/spec/unit/puppet/parser/functions/is_array_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_array function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("is_array").should == "function_is_array" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_is_array([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if passed an array" do - result = scope.function_is_array([[1,2,3]]) - result.should(eq(true)) - end - - it "should return false if passed a hash" do - result = scope.function_is_array([{'a'=>1}]) - result.should(eq(false)) - end - - it "should return false if passed a string" do - result = scope.function_is_array(["asdf"]) - result.should(eq(false)) - end -end diff --git a/spec/unit/puppet/parser/functions/is_bool_spec.rb b/spec/unit/puppet/parser/functions/is_bool_spec.rb deleted file mode 100755 index c94e83a..0000000 --- a/spec/unit/puppet/parser/functions/is_bool_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_bool function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("is_bool").should == "function_is_bool" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_is_bool([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if passed a TrueClass" do - result = scope.function_is_bool([true]) - result.should(eq(true)) - end - - it "should return true if passed a FalseClass" do - result = scope.function_is_bool([false]) - result.should(eq(true)) - end - - it "should return false if passed the string 'true'" do - result = scope.function_is_bool(['true']) - result.should(eq(false)) - end - - it "should return false if passed the string 'false'" do - result = scope.function_is_bool(['false']) - result.should(eq(false)) - end - - it "should return false if passed an array" do - result = scope.function_is_bool([["a","b"]]) - result.should(eq(false)) - end - - it "should return false if passed a hash" do - result = scope.function_is_bool([{"a" => "b"}]) - result.should(eq(false)) - end -end diff --git a/spec/unit/puppet/parser/functions/is_domain_name_spec.rb b/spec/unit/puppet/parser/functions/is_domain_name_spec.rb deleted file mode 100755 index f2ea76d..0000000 --- a/spec/unit/puppet/parser/functions/is_domain_name_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_domain_name function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("is_domain_name").should == "function_is_domain_name" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if a valid short domain name" do - result = scope.function_is_domain_name(["x.com"]) - result.should(be_true) - end - - it "should return true if the domain is ." do - result = scope.function_is_domain_name(["."]) - result.should(be_true) - end - - it "should return true if the domain is x.com." do - result = scope.function_is_domain_name(["x.com."]) - result.should(be_true) - end - - it "should return true if a valid domain name" do - result = scope.function_is_domain_name(["foo.bar.com"]) - result.should(be_true) - end - - it "should allow domain parts to start with numbers" do - result = scope.function_is_domain_name(["3foo.2bar.com"]) - result.should(be_true) - end - - it "should allow domain to end with a dot" do - result = scope.function_is_domain_name(["3foo.2bar.com."]) - result.should(be_true) - end - - it "should allow a single part domain" do - result = scope.function_is_domain_name(["orange"]) - result.should(be_true) - end - - it "should return false if domain parts start with hyphens" do - result = scope.function_is_domain_name(["-3foo.2bar.com"]) - result.should(be_false) - end - - it "should return true if domain contains hyphens" do - result = scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"]) - result.should(be_true) - end - - it "should return false if domain name contains spaces" do - result = scope.function_is_domain_name(["not valid"]) - result.should(be_false) - end -end diff --git a/spec/unit/puppet/parser/functions/is_float_spec.rb b/spec/unit/puppet/parser/functions/is_float_spec.rb deleted file mode 100755 index b7d73b0..0000000 --- a/spec/unit/puppet/parser/functions/is_float_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_float function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("is_float").should == "function_is_float" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_is_float([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if a float" do - result = scope.function_is_float(["0.12"]) - result.should(eq(true)) - end - - it "should return false if a string" do - result = scope.function_is_float(["asdf"]) - result.should(eq(false)) - end - - it "should return false if an integer" do - result = scope.function_is_float(["3"]) - result.should(eq(false)) - end - it "should return true if a float is created from an arithmetical operation" do - result = scope.function_is_float([3.2*2]) - result.should(eq(true)) - end -end diff --git a/spec/unit/puppet/parser/functions/is_function_available.rb b/spec/unit/puppet/parser/functions/is_function_available.rb deleted file mode 100755 index d5669a7..0000000 --- a/spec/unit/puppet/parser/functions/is_function_available.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_function_available function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("is_function_available").should == "function_is_function_available" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_is_function_available([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return false if a nonexistent function is passed" do - result = @scope.function_is_function_available(['jeff_mccunes_left_sock']) - result.should(eq(false)) - end - - it "should return true if an available function is passed" do - result = @scope.function_is_function_available(['require']) - result.should(eq(true)) - end - -end diff --git a/spec/unit/puppet/parser/functions/is_hash_spec.rb b/spec/unit/puppet/parser/functions/is_hash_spec.rb deleted file mode 100755 index bbebf39..0000000 --- a/spec/unit/puppet/parser/functions/is_hash_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_hash function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("is_hash").should == "function_is_hash" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if passed a hash" do - result = scope.function_is_hash([{"a"=>1,"b"=>2}]) - result.should(eq(true)) - end - - it "should return false if passed an array" do - result = scope.function_is_hash([["a","b"]]) - result.should(eq(false)) - end - - it "should return false if passed a string" do - result = scope.function_is_hash(["asdf"]) - result.should(eq(false)) - end -end diff --git a/spec/unit/puppet/parser/functions/is_integer_spec.rb b/spec/unit/puppet/parser/functions/is_integer_spec.rb deleted file mode 100755 index 24141cc..0000000 --- a/spec/unit/puppet/parser/functions/is_integer_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_integer function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("is_integer").should == "function_is_integer" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if an integer" do - result = scope.function_is_integer(["3"]) - result.should(eq(true)) - end - - it "should return true if a negative integer" do - result = scope.function_is_integer(["-7"]) - result.should(eq(true)) - end - - it "should return false if a float" do - result = scope.function_is_integer(["3.2"]) - result.should(eq(false)) - end - - it "should return false if a string" do - result = scope.function_is_integer(["asdf"]) - result.should(eq(false)) - end - - it "should return true if an integer is created from an arithmetical operation" do - result = scope.function_is_integer([3*2]) - result.should(eq(true)) - end - - it "should return false if an array" do - result = scope.function_is_numeric([["asdf"]]) - result.should(eq(false)) - end - - it "should return false if a hash" do - result = scope.function_is_numeric([{"asdf" => false}]) - result.should(eq(false)) - end - - it "should return false if a boolean" do - result = scope.function_is_numeric([true]) - result.should(eq(false)) - end - - it "should return false if a whitespace is in the string" do - result = scope.function_is_numeric([" -1324"]) - result.should(eq(false)) - end - - it "should return false if it is zero prefixed" do - result = scope.function_is_numeric(["0001234"]) - result.should(eq(false)) - end - - it "should return false if it is wrapped inside an array" do - result = scope.function_is_numeric([[1234]]) - result.should(eq(false)) - end -end diff --git a/spec/unit/puppet/parser/functions/is_ip_address_spec.rb b/spec/unit/puppet/parser/functions/is_ip_address_spec.rb deleted file mode 100755 index c0debb3..0000000 --- a/spec/unit/puppet/parser/functions/is_ip_address_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_ip_address function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("is_ip_address").should == "function_is_ip_address" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if an IPv4 address" do - result = scope.function_is_ip_address(["1.2.3.4"]) - result.should(eq(true)) - end - - it "should return true if a full IPv6 address" do - result = scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"]) - result.should(eq(true)) - end - - it "should return true if a compressed IPv6 address" do - result = scope.function_is_ip_address(["fe00::1"]) - result.should(eq(true)) - end - - it "should return false if not valid" do - result = scope.function_is_ip_address(["asdf"]) - result.should(eq(false)) - end - - it "should return false if IP octets out of range" do - result = scope.function_is_ip_address(["1.1.1.300"]) - result.should(eq(false)) - end -end diff --git a/spec/unit/puppet/parser/functions/is_mac_address_spec.rb b/spec/unit/puppet/parser/functions/is_mac_address_spec.rb deleted file mode 100755 index ca9c590..0000000 --- a/spec/unit/puppet/parser/functions/is_mac_address_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_mac_address function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("is_mac_address").should == "function_is_mac_address" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if a valid mac address" do - result = scope.function_is_mac_address(["00:a0:1f:12:7f:a0"]) - result.should(eq(true)) - end - - it "should return false if octets are out of range" do - result = scope.function_is_mac_address(["00:a0:1f:12:7f:g0"]) - result.should(eq(false)) - end - - it "should return false if not valid" do - result = scope.function_is_mac_address(["not valid"]) - result.should(eq(false)) - end -end diff --git a/spec/unit/puppet/parser/functions/is_numeric_spec.rb b/spec/unit/puppet/parser/functions/is_numeric_spec.rb deleted file mode 100755 index 1df1497..0000000 --- a/spec/unit/puppet/parser/functions/is_numeric_spec.rb +++ /dev/null @@ -1,119 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_numeric function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("is_numeric").should == "function_is_numeric" - end - - it "should raise a ParseError if there is less than 1 argument" do - lambda { scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if an integer" do - result = scope.function_is_numeric(["3"]) - result.should(eq(true)) - end - - it "should return true if a float" do - result = scope.function_is_numeric(["3.2"]) - result.should(eq(true)) - end - - it "should return true if an integer is created from an arithmetical operation" do - result = scope.function_is_numeric([3*2]) - result.should(eq(true)) - end - - it "should return true if a float is created from an arithmetical operation" do - result = scope.function_is_numeric([3.2*2]) - result.should(eq(true)) - end - - it "should return false if a string" do - result = scope.function_is_numeric(["asdf"]) - result.should(eq(false)) - end - - it "should return false if an array" do - result = scope.function_is_numeric([["asdf"]]) - result.should(eq(false)) - end - - it "should return false if an array of integers" do - result = scope.function_is_numeric([[1,2,3,4]]) - result.should(eq(false)) - end - - it "should return false if a hash" do - result = scope.function_is_numeric([{"asdf" => false}]) - result.should(eq(false)) - end - - it "should return false if a hash with numbers in it" do - result = scope.function_is_numeric([{1 => 2}]) - result.should(eq(false)) - end - - it "should return false if a boolean" do - result = scope.function_is_numeric([true]) - result.should(eq(false)) - end - - it "should return true if a negative float with exponent" do - result = scope.function_is_numeric(["-342.2315e-12"]) - result.should(eq(true)) - end - - it "should return false if a negative integer with whitespaces before/after the dash" do - result = scope.function_is_numeric([" - 751"]) - result.should(eq(false)) - end - -# it "should return true if a hexadecimal" do -# result = scope.function_is_numeric(["0x52F8c"]) -# result.should(eq(true)) -# end -# -# it "should return true if a hexadecimal with uppercase 0X prefix" do -# result = scope.function_is_numeric(["0X52F8c"]) -# result.should(eq(true)) -# end -# -# it "should return false if a hexadecimal without a prefix" do -# result = scope.function_is_numeric(["52F8c"]) -# result.should(eq(false)) -# end -# -# it "should return true if a octal" do -# result = scope.function_is_numeric(["0751"]) -# result.should(eq(true)) -# end -# -# it "should return true if a negative hexadecimal" do -# result = scope.function_is_numeric(["-0x52F8c"]) -# result.should(eq(true)) -# end -# -# it "should return true if a negative octal" do -# result = scope.function_is_numeric(["-0751"]) -# result.should(eq(true)) -# end -# -# it "should return false if a negative octal with whitespaces before/after the dash" do -# result = scope.function_is_numeric([" - 0751"]) -# result.should(eq(false)) -# end -# -# it "should return false if a bad hexadecimal" do -# result = scope.function_is_numeric(["0x23d7g"]) -# result.should(eq(false)) -# end -# -# it "should return false if a bad octal" do -# result = scope.function_is_numeric(["0287"]) -# result.should(eq(false)) -# end -end diff --git a/spec/unit/puppet/parser/functions/is_string_spec.rb b/spec/unit/puppet/parser/functions/is_string_spec.rb deleted file mode 100755 index 3756bea..0000000 --- a/spec/unit/puppet/parser/functions/is_string_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the is_string function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("is_string").should == "function_is_string" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_is_string([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if a string" do - result = scope.function_is_string(["asdf"]) - result.should(eq(true)) - end - - it "should return false if an integer" do - result = scope.function_is_string(["3"]) - result.should(eq(false)) - end - - it "should return false if a float" do - result = scope.function_is_string(["3.23"]) - result.should(eq(false)) - end - - it "should return false if an array" do - result = scope.function_is_string([["a","b","c"]]) - result.should(eq(false)) - end -end diff --git a/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb b/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb deleted file mode 100755 index a52fb71..0000000 --- a/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the join_keys_to_values function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("join_keys_to_values").should == "function_join_keys_to_values" - end - - it "should raise a ParseError if there are fewer than two arguments" do - lambda { scope.function_join_keys_to_values([{}]) }.should raise_error Puppet::ParseError - end - - it "should raise a ParseError if there are greater than two arguments" do - lambda { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.should raise_error Puppet::ParseError - end - - it "should raise a TypeError if the first argument is an array" do - lambda { scope.function_join_keys_to_values([[1,2], ',']) }.should raise_error TypeError - end - - it "should raise a TypeError if the second argument is an array" do - lambda { scope.function_join_keys_to_values([{}, [1,2]]) }.should raise_error TypeError - end - - it "should raise a TypeError if the second argument is a number" do - lambda { scope.function_join_keys_to_values([{}, 1]) }.should raise_error TypeError - end - - it "should return an empty array given an empty hash" do - result = scope.function_join_keys_to_values([{}, ":"]) - result.should == [] - end - - it "should join hash's keys to its values" do - result = scope.function_join_keys_to_values([{'a'=>1,2=>'foo',:b=>nil}, ":"]) - result.should =~ ['a:1','2:foo','b:'] - end -end diff --git a/spec/unit/puppet/parser/functions/join_spec.rb b/spec/unit/puppet/parser/functions/join_spec.rb deleted file mode 100755 index aafa1a7..0000000 --- a/spec/unit/puppet/parser/functions/join_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the join function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("join").should == "function_join" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_join([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should join an array into a string" do - result = scope.function_join([["a","b","c"], ":"]) - result.should(eq("a:b:c")) - end -end diff --git a/spec/unit/puppet/parser/functions/keys_spec.rb b/spec/unit/puppet/parser/functions/keys_spec.rb deleted file mode 100755 index fdd7a70..0000000 --- a/spec/unit/puppet/parser/functions/keys_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the keys function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("keys").should == "function_keys" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_keys([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return an array of keys when given a hash" do - result = scope.function_keys([{'a'=>1, 'b'=>2}]) - # =~ performs 'array with same elements' (set) matching - # For more info see RSpec::Matchers::MatchArray - result.should =~ ['a','b'] - end -end diff --git a/spec/unit/puppet/parser/functions/loadyaml_spec.rb b/spec/unit/puppet/parser/functions/loadyaml_spec.rb deleted file mode 100755 index fe16318..0000000 --- a/spec/unit/puppet/parser/functions/loadyaml_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the loadyaml function" do - include PuppetlabsSpec::Files - - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("loadyaml").should == "function_loadyaml" - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_loadyaml([]) }.to raise_error(Puppet::ParseError) - end - - it "should convert YAML file to a data structure" do - yaml_file = tmpfilename ('yamlfile') - File.open(yaml_file, 'w') do |fh| - fh.write("---\n aaa: 1\n bbb: 2\n ccc: 3\n ddd: 4\n") - end - result = scope.function_loadyaml([yaml_file]) - result.should == {"aaa" => 1, "bbb" => 2, "ccc" => 3, "ddd" => 4 } - end -end diff --git a/spec/unit/puppet/parser/functions/lstrip_spec.rb b/spec/unit/puppet/parser/functions/lstrip_spec.rb deleted file mode 100755 index b280ae7..0000000 --- a/spec/unit/puppet/parser/functions/lstrip_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the lstrip function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("lstrip").should == "function_lstrip" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should lstrip a string" do - result = scope.function_lstrip([" asdf"]) - result.should(eq('asdf')) - end -end diff --git a/spec/unit/puppet/parser/functions/max_spec.rb b/spec/unit/puppet/parser/functions/max_spec.rb deleted file mode 100755 index ff6f2b3..0000000 --- a/spec/unit/puppet/parser/functions/max_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe "the max function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("max").should == "function_max" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_max([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should be able to compare strings" do - scope.function_max(["albatross","dog","horse"]).should(eq("horse")) - end - - it "should be able to compare numbers" do - scope.function_max([6,8,4]).should(eq(8)) - end - - it "should be able to compare a number with a stringified number" do - scope.function_max([1,"2"]).should(eq("2")) - end -end diff --git a/spec/unit/puppet/parser/functions/member_spec.rb b/spec/unit/puppet/parser/functions/member_spec.rb deleted file mode 100755 index 6e9a023..0000000 --- a/spec/unit/puppet/parser/functions/member_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the member function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("member").should == "function_member" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_member([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if a member is in an array" do - result = scope.function_member([["a","b","c"], "a"]) - result.should(eq(true)) - end - - it "should return false if a member is not in an array" do - result = scope.function_member([["a","b","c"], "d"]) - result.should(eq(false)) - end -end diff --git a/spec/unit/puppet/parser/functions/merge_spec.rb b/spec/unit/puppet/parser/functions/merge_spec.rb deleted file mode 100755 index 15a5d94..0000000 --- a/spec/unit/puppet/parser/functions/merge_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:merge) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling merge from puppet' do - it "should not compile when no arguments are passed" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$x = merge()' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should not compile when 1 argument is passed" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - end - - describe 'when calling merge on the scope instance' do - it 'should require all parameters are hashes' do - expect { new_hash = scope.function_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/) - expect { new_hash = scope.function_merge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) - end - - it 'should accept empty strings as puppet undef' do - expect { new_hash = scope.function_merge([{}, ''])}.not_to raise_error - end - - it 'should be able to merge two hashes' do - new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}]) - new_hash['one'].should == '1' - new_hash['two'].should == '2' - new_hash['three'].should == '2' - end - - it 'should merge multiple hashes' do - hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) - hash['one'].should == '3' - end - - it 'should accept empty hashes' do - scope.function_merge([{},{},{}]).should == {} - end - end -end diff --git a/spec/unit/puppet/parser/functions/min_spec.rb b/spec/unit/puppet/parser/functions/min_spec.rb deleted file mode 100755 index 71d593e..0000000 --- a/spec/unit/puppet/parser/functions/min_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe "the min function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("min").should == "function_min" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_min([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should be able to compare strings" do - scope.function_min(["albatross","dog","horse"]).should(eq("albatross")) - end - - it "should be able to compare numbers" do - scope.function_min([6,8,4]).should(eq(4)) - end - - it "should be able to compare a number with a stringified number" do - scope.function_min([1,"2"]).should(eq(1)) - end -end diff --git a/spec/unit/puppet/parser/functions/num2bool_spec.rb b/spec/unit/puppet/parser/functions/num2bool_spec.rb deleted file mode 100755 index b56196d..0000000 --- a/spec/unit/puppet/parser/functions/num2bool_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the num2bool function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("num2bool").should == "function_num2bool" - end - - it "should raise a ParseError if there are no arguments" do - lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there are more than 1 arguments" do - lambda { scope.function_num2bool(["foo","bar"]) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if passed something non-numeric" do - lambda { scope.function_num2bool(["xyzzy"]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if passed string 1" do - result = scope.function_num2bool(["1"]) - result.should(be_true) - end - - it "should return true if passed string 1.5" do - result = scope.function_num2bool(["1.5"]) - result.should(be_true) - end - - it "should return true if passed number 1" do - result = scope.function_num2bool([1]) - result.should(be_true) - end - - it "should return false if passed string 0" do - result = scope.function_num2bool(["0"]) - result.should(be_false) - end - - it "should return false if passed number 0" do - result = scope.function_num2bool([0]) - result.should(be_false) - end - - it "should return false if passed string -1" do - result = scope.function_num2bool(["-1"]) - result.should(be_false) - end - - it "should return false if passed string -1.5" do - result = scope.function_num2bool(["-1.5"]) - result.should(be_false) - end - - it "should return false if passed number -1" do - result = scope.function_num2bool([-1]) - result.should(be_false) - end - - it "should return false if passed float -1.5" do - result = scope.function_num2bool([-1.5]) - result.should(be_false) - end -end diff --git a/spec/unit/puppet/parser/functions/parsejson_spec.rb b/spec/unit/puppet/parser/functions/parsejson_spec.rb deleted file mode 100755 index f179ac1..0000000 --- a/spec/unit/puppet/parser/functions/parsejson_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the parsejson function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("parsejson").should == "function_parsejson" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should convert JSON to a data structure" do - json = <<-EOS -["aaa","bbb","ccc"] -EOS - result = scope.function_parsejson([json]) - result.should(eq(['aaa','bbb','ccc'])) - end -end diff --git a/spec/unit/puppet/parser/functions/parseyaml_spec.rb b/spec/unit/puppet/parser/functions/parseyaml_spec.rb deleted file mode 100755 index 0c7aea8..0000000 --- a/spec/unit/puppet/parser/functions/parseyaml_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the parseyaml function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should convert YAML to a data structure" do - yaml = <<-EOS -- aaa -- bbb -- ccc -EOS - result = scope.function_parseyaml([yaml]) - result.should(eq(['aaa','bbb','ccc'])) - end -end diff --git a/spec/unit/puppet/parser/functions/pick_default_spec.rb b/spec/unit/puppet/parser/functions/pick_default_spec.rb deleted file mode 100755 index c9235b5..0000000 --- a/spec/unit/puppet/parser/functions/pick_default_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the pick_default function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("pick_default").should == "function_pick_default" - end - - it 'should return the correct value' do - scope.function_pick_default(['first', 'second']).should == 'first' - end - - it 'should return the correct value if the first value is empty' do - scope.function_pick_default(['', 'second']).should == 'second' - end - - it 'should skip empty string values' do - scope.function_pick_default(['', 'first']).should == 'first' - end - - it 'should skip :undef values' do - scope.function_pick_default([:undef, 'first']).should == 'first' - end - - it 'should skip :undefined values' do - scope.function_pick_default([:undefined, 'first']).should == 'first' - end - - it 'should return the empty string if it is the last possibility' do - scope.function_pick_default([:undef, :undefined, '']).should == '' - end - - it 'should return :undef if it is the last possibility' do - scope.function_pick_default(['', :undefined, :undef]).should == :undef - end - - it 'should return :undefined if it is the last possibility' do - scope.function_pick_default([:undef, '', :undefined]).should == :undefined - end - - it 'should return the empty string if it is the only possibility' do - scope.function_pick_default(['']).should == '' - end - - it 'should return :undef if it is the only possibility' do - scope.function_pick_default([:undef]).should == :undef - end - - it 'should return :undefined if it is the only possibility' do - scope.function_pick_default([:undefined]).should == :undefined - end - - it 'should error if no values are passed' do - expect { scope.function_pick_default([]) }.to raise_error(Puppet::Error, /Must receive at least one argument./) - end -end diff --git a/spec/unit/puppet/parser/functions/pick_spec.rb b/spec/unit/puppet/parser/functions/pick_spec.rb deleted file mode 100755 index f53fa80..0000000 --- a/spec/unit/puppet/parser/functions/pick_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the pick function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("pick").should == "function_pick" - end - - it 'should return the correct value' do - scope.function_pick(['first', 'second']).should == 'first' - end - - it 'should return the correct value if the first value is empty' do - scope.function_pick(['', 'second']).should == 'second' - end - - it 'should remove empty string values' do - scope.function_pick(['', 'first']).should == 'first' - end - - it 'should remove :undef values' do - scope.function_pick([:undef, 'first']).should == 'first' - end - - it 'should remove :undefined values' do - scope.function_pick([:undefined, 'first']).should == 'first' - end - - it 'should error if no values are passed' do - expect { scope.function_pick([]) }.to( raise_error(Puppet::ParseError, "pick(): must receive at least one non empty value")) - end -end diff --git a/spec/unit/puppet/parser/functions/prefix_spec.rb b/spec/unit/puppet/parser/functions/prefix_spec.rb deleted file mode 100755 index 6e8ddc5..0000000 --- a/spec/unit/puppet/parser/functions/prefix_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the prefix function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "raises a ParseError if there is less than 1 arguments" do - expect { scope.function_prefix([]) }.to raise_error(Puppet::ParseError, /number of arguments/) - end - - it "raises an error if the first argument is not an array" do - expect { - scope.function_prefix([Object.new]) - }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/) - end - - - it "raises an error if the second argument is not a string" do - expect { - scope.function_prefix([['first', 'second'], 42]) - }.to raise_error(Puppet::ParseError, /expected second argument to be a String/) - end - - it "returns a prefixed array" do - result = scope.function_prefix([['a','b','c'], 'p']) - result.should(eq(['pa','pb','pc'])) - end -end diff --git a/spec/unit/puppet/parser/functions/range_spec.rb b/spec/unit/puppet/parser/functions/range_spec.rb deleted file mode 100755 index 0e1ad37..0000000 --- a/spec/unit/puppet/parser/functions/range_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the range function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "exists" do - Puppet::Parser::Functions.function("range").should == "function_range" - end - - it "raises a ParseError if there is less than 1 arguments" do - expect { scope.function_range([]) }.to raise_error Puppet::ParseError, /Wrong number of arguments.*0 for 1/ - end - - describe 'with a letter range' do - it "returns a letter range" do - result = scope.function_range(["a","d"]) - result.should eq ['a','b','c','d'] - end - - it "returns a letter range given a step of 1" do - result = scope.function_range(["a","d","1"]) - result.should eq ['a','b','c','d'] - end - - it "returns a stepped letter range" do - result = scope.function_range(["a","d","2"]) - result.should eq ['a','c'] - end - - it "returns a stepped letter range given a negative step" do - result = scope.function_range(["a","d","-2"]) - result.should eq ['a','c'] - end - end - - describe 'with a number range' do - it "returns a number range" do - result = scope.function_range(["1","4"]) - result.should eq [1,2,3,4] - end - - it "returns a number range given a step of 1" do - result = scope.function_range(["1","4","1"]) - result.should eq [1,2,3,4] - end - - it "returns a stepped number range" do - result = scope.function_range(["1","4","2"]) - result.should eq [1,3] - end - - it "returns a stepped number range given a negative step" do - result = scope.function_range(["1","4","-2"]) - result.should eq [1,3] - end - end - - describe 'with a numeric-like string range' do - it "works with padded hostname like strings" do - expected = ("host01".."host10").to_a - scope.function_range(["host01","host10"]).should eq expected - end - - it "coerces zero padded digits to integers" do - expected = (0..10).to_a - scope.function_range(["00", "10"]).should eq expected - end - end -end diff --git a/spec/unit/puppet/parser/functions/reject_spec.rb b/spec/unit/puppet/parser/functions/reject_spec.rb deleted file mode 100755 index f2cb741..0000000 --- a/spec/unit/puppet/parser/functions/reject_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env ruby - -require 'spec_helper' - -describe "the reject function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("reject").should == "function_reject" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_reject([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should reject contents from an array" do - result = scope.function_reject([["1111", "aaabbb","bbbccc","dddeee"], "bbb"]) - result.should(eq(["1111", "dddeee"])) - end -end diff --git a/spec/unit/puppet/parser/functions/reverse_spec.rb b/spec/unit/puppet/parser/functions/reverse_spec.rb deleted file mode 100755 index 1b59206..0000000 --- a/spec/unit/puppet/parser/functions/reverse_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the reverse function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("reverse").should == "function_reverse" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_reverse([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should reverse a string" do - result = scope.function_reverse(["asdfghijkl"]) - result.should(eq('lkjihgfdsa')) - end -end diff --git a/spec/unit/puppet/parser/functions/rstrip_spec.rb b/spec/unit/puppet/parser/functions/rstrip_spec.rb deleted file mode 100755 index d90de1d..0000000 --- a/spec/unit/puppet/parser/functions/rstrip_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the rstrip function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("rstrip").should == "function_rstrip" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_rstrip([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should rstrip a string" do - result = scope.function_rstrip(["asdf "]) - result.should(eq('asdf')) - end - - it "should rstrip each element in an array" do - result = scope.function_rstrip([["a ","b ", "c "]]) - result.should(eq(['a','b','c'])) - end -end diff --git a/spec/unit/puppet/parser/functions/shuffle_spec.rb b/spec/unit/puppet/parser/functions/shuffle_spec.rb deleted file mode 100755 index 93346d5..0000000 --- a/spec/unit/puppet/parser/functions/shuffle_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the shuffle function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("shuffle").should == "function_shuffle" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_shuffle([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should shuffle a string and the result should be the same size" do - result = scope.function_shuffle(["asdf"]) - result.size.should(eq(4)) - end - - it "should shuffle a string but the sorted contents should still be the same" do - result = scope.function_shuffle(["adfs"]) - result.split("").sort.join("").should(eq("adfs")) - end -end diff --git a/spec/unit/puppet/parser/functions/size_spec.rb b/spec/unit/puppet/parser/functions/size_spec.rb deleted file mode 100755 index b1c435a..0000000 --- a/spec/unit/puppet/parser/functions/size_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the size function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("size").should == "function_size" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_size([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return the size of a string" do - result = scope.function_size(["asdf"]) - result.should(eq(4)) - end - - it "should return the size of an array" do - result = scope.function_size([["a","b","c"]]) - result.should(eq(3)) - end -end diff --git a/spec/unit/puppet/parser/functions/sort_spec.rb b/spec/unit/puppet/parser/functions/sort_spec.rb deleted file mode 100755 index 3187a5a..0000000 --- a/spec/unit/puppet/parser/functions/sort_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the sort function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("sort").should == "function_sort" - end - - it "should raise a ParseError if there is not 1 arguments" do - lambda { scope.function_sort(['','']) }.should( raise_error(Puppet::ParseError)) - end - - it "should sort an array" do - result = scope.function_sort([["a","c","b"]]) - result.should(eq(['a','b','c'])) - end - - it "should sort a string" do - result = scope.function_sort(["acb"]) - result.should(eq('abc')) - end -end diff --git a/spec/unit/puppet/parser/functions/squeeze_spec.rb b/spec/unit/puppet/parser/functions/squeeze_spec.rb deleted file mode 100755 index 60e5a30..0000000 --- a/spec/unit/puppet/parser/functions/squeeze_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the squeeze function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("squeeze").should == "function_squeeze" - end - - it "should raise a ParseError if there is less than 2 arguments" do - lambda { scope.function_squeeze([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should squeeze a string" do - result = scope.function_squeeze(["aaabbbbcccc"]) - result.should(eq('abc')) - end - - it "should squeeze all elements in an array" do - result = scope.function_squeeze([["aaabbbbcccc","dddfff"]]) - result.should(eq(['abc','df'])) - end -end diff --git a/spec/unit/puppet/parser/functions/str2bool_spec.rb b/spec/unit/puppet/parser/functions/str2bool_spec.rb deleted file mode 100755 index 73c09c7..0000000 --- a/spec/unit/puppet/parser/functions/str2bool_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the str2bool function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("str2bool").should == "function_str2bool" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_str2bool([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should convert string 'true' to true" do - result = scope.function_str2bool(["true"]) - result.should(eq(true)) - end - - it "should convert string 'undef' to false" do - result = scope.function_str2bool(["undef"]) - result.should(eq(false)) - end - - it "should return the boolean it was called with" do - result = scope.function_str2bool([true]) - result.should(eq(true)) - result = scope.function_str2bool([false]) - result.should(eq(false)) - end -end diff --git a/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb b/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb deleted file mode 100755 index df8fb8e..0000000 --- a/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the str2saltedsha512 function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("str2saltedsha512").should == "function_str2saltedsha512" - end - - it "should raise a ParseError if there is less than 1 argument" do - expect { scope.function_str2saltedsha512([]) }.to( raise_error(Puppet::ParseError) ) - end - - it "should raise a ParseError if there is more than 1 argument" do - expect { scope.function_str2saltedsha512(['foo', 'bar', 'baz']) }.to( raise_error(Puppet::ParseError) ) - end - - it "should return a salted-sha512 password hash 136 characters in length" do - result = scope.function_str2saltedsha512(["password"]) - result.length.should(eq(136)) - end - - it "should raise an error if you pass a non-string password" do - expect { scope.function_str2saltedsha512([1234]) }.to( raise_error(Puppet::ParseError) ) - end - - it "should generate a valid password" do - # Allow the function to generate a password based on the string 'password' - password_hash = scope.function_str2saltedsha512(["password"]) - - # Separate the Salt and Password from the Password Hash - salt = password_hash[0..7] - password = password_hash[8..-1] - - # Convert the Salt and Password from Hex to Binary Data - str_salt = Array(salt.lines).pack('H*') - str_password = Array(password.lines).pack('H*') - - # Combine the Binary Salt with 'password' and compare the end result - saltedpass = Digest::SHA512.digest(str_salt + 'password') - result = (str_salt + saltedpass).unpack('H*')[0] - result.should == password_hash - end -end diff --git a/spec/unit/puppet/parser/functions/strftime_spec.rb b/spec/unit/puppet/parser/functions/strftime_spec.rb deleted file mode 100755 index df42b6f..0000000 --- a/spec/unit/puppet/parser/functions/strftime_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the strftime function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("strftime").should == "function_strftime" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_strftime([]) }.should( raise_error(Puppet::ParseError)) - end - - it "using %s should be higher then when I wrote this test" do - result = scope.function_strftime(["%s"]) - result.to_i.should(be > 1311953157) - end - - it "using %s should be lower then 1.5 trillion" do - result = scope.function_strftime(["%s"]) - result.to_i.should(be < 1500000000) - end - - it "should return a date when given %Y-%m-%d" do - result = scope.function_strftime(["%Y-%m-%d"]) - result.should =~ /^\d{4}-\d{2}-\d{2}$/ - end -end diff --git a/spec/unit/puppet/parser/functions/strip_spec.rb b/spec/unit/puppet/parser/functions/strip_spec.rb deleted file mode 100755 index fccdd26..0000000 --- a/spec/unit/puppet/parser/functions/strip_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the strip function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - Puppet::Parser::Functions.function("strip").should == "function_strip" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_strip([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should strip a string" do - result = scope.function_strip([" ab cd "]) - result.should(eq('ab cd')) - end -end diff --git a/spec/unit/puppet/parser/functions/suffix_spec.rb b/spec/unit/puppet/parser/functions/suffix_spec.rb deleted file mode 100755 index 89ba3b8..0000000 --- a/spec/unit/puppet/parser/functions/suffix_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the suffix function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "raises a ParseError if there is less than 1 arguments" do - expect { scope.function_suffix([]) }.to raise_error(Puppet::ParseError, /number of arguments/) - end - - it "raises an error if the first argument is not an array" do - expect { - scope.function_suffix([Object.new]) - }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/) - end - - it "raises an error if the second argument is not a string" do - expect { - scope.function_suffix([['first', 'second'], 42]) - }.to raise_error(Puppet::ParseError, /expected second argument to be a String/) - end - - it "returns a suffixed array" do - result = scope.function_suffix([['a','b','c'], 'p']) - result.should(eq(['ap','bp','cp'])) - end -end diff --git a/spec/unit/puppet/parser/functions/swapcase_spec.rb b/spec/unit/puppet/parser/functions/swapcase_spec.rb deleted file mode 100755 index 808b415..0000000 --- a/spec/unit/puppet/parser/functions/swapcase_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the swapcase function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("swapcase").should == "function_swapcase" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_swapcase([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should swapcase a string" do - result = scope.function_swapcase(["aaBBccDD"]) - result.should(eq('AAbbCCdd')) - end -end diff --git a/spec/unit/puppet/parser/functions/time_spec.rb b/spec/unit/puppet/parser/functions/time_spec.rb deleted file mode 100755 index e9fb76e..0000000 --- a/spec/unit/puppet/parser/functions/time_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the time function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("time").should == "function_time" - end - - it "should raise a ParseError if there is more than 2 arguments" do - lambda { scope.function_time(['','']) }.should( raise_error(Puppet::ParseError)) - end - - it "should return a number" do - result = scope.function_time([]) - result.should be_an(Integer) - end - - it "should be higher then when I wrote this test" do - result = scope.function_time([]) - result.should(be > 1311953157) - end - - it "should be lower then 1.5 trillion" do - result = scope.function_time([]) - result.should(be < 1500000000) - end -end diff --git a/spec/unit/puppet/parser/functions/to_bytes_spec.rb b/spec/unit/puppet/parser/functions/to_bytes_spec.rb deleted file mode 100755 index d1ea4c8..0000000 --- a/spec/unit/puppet/parser/functions/to_bytes_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe "the to_bytes function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("to_bytes").should == "function_to_bytes" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_to_bytes([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should convert kB to B" do - result = scope.function_to_bytes(["4 kB"]) - result.should(eq(4096)) - end - - it "should work without B in unit" do - result = scope.function_to_bytes(["4 k"]) - result.should(eq(4096)) - end - - it "should work without a space before unit" do - result = scope.function_to_bytes(["4k"]) - result.should(eq(4096)) - end - - it "should work without a unit" do - result = scope.function_to_bytes(["5678"]) - result.should(eq(5678)) - end - - it "should convert fractions" do - result = scope.function_to_bytes(["1.5 kB"]) - result.should(eq(1536)) - end - - it "should convert scientific notation" do - result = scope.function_to_bytes(["1.5e2 B"]) - result.should(eq(150)) - end - - it "should do nothing with a positive number" do - result = scope.function_to_bytes([5678]) - result.should(eq(5678)) - end - - it "should should raise a ParseError if input isn't a number" do - lambda { scope.function_to_bytes(["foo"]) }.should( raise_error(Puppet::ParseError)) - end - - it "should should raise a ParseError if prefix is unknown" do - lambda { scope.function_to_bytes(["5 uB"]) }.should( raise_error(Puppet::ParseError)) - end -end diff --git a/spec/unit/puppet/parser/functions/type_spec.rb b/spec/unit/puppet/parser/functions/type_spec.rb deleted file mode 100755 index 8fec88f..0000000 --- a/spec/unit/puppet/parser/functions/type_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the type function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - Puppet::Parser::Functions.function("type").should == "function_type" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_type([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return string when given a string" do - result = scope.function_type(["aaabbbbcccc"]) - result.should(eq('string')) - end - - it "should return array when given an array" do - result = scope.function_type([["aaabbbbcccc","asdf"]]) - result.should(eq('array')) - end - - it "should return hash when given a hash" do - result = scope.function_type([{"a"=>1,"b"=>2}]) - result.should(eq('hash')) - end - - it "should return integer when given an integer" do - result = scope.function_type(["1"]) - result.should(eq('integer')) - end - - it "should return float when given a float" do - result = scope.function_type(["1.34"]) - result.should(eq('float')) - end - - it "should return boolean when given a boolean" do - result = scope.function_type([true]) - result.should(eq('boolean')) - end -end diff --git a/spec/unit/puppet/parser/functions/union_spec.rb b/spec/unit/puppet/parser/functions/union_spec.rb deleted file mode 100755 index 0d282ca..0000000 --- a/spec/unit/puppet/parser/functions/union_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the union function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("union").should == "function_union" - end - - it "should raise a ParseError if there are fewer than 2 arguments" do - lambda { scope.function_union([]) }.should( raise_error(Puppet::ParseError) ) - end - - it "should join two arrays together" do - result = scope.function_union([["a","b","c"],["b","c","d"]]) - result.should(eq(["a","b","c","d"])) - end -end diff --git a/spec/unit/puppet/parser/functions/unique_spec.rb b/spec/unit/puppet/parser/functions/unique_spec.rb deleted file mode 100755 index 5d48d49..0000000 --- a/spec/unit/puppet/parser/functions/unique_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the unique function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("unique").should == "function_unique" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_unique([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should remove duplicate elements in a string" do - result = scope.function_unique(["aabbc"]) - result.should(eq('abc')) - end - - it "should remove duplicate elements in an array" do - result = scope.function_unique([["a","a","b","b","c"]]) - result.should(eq(['a','b','c'])) - end -end diff --git a/spec/unit/puppet/parser/functions/upcase_spec.rb b/spec/unit/puppet/parser/functions/upcase_spec.rb deleted file mode 100755 index 5db5513..0000000 --- a/spec/unit/puppet/parser/functions/upcase_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the upcase function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("upcase").should == "function_upcase" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_upcase([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should upcase a string" do - result = scope.function_upcase(["abc"]) - result.should(eq('ABC')) - end - - it "should do nothing if a string is already upcase" do - result = scope.function_upcase(["ABC"]) - result.should(eq('ABC')) - end -end diff --git a/spec/unit/puppet/parser/functions/uriescape_spec.rb b/spec/unit/puppet/parser/functions/uriescape_spec.rb deleted file mode 100755 index 7211c88..0000000 --- a/spec/unit/puppet/parser/functions/uriescape_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the uriescape function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("uriescape").should == "function_uriescape" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_uriescape([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should uriescape a string" do - result = scope.function_uriescape([":/?#[]@!$&'()*+,;= \"{}"]) - result.should(eq(':/?%23[]@!$&\'()*+,;=%20%22%7B%7D')) - end - - it "should do nothing if a string is already safe" do - result = scope.function_uriescape(["ABCdef"]) - result.should(eq('ABCdef')) - end -end diff --git a/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb b/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb deleted file mode 100755 index 342ae84..0000000 --- a/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:validate_absolute_path) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - # The subject of these examples is the method itself. - subject do - # This makes sure the function is loaded within each test - function_name = Puppet::Parser::Functions.function(:validate_absolute_path) - scope.method(function_name) - end - - describe "Valid Paths" do - def self.valid_paths - %w{ - C:/ - C:\\ - C:\\WINDOWS\\System32 - C:/windows/system32 - X:/foo/bar - X:\\foo\\bar - /var/tmp - /var/lib/puppet - /var/opt/../lib/puppet - } - end - - context "Without Puppet::Util.absolute_path? (e.g. Puppet <= 2.6)" do - before :each do - # The intent here is to mock Puppet to behave like Puppet 2.6 does. - # Puppet 2.6 does not have the absolute_path? method. This is only a - # convenience test, stdlib should be run with the Puppet 2.6.x in the - # $LOAD_PATH in addition to 2.7.x and master. - Puppet::Util.expects(:respond_to?).with(:absolute_path?).returns(false) - end - valid_paths.each do |path| - it "validate_absolute_path(#{path.inspect}) should not fail" do - expect { subject.call [path] }.not_to raise_error - end - end - end - - context "Puppet without mocking" do - valid_paths.each do |path| - it "validate_absolute_path(#{path.inspect}) should not fail" do - expect { subject.call [path] }.not_to raise_error - end - end - end - end - - describe 'Invalid paths' do - context 'Garbage inputs' do - [ - nil, - [ nil ], - { 'foo' => 'bar' }, - { }, - '', - ].each do |path| - it "validate_absolute_path(#{path.inspect}) should fail" do - expect { subject.call [path] }.to raise_error Puppet::ParseError - end - end - end - - context 'Relative paths' do - %w{ - relative1 - . - .. - ./foo - ../foo - etc/puppetlabs/puppet - opt/puppet/bin - }.each do |path| - it "validate_absolute_path(#{path.inspect}) should fail" do - expect { subject.call [path] }.to raise_error Puppet::ParseError - end - end - end - end -end diff --git a/spec/unit/puppet/parser/functions/validate_array_spec.rb b/spec/unit/puppet/parser/functions/validate_array_spec.rb deleted file mode 100755 index 4b31cfd..0000000 --- a/spec/unit/puppet/parser/functions/validate_array_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:validate_array) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - describe 'when calling validate_array from puppet' do - - %w{ true false }.each do |the_string| - it "should not compile when #{the_string} is a string" do - Puppet[:code] = "validate_array('#{the_string}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) - end - - it "should not compile when #{the_string} is a bare word" do - Puppet[:code] = "validate_array(#{the_string})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) - end - end - - it "should compile when multiple array arguments are passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = [ ] - $bar = [ 'one', 'two' ] - validate_array($foo, $bar) - ENDofPUPPETcode - scope.compiler.compile - end - - it "should not compile when an undef variable is passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = undef - validate_array($foo) - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) - end - end -end diff --git a/spec/unit/puppet/parser/functions/validate_augeas_spec.rb b/spec/unit/puppet/parser/functions/validate_augeas_spec.rb deleted file mode 100755 index c695ba2..0000000 --- a/spec/unit/puppet/parser/functions/validate_augeas_spec.rb +++ /dev/null @@ -1,103 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:validate_augeas), :if => Puppet.features.augeas? do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - # The subject of these examplres is the method itself. - subject do - # This makes sure the function is loaded within each test - function_name = Puppet::Parser::Functions.function(:validate_augeas) - scope.method(function_name) - end - - context 'Using Puppet::Parser::Scope.new' do - - describe 'Garbage inputs' do - inputs = [ - [ nil ], - [ [ nil ] ], - [ { 'foo' => 'bar' } ], - [ { } ], - [ '' ], - [ "one", "one", "MSG to User", "4th arg" ], - ] - - inputs.each do |input| - it "validate_augeas(#{input.inspect}) should fail" do - expect { subject.call [input] }.to raise_error Puppet::ParseError - end - end - end - - describe 'Valid inputs' do - inputs = [ - [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns' ], - [ "proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'], - ] - - inputs.each do |input| - it "validate_augeas(#{input.inspect}) should not fail" do - expect { subject.call input }.not_to raise_error - end - end - end - - describe "Valid inputs which should raise an exception without a message" do - # The intent here is to make sure valid inputs raise exceptions when they - # don't specify an error message to display. This is the behvior in - # 2.2.x and prior. - inputs = [ - [ "root:x:0:0:root\n", 'Passwd.lns' ], - [ "127.0.1.1\n", 'Hosts.lns' ], - ] - - inputs.each do |input| - it "validate_augeas(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /validate_augeas.*?matched less than it should/ - end - end - end - - describe "Nicer Error Messages" do - # The intent here is to make sure the function returns the 3rd argument - # in the exception thrown - inputs = [ - [ "root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content' ], - [ "127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content' ], - ] - - inputs.each do |input| - it "validate_augeas(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /#{input[2]}/ - end - end - end - - describe "Passing simple unit tests" do - inputs = [ - [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']], - [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']], - ] - - inputs.each do |input| - it "validate_augeas(#{input.inspect}) should fail" do - expect { subject.call input }.not_to raise_error - end - end - end - - describe "Failing simple unit tests" do - inputs = [ - [ "foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']], - [ "root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']], - ] - - inputs.each do |input| - it "validate_augeas(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /testing path/ - end - end - end - end -end diff --git a/spec/unit/puppet/parser/functions/validate_bool_spec.rb b/spec/unit/puppet/parser/functions/validate_bool_spec.rb deleted file mode 100755 index a352d3b..0000000 --- a/spec/unit/puppet/parser/functions/validate_bool_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:validate_bool) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - describe 'when calling validate_bool from puppet' do - - %w{ true false }.each do |the_string| - - it "should not compile when #{the_string} is a string" do - Puppet[:code] = "validate_bool('#{the_string}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/) - end - - it "should compile when #{the_string} is a bare word" do - Puppet[:code] = "validate_bool(#{the_string})" - scope.compiler.compile - end - - end - - it "should not compile when an arbitrary string is passed" do - Puppet[:code] = 'validate_bool("jeff and dan are awesome")' - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/) - end - - it "should not compile when no arguments are passed" do - Puppet[:code] = 'validate_bool()' - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - - it "should compile when multiple boolean arguments are passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = true - $bar = false - validate_bool($foo, $bar, true, false) - ENDofPUPPETcode - scope.compiler.compile - end - - it "should compile when multiple boolean arguments are passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = true - $bar = false - validate_bool($foo, $bar, true, false, 'jeff') - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/) - end - end -end diff --git a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/spec/unit/puppet/parser/functions/validate_cmd_spec.rb deleted file mode 100755 index a6e68df..0000000 --- a/spec/unit/puppet/parser/functions/validate_cmd_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -TESTEXE = File.exists?('/usr/bin/test') ? '/usr/bin/test' : '/bin/test' -TOUCHEXE = File.exists?('/usr/bin/touch') ? '/usr/bin/touch' : '/bin/touch' - -describe Puppet::Parser::Functions.function(:validate_cmd) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - subject do - function_name = Puppet::Parser::Functions.function(:validate_cmd) - scope.method(function_name) - end - - describe "with an explicit failure message" do - it "prints the failure message on error" do - expect { - subject.call ['', '/bin/false', 'failure message!'] - }.to raise_error Puppet::ParseError, /failure message!/ - end - end - - describe "on validation failure" do - it "includes the command error output" do - expect { - subject.call ['', "#{TOUCHEXE} /cant/touch/this"] - }.to raise_error Puppet::ParseError, /(cannot touch|o such file or)/ - end - - it "includes the command return value" do - expect { - subject.call ['', '/cant/run/this'] - }.to raise_error Puppet::ParseError, /returned 1\b/ - end - end - - describe "when performing actual validation" do - it "can positively validate file content" do - expect { subject.call ["non-empty", "#{TESTEXE} -s"] }.to_not raise_error - end - - it "can negatively validate file content" do - expect { - subject.call ["", "#{TESTEXE} -s"] - }.to raise_error Puppet::ParseError, /failed to validate.*test -s/ - end - end -end diff --git a/spec/unit/puppet/parser/functions/validate_hash_spec.rb b/spec/unit/puppet/parser/functions/validate_hash_spec.rb deleted file mode 100755 index a0c35c2..0000000 --- a/spec/unit/puppet/parser/functions/validate_hash_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:validate_hash) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling validate_hash from puppet' do - - %w{ true false }.each do |the_string| - - it "should not compile when #{the_string} is a string" do - Puppet[:code] = "validate_hash('#{the_string}')" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) - end - - it "should not compile when #{the_string} is a bare word" do - Puppet[:code] = "validate_hash(#{the_string})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) - end - - end - - it "should compile when multiple hash arguments are passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = {} - $bar = { 'one' => 'two' } - validate_hash($foo, $bar) - ENDofPUPPETcode - scope.compiler.compile - end - - it "should not compile when an undef variable is passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = undef - validate_hash($foo) - ENDofPUPPETcode - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) - end - - end - -end diff --git a/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb b/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb deleted file mode 100755 index 45401a4..0000000 --- a/spec/unit/puppet/parser/functions/validate_ipv4_address_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require "spec_helper" - -describe Puppet::Parser::Functions.function(:validate_ipv4_address) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe "when calling validate_ipv4_address from puppet" do - describe "when given IPv4 address strings" do - it "should compile with one argument" do - Puppet[:code] = "validate_ipv4_address('1.2.3.4')" - scope.compiler.compile - end - - it "should compile with multiple arguments" do - Puppet[:code] = "validate_ipv4_address('1.2.3.4', '5.6.7.8')" - scope.compiler.compile - end - end - - describe "when given an IPv6 address" do - it "should not compile" do - Puppet[:code] = "validate_ipv4_address('3ffe:505')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv4 address/) - end - end - - describe "when given other strings" do - it "should not compile" do - Puppet[:code] = "validate_ipv4_address('hello', 'world')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv4 address/) - end - end - - describe "when given numbers" do - it "should not compile" do - Puppet[:code] = "validate_ipv4_address(1, 2)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /is not a valid IPv4 address/) - end - end - - describe "when given booleans" do - it "should not compile" do - Puppet[:code] = "validate_ipv4_address(true, false)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /is not a string/) - end - end - - it "should not compile when no arguments are passed" do - Puppet[:code] = "validate_ipv4_address()" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - end -end diff --git a/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb b/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb deleted file mode 100755 index a839d90..0000000 --- a/spec/unit/puppet/parser/functions/validate_ipv6_address_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require "spec_helper" - -describe Puppet::Parser::Functions.function(:validate_ipv6_address) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe "when calling validate_ipv6_address from puppet" do - describe "when given IPv6 address strings" do - it "should compile with one argument" do - Puppet[:code] = "validate_ipv6_address('3ffe:0505:0002::')" - scope.compiler.compile - end - - it "should compile with multiple arguments" do - Puppet[:code] = "validate_ipv6_address('3ffe:0505:0002::', '3ffe:0505:0001::')" - scope.compiler.compile - end - end - - describe "when given an ipv4 address" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address('1.2.3.4')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/) - end - end - - describe "when given other strings" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address('hello', 'world')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/) - end - end - - # 1.8.7 is EOL'd and also absolutely insane about ipv6 - unless RUBY_VERSION == '1.8.7' - describe "when given numbers" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address(1, 2)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/) - end - end - end - - describe "when given booleans" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address(true, false)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /is not a string/) - end - end - - it "should not compile when no arguments are passed" do - Puppet[:code] = "validate_ipv6_address()" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end - end -end diff --git a/spec/unit/puppet/parser/functions/validate_re_spec.rb b/spec/unit/puppet/parser/functions/validate_re_spec.rb deleted file mode 100755 index d29988b..0000000 --- a/spec/unit/puppet/parser/functions/validate_re_spec.rb +++ /dev/null @@ -1,77 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:validate_re) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - # The subject of these examplres is the method itself. - subject do - # This makes sure the function is loaded within each test - function_name = Puppet::Parser::Functions.function(:validate_re) - scope.method(function_name) - end - - context 'Using Puppet::Parser::Scope.new' do - - describe 'Garbage inputs' do - inputs = [ - [ nil ], - [ [ nil ] ], - [ { 'foo' => 'bar' } ], - [ { } ], - [ '' ], - [ "one", "one", "MSG to User", "4th arg" ], - ] - - inputs.each do |input| - it "validate_re(#{input.inspect}) should fail" do - expect { subject.call [input] }.to raise_error Puppet::ParseError - end - end - end - - describe 'Valid inputs' do - inputs = [ - [ '/full/path/to/something', '^/full' ], - [ '/full/path/to/something', 'full' ], - [ '/full/path/to/something', ['full', 'absent'] ], - [ '/full/path/to/something', ['full', 'absent'], 'Message to the user' ], - ] - - inputs.each do |input| - it "validate_re(#{input.inspect}) should not fail" do - expect { subject.call input }.not_to raise_error - end - end - end - describe "Valid inputs which should raise an exception without a message" do - # The intent here is to make sure valid inputs raise exceptions when they - # don't specify an error message to display. This is the behvior in - # 2.2.x and prior. - inputs = [ - [ "hello", [ "bye", "later", "adios" ] ], - [ "greetings", "salutations" ], - ] - - inputs.each do |input| - it "validate_re(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /validate_re.*?does not match/ - end - end - end - describe "Nicer Error Messages" do - # The intent here is to make sure the function returns the 3rd argument - # in the exception thrown - inputs = [ - [ "hello", [ "bye", "later", "adios" ], "MSG to User" ], - [ "greetings", "salutations", "Error, greetings does not match salutations" ], - ] - - inputs.each do |input| - it "validate_re(#{input.inspect}) should fail" do - expect { subject.call input }.to raise_error /#{input[2]}/ - end - end - end - end -end diff --git a/spec/unit/puppet/parser/functions/validate_slength_spec.rb b/spec/unit/puppet/parser/functions/validate_slength_spec.rb deleted file mode 100755 index 851835f..0000000 --- a/spec/unit/puppet/parser/functions/validate_slength_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe "the validate_slength function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("validate_slength").should == "function_validate_slength" - end - - describe "validating the input argument types" do - it "raises an error if there are less than two arguments" do - expect { scope.function_validate_slength([]) }.to raise_error Puppet::ParseError, /Wrong number of arguments/ - end - - it "raises an error if there are more than three arguments" do - expect { scope.function_validate_slength(['input', 1, 2, 3]) }.to raise_error Puppet::ParseError, /Wrong number of arguments/ - end - - it "raises an error if the first argument is not a string" do - expect { scope.function_validate_slength([Object.new, 2, 1]) }.to raise_error Puppet::ParseError, /Expected first argument.*got .*Object/ - end - - it "raises an error if the second argument cannot be cast to an Integer" do - expect { scope.function_validate_slength(['input', Object.new]) }.to raise_error Puppet::ParseError, /Expected second argument.*got .*Object/ - end - - it "raises an error if the third argument cannot be cast to an Integer" do - expect { scope.function_validate_slength(['input', 1, Object.new]) }.to raise_error Puppet::ParseError, /Expected third argument.*got .*Object/ - end - - it "raises an error if the second argument is smaller than the third argument" do - expect { scope.function_validate_slength(['input', 1, 2]) }.to raise_error Puppet::ParseError, /Expected second argument to be larger than third argument/ - end - end - - describe "validating the input string length" do - describe "when the input is a string" do - it "fails validation if the string is larger than the max length" do - expect { scope.function_validate_slength(['input', 1]) }.to raise_error Puppet::ParseError, /Expected length .* between 0 and 1, was 5/ - end - - it "fails validation if the string is less than the min length" do - expect { scope.function_validate_slength(['input', 10, 6]) }.to raise_error Puppet::ParseError, /Expected length .* between 6 and 10, was 5/ - end - - it "doesn't raise an error if the string is under the max length" do - scope.function_validate_slength(['input', 10]) - end - - it "doesn't raise an error if the string is equal to the max length" do - scope.function_validate_slength(['input', 5]) - end - - it "doesn't raise an error if the string is equal to the min length" do - scope.function_validate_slength(['input', 10, 5]) - end - end - - describe "when the input is an array" do - it "fails validation if one of the array elements is not a string" do - expect { scope.function_validate_slength([["a", "b", Object.new], 2]) }.to raise_error Puppet::ParseError, /Expected element at array position 2 .*String, got .*Object/ - end - end - end -end diff --git a/spec/unit/puppet/parser/functions/validate_string_spec.rb b/spec/unit/puppet/parser/functions/validate_string_spec.rb deleted file mode 100755 index 3b4fb3e..0000000 --- a/spec/unit/puppet/parser/functions/validate_string_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -describe Puppet::Parser::Functions.function(:validate_string) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe 'when calling validate_string from puppet' do - - %w{ foo bar baz }.each do |the_string| - - it "should compile when #{the_string} is a string" do - Puppet[:code] = "validate_string('#{the_string}')" - scope.compiler.compile - end - - it "should compile when #{the_string} is a bare word" do - Puppet[:code] = "validate_string(#{the_string})" - scope.compiler.compile - end - - end - - %w{ true false }.each do |the_string| - it "should compile when #{the_string} is a string" do - Puppet[:code] = "validate_string('#{the_string}')" - scope.compiler.compile - end - - it "should not compile when #{the_string} is a bare word" do - Puppet[:code] = "validate_string(#{the_string})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a string/) - end - end - - it "should compile when multiple string arguments are passed" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = '' - $bar = 'two' - validate_string($foo, $bar) - ENDofPUPPETcode - scope.compiler.compile - end - - it "should compile when an explicitly undef variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do - Puppet[:code] = <<-'ENDofPUPPETcode' - $foo = undef - validate_string($foo) - ENDofPUPPETcode - scope.compiler.compile - end - - it "should compile when an undefined variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do - Puppet[:code] = <<-'ENDofPUPPETcode' - validate_string($foobarbazishouldnotexist) - ENDofPUPPETcode - scope.compiler.compile - end - end -end diff --git a/spec/unit/puppet/parser/functions/values_at_spec.rb b/spec/unit/puppet/parser/functions/values_at_spec.rb deleted file mode 100755 index 08e95a5..0000000 --- a/spec/unit/puppet/parser/functions/values_at_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the values_at function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("values_at").should == "function_values_at" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_values_at([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if you try to use a range where stop is greater then start" do - lambda { scope.function_values_at([['a','b'],["3-1"]]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return a value at from an array" do - result = scope.function_values_at([['a','b','c'],"1"]) - result.should(eq(['b'])) - end - - it "should return a value at from an array when passed a range" do - result = scope.function_values_at([['a','b','c'],"0-1"]) - result.should(eq(['a','b'])) - end - - it "should return chosen values from an array when passed number of indexes" do - result = scope.function_values_at([['a','b','c'],["0","2"]]) - result.should(eq(['a','c'])) - end - - it "should return chosen values from an array when passed ranges and multiple indexes" do - result = scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]]) - result.should(eq(['a','c','e','f'])) - end -end diff --git a/spec/unit/puppet/parser/functions/values_spec.rb b/spec/unit/puppet/parser/functions/values_spec.rb deleted file mode 100755 index 14ae417..0000000 --- a/spec/unit/puppet/parser/functions/values_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the values function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("values").should == "function_values" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_values([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return values from a hash" do - result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}]) - # =~ is the RSpec::Matchers::MatchArray matcher. - # A.K.A. "array with same elements" (multiset) matching - result.should =~ %w{ 1 2 3 } - end - - it "should return a multiset" do - result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}]) - result.should =~ %w{ 1 3 3 } - result.should_not =~ %w{ 1 3 } - end - - it "should raise a ParseError unless a Hash is provided" do - lambda { scope.function_values([['a','b','c']]) }.should( raise_error(Puppet::ParseError)) - end -end diff --git a/spec/unit/puppet/parser/functions/zip_spec.rb b/spec/unit/puppet/parser/functions/zip_spec.rb deleted file mode 100755 index f45ab17..0000000 --- a/spec/unit/puppet/parser/functions/zip_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the zip function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_zip([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should be able to zip an array" do - result = scope.function_zip([['1','2','3'],['4','5','6']]) - result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]])) - end -end -- cgit v1.2.3 From 0761fcf0433b1c73ff9925d1b8fa20a618f28875 Mon Sep 17 00:00:00 2001 From: Ryan McKern Date: Tue, 13 May 2014 15:33:49 -0700 Subject: (maint) Add bool2str & camelcase spec tests --- spec/unit/puppet/parser/functions/bool2str_spec.rb | 34 ++++++++++++++++++++++ .../unit/puppet/parser/functions/camelcase_spec.rb | 24 +++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 spec/unit/puppet/parser/functions/bool2str_spec.rb create mode 100755 spec/unit/puppet/parser/functions/camelcase_spec.rb (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/bool2str_spec.rb b/spec/unit/puppet/parser/functions/bool2str_spec.rb new file mode 100755 index 0000000..c73f7df --- /dev/null +++ b/spec/unit/puppet/parser/functions/bool2str_spec.rb @@ -0,0 +1,34 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the bool2str function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("bool2str").should == "function_bool2str" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_bool2str([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert true to 'true'" do + result = scope.function_bool2str([true]) + result.should(eq('true')) + end + + it "should convert true to a string" do + result = scope.function_bool2str([true]) + result.class.should(eq(String)) + end + + it "should convert false to 'false'" do + result = scope.function_bool2str([false]) + result.should(eq('false')) + end + + it "should convert false to a string" do + result = scope.function_bool2str([false]) + result.class.should(eq(String)) + end +end diff --git a/spec/unit/puppet/parser/functions/camelcase_spec.rb b/spec/unit/puppet/parser/functions/camelcase_spec.rb new file mode 100755 index 0000000..3b1f1d0 --- /dev/null +++ b/spec/unit/puppet/parser/functions/camelcase_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the camelcase function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("camelcase").should == "function_camelcase" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_camelcase([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should capitalize the beginning of a normal string" do + result = scope.function_camelcase(["abc"]) + result.should(eq("Abc")) + end + + it "should camelcase an underscore-delimited string" do + result = scope.function_camelcase(["aa_bb_cc"]) + result.should(eq("AaBbCc")) + end +end -- cgit v1.2.3 From 557d38bdc63b9b7d418f4bf0ce736406e71380b7 Mon Sep 17 00:00:00 2001 From: Ryan McKern Date: Thu, 15 May 2014 16:45:02 -0700 Subject: (MODULES-905) Extend spec tests for bool2str The extended spec tests validate that the common types of values that could be passed to bool2str() are rejected. --- spec/unit/puppet/parser/functions/bool2str_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/bool2str_spec.rb b/spec/unit/puppet/parser/functions/bool2str_spec.rb index c73f7df..bed7e68 100755 --- a/spec/unit/puppet/parser/functions/bool2str_spec.rb +++ b/spec/unit/puppet/parser/functions/bool2str_spec.rb @@ -31,4 +31,16 @@ describe "the bool2str function" do result = scope.function_bool2str([false]) result.class.should(eq(String)) end + + it "should not accept a string" do + lambda { scope.function_bool2str(["false"]) }.should( raise_error(Puppet::ParseError)) + end + + it "should not accept a nil value" do + lambda { scope.function_bool2str([nil]) }.should( raise_error(Puppet::ParseError)) + end + + it "should not accept an undef" do + lambda { scope.function_bool2str([:undef]) }.should( raise_error(Puppet::ParseError)) + end end -- cgit v1.2.3 From d65d2354a7458c3281386e7065bd1938d2c2adee Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 4 Jun 2014 14:37:45 -0400 Subject: Convert specs to RSpec 2.99.0 syntax with Transpec This conversion is done by Transpec 2.2.1 with the following command: transpec spec/unit * 53 conversions from: obj.should to: expect(obj).to * 19 conversions from: == expected to: eq(expected) * 5 conversions from: lambda { }.should to: expect { }.to * 2 conversions from: be_true to: be_truthy For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/unit/puppet/parser/functions/bool2str_spec.rb | 18 +++++++++--------- spec/unit/puppet/parser/functions/camelcase_spec.rb | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/bool2str_spec.rb b/spec/unit/puppet/parser/functions/bool2str_spec.rb index bed7e68..b878891 100755 --- a/spec/unit/puppet/parser/functions/bool2str_spec.rb +++ b/spec/unit/puppet/parser/functions/bool2str_spec.rb @@ -5,42 +5,42 @@ describe "the bool2str function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("bool2str").should == "function_bool2str" + expect(Puppet::Parser::Functions.function("bool2str")).to eq("function_bool2str") end it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_bool2str([]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_bool2str([]) }.to( raise_error(Puppet::ParseError)) end it "should convert true to 'true'" do result = scope.function_bool2str([true]) - result.should(eq('true')) + expect(result).to(eq('true')) end it "should convert true to a string" do result = scope.function_bool2str([true]) - result.class.should(eq(String)) + expect(result.class).to(eq(String)) end it "should convert false to 'false'" do result = scope.function_bool2str([false]) - result.should(eq('false')) + expect(result).to(eq('false')) end it "should convert false to a string" do result = scope.function_bool2str([false]) - result.class.should(eq(String)) + expect(result.class).to(eq(String)) end it "should not accept a string" do - lambda { scope.function_bool2str(["false"]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_bool2str(["false"]) }.to( raise_error(Puppet::ParseError)) end it "should not accept a nil value" do - lambda { scope.function_bool2str([nil]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_bool2str([nil]) }.to( raise_error(Puppet::ParseError)) end it "should not accept an undef" do - lambda { scope.function_bool2str([:undef]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_bool2str([:undef]) }.to( raise_error(Puppet::ParseError)) end end diff --git a/spec/unit/puppet/parser/functions/camelcase_spec.rb b/spec/unit/puppet/parser/functions/camelcase_spec.rb index 3b1f1d0..70382ad 100755 --- a/spec/unit/puppet/parser/functions/camelcase_spec.rb +++ b/spec/unit/puppet/parser/functions/camelcase_spec.rb @@ -5,20 +5,20 @@ describe "the camelcase function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("camelcase").should == "function_camelcase" + expect(Puppet::Parser::Functions.function("camelcase")).to eq("function_camelcase") end it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_camelcase([]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_camelcase([]) }.to( raise_error(Puppet::ParseError)) end it "should capitalize the beginning of a normal string" do result = scope.function_camelcase(["abc"]) - result.should(eq("Abc")) + expect(result).to(eq("Abc")) end it "should camelcase an underscore-delimited string" do result = scope.function_camelcase(["aa_bb_cc"]) - result.should(eq("AaBbCc")) + expect(result).to(eq("AaBbCc")) end end -- cgit v1.2.3 From ef3d42f7bbdf95b21f46e580de309298cad300ea Mon Sep 17 00:00:00 2001 From: Rob Fugina Date: Mon, 17 Nov 2014 16:01:42 -0600 Subject: Added basename() based on Ruby's File.basename Based on dirname code. Includes RSpec tests and docs. --- spec/unit/puppet/parser/functions/basename_spec.rb | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 spec/unit/puppet/parser/functions/basename_spec.rb (limited to 'spec/unit/puppet/parser') diff --git a/spec/unit/puppet/parser/functions/basename_spec.rb b/spec/unit/puppet/parser/functions/basename_spec.rb new file mode 100755 index 0000000..8a2d0dc --- /dev/null +++ b/spec/unit/puppet/parser/functions/basename_spec.rb @@ -0,0 +1,46 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the basename function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("basename").should == "function_basename" + end + + it "should raise a ParseError if there is less than 1 argument" do + lambda { scope.function_basename([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if there are more than 2 arguments" do + lambda { scope.function_basename(['a', 'b', 'c']) }.should( raise_error(Puppet::ParseError)) + end + + it "should return basename for an absolute path" do + result = scope.function_basename(['/path/to/a/file.ext']) + result.should(eq('file.ext')) + end + + it "should return basename for a relative path" do + result = scope.function_basename(['path/to/a/file.ext']) + result.should(eq('file.ext')) + end + + it "should strip extention when extension specified (absolute path)" do + result = scope.function_basename(['/path/to/a/file.ext', '.ext']) + result.should(eq('file')) + end + + it "should strip extention when extension specified (relative path)" do + result = scope.function_basename(['path/to/a/file.ext', '.ext']) + result.should(eq('file')) + end + + it "should complain about non-string first argument" do + lambda { scope.function_basename([[]]) }.should( raise_error(Puppet::ParseError)) + end + + it "should complain about non-string second argument" do + lambda { scope.function_basename(['/path/to/a/file.ext', []]) }.should( raise_error(Puppet::ParseError)) + end +end -- cgit v1.2.3