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 --- README.markdown | 2 ++ spec/unit/puppet/parser/functions/delete_values_spec.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 1e51e1d..a176d88 100644 --- a/README.markdown +++ b/README.markdown @@ -215,6 +215,8 @@ Deletes all instances of a given value from a hash. Would return: {'a'=>'A','c'=>'C','B'=>'D'} +- *Type*: rvalue + delete_undef_values ------------------- Deletes all instances of the undef value from an array or hash. 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 10575587f42fcd84284e0ba85a6c656a37870aa8 Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Thu, 29 Aug 2013 12:59:44 -0700 Subject: (maint) Fix location_for helper method Without this patch the location_for helper method in the Gemfile incorrectly assumes the mdata variable has a value. This patch addresses the problem by explicitly binding the regular expression match results to the mdata variable to ensure it has a value when accessed by index. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 197cc6b..636f930 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ def location_for(place, fake_version = nil) mdata = /^(git:[^#]*)#(.*)/.match(place) if mdata [fake_version, { :git => mdata[1], :branch => mdata[2], :require => false }].compact - elsif place =~ /^file:\/\/(.*)/ + elsif mdata = /^file:\/\/(.*)/.match(place) ['>= 0', { :path => File.expand_path(mdata[1]), :require => false }] else [place, { :require => false }] -- cgit v1.2.3 From 806430224ad0da860be3761ab83f1e574b64fc60 Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Thu, 29 Aug 2013 12:54:14 -0700 Subject: (maint) Fix failing spec test with Puppet 3.3.0-rc2 Without this patch the stdlib spec tests are failing against recent versions of Puppet. The root cause of this problem is a change in the behavior of create_resources in Puppet 6baa57b. The change in behavior caused the :name key to be omitted from the hash returned by Puppet::Parser::Resource#to_hash which in turn is causing the test failure. This patch addresses the problem by updating the test to match the description of the example. Only the attribute :ensure is checked instead of the full hash itself. --- spec/functions/ensure_packages_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index 1c2a328..6fd56d5 100644 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -36,7 +36,7 @@ describe 'ensure_packages' do it 'declares package resources with ensure => present' do should run.with_params(['facter']) rsrc = compiler.catalog.resource('Package[facter]') - rsrc.to_hash.should == {:name => "facter", :ensure => "present"} + rsrc.to_hash[:ensure].should eq("present") end end end -- cgit v1.2.3 From 221277e8522b42bf170fded6ea23dfc526703b07 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Thu, 29 Aug 2013 12:19:16 -0400 Subject: Update file_line resource to support 'after'. When adding new lines to a file the 'after' option can be useful when you need to insert file lines into the middle of a file. This is particularly helpful when using file_line with sectioned config files. NOTE: the after option only works when adding new lines. If you are updating an existing (matched) line it will simply modify it in place. This assumes it was in the right place to begin with. --- lib/puppet/provider/file_line/ruby.rb | 28 +++++++++++++++++++++--- lib/puppet/type/file_line.rb | 4 ++++ spec/unit/puppet/provider/file_line/ruby_spec.rb | 18 +++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb index 3cb9f6e..7ddb39f 100644 --- a/lib/puppet/provider/file_line/ruby.rb +++ b/lib/puppet/provider/file_line/ruby.rb @@ -49,10 +49,32 @@ Puppet::Type.type(:file_line).provide(:ruby) do end def handle_create_without_match - File.open(resource[:path], 'a') do |fh| - fh.puts resource[:line] + + regex = resource[:after] ? Regexp.new(resource[:after]) : nil + after_count = File.exists?(resource[:path]) ? lines.select { |l| regex.match(l) }.size : 0 + if after_count > 1 then + raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches after pattern '#{resource[:after]}'" end - end + if (after_count == 0) + + File.open(resource[:path], 'a') do |fh| + fh.puts resource[:line] + end + + else + + File.open(resource[:path], 'w') do |fh| + lines.each do |l| + fh.puts(l) + if regex.match(l) then + fh.puts(resource[:line]) + end + end + end + + end + + end end diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb index 14946bb..323fc4c 100644 --- a/lib/puppet/type/file_line.rb +++ b/lib/puppet/type/file_line.rb @@ -42,6 +42,10 @@ Puppet::Type.newtype(:file_line) do newvalues(true, false) end + newparam(:after) do + desc 'An optional value used to specify the line after which we will add any new lines. (Existing lines are added in place)' + end + newparam(:line) do desc 'The line to be appended to the file located by the path parameter.' end diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb index 648c05b..c8575ab 100644 --- a/spec/unit/puppet/provider/file_line/ruby_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -80,6 +80,24 @@ describe provider_class do File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2\nfoo = bar") end + it 'should replace all lines that matches with after' do + @resource = Puppet::Type::File_line.new( + { + :name => 'foo', + :path => @tmpfile, + :line => 'inserted = line', + :after => '^foo1', + } + ) + @provider = provider_class.new(@resource) + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo = blah\nfoo2\nfoo = baz") + end + @provider.exists?.should be_nil + @provider.create + File.read(@tmpfile).chomp.should eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo = baz") + end + it 'should raise an error with invalid values' do expect { @resource = Puppet::Type::File_line.new( -- cgit v1.2.3 From 948be0bb99374c699d79eb11c00366a6e2d2f977 Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Thu, 29 Aug 2013 16:27:27 -0700 Subject: (maint) Improve the tests and readability of file_line Without this patch the implementation of the file_line provider is a bit convoluted with respect to the newly introduced "after" parameter. This patch addresses the problem by separating out the concerns of each case into their own methods of handling the behavior with the match parameter, handling the behavior with the after parameter, or simply appending the line. --- lib/puppet/provider/file_line/ruby.rb | 41 ++--- spec/unit/puppet/provider/file_line/ruby_spec.rb | 208 ++++++++++++++--------- 2 files changed, 149 insertions(+), 100 deletions(-) diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb index 7ddb39f..94e7fac 100644 --- a/lib/puppet/provider/file_line/ruby.rb +++ b/lib/puppet/provider/file_line/ruby.rb @@ -1,5 +1,4 @@ Puppet::Type.type(:file_line).provide(:ruby) do - def exists? lines.find do |line| line.chomp == resource[:line].chomp @@ -8,9 +7,11 @@ Puppet::Type.type(:file_line).provide(:ruby) do def create if resource[:match] - handle_create_with_match() + handle_create_with_match + elsif resource[:after] + handle_create_with_after else - handle_create_without_match() + append_line end end @@ -48,22 +49,13 @@ Puppet::Type.type(:file_line).provide(:ruby) do end end - def handle_create_without_match - - regex = resource[:after] ? Regexp.new(resource[:after]) : nil - after_count = File.exists?(resource[:path]) ? lines.select { |l| regex.match(l) }.size : 0 - if after_count > 1 then - raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches after pattern '#{resource[:after]}'" - end - - if (after_count == 0) - - File.open(resource[:path], 'a') do |fh| - fh.puts resource[:line] - end + def handle_create_with_after + regex = Regexp.new(resource[:after]) - else + count = lines.count {|l| l.match(regex)} + case count + when 1 # find the line to put our line after File.open(resource[:path], 'w') do |fh| lines.each do |l| fh.puts(l) @@ -72,9 +64,20 @@ Puppet::Type.type(:file_line).provide(:ruby) do end end end - + when 0 # append the line to the end of the file + append_line + else + raise Puppet::Error, "#{count} lines match pattern '#{resource[:after]}' in file '#{resource[:path]}'. One or no line must match the pattern." end - end + ## + # append the line to the file. + # + # @api private + def append_line + File.open(resource[:path], 'a') do |fh| + fh.puts resource[:line] + end + end end diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb index c8575ab..65b5d20 100644 --- a/spec/unit/puppet/provider/file_line/ruby_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -3,33 +3,36 @@ require 'tempfile' provider_class = Puppet::Type.type(:file_line).provider(:ruby) describe provider_class do context "when adding" do - before :each do - # TODO: these should be ported over to use the PuppetLabs spec_helper - # file fixtures once the following pull request has been merged: - # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files + let :tmpfile do tmp = Tempfile.new('tmp') - @tmpfile = tmp.path + path = tmp.path tmp.close! - @resource = Puppet::Type::File_line.new( - {:name => 'foo', :path => @tmpfile, :line => 'foo'} + path + end + let :resource do + Puppet::Type::File_line.new( + {:name => 'foo', :path => tmpfile, :line => 'foo'} ) - @provider = provider_class.new(@resource) end + let :provider do + provider_class.new(resource) + end + it 'should detect if the line exists in the file' do - File.open(@tmpfile, 'w') do |fh| + File.open(tmpfile, 'w') do |fh| fh.write('foo') end - @provider.exists?.should be_true + provider.exists?.should be_true end it 'should detect if the line does not exist in the file' do - File.open(@tmpfile, 'w') do |fh| + File.open(tmpfile, 'w') do |fh| fh.write('foo1') end - @provider.exists?.should be_nil + provider.exists?.should be_nil end it 'should append to an existing file when creating' do - @provider.create - File.read(@tmpfile).chomp.should == 'foo' + provider.create + File.read(tmpfile).chomp.should == 'foo' end end @@ -52,89 +55,132 @@ describe provider_class do @provider = provider_class.new(@resource) end - it 'should raise an error if more than one line matches, and should not have modified the file' do - File.open(@tmpfile, 'w') do |fh| - fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") + describe 'using match' do + it 'should raise an error if more than one line matches, and should not have modified the file' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") + end + @provider.exists?.should be_nil + expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/) + File.read(@tmpfile).should eql("foo1\nfoo=blah\nfoo2\nfoo=baz") end - @provider.exists?.should be_nil - expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/) - File.read(@tmpfile).should eql("foo1\nfoo=blah\nfoo2\nfoo=baz") - end - it 'should replace all lines that matches' do - @resource = Puppet::Type::File_line.new( + it 'should replace all lines that matches' do + @resource = Puppet::Type::File_line.new( { - :name => 'foo', - :path => @tmpfile, - :line => 'foo = bar', - :match => '^foo\s*=.*$', - :multiple => true + :name => 'foo', + :path => @tmpfile, + :line => 'foo = bar', + :match => '^foo\s*=.*$', + :multiple => true } - ) - @provider = provider_class.new(@resource) - File.open(@tmpfile, 'w') do |fh| - fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") + ) + @provider = provider_class.new(@resource) + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") + end + @provider.exists?.should be_nil + @provider.create + File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2\nfoo = bar") end - @provider.exists?.should be_nil - @provider.create - File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2\nfoo = bar") - end - it 'should replace all lines that matches with after' do - @resource = Puppet::Type::File_line.new( - { - :name => 'foo', - :path => @tmpfile, - :line => 'inserted = line', - :after => '^foo1', - } - ) - @provider = provider_class.new(@resource) - File.open(@tmpfile, 'w') do |fh| - fh.write("foo1\nfoo = blah\nfoo2\nfoo = baz") + it 'should raise an error with invalid values' do + expect { + @resource = Puppet::Type::File_line.new( + { + :name => 'foo', + :path => @tmpfile, + :line => 'foo = bar', + :match => '^foo\s*=.*$', + :multiple => 'asgadga' + } + ) + }.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false\./) + end + + it 'should replace a line that matches' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo=blah\nfoo2") + end + @provider.exists?.should be_nil + @provider.create + File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2") + end + it 'should add a new line if no lines match' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo2") + end + @provider.exists?.should be_nil + @provider.create + File.read(@tmpfile).should eql("foo1\nfoo2\nfoo = bar\n") + end + it 'should do nothing if the exact line already exists' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo = bar\nfoo2") + end + @provider.exists?.should be_true + @provider.create + File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2") end - @provider.exists?.should be_nil - @provider.create - File.read(@tmpfile).chomp.should eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo = baz") end - it 'should raise an error with invalid values' do - expect { - @resource = Puppet::Type::File_line.new( + describe 'using after' do + let :resource do + Puppet::Type::File_line.new( { - :name => 'foo', - :path => @tmpfile, - :line => 'foo = bar', - :match => '^foo\s*=.*$', - :multiple => 'asgadga' + :name => 'foo', + :path => @tmpfile, + :line => 'inserted = line', + :after => '^foo1', } ) - }.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false\./) - end + end - it 'should replace a line that matches' do - File.open(@tmpfile, 'w') do |fh| - fh.write("foo1\nfoo=blah\nfoo2") + let :provider do + provider_class.new(resource) end - @provider.exists?.should be_nil - @provider.create - File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2") - end - it 'should add a new line if no lines match' do - File.open(@tmpfile, 'w') do |fh| - fh.write("foo1\nfoo2") + + context 'with one line matching the after expression' do + before :each do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo = blah\nfoo2\nfoo = baz") + end + end + + it 'inserts the specified line after the line matching the "after" expression' do + provider.create + File.read(@tmpfile).chomp.should eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo = baz") + end end - @provider.exists?.should be_nil - @provider.create - File.read(@tmpfile).should eql("foo1\nfoo2\nfoo = bar\n") - end - it 'should do nothing if the exact line already exists' do - File.open(@tmpfile, 'w') do |fh| - fh.write("foo1\nfoo = bar\nfoo2") + + context 'with two lines matching the after expression' do + before :each do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo = blah\nfoo2\nfoo1\nfoo = baz") + end + end + + it 'errors out stating "One or no line must match the pattern"' do + expect { provider.create }.to raise_error(Puppet::Error, /One or no line must match the pattern/) + end + end + + context 'with no lines matching the after expression' do + let :content do + "foo3\nfoo = blah\nfoo2\nfoo = baz\n" + end + + before :each do + File.open(@tmpfile, 'w') do |fh| + fh.write(content) + end + end + + it 'appends the specified line to the file' do + provider.create + File.read(@tmpfile).should eq(content << resource[:line] << "\n") + end end - @provider.exists?.should be_true - @provider.create - File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2") end end -- cgit v1.2.3 From 34944a78f9c152ca39ab045908b3029208fbc03f Mon Sep 17 00:00:00 2001 From: floatingatoll Date: Wed, 4 Sep 2013 10:26:14 -0700 Subject: (maint) fix RST formatting of has_interface_with code examples --- README.markdown | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index a176d88..f1d281c 100644 --- a/README.markdown +++ b/README.markdown @@ -405,12 +405,16 @@ Returns boolean based on kind and value: * ipaddress * network -has_interface_with("macaddress", "x:x:x:x:x:x") -has_interface_with("ipaddress", "127.0.0.1") => true +*Examples:* + + has_interface_with("macaddress", "x:x:x:x:x:x") + has_interface_with("ipaddress", "127.0.0.1") => true + etc. If no "kind" is given, then the presence of the interface is checked: -has_interface_with("lo") => true + + has_interface_with("lo") => true - *Type*: rvalue -- cgit v1.2.3 From 6bd2b4874c861c56f25ba924ac3ab20aeb4cebcf Mon Sep 17 00:00:00 2001 From: Spencer Krum Date: Wed, 11 Sep 2013 15:37:59 -0700 Subject: Minor grammar fix --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index f1d281c..6ac1b8a 100644 --- a/README.markdown +++ b/README.markdown @@ -770,7 +770,7 @@ are replaced by a single character. str2bool -------- -This converts a string to a boolean. This attempt to convert strings that +This converts a string to a boolean. This attempts to convert strings that contain things like: y, 1, t, true to 'true' and strings that contain things like: 0, f, n, false, no to 'false'. -- 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 --- lib/puppet/parser/functions/pick.rb | 2 +- spec/unit/puppet/parser/functions/pick_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/functions/pick.rb b/lib/puppet/parser/functions/pick.rb index cbc0300..e9e5d66 100644 --- a/lib/puppet/parser/functions/pick.rb +++ b/lib/puppet/parser/functions/pick.rb @@ -21,7 +21,7 @@ EOS args.delete(:undefined) args.delete("") if args[0].to_s.empty? then - fail "Must provide non empty value." + fail Puppet::ParseError, "pick(): must receive at last one non empty value" else return args[0] end 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. --- lib/puppet/parser/functions/delete.rb | 2 +- spec/unit/puppet/parser/functions/delete_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/delete.rb b/lib/puppet/parser/functions/delete.rb index f814344..d03a293 100644 --- a/lib/puppet/parser/functions/delete.rb +++ b/lib/puppet/parser/functions/delete.rb @@ -27,7 +27,7 @@ string, or key from a hash. "given #{arguments.size} for 2.") end - collection = arguments[0] + collection = arguments[0].dup item = arguments[1] case collection 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. --- lib/puppet/parser/functions/delete_values.rb | 2 +- spec/unit/puppet/parser/functions/delete_values_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/delete_values.rb b/lib/puppet/parser/functions/delete_values.rb index 17b9d37..ca8eef5 100644 --- a/lib/puppet/parser/functions/delete_values.rb +++ b/lib/puppet/parser/functions/delete_values.rb @@ -21,6 +21,6 @@ Would return: {'a'=>'A','c'=>'C','B'=>'D'} raise(TypeError, "delete_values(): First argument must be a Hash. " + \ "Given an argument of class #{hash.class}.") end - hash.delete_if { |key, val| item == val } + hash.dup.delete_if { |key, val| item == val } 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 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(+) 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 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. --- lib/puppet/parser/functions/delete_undef_values.rb | 12 ++++++------ .../unit/puppet/parser/functions/delete_undef_values_spec.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/puppet/parser/functions/delete_undef_values.rb b/lib/puppet/parser/functions/delete_undef_values.rb index 4eecab2..532639e 100644 --- a/lib/puppet/parser/functions/delete_undef_values.rb +++ b/lib/puppet/parser/functions/delete_undef_values.rb @@ -18,16 +18,16 @@ Would return: ['A','',false] raise(Puppet::ParseError, "delete_undef_values(): Wrong number of arguments given " + "(#{args.size})") if args.size < 1 - - result = args[0] + + unless args[0].is_a? Array or args[0].is_a? Hash + raise(Puppet::ParseError, + "delete_undef_values(): expected an array or hash, got #{args[0]} type #{args[0].class} ") + end + result = args[0].dup if result.is_a?(Hash) result.delete_if {|key, val| val.equal? :undef} elsif result.is_a?(Array) result.delete :undef - else - raise(Puppet::ParseError, - "delete_undef_values(): Wrong argument type #{args[0].class} " + - "for first argument") end result 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 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. --- lib/puppet/parser/functions/validate_cmd.rb | 1 + spec/unit/puppet/parser/functions/validate_cmd_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb index 344a80c..2ebe91c 100644 --- a/lib/puppet/parser/functions/validate_cmd.rb +++ b/lib/puppet/parser/functions/validate_cmd.rb @@ -32,6 +32,7 @@ module Puppet::Parser::Functions tmpfile = Tempfile.new("validate_cmd") begin tmpfile.write(content) + tmpfile.close if Puppet::Util::Execution.respond_to?('execute') Puppet::Util::Execution.execute("#{checkscript} #{tmpfile.path}") else 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(-) 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 753801537f2e791d36cdded2e022878049a86119 Mon Sep 17 00:00:00 2001 From: Tehmasp Chaudhri Date: Fri, 25 Oct 2013 15:26:21 -0600 Subject: Fixed 'separator' typos --- README.markdown | 2 +- lib/puppet/parser/functions/join.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 6ac1b8a..5635343 100644 --- a/README.markdown +++ b/README.markdown @@ -544,7 +544,7 @@ Returns true if the variable passed to this function is a string. join ---- -This function joins an array into a string using a seperator. +This function joins an array into a string using a separator. *Examples:* diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb index 005a46e..6c0a6ba 100644 --- a/lib/puppet/parser/functions/join.rb +++ b/lib/puppet/parser/functions/join.rb @@ -4,7 +4,7 @@ module Puppet::Parser::Functions newfunction(:join, :type => :rvalue, :doc => <<-EOS -This function joins an array into a string using a seperator. +This function joins an array into a string using a separator. *Examples:* -- 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" --- lib/puppet/parser/functions/pick.rb | 2 +- spec/unit/puppet/parser/functions/pick_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 spec/unit/puppet/parser/functions/pick_spec.rb diff --git a/lib/puppet/parser/functions/pick.rb b/lib/puppet/parser/functions/pick.rb index e9e5d66..fdd0aef 100644 --- a/lib/puppet/parser/functions/pick.rb +++ b/lib/puppet/parser/functions/pick.rb @@ -21,7 +21,7 @@ EOS args.delete(:undefined) args.delete("") if args[0].to_s.empty? then - fail Puppet::ParseError, "pick(): must receive at last one non empty value" + fail Puppet::ParseError, "pick(): must receive at least one non empty value" else return args[0] end 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. --- lib/puppet/parser/functions/deep_merge.rb | 44 +++++++++++++ .../puppet/parser/functions/deep_merge_spec.rb | 77 ++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 lib/puppet/parser/functions/deep_merge.rb create mode 100644 spec/unit/puppet/parser/functions/deep_merge_spec.rb diff --git a/lib/puppet/parser/functions/deep_merge.rb b/lib/puppet/parser/functions/deep_merge.rb new file mode 100644 index 0000000..94677b8 --- /dev/null +++ b/lib/puppet/parser/functions/deep_merge.rb @@ -0,0 +1,44 @@ +module Puppet::Parser::Functions + newfunction(:deep_merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| + Recursively merges two or more hashes together and returns the resulting hash. + + For example: + + $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } } + $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } } + $merged_hash = deep_merge($hash1, $hash2) + # The resulting hash is equivalent to: + # $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } + + When there is a duplicate key that is a hash, they are recursively merged. + When there is a duplicate key that is not a hash, the key in the rightmost hash will "win." + + ENDHEREDOC + + if args.length < 2 + raise Puppet::ParseError, ("deep_merge(): wrong number of arguments (#{args.length}; must be at least 2)") + end + + deep_merge = Proc.new do |hash1,hash2| + hash1.merge!(hash2) do |key,old_value,new_value| + if old_value.is_a?(Hash) && new_value.is_a?(Hash) + deep_merge.call(old_value, new_value) + else + new_value + end + end + end + + result = Hash.new + args.each do |arg| + next if arg.is_a? String and arg.empty? # empty string is synonym for puppet's undef + # If the argument was not a hash, skip it. + unless arg.is_a?(Hash) + raise Puppet::ParseError, "deep_merge: unexpected argument type #{arg.class}, only expects hash arguments" + end + + deep_merge.call(result, arg) + end + return( result ) + end +end 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(-) 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(-) 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 ec8aaeecfaca4b0777683e25308fcc6960d78485 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Sat, 30 Nov 2013 10:40:27 -0500 Subject: Remove unintentional link from README Markdown interprets [] folowed by () as a link, which was a 404 and not the intention of the original author. This patch ensures that the document reads as intended, without the link. --- README.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 5635343..6a00772 100644 --- a/README.markdown +++ b/README.markdown @@ -702,8 +702,8 @@ Will return: [0,1,2,3,4,5,6,7,8,9] range("00", "09") -Will return: [0,1,2,3,4,5,6,7,8,9] (Zero padded strings are converted to -integers automatically) +Will return: [0,1,2,3,4,5,6,7,8,9] - Zero padded strings are converted to +integers automatically range("a", "c") -- cgit v1.2.3 From 9226037e4e1a3648f8b6809726612acae3046d74 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Sat, 30 Nov 2013 11:18:43 -0500 Subject: Add rake tasks to validate and lint files and check with Travis This patch adds the ability to validate syntax of manifests, templates, and ruby files in lib/ via `rake validate` and the linting of manifests with puppet-lint via `rake lint`. These two commands are chained with running the spec tests in Travis to ensure there are no syntax or style issues. --- .travis.yml | 2 +- Gemfile | 2 ++ Rakefile | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1bb1889..8334d42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby bundler_args: --without development -script: "bundle exec rake spec SPEC_OPTS='--color --format documentation'" +script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'" rvm: - 1.8.7 - 1.9.3 diff --git a/Gemfile b/Gemfile index 636f930..1b788fd 100644 --- a/Gemfile +++ b/Gemfile @@ -39,4 +39,6 @@ else gem 'puppet', :require => false end +gem 'puppet-lint', '>= 0.3.2' + # vim:ft=ruby diff --git a/Rakefile b/Rakefile index 14f1c24..4ed1327 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,18 @@ require 'rubygems' require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] + +desc "Validate manifests, templates, and ruby files in lib." +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['lib/**/*.rb'].each do |lib_file| + sh "ruby -c #{lib_file}" + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end -- cgit v1.2.3 From 7d78b3867acfdd770efe8604c4a93b0a74613ee1 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 6 Dec 2013 18:50:09 -0500 Subject: Pin rspec-puppet to 0.1.6 for now as the change to 1.0.0 has broken things involving Mocha badly. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 636f930..1cf399f 100644 --- a/Gemfile +++ b/Gemfile @@ -21,7 +21,7 @@ group :development, :test do gem 'rspec', "~> 2.11.0", :require => false gem 'mocha', "~> 0.10.5", :require => false gem 'puppetlabs_spec_helper', :require => false - gem 'rspec-puppet', :require => false + gem 'rspec-puppet', "~> 0.1.6", :require => false end facterversion = ENV['GEM_FACTER_VERSION'] -- 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 --- README.markdown | 6 ++++ lib/puppet/parser/functions/is_bool.rb | 22 ++++++++++++ lib/puppet/parser/functions/validate_bool.rb | 2 +- spec/unit/puppet/parser/functions/is_bool_spec.rb | 44 +++++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 lib/puppet/parser/functions/is_bool.rb create mode 100644 spec/unit/puppet/parser/functions/is_bool_spec.rb diff --git a/README.markdown b/README.markdown index 5635343..b592946 100644 --- a/README.markdown +++ b/README.markdown @@ -486,6 +486,12 @@ Returns true if the variable passed to this function is an array. - *Type*: rvalue +is_bool +-------- +Returns true if the variable passed to this function is a boolean. + +- *Type*: rvalue + is_domain_name -------------- Returns true if the string passed to this function is a syntactically correct domain name. diff --git a/lib/puppet/parser/functions/is_bool.rb b/lib/puppet/parser/functions/is_bool.rb new file mode 100644 index 0000000..8bbdbc8 --- /dev/null +++ b/lib/puppet/parser/functions/is_bool.rb @@ -0,0 +1,22 @@ +# +# is_bool.rb +# + +module Puppet::Parser::Functions + newfunction(:is_bool, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a boolean. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "is_bool(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size != 1 + + type = arguments[0] + + result = type.is_a?(TrueClass) || type.is_a?(FalseClass) + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/validate_bool.rb b/lib/puppet/parser/functions/validate_bool.rb index 62c1d88..59a0805 100644 --- a/lib/puppet/parser/functions/validate_bool.rb +++ b/lib/puppet/parser/functions/validate_bool.rb @@ -24,7 +24,7 @@ module Puppet::Parser::Functions end args.each do |arg| - unless (arg.is_a?(TrueClass) || arg.is_a?(FalseClass)) + unless function_is_bool([arg]) raise Puppet::ParseError, ("#{arg.inspect} is not a boolean. It looks to be a #{arg.class}") end end 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 5d4c95ec50f2814a42472e5841b486338a28698b Mon Sep 17 00:00:00 2001 From: Jeff McCune Date: Thu, 12 Dec 2013 11:12:12 -0500 Subject: (maint) Update README stating stdlib 4.x supports Puppet 2.7.x Without this patch there is a disconnect between the documentation in the README and our decision to not merge pull requests into the 4.x series that break compatibility with Puppet 2.7.x For example: @jeffmccune I think the real issue here is that "policy" is out of sync with the documentation. The README claims that 4.x does not support puppet 2.7.x, yet the "policy" is not to merge patches that break 2.7.x. Due to that I'm sure there are a lot of 2.7.x installations out there that have a 4.x version of stdlib installed. That's going to cause a rather rude surprise if some future version of 4.x stops working where a prior minor release was functioning. I'd like to suggest that the documentation be changed to reflect 4.x supporting 2.7.x and that a new major version bump is made when 2.7.x support can in fact be dropped. An alternative solution would be update the README with a note to developers about the kinda/sorta/maybe/fishy/quasi support of 2.7.x. Please also see this discussion: https://github.com/puppetlabs/puppetlabs-stdlib/pull/176#issuecomment-30251414 --- README.markdown | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index 5635343..fa02274 100644 --- a/README.markdown +++ b/README.markdown @@ -31,8 +31,9 @@ list of integration branches are: * v2.1.x (v2.1.1 released in PE 1) * v2.2.x (Never released as part of PE, only to the Forge) * v2.3.x (Released in PE 2) - * v3.0.x (Never released as part of PE, only to the Forge) - * v4.0.x (Drops support for Puppet 2.7) + * v3.0.x (Released in PE 3) + * v4.0.x (Maintains compatibility with v3.x despite the major semantic version bump. Compatible with Puppet 2.7.x) + * v5.x (To be released when stdlib can drop support for Puppet 2.7.x. Please see [this discussion](https://github.com/puppetlabs/puppetlabs-stdlib/pull/176#issuecomment-30251414)) * master (mainline development branch) The first Puppet Enterprise version including the stdlib module is Puppet @@ -44,7 +45,7 @@ Puppet Versions | < 2.6 | 2.6 | 2.7 | 3.x | :---------------|:-----:|:---:|:---:|:----: **stdlib 2.x** | no | **yes** | **yes** | no **stdlib 3.x** | no | no | **yes** | **yes** -**stdlib 4.x** | no | no | no | **yes** +**stdlib 4.x** | no | no | **yes** | **yes** The stdlib module does not work with Puppet versions released prior to Puppet 2.6.0. @@ -60,8 +61,10 @@ supports Puppet 2 and Puppet 3. ## stdlib 4.x ## -The 4.0 major release of stdlib drops support for Puppet 2.7. Stdlib 4.x -supports Puppet 3. Notably, ruby 1.8.5 is no longer supported though ruby +The 4.0 major release of stdlib was intended to drop support for Puppet 2.7, +but the impact on end users was too high. The decision was made to treat +stdlib 4.x as a continuation of stdlib 3.x support. Stdlib 4.x supports Puppet +2.7 and 3. Notably, ruby 1.8.5 is no longer supported though ruby 1.8.7, 1.9.3, and 2.0.0 are fully supported. # Functions # -- cgit v1.2.3 From 799e968f5c8ba901a8b395cff6f8848caf8b00e9 Mon Sep 17 00:00:00 2001 From: Andrew Parker Date: Wed, 18 Dec 2013 14:46:54 -0800 Subject: (Maint) Update stubbing to work with facter 1.7.4 Facter 1.7.4 changed how it decides on what directory to look in for facts.d based on the user it is running as. This stubs out that bit of code to make it think it is running as root. --- spec/unit/facter/pe_required_facts_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/unit/facter/pe_required_facts_spec.rb b/spec/unit/facter/pe_required_facts_spec.rb index f219b37..85ff6ab 100644 --- a/spec/unit/facter/pe_required_facts_spec.rb +++ b/spec/unit/facter/pe_required_facts_spec.rb @@ -9,6 +9,7 @@ describe "External facts in /etc/puppetlabs/facter/facts.d/puppet_enterprise_ins context "With Facter 1.6.17 which does not have external facts support" do before :each do Facter.stubs(:version).returns("1.6.17") + Facter::Util::Root.stubs(:root?).returns(true) # Stub out the filesystem for stdlib Dir.stubs(:entries).with("/etc/puppetlabs/facter/facts.d"). returns(['puppet_enterprise_installer.txt']) -- cgit v1.2.3 From 7991dd20738209ab86a657ba62f2600ba39ca8ef Mon Sep 17 00:00:00 2001 From: Franco Catena Date: Thu, 5 Dec 2013 16:11:59 -0300 Subject: Fix prefix exception message (Closes #23364) --- lib/puppet/parser/functions/prefix.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/prefix.rb b/lib/puppet/parser/functions/prefix.rb index 62211ae..d02286a 100644 --- a/lib/puppet/parser/functions/prefix.rb +++ b/lib/puppet/parser/functions/prefix.rb @@ -28,7 +28,7 @@ Will return: ['pa','pb','pc'] if prefix unless prefix.is_a?(String) - raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{suffix.inspect}" + raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{prefix.inspect}" 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(-) 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 bce5b76f66669a106df87c70d0709259aef0624b Mon Sep 17 00:00:00 2001 From: Andrew Parker Date: Mon, 23 Dec 2013 15:35:08 -0800 Subject: (doc) Update to point to Jira Since we've moved from Redmine to Jira the links need to be updated so that people know where to look for issues. At the moment stdlib is being tracked with puppet in the PUP project. This doesn't seem like a good, long term solution, but it is where we are right now. --- CONTRIBUTING.md | 6 +++--- README.markdown | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bd11f63..5280da1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ top of things. ## Getting Started -* Make sure you have a [Redmine account](http://projects.puppetlabs.com) +* Make sure you have a [Jira account](http://tickets.puppetlabs.com) * Make sure you have a [GitHub account](https://github.com/signup/free) * Submit a ticket for your issue, assuming one does not already exist. * Clearly describe the issue including steps to reproduce when it is a bug. @@ -52,13 +52,13 @@ top of things. * Sign the [Contributor License Agreement](http://links.puppetlabs.com/cla). * Push your changes to a topic branch in your fork of the repository. * Submit a pull request to the repository in the puppetlabs organization. -* Update your Redmine ticket to mark that you have submitted code and are ready for it to be reviewed. +* Update your ticket to mark that you have submitted code and are ready for it to be reviewed. * Include a link to the pull request in the ticket # Additional Resources * [More information on contributing](http://links.puppetlabs.com/contribute-to-puppet) -* [Bug tracker (Redmine)](http://projects.puppetlabs.com) +* [Bug tracker (Jira)](http://tickets.puppetlabs.com) * [Contributor License Agreement](http://links.puppetlabs.com/cla) * [General GitHub documentation](http://help.github.com/) * [GitHub pull request documentation](http://help.github.com/send-pull-requests/) diff --git a/README.markdown b/README.markdown index f8ff99c..822b8af 100644 --- a/README.markdown +++ b/README.markdown @@ -17,7 +17,7 @@ Puppet Labs writes and distributes will make heavy use of this standard library. To report or research a bug with any part of this module, please go to -[http://projects.puppetlabs.com/projects/stdlib](http://projects.puppetlabs.com/projects/stdlib) +[http://tickets.puppetlabs.com/browse/PUP](http://tickets.puppetlabs.com/browse/PUP) # Versions # -- cgit v1.2.3 From 735db82bef56bf939c971ab76a66647269d6ae35 Mon Sep 17 00:00:00 2001 From: Tomas Doran Date: Tue, 19 Nov 2013 18:38:12 +0000 Subject: Allow a single argument, rather than an array --- lib/puppet/parser/functions/ensure_packages.rb | 3 +-- spec/functions/ensure_packages_spec.rb | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb index 450ea02..371d63a 100644 --- a/lib/puppet/parser/functions/ensure_packages.rb +++ b/lib/puppet/parser/functions/ensure_packages.rb @@ -11,8 +11,7 @@ Takes a list of packages and only installs them if they don't already exist. raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " + "given (#{arguments.size} for 1)") if arguments.size != 1 - raise(Puppet::ParseError, "ensure_packages(): Requires array " + - "given (#{arguments[0].class})") if !arguments[0].kind_of?(Array) + arguments[0] = [ arguments[0] ] unless arguments[0].kind_of?(Array) Puppet::Parser::Functions.function(:ensure_resource) arguments[0].each { |package_name| diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index 6fd56d5..f6272af 100644 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -13,8 +13,9 @@ describe 'ensure_packages' do it 'requires an array' do lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error end - it 'fails when given a string' do - should run.with_params('foo').and_raise_error(Puppet::ParseError) + + it 'accepts a single package name as a string' do + scope.function_ensure_packages(['foo']) end end -- cgit v1.2.3 From 686a05aea20eb45560698caaad5c9f2f01821ae6 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Wed, 15 Jan 2014 11:03:49 -0800 Subject: (maint) refactor ensure_packages for clarity --- lib/puppet/parser/functions/ensure_packages.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb index 371d63a..1e0f225 100644 --- a/lib/puppet/parser/functions/ensure_packages.rb +++ b/lib/puppet/parser/functions/ensure_packages.rb @@ -1,7 +1,6 @@ # # ensure_packages.rb # -require 'puppet/parser/functions' module Puppet::Parser::Functions newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS @@ -9,12 +8,15 @@ Takes a list of packages and only installs them if they don't already exist. EOS ) do |arguments| - raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size != 1 - arguments[0] = [ arguments[0] ] unless arguments[0].kind_of?(Array) + if arguments.size != 1 + raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") + end + + packages = Array(arguments[0]) Puppet::Parser::Functions.function(:ensure_resource) - arguments[0].each { |package_name| + packages.each { |package_name| function_ensure_resource(['package', package_name, {'ensure' => 'present' } ]) } end -- cgit v1.2.3 From 75341f01d921352caf98caaff7ac30dcb6b626ed Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Wed, 15 Jan 2014 11:04:03 -0800 Subject: (maint) Update ensure_package specs to confirm expected behavior The previous behavior of the tests checked the behavior of the underlying functions library when called with no arguments; this commit updates the tests to conform to the functions API and test what happens when a function is called with no args. --- spec/functions/ensure_packages_spec.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index f6272af..a13c282 100644 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -8,10 +8,13 @@ describe 'ensure_packages' do describe 'argument handling' do it 'fails with no arguments' do - should run.with_params().and_raise_error(Puppet::ParseError) + expect { + scope.function_ensure_packages([]) + }.to raise_error(Puppet::ParseError, /0 for 1/) end - it 'requires an array' do - lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error + + it 'accepts an array of values' do + scope.function_ensure_packages([['foo']]) end it 'accepts a single package name as a string' do -- cgit v1.2.3 From fe676f0ac4e1d96e77ba7fe894408d8e7647eacc Mon Sep 17 00:00:00 2001 From: William Van Hevelingen Date: Thu, 16 Jan 2014 22:22:38 -0800 Subject: (PUP-1459) Add support for root_home on OS X 10.9 getent does not exist on 10.9 so this commit uses dscacheutil to query the homedir for the root user. --- lib/facter/root_home.rb | 13 +++++++++++++ spec/fixtures/dscacheutil/root | 8 ++++++++ spec/unit/facter/root_home_spec.rb | 29 ++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 spec/fixtures/dscacheutil/root diff --git a/lib/facter/root_home.rb b/lib/facter/root_home.rb index 8249f7d..b4f87ff 100644 --- a/lib/facter/root_home.rb +++ b/lib/facter/root_home.rb @@ -17,3 +17,16 @@ end Facter.add(:root_home) do setcode { Facter::Util::RootHome.get_root_home } end + +Facter.add(:root_home) do + confine :kernel => :darwin + setcode do + str = Facter::Util::Resolution.exec("dscacheutil -q user -a name root") + hash = {} + str.split("\n").each do |pair| + key,value = pair.split(/:/) + hash[key] = value + end + hash['dir'].strip + end +end diff --git a/spec/fixtures/dscacheutil/root b/spec/fixtures/dscacheutil/root new file mode 100644 index 0000000..1e34519 --- /dev/null +++ b/spec/fixtures/dscacheutil/root @@ -0,0 +1,8 @@ +name: root +password: * +uid: 0 +gid: 0 +dir: /var/root +shell: /bin/bash +gecos: rawr Root + diff --git a/spec/unit/facter/root_home_spec.rb b/spec/unit/facter/root_home_spec.rb index ce80684..532fae1 100644 --- a/spec/unit/facter/root_home_spec.rb +++ b/spec/unit/facter/root_home_spec.rb @@ -20,15 +20,6 @@ describe Facter::Util::RootHome do Facter::Util::RootHome.get_root_home.should == expected_root_home end end - context "macosx" do - let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" } - let(:expected_root_home) { "/var/root" } - - it "should return /var/root" do - Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent) - Facter::Util::RootHome.get_root_home.should == expected_root_home - end - end context "windows" do before :each do Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil) @@ -38,3 +29,23 @@ describe Facter::Util::RootHome do end end end + +describe 'root_home', :type => :fact do + before { Facter.clear } + after { Facter.clear } + + context "macosx" do + before do + Facter.fact(:kernel).stubs(:value).returns("Darwin") + Facter.fact(:osfamily).stubs(:value).returns("Darwin") + end + let(:expected_root_home) { "/var/root" } + sample_dscacheutil = File.read(fixtures('dscacheutil','root')) + + it "should return /var/root" do + Facter::Util::Resolution.stubs(:exec).with("dscacheutil -q user -a name root").returns(sample_dscacheutil) + Facter.fact(:root_home).value.should == expected_root_home + end + end + +end -- cgit v1.2.3 From 8f192a5a827919d47c65882d10271b9340d50e10 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Thu, 23 Jan 2014 14:18:50 -0500 Subject: Enable fast finish in Travis http://blog.travis-ci.com/2013-11-27-fast-finishing-builds/ --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8334d42..34d8cc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +--- language: ruby bundler_args: --without development script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'" @@ -9,6 +10,7 @@ rvm: env: - PUPPET_GEM_VERSION=">= 3.0.0" matrix: + fast_finish: true allow_failures: - rvm: 2.0.0 - rvm: ruby-head -- 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}" --- lib/puppet/parser/functions/is_integer.rb | 26 +++++-- lib/puppet/parser/functions/is_numeric.rb | 50 +++++++++++++- .../puppet/parser/functions/is_integer_spec.rb | 35 ++++++++++ .../puppet/parser/functions/is_numeric_spec.rb | 80 ++++++++++++++++++++++ 4 files changed, 184 insertions(+), 7 deletions(-) diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb index 6b29e98..3c4874e 100644 --- a/lib/puppet/parser/functions/is_integer.rb +++ b/lib/puppet/parser/functions/is_integer.rb @@ -4,7 +4,10 @@ module Puppet::Parser::Functions newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS -Returns true if the variable returned to this string is an integer. +Returns true if the variable passed to this function is an integer. + +If the variable is a string it has to be in the correct format of an +integer. EOS ) do |arguments| @@ -15,12 +18,25 @@ Returns true if the variable returned to this string is an integer. value = arguments[0] - if value != value.to_i.to_s and !value.is_a? Fixnum then - return false - else + # Regex is taken from the lexer of puppet + # puppet/pops/parser/lexer.rb but modified to match also + # negative values and disallow numbers prefixed with multiple + # 0's + # + # TODO these parameter should be a constant but I'm not sure + # if there is no risk to declare it inside of the module + # Puppet::Parser::Functions + + # Integer numbers like + # -1234568981273 + # 47291 + numeric = %r{^-?(?:(?:[1-9]\d*)|0)$} + + if value.is_a? Integer or (value.is_a? String and value.match numeric) return true + else + return false end - end end diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb index abf0321..f2417f3 100644 --- a/lib/puppet/parser/functions/is_numeric.rb +++ b/lib/puppet/parser/functions/is_numeric.rb @@ -5,6 +5,20 @@ module Puppet::Parser::Functions newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS Returns true if the variable passed to this function is a number. + +The function recognizes only integer and float but not hex or octal +numbers (for now) until a decision is made how to handle these types. + +The parameter can be in the native format or given as string representation +of a number. + +Valid examples: + + 77435 + 10e-12 + -8475 + 0.2343 + -23.561e3 EOS ) do |arguments| @@ -15,12 +29,44 @@ Returns true if the variable passed to this function is a number. value = arguments[0] - if value == value.to_f.to_s or value == value.to_i.to_s or value.is_a? Numeric then + # Regex is taken from the lexer of puppet + # puppet/pops/parser/lexer.rb but modified to match also + # negative values and disallow invalid octal numbers or + # numbers prefixed with multiple 0's (except in hex numbers) + # + # TODO these parameters should be constants but I'm not sure + # if there is no risk to declare them inside of the module + # Puppet::Parser::Functions + + # TODO decide if this should be used + # HEX numbers like + # 0xaa230F + # 0X1234009C + # 0x0012 + # -12FcD + #numeric_hex = %r{^-?0[xX][0-9A-Fa-f]+$} + + # TODO decide if this should be used + # OCTAL numbers like + # 01234567 + # -045372 + #numeric_oct = %r{^-?0[1-7][0-7]*$} + + # Integer/Float numbers like + # -0.1234568981273 + # 47291 + # 42.12345e-12 + numeric = %r{^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)?(?:[eE]-?\d+)?$} + + if value.is_a? Numeric or (value.is_a? String and ( + value.match(numeric) #or + # value.match(numeric_hex) or + # value.match(numeric_oct) + )) return true else return false end - end end 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 2c8450d830453e452b819bfb05678768336c3031 Mon Sep 17 00:00:00 2001 From: Henrik Lindberg Date: Fri, 24 Jan 2014 00:22:09 +0100 Subject: (PUP-1195) Rephrase documentation for is_integer and is_numeric The documentation contained references to future decisions about functionality. Text rephrased for clarity. --- lib/puppet/parser/functions/is_integer.rb | 8 +++++--- lib/puppet/parser/functions/is_numeric.rb | 12 +++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb index 3c4874e..c03d28d 100644 --- a/lib/puppet/parser/functions/is_integer.rb +++ b/lib/puppet/parser/functions/is_integer.rb @@ -4,10 +4,12 @@ module Puppet::Parser::Functions newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS -Returns true if the variable passed to this function is an integer. +Returns true if the variable passed to this function is an Integer or +a decimal (base 10) integer in String form. The string may +start with a '-' (minus). A value of '0' is allowed, but a leading '0' digit may not +be followed by other digits as this indicates that the value is octal (base 8). -If the variable is a string it has to be in the correct format of an -integer. +If given any other argument `false` is returned. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb index f2417f3..e7e1d2a 100644 --- a/lib/puppet/parser/functions/is_numeric.rb +++ b/lib/puppet/parser/functions/is_numeric.rb @@ -4,13 +4,15 @@ module Puppet::Parser::Functions newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS -Returns true if the variable passed to this function is a number. +Returns true if the given argument is a Numeric (Integer or Float), +or a String containing either a valid integer in decimal base 10 form, or +a valid floating point string representation. -The function recognizes only integer and float but not hex or octal -numbers (for now) until a decision is made how to handle these types. +The function recognizes only decimal (base 10) integers and float but not +integers in hex (base 16) or octal (base 8) form. -The parameter can be in the native format or given as string representation -of a number. +The string representation may start with a '-' (minus). If a decimal '.' is used, +it must be followed by at least one digit. Valid examples: -- cgit v1.2.3 From dbba655c106f951061206aaf0863f4f8d18da7b1 Mon Sep 17 00:00:00 2001 From: David Bishop Date: Sat, 25 Jan 2014 13:23:17 -0500 Subject: (DOCUMENT-21) add docs for file_line to README.markdown Without this, you have to look at the source file (lib/puppet/type/file_line.rb) to know what it does. This adds that documentation. --- README.markdown | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.markdown b/README.markdown index 822b8af..85bfada 100644 --- a/README.markdown +++ b/README.markdown @@ -305,6 +305,26 @@ the type and parameters specified if it doesn't already exist. - *Type*: statement +file_line +--------- +This resource ensures that a given line is contained within a file. You can also use +"match" to replace existing lines. + +*Examples:* + + file_line { 'sudo_rule': + path => '/etc/sudoers', + line => '%sudo ALL=(ALL) ALL', + } + + file_line { 'change_mount': + path => '/etc/fstab', + line => '10.0.0.1:/vol/data /opt/data nfs defaults 0 0', + match => '^172.16.17.2:/vol/old', + } + +- *Type*: resource + flatten ------- This function flattens any deeply nested arrays and returns a single flat array -- cgit v1.2.3 From 9346b108ce7996bcb363a94d84d087984d74bc86 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 14 Aug 2013 10:33:39 +0200 Subject: (PUP-636) Ignore generated file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2e3ca63..690e67e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ spec/fixtures/ Gemfile.lock .bundle/ vendor/bundle/ +/metadata.json -- 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. --- lib/puppet/parser/functions/pick_default.rb | 35 +++++++++++++ .../puppet/parser/functions/pick_default_spec.rb | 58 ++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 lib/puppet/parser/functions/pick_default.rb create mode 100644 spec/unit/puppet/parser/functions/pick_default_spec.rb diff --git a/lib/puppet/parser/functions/pick_default.rb b/lib/puppet/parser/functions/pick_default.rb new file mode 100644 index 0000000..36e33ab --- /dev/null +++ b/lib/puppet/parser/functions/pick_default.rb @@ -0,0 +1,35 @@ +module Puppet::Parser::Functions + newfunction(:pick_default, :type => :rvalue, :doc => <<-EOS + +This function is similar to a coalesce function in SQL in that it will return +the first value in a list of values that is not undefined or an empty string +(two things in Puppet that will return a boolean false value). If no value is +found, it will return the last argument. + +Typically, this function is used to check for a value in the Puppet +Dashboard/Enterprise Console, and failover to a default value like the +following: + + $real_jenkins_version = pick_default($::jenkins_version, '1.449') + +The value of $real_jenkins_version will first look for a top-scope variable +called 'jenkins_version' (note that parameters set in the Puppet Dashboard/ +Enterprise Console are brought into Puppet as top-scope variables), and, +failing that, will use a default value of 1.449. + +Note that, contrary to the pick() function, the pick_default does not fail if +all arguments are empty. This allows pick_default to use an empty value as +default. + +EOS +) do |args| + fail "Must receive at least one argument." if args.empty? + default = args.last + args = args[0..-2].compact + args.delete(:undef) + args.delete(:undefined) + args.delete("") + args << default + return args[0] + end +end 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 --- README.markdown | 2 +- lib/puppet/parser/functions/base64.rb | 12 ++++++------ lib/puppet/parser/functions/delete_undef_values.rb | 10 +++++----- lib/puppet/parser/functions/delete_values.rb | 2 +- lib/puppet/parser/functions/range.rb | 2 +- lib/puppet/parser/functions/str2bool.rb | 2 +- spec/unit/puppet/parser/functions/delete_at_spec.rb | 4 ++-- spec/unit/puppet/parser/functions/delete_spec.rb | 6 +++--- .../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 +- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.markdown b/README.markdown index 822b8af..273c47a 100644 --- a/README.markdown +++ b/README.markdown @@ -225,7 +225,7 @@ delete_undef_values Deletes all instances of the undef value from an array or hash. *Examples:* - + $hash = delete_undef_values({a=>'A', b=>'', c=>undef, d => false}) Would return: {a => 'A', b => '', d => false} diff --git a/lib/puppet/parser/functions/base64.rb b/lib/puppet/parser/functions/base64.rb index d9a590a..617ba31 100644 --- a/lib/puppet/parser/functions/base64.rb +++ b/lib/puppet/parser/functions/base64.rb @@ -1,5 +1,5 @@ module Puppet::Parser::Functions - + newfunction(:base64, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| Base64 encode or decode a string based on the command and the string submitted @@ -10,9 +10,9 @@ module Puppet::Parser::Functions $decodestring = base64('decode','dGhlc3RyaW5n') ENDHEREDOC - + require 'base64' - + raise Puppet::ParseError, ("base64(): Wrong number of arguments (#{args.length}; must be = 2)") unless args.length == 2 actions = ['encode','decode'] @@ -20,18 +20,18 @@ module Puppet::Parser::Functions unless actions.include?(args[0]) raise Puppet::ParseError, ("base64(): the first argument must be one of 'encode' or 'decode'") end - + unless args[1].is_a?(String) raise Puppet::ParseError, ("base64(): the second argument must be a string to base64") end - + case args[0] when 'encode' result = Base64.encode64(args[1]) when 'decode' result = Base64.decode64(args[1]) end - + return result end end diff --git a/lib/puppet/parser/functions/delete_undef_values.rb b/lib/puppet/parser/functions/delete_undef_values.rb index 532639e..f94d4da 100644 --- a/lib/puppet/parser/functions/delete_undef_values.rb +++ b/lib/puppet/parser/functions/delete_undef_values.rb @@ -3,7 +3,7 @@ module Puppet::Parser::Functions Returns a copy of input hash or array with all undefs deleted. *Examples:* - + $hash = delete_undef_values({a=>'A', b=>'', c=>undef, d => false}) Would return: {a => 'A', b => '', d => false} @@ -11,19 +11,19 @@ Would return: {a => 'A', b => '', d => false} $array = delete_undef_values(['A','',undef,false]) Would return: ['A','',false] - + EOS ) do |args| raise(Puppet::ParseError, "delete_undef_values(): Wrong number of arguments given " + "(#{args.size})") if args.size < 1 - - unless args[0].is_a? Array or args[0].is_a? Hash + + unless args[0].is_a? Array or args[0].is_a? Hash raise(Puppet::ParseError, "delete_undef_values(): expected an array or hash, got #{args[0]} type #{args[0].class} ") end - result = args[0].dup + result = args[0].dup if result.is_a?(Hash) result.delete_if {|key, val| val.equal? :undef} elsif result.is_a?(Array) diff --git a/lib/puppet/parser/functions/delete_values.rb b/lib/puppet/parser/functions/delete_values.rb index ca8eef5..f6c8c0e 100644 --- a/lib/puppet/parser/functions/delete_values.rb +++ b/lib/puppet/parser/functions/delete_values.rb @@ -19,7 +19,7 @@ Would return: {'a'=>'A','c'=>'C','B'=>'D'} if not hash.is_a?(Hash) raise(TypeError, "delete_values(): First argument must be a Hash. " + \ - "Given an argument of class #{hash.class}.") + "Given an argument of class #{hash.class}.") end hash.dup.delete_if { |key, val| item == val } end diff --git a/lib/puppet/parser/functions/range.rb b/lib/puppet/parser/functions/range.rb index 0849491..ffbdf84 100644 --- a/lib/puppet/parser/functions/range.rb +++ b/lib/puppet/parser/functions/range.rb @@ -28,7 +28,7 @@ Will return: ["a","b","c"] Will return: ["host01", "host02", ..., "host09", "host10"] -Passing a third argument will cause the generated range to step by that +Passing a third argument will cause the generated range to step by that interval, e.g. range("0", "9", "2") diff --git a/lib/puppet/parser/functions/str2bool.rb b/lib/puppet/parser/functions/str2bool.rb index fece7a6..446732e 100644 --- a/lib/puppet/parser/functions/str2bool.rb +++ b/lib/puppet/parser/functions/str2bool.rb @@ -14,7 +14,7 @@ like: 0, f, n, false, no to 'false'. "given (#{arguments.size} for 1)") if arguments.size < 1 string = arguments[0] - + # If string is already Boolean, return it if !!string == string return string 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 d4722d7af5becfce52514fc3fa6aa3e4f389fd98 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Tue, 11 Feb 2014 15:57:22 +0000 Subject: Fix strftime documentation in README Markdown was barfing due to typo --- README.markdown | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 273c47a..344fd64 100644 --- a/README.markdown +++ b/README.markdown @@ -831,8 +831,7 @@ To return the date: %L - Millisecond of the second (000..999) %m - Month of the year (01..12) %M - Minute of the hour (00..59) - %n - Newline ( -) + %n - Newline (\n) %N - Fractional seconds digits, default is 9 digits (nanosecond) %3N millisecond (3 digits) %6N microsecond (6 digits) -- 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. --- lib/puppet/parser/functions/deep_merge.rb | 4 ++-- .../puppet/parser/functions/deep_merge_spec.rb | 28 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/functions/deep_merge.rb b/lib/puppet/parser/functions/deep_merge.rb index 94677b8..6df32e9 100644 --- a/lib/puppet/parser/functions/deep_merge.rb +++ b/lib/puppet/parser/functions/deep_merge.rb @@ -20,7 +20,7 @@ module Puppet::Parser::Functions end deep_merge = Proc.new do |hash1,hash2| - hash1.merge!(hash2) do |key,old_value,new_value| + hash1.merge(hash2) do |key,old_value,new_value| if old_value.is_a?(Hash) && new_value.is_a?(Hash) deep_merge.call(old_value, new_value) else @@ -37,7 +37,7 @@ module Puppet::Parser::Functions raise Puppet::ParseError, "deep_merge: unexpected argument type #{arg.class}, only expects hash arguments" end - deep_merge.call(result, arg) + result = deep_merge.call(result, arg) end return( result ) end 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 908db6d403e16e345a78427e8eef397d5f8533e8 Mon Sep 17 00:00:00 2001 From: Juan Treminio Date: Wed, 19 Feb 2014 23:37:38 -0600 Subject: hash example has misplaced comas --- README.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 1e70f39..76c546f 100644 --- a/README.markdown +++ b/README.markdown @@ -650,8 +650,8 @@ Merges two or more hashes together and returns the resulting hash. For example: - $hash1 = {'one' => 1, 'two', => 2} - $hash2 = {'two' => 'dos', 'three', => 'tres'} + $hash1 = {'one' => 1, 'two' => 2} + $hash2 = {'two' => 'dos', 'three' => 'tres'} $merged_hash = merge($hash1, $hash2) # The resulting hash is equivalent to: # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'} -- 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 --- README.markdown | 5 +++++ lib/puppet/parser/functions/concat.rb | 10 +++++++--- spec/unit/puppet/parser/functions/concat_spec.rb | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index 1e70f39..3a6c0cf 100644 --- a/README.markdown +++ b/README.markdown @@ -145,6 +145,11 @@ Would result in: ['1','2','3','4','5','6'] + concat(['1','2','3'],'4') + +Would result in: + + ['1','2','3','4'] - *Type*: rvalue diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb index c86aa00..6c86382 100644 --- a/lib/puppet/parser/functions/concat.rb +++ b/lib/puppet/parser/functions/concat.rb @@ -23,12 +23,16 @@ Would result in: a = arguments[0] b = arguments[1] - # Check that both args are arrays. - unless a.is_a?(Array) and b.is_a?(Array) + # Check that the first parameter is an array + unless a.is_a?(Array) raise(Puppet::ParseError, 'concat(): Requires array to work with') end - result = a.concat(b) + if b.is_a?(Array) + result = a.concat(b) + else + result = a << b + end return result end 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 ff47b2e0400991a7134a9e3c67d89562b3c76426 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 3 Mar 2014 17:47:04 +0000 Subject: Prepare for supported modules. --- .gitignore | 2 -- metadata.json | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 metadata.json diff --git a/.gitignore b/.gitignore index 690e67e..7d0fd8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,7 @@ pkg/ .DS_Store -metadata.json coverage/ spec/fixtures/ Gemfile.lock .bundle/ vendor/bundle/ -/metadata.json diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..384f3a0 --- /dev/null +++ b/metadata.json @@ -0,0 +1,81 @@ +{ + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "5", + "6" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "5", + "6" + ] + }, + { + "operatingsystem": "OracleLinux", + "operatingsystemrelease": [ + "5", + "6" + ] + }, + { + "operatingsystem": "Scientific", + "operatingsystemrelease": [ + "5", + "6" + ] + }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "11 SP1" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "10.04", + "12.04" + ] + }, + { + "operatingsystem": "Solaris", + "operatingsystemrelease": [ + "10", + "11" + ] + }, + { + "operatingsystem": "Windows", + "operatingsystemrelease": [ + "Server 2003 R2", + "Server 2008 R2", + "Server 2012", + "Server 2012 R2", + "7" + ] + }, + { + "operatingsystem": "AIX", + "operatingsystemrelease": [ + "5.3", + "6.1", + "7.1" + ] + } + ], + "requirements": [ + { "name": "pe", "version_requirement": "3.2.x" }, + { "name": "puppet", "version_requirement": "3.x" } + ] +} -- cgit v1.2.3 From b3490f6318f6c6d5da7a7c8316379df571daa9b9 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 3 Mar 2014 12:45:43 -0800 Subject: Supported Release 3.2.1 Summary This is a supported release Bugfixes - Fixed `is_integer`/`is_float`/`is_numeric` for checking the value of arithmatic expressions. Known bugs * No known bugs --- .gitignore | 1 - CHANGELOG | 177 ------------------------------------------- CHANGELOG.md | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Modulefile | 2 +- metadata.json | 88 ++++++++++++++++++++++ 5 files changed, 325 insertions(+), 179 deletions(-) delete mode 100644 CHANGELOG create mode 100644 CHANGELOG.md create mode 100644 metadata.json diff --git a/.gitignore b/.gitignore index 481fc81..db949df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ pkg/ .DS_Store -metadata.json coverage/ diff --git a/CHANGELOG b/CHANGELOG deleted file mode 100644 index 313b83c..0000000 --- a/CHANGELOG +++ /dev/null @@ -1,177 +0,0 @@ -2012-11-28 - Peter Meier - 3.2.0 - * Add reject() function (a79b2cd) - -2012-09-18 - Chad Metcalf - 3.2.0 - * Add an ensure_packages function. (8a8c09e) - -2012-11-23 - Erik Dalén - 3.2.0 - * (#17797) min() and max() functions (9954133) - -2012-05-23 - Peter Meier - 3.2.0 - * (#14670) autorequire a file_line resource's path (dfcee63) - -2012-11-19 - Joshua Harlan Lifton - 3.2.0 - * Add join_keys_to_values function (ee0f2b3) - -2012-11-17 - Joshua Harlan Lifton - 3.2.0 - * Extend delete function for strings and hashes (7322e4d) - -2012-08-03 - Gary Larizza - 3.2.0 - * Add the pick() function (ba6dd13) - -2012-03-20 - Wil Cooley - 3.2.0 - * (#13974) Add predicate functions for interface facts (f819417) - -2012-11-06 - Joe Julian - 3.2.0 - * Add function, uriescape, to URI.escape strings. Redmine #17459 (70f4a0e) - -2012-10-25 - Jeff McCune - 3.1.1 - * (maint) Fix spec failures resulting from Facter API changes (97f836f) - -2012-10-23 - Matthaus Owens - 3.1.0 - * Add PE facts to stdlib (cdf3b05) - -2012-08-16 - Jeff McCune - 3.0.1 - * Fix accidental removal of facts_dot_d.rb in 3.0.0 release - -2012-08-16 - Jeff McCune - 3.0.0 - * stdlib 3.0 drops support with Puppet 2.6 - * stdlib 3.0 preserves support with Puppet 2.7 - -2012-08-07 - Dan Bode - 3.0.0 - * Add function ensure_resource and defined_with_params (ba789de) - -2012-07-10 - Hailee Kenney - 3.0.0 - * (#2157) Remove facter_dot_d for compatibility with external facts (f92574f) - -2012-04-10 - Chris Price - 3.0.0 - * (#13693) moving logic from local spec_helper to puppetlabs_spec_helper (85f96df) - -2012-10-25 - Jeff McCune - 2.5.1 - * (maint) Fix spec failures resulting from Facter API changes (97f836f) - -2012-10-23 - Matthaus Owens - 2.5.0 - * Add PE facts to stdlib (cdf3b05) - -2012-08-15 - Dan Bode - 2.5.0 - * Explicitly load functions used by ensure_resource (9fc3063) - -2012-08-13 - Dan Bode - 2.5.0 - * Add better docs about duplicate resource failures (97d327a) - -2012-08-13 - Dan Bode - 2.5.0 - * Handle undef for parameter argument (4f8b133) - -2012-08-07 - Dan Bode - 2.5.0 - * Add function ensure_resource and defined_with_params (a0cb8cd) - -2012-08-20 - Jeff McCune - 2.5.0 - * Disable tests that fail on 2.6.x due to #15912 (c81496e) - -2012-08-20 - Jeff McCune - 2.5.0 - * (Maint) Fix mis-use of rvalue functions as statements (4492913) - -2012-08-20 - Jeff McCune - 2.5.0 - * Add .rspec file to repo root (88789e8) - -2012-06-07 - Chris Price - 2.4.0 - * Add support for a 'match' parameter to file_line (a06c0d8) - -2012-08-07 - Erik Dalén - 2.4.0 - * (#15872) Add to_bytes function (247b69c) - -2012-07-19 - Jeff McCune - 2.4.0 - * (Maint) use PuppetlabsSpec::PuppetInternals.scope (master) (deafe88) - -2012-07-10 - Hailee Kenney - 2.4.0 - * (#2157) Make facts_dot_d compatible with external facts (5fb0ddc) - -2012-03-16 - Steve Traylen - 2.4.0 - * (#13205) Rotate array/string randomley based on fqdn, fqdn_rotate() (fef247b) - -2012-05-22 - Peter Meier - 2.3.3 - * fix regression in #11017 properly (f0a62c7) - -2012-05-10 - Jeff McCune - 2.3.3 - * Fix spec tests using the new spec_helper (7d34333) - -2012-05-10 - Puppet Labs - 2.3.2 - * Make file_line default to ensure => present (1373e70) - * Memoize file_line spec instance variables (20aacc5) - * Fix spec tests using the new spec_helper (1ebfa5d) - * (#13595) initialize_everything_for_tests couples modules Puppet ver (3222f35) - * (#13439) Fix MRI 1.9 issue with spec_helper (15c5fd1) - * (#13439) Fix test failures with Puppet 2.6.x (665610b) - * (#13439) refactor spec helper for compatibility with both puppet 2.7 and master (82194ca) - * (#13494) Specify the behavior of zero padded strings (61891bb) - -2012-03-29 Puppet Labs - 2.1.3 -* (#11607) Add Rakefile to enable spec testing -* (#12377) Avoid infinite loop when retrying require json - -2012-03-13 Puppet Labs - 2.3.1 -* (#13091) Fix LoadError bug with puppet apply and puppet_vardir fact - -2012-03-12 Puppet Labs - 2.3.0 -* Add a large number of new Puppet functions -* Backwards compatibility preserved with 2.2.x - -2011-12-30 Puppet Labs - 2.2.1 -* Documentation only release for the Forge - -2011-12-30 Puppet Labs - 2.1.2 -* Documentation only release for PE 2.0.x - -2011-11-08 Puppet Labs - 2.2.0 -* #10285 - Refactor json to use pson instead. -* Maint - Add watchr autotest script -* Maint - Make rspec tests work with Puppet 2.6.4 -* #9859 - Add root_home fact and tests - -2011-08-18 Puppet Labs - 2.1.1 -* Change facts.d paths to match Facter 2.0 paths. -* /etc/facter/facts.d -* /etc/puppetlabs/facter/facts.d - -2011-08-17 Puppet Labs - 2.1.0 -* Add R.I. Pienaar's facts.d custom facter fact -* facts defined in /etc/facts.d and /etc/puppetlabs/facts.d are - automatically loaded now. - -2011-08-04 Puppet Labs - 2.0.0 -* Rename whole_line to file_line -* This is an API change and as such motivating a 2.0.0 release according to semver.org. - -2011-08-04 Puppet Labs - 1.1.0 -* Rename append_line to whole_line -* This is an API change and as such motivating a 1.1.0 release. - -2011-08-04 Puppet Labs - 1.0.0 -* Initial stable release -* Add validate_array and validate_string functions -* Make merge() function work with Ruby 1.8.5 -* Add hash merging function -* Add has_key function -* Add loadyaml() function -* Add append_line native - -2011-06-21 Jeff McCune - 0.1.7 -* Add validate_hash() and getvar() functions - -2011-06-15 Jeff McCune - 0.1.6 -* Add anchor resource type to provide containment for composite classes - -2011-06-03 Jeff McCune - 0.1.5 -* Add validate_bool() function to stdlib - -0.1.4 2011-05-26 Jeff McCune -* Move most stages after main - -0.1.3 2011-05-25 Jeff McCune -* Add validate_re() function - -0.1.2 2011-05-24 Jeff McCune -* Update to add annotated tag - -0.1.1 2011-05-24 Jeff McCune -* Add stdlib::stages class with a standard set of stages diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7f0ec67 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,236 @@ +##2014-03-04 - Supported Release - 3.2.1 +###Summary +This is a supported release + +####Bugfixes +- Fixed `is_integer`/`is_float`/`is_numeric` for checking the value of arithmatic expressions. + +####Known bugs +* No known bugs + +--- + +##### 2012-09-18 - Chad Metcalf - 3.2.0 + + * Add an ensure\_packages function. (8a8c09e) + +##### 2012-11-23 - Erik Dalén - 3.2.0 + + * (#17797) min() and max() functions (9954133) + +##### 2012-05-23 - Peter Meier - 3.2.0 + + * (#14670) autorequire a file\_line resource's path (dfcee63) + +##### 2012-11-19 - Joshua Harlan Lifton - 3.2.0 + + * Add join\_keys\_to\_values function (ee0f2b3) + +##### 2012-11-17 - Joshua Harlan Lifton - 3.2.0 + + * Extend delete function for strings and hashes (7322e4d) + +##### 2012-08-03 - Gary Larizza - 3.2.0 + + * Add the pick() function (ba6dd13) + +##### 2012-03-20 - Wil Cooley - 3.2.0 + + * (#13974) Add predicate functions for interface facts (f819417) + +##### 2012-11-06 - Joe Julian - 3.2.0 + + * Add function, uriescape, to URI.escape strings. Redmine #17459 (70f4a0e) + +##### 2012-10-25 - Jeff McCune - 3.1.1 + + * (maint) Fix spec failures resulting from Facter API changes (97f836f) + +##### 2012-10-23 - Matthaus Owens - 3.1.0 + + * Add PE facts to stdlib (cdf3b05) + +##### 2012-08-16 - Jeff McCune - 3.0.1 + + * Fix accidental removal of facts\_dot\_d.rb in 3.0.0 release + +##### 2012-08-16 - Jeff McCune - 3.0.0 + + * stdlib 3.0 drops support with Puppet 2.6 + * stdlib 3.0 preserves support with Puppet 2.7 + +##### 2012-08-07 - Dan Bode - 3.0.0 + + * Add function ensure\_resource and defined\_with\_params (ba789de) + +##### 2012-07-10 - Hailee Kenney - 3.0.0 + + * (#2157) Remove facter\_dot\_d for compatibility with external facts (f92574f) + +##### 2012-04-10 - Chris Price - 3.0.0 + + * (#13693) moving logic from local spec\_helper to puppetlabs\_spec\_helper (85f96df) + +##### 2012-10-25 - Jeff McCune - 2.5.1 + + * (maint) Fix spec failures resulting from Facter API changes (97f836f) + +##### 2012-10-23 - Matthaus Owens - 2.5.0 + + * Add PE facts to stdlib (cdf3b05) + +##### 2012-08-15 - Dan Bode - 2.5.0 + + * Explicitly load functions used by ensure\_resource (9fc3063) + +##### 2012-08-13 - Dan Bode - 2.5.0 + + * Add better docs about duplicate resource failures (97d327a) + +##### 2012-08-13 - Dan Bode - 2.5.0 + + * Handle undef for parameter argument (4f8b133) + +##### 2012-08-07 - Dan Bode - 2.5.0 + + * Add function ensure\_resource and defined\_with\_params (a0cb8cd) + +##### 2012-08-20 - Jeff McCune - 2.5.0 + + * Disable tests that fail on 2.6.x due to #15912 (c81496e) + +##### 2012-08-20 - Jeff McCune - 2.5.0 + + * (Maint) Fix mis-use of rvalue functions as statements (4492913) + +##### 2012-08-20 - Jeff McCune - 2.5.0 + + * Add .rspec file to repo root (88789e8) + +##### 2012-06-07 - Chris Price - 2.4.0 + + * Add support for a 'match' parameter to file\_line (a06c0d8) + +##### 2012-08-07 - Erik Dalén - 2.4.0 + + * (#15872) Add to\_bytes function (247b69c) + +##### 2012-07-19 - Jeff McCune - 2.4.0 + + * (Maint) use PuppetlabsSpec::PuppetInternals.scope (master) (deafe88) + +##### 2012-07-10 - Hailee Kenney - 2.4.0 + + * (#2157) Make facts\_dot\_d compatible with external facts (5fb0ddc) + +##### 2012-03-16 - Steve Traylen - 2.4.0 + + * (#13205) Rotate array/string randomley based on fqdn, fqdn\_rotate() (fef247b) + +##### 2012-05-22 - Peter Meier - 2.3.3 + + * fix regression in #11017 properly (f0a62c7) + +##### 2012-05-10 - Jeff McCune - 2.3.3 + + * Fix spec tests using the new spec\_helper (7d34333) + +##### 2012-05-10 - Puppet Labs - 2.3.2 + + * Make file\_line default to ensure => present (1373e70) + * Memoize file\_line spec instance variables (20aacc5) + * Fix spec tests using the new spec\_helper (1ebfa5d) + * (#13595) initialize\_everything\_for\_tests couples modules Puppet ver (3222f35) + * (#13439) Fix MRI 1.9 issue with spec\_helper (15c5fd1) + * (#13439) Fix test failures with Puppet 2.6.x (665610b) + * (#13439) refactor spec helper for compatibility with both puppet 2.7 and master (82194ca) + * (#13494) Specify the behavior of zero padded strings (61891bb) + +##### 2012-03-29 Puppet Labs - 2.1.3 + +* (#11607) Add Rakefile to enable spec testing +* (#12377) Avoid infinite loop when retrying require json + +##### 2012-03-13 Puppet Labs - 2.3.1 + +* (#13091) Fix LoadError bug with puppet apply and puppet\_vardir fact + +##### 2012-03-12 Puppet Labs - 2.3.0 + +* Add a large number of new Puppet functions +* Backwards compatibility preserved with 2.2.x + +##### 2011-12-30 Puppet Labs - 2.2.1 + +* Documentation only release for the Forge + +##### 2011-12-30 Puppet Labs - 2.1.2 + +* Documentation only release for PE 2.0.x + +##### 2011-11-08 Puppet Labs - 2.2.0 + +* #10285 - Refactor json to use pson instead. +* Maint - Add watchr autotest script +* Maint - Make rspec tests work with Puppet 2.6.4 +* #9859 - Add root\_home fact and tests + +##### 2011-08-18 Puppet Labs - 2.1.1 + +* Change facts.d paths to match Facter 2.0 paths. +* /etc/facter/facts.d +* /etc/puppetlabs/facter/facts.d + +##### 2011-08-17 Puppet Labs - 2.1.0 + +* Add R.I. Pienaar's facts.d custom facter fact +* facts defined in /etc/facts.d and /etc/puppetlabs/facts.d are + automatically loaded now. + +##### 2011-08-04 Puppet Labs - 2.0.0 + +* Rename whole\_line to file\_line +* This is an API change and as such motivating a 2.0.0 release according to semver.org. + +##### 2011-08-04 Puppet Labs - 1.1.0 + +* Rename append\_line to whole\_line +* This is an API change and as such motivating a 1.1.0 release. + +##### 2011-08-04 Puppet Labs - 1.0.0 + +* Initial stable release +* Add validate\_array and validate\_string functions +* Make merge() function work with Ruby 1.8.5 +* Add hash merging function +* Add has\_key function +* Add loadyaml() function +* Add append\_line native + +##### 2011-06-21 Jeff McCune - 0.1.7 + +* Add validate\_hash() and getvar() functions + +##### 2011-06-15 Jeff McCune - 0.1.6 + +* Add anchor resource type to provide containment for composite classes + +##### 2011-06-03 Jeff McCune - 0.1.5 + +* Add validate\_bool() function to stdlib + +##### 0.1.4 2011-05-26 Jeff McCune + +* Move most stages after main + +##### 0.1.3 2011-05-25 Jeff McCune + +* Add validate\_re() function + +##### 0.1.2 2011-05-24 Jeff McCune + +* Update to add annotated tag + +##### 0.1.1 2011-05-24 Jeff McCune + +* Add stdlib::stages class with a standard set of stages diff --git a/Modulefile b/Modulefile index 34564fa..07cd697 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'puppetlabs-stdlib' -version '3.2.0' +version '3.2.1' source 'git://github.com/puppetlabs/puppetlabs-stdlib' author 'puppetlabs' license 'Apache 2.0' diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..b17b0f1 --- /dev/null +++ b/metadata.json @@ -0,0 +1,88 @@ +{ + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "OracleLinux", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "Scientific", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "11 SP1" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "10.04", + "12.04" + ] + }, + { + "operatingsystem": "Solaris", + "operatingsystemrelease": [ + "10", + "11" + ] + }, + { + "operatingsystem": "Windows", + "operatingsystemrelease": [ + "Server 2003", + "Server 2003 R2", + "Server 2008", + "Server 2008 R2", + "Server 2012", + "Server 2012 R2", + "7" + "8" + ] + }, + { + "operatingsystem": "AIX", + "operatingsystemrelease": [ + "5.3", + "6.1", + "7.1" + ] + } + ], + "requirements": [ + { "name": "pe", "version_requirement": "3.2.x" }, + { "name": "puppet", "version_requirement": ">=2.7.20 <4.0.0" } + ] +} -- cgit v1.2.3 From 4f65539c2e6734af69216d8d6d6fed68e631358b Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 3 Mar 2014 13:56:13 -0800 Subject: Patch metadata --- metadata.json | 189 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 103 insertions(+), 86 deletions(-) diff --git a/metadata.json b/metadata.json index b17b0f1..5e9fb0e 100644 --- a/metadata.json +++ b/metadata.json @@ -1,88 +1,105 @@ { - "operatingsystem_support": [ - { - "operatingsystem": "RedHat", - "operatingsystemrelease": [ - "4", - "5", - "6" - ] - }, - { - "operatingsystem": "CentOS", - "operatingsystemrelease": [ - "4", - "5", - "6" - ] - }, - { - "operatingsystem": "OracleLinux", - "operatingsystemrelease": [ - "4", - "5", - "6" - ] - }, - { - "operatingsystem": "Scientific", - "operatingsystemrelease": [ - "4", - "5", - "6" - ] - }, - { - "operatingsystem": "SLES", - "operatingsystemrelease": [ - "11 SP1" - ] - }, - { - "operatingsystem": "Debian", - "operatingsystemrelease": [ - "6", - "7" - ] - }, - { - "operatingsystem": "Ubuntu", - "operatingsystemrelease": [ - "10.04", - "12.04" - ] - }, - { - "operatingsystem": "Solaris", - "operatingsystemrelease": [ - "10", - "11" - ] - }, - { - "operatingsystem": "Windows", - "operatingsystemrelease": [ - "Server 2003", - "Server 2003 R2", - "Server 2008", - "Server 2008 R2", - "Server 2012", - "Server 2012 R2", - "7" - "8" - ] - }, - { - "operatingsystem": "AIX", - "operatingsystemrelease": [ - "5.3", - "6.1", - "7.1" - ] - } - ], - "requirements": [ - { "name": "pe", "version_requirement": "3.2.x" }, - { "name": "puppet", "version_requirement": ">=2.7.20 <4.0.0" } - ] + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "OracleLinux", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "Scientific", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "11 SP1" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "10.04", + "12.04" + ] + }, + { + "operatingsystem": "Solaris", + "operatingsystemrelease": [ + "10", + "11" + ] + }, + { + "operatingsystem": "Windows", + "operatingsystemrelease": [ + "Server 2003", + "Server 2003 R2", + "Server 2008", + "Server 2008 R2", + "Server 2012", + "Server 2012 R2", + "7", + "8" + ] + }, + { + "operatingsystem": "AIX", + "operatingsystemrelease": [ + "5.3", + "6.1", + "7.1" + ] + } + ], + "requirements": [ + { + "name": "pe", + "version_requirement": "3.2.x" + }, + { + "name": "puppet", + "version_requirement": ">=2.7.20 <4.0.0" + } + ], + "name": "puppetlabs-stdlib", + "version": "3.2.1", + "source": "git://github.com/puppetlabs/puppetlabs-stdlib", + "author": "puppetlabs", + "license": "Apache 2.0", + "summary": "Puppet Module Standard Library", + "description": "Standard Library for Puppet Modules", + "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib", + "dependencies": [ + + ] } -- 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. --- Gemfile | 50 +++------ spec/classes/anchor_spec.rb | 39 +++---- spec/functions/ensure_packages_spec.rb | 48 ++++++-- spec/functions/ensure_resource_spec.rb | 124 ++++++++++++++------- spec/functions/getparam_spec.rb | 75 ++++++++++--- spec/lib/puppet_spec/compiler.rb | 46 ++++++++ spec/lib/puppet_spec/database.rb | 29 +++++ spec/lib/puppet_spec/files.rb | 60 ++++++++++ spec/lib/puppet_spec/fixtures.rb | 28 +++++ spec/lib/puppet_spec/matchers.rb | 120 ++++++++++++++++++++ spec/lib/puppet_spec/modules.rb | 26 +++++ spec/lib/puppet_spec/pops.rb | 16 +++ spec/lib/puppet_spec/scope.rb | 14 +++ spec/lib/puppet_spec/settings.rb | 15 +++ spec/lib/puppet_spec/verbose.rb | 9 ++ spec/spec_helper.rb | 30 +++-- .../puppet/parser/functions/deep_merge_spec.rb | 2 +- spec/unit/puppet/parser/functions/merge_spec.rb | 2 +- .../functions/validate_absolute_path_spec.rb | 4 +- spec/unit/puppet/provider/file_line/ruby_spec.rb | 2 +- spec/unit/puppet/type/anchor_spec.rb | 2 +- spec/unit/puppet/type/file_line_spec.rb | 2 +- spec/watchr.rb | 86 -------------- 23 files changed, 603 insertions(+), 226 deletions(-) create mode 100644 spec/lib/puppet_spec/compiler.rb create mode 100644 spec/lib/puppet_spec/database.rb create mode 100755 spec/lib/puppet_spec/files.rb create mode 100755 spec/lib/puppet_spec/fixtures.rb create mode 100644 spec/lib/puppet_spec/matchers.rb create mode 100644 spec/lib/puppet_spec/modules.rb create mode 100644 spec/lib/puppet_spec/pops.rb create mode 100644 spec/lib/puppet_spec/scope.rb create mode 100644 spec/lib/puppet_spec/settings.rb create mode 100755 spec/lib/puppet_spec/verbose.rb delete mode 100644 spec/watchr.rb diff --git a/Gemfile b/Gemfile index 75c7d85..3d6d5ea 100644 --- a/Gemfile +++ b/Gemfile @@ -1,44 +1,24 @@ -source "https://rubygems.org" - -def location_for(place, fake_version = nil) - mdata = /^(git:[^#]*)#(.*)/.match(place) - if mdata - [fake_version, { :git => mdata[1], :branch => mdata[2], :require => false }].compact - elsif mdata = /^file:\/\/(.*)/.match(place) - ['>= 0', { :path => File.expand_path(mdata[1]), :require => false }] - else - [place, { :require => false }] - end -end - -group :development do - gem 'watchr' -end +source ENV['GEM_SOURCE'] || 'https://rubygems.org' group :development, :test do - gem 'rake' - gem 'puppetmodule-stdlib', ">= 1.0.0", :path => File.expand_path("..", __FILE__) - gem 'rspec', "~> 2.11.0", :require => false - gem 'mocha', "~> 0.10.5", :require => false - gem 'puppetlabs_spec_helper', :require => false - gem 'rspec-puppet', "~> 0.1.6", :require => false + gem 'rake', :require => false + gem 'rspec-puppet', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'rspec-system', :require => false + gem 'rspec-system-puppet', :require => false + gem 'rspec-system-serverspec', :require => false + gem 'serverspec', :require => false + gem 'puppet-lint', :require => false + gem 'pry', :require => false + gem 'simplecov', :require => false + gem 'beaker', :require => false + gem 'beaker-rspec', :require => false end -facterversion = ENV['GEM_FACTER_VERSION'] -if facterversion - gem 'facter', *location_for(facterversion) -else - gem 'facter', :require => false -end - -ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION'] -puppetversion = ENV['GEM_PUPPET_VERSION'] -if puppetversion - gem 'puppet', *location_for(puppetversion) +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false else gem 'puppet', :require => false end -gem 'puppet-lint', '>= 0.3.2' - # vim:ft=ruby diff --git a/spec/classes/anchor_spec.rb b/spec/classes/anchor_spec.rb index 2dd17de..2e1fcba 100644 --- a/spec/classes/anchor_spec.rb +++ b/spec/classes/anchor_spec.rb @@ -1,31 +1,28 @@ -require 'puppet' -require 'rspec-puppet' +require 'spec_helper' +require 'puppet_spec/compiler' describe "anchorrefresh" do - let(:node) { 'testhost.example.com' } - let :pre_condition do - <<-ANCHORCLASS -class anchored { - anchor { 'anchored::begin': } - ~> anchor { 'anchored::end': } -} + include PuppetSpec::Compiler -class anchorrefresh { - notify { 'first': } - ~> class { 'anchored': } - ~> anchor { 'final': } -} - ANCHORCLASS - end + let :transaction do + apply_compiled_manifest(<<-ANCHORCLASS) + class anchored { + anchor { 'anchored::begin': } + ~> anchor { 'anchored::end': } + } - def apply_catalog_and_return_exec_rsrc - catalog = subject.to_ral - transaction = catalog.apply - transaction.resource_status("Anchor[final]") + class anchorrefresh { + notify { 'first': } + ~> class { 'anchored': } + ~> anchor { 'final': } + } + + include anchorrefresh + ANCHORCLASS end it 'propagates events through the anchored class' do - resource = apply_catalog_and_return_exec_rsrc + resource = transaction.resource_status('Anchor[final]') expect(resource.restarted).to eq(true) end diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index a13c282..bf62eff 100644 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -2,9 +2,31 @@ require 'spec_helper' require 'rspec-puppet' +require 'puppet_spec/compiler' describe 'ensure_packages' do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + 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 @@ -22,25 +44,27 @@ describe 'ensure_packages' do end end - context 'given a catalog containing Package[puppet]{ensure => absent}' do - let :pre_condition do - 'package { puppet: ensure => absent }' + 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 - # NOTE: should run.with_params has the side effect of making the compiler - # available to the test harness. it 'has no effect on Package[puppet]' do - should run.with_params(['puppet']) - rsrc = compiler.catalog.resource('Package[puppet]') - rsrc.to_hash.should == {:ensure => "absent"} + 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 - should run.with_params(['facter']) - rsrc = compiler.catalog.resource('Package[facter]') - rsrc.to_hash[:ensure].should eq("present") + expect(catalog.resource(:package, 'facter')['ensure']).to eq('present') end end end diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb index 2e8aefc..459d917 100644 --- a/spec/functions/ensure_resource_spec.rb +++ b/spec/functions/ensure_resource_spec.rb @@ -1,64 +1,112 @@ -#! /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 { should run.with_params().and_raise_error(ArgumentError) } - it { should run.with_params(['type']).and_raise_error(ArgumentError) } + 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 :pre_condition do - 'user { "dan": }' + let :catalog do + compile_to_catalog(<<-EOS + user { "dan": } + ensure_resource('user', 'dan', {}) + EOS + ) end - it "should contain the the ensured resources" do - subject.should run.with_params('user', 'dan', {}) - compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' + + it 'should contain the the ensured resources' do + expect(catalog.resource(:user, 'dan').to_s).to eq('User[dan]') end end - describe 'when compared against a resource with attributes' do - let :pre_condition do - 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}' + 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 - # these first three should not fail - it { should run.with_params('User', 'dan', {}) } - it { should run.with_params('User', 'dan', '') } - it { should run.with_params('User', 'dan', {'ensure' => 'present'}) } - it { should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false}) } - # test that this fails - it { should run.with_params('User', 'dan', {'ensure' => 'absent', 'managehome' => false}).and_raise_error(Puppet::Error) } + 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 - it "should contain the ensured resources" do - subject.should run.with_params('User', ['dan', 'alex'], {}) - compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' - compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]' + 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 - let :pre_condition do - 'user { "dan": ensure => present; "alex": ensure => present }' + 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 - subject.should run.with_params('User', ['dan', 'alex'], {}) - compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' - compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]' + + 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 'when compared against existing resources with attributes' do - let :pre_condition do - 'user { "dan": ensure => present; "alex": ensure => present }' + 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 - # These should not fail - it { should run.with_params('User', ['dan', 'alex'], {}) } - it { should run.with_params('User', ['dan', 'alex'], '') } - it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'present'}) } - # This should fail - it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'absent'}).and_raise_error(Puppet::Error) } 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/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb index d9c50a6..7f5ad1a 100644 --- a/spec/functions/getparam_spec.rb +++ b/spec/functions/getparam_spec.rb @@ -1,34 +1,75 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' - require 'rspec-puppet' +require 'puppet_spec/compiler' + describe 'getparam' do - describe 'when a resource is not specified' do - it do - should run.with_params().and_raise_error(ArgumentError) - should run.with_params('User[dan]').and_raise_error(ArgumentError) - should run.with_params('User[dan]', {}).and_raise_error(ArgumentError) - should run.with_params('User[dan]', '').and_return('') + 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 :pre_condition do - 'user { "dan": }' + let :catalog do + compile_to_catalog(<<-EOS + user { "dan": } + EOS + ) end + it do - should run.with_params('User[dan]', 'shell').and_return('') + expect(scope.function_getparam(['User[dan]', 'shell'])).to eq('') end end describe 'when compared against a resource with params' do - let :pre_condition do - 'user { "dan": ensure => present, shell => "/bin/sh", managehome => false}' + 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 - should run.with_params('User[dan]', 'shell').and_return('/bin/sh') - should run.with_params('User[dan]', '').and_return('') - should run.with_params('User[dan]', 'ensure').and_return('present') - should run.with_params('User[dan]', 'managehome').and_return(false) + 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/lib/puppet_spec/compiler.rb b/spec/lib/puppet_spec/compiler.rb new file mode 100644 index 0000000..22e923d --- /dev/null +++ b/spec/lib/puppet_spec/compiler.rb @@ -0,0 +1,46 @@ +module PuppetSpec::Compiler + def compile_to_catalog(string, node = Puppet::Node.new('foonode')) + Puppet[:code] = string + Puppet::Parser::Compiler.compile(node) + end + + def compile_to_ral(manifest) + catalog = compile_to_catalog(manifest) + ral = catalog.to_ral + ral.finalize + ral + end + + def compile_to_relationship_graph(manifest, prioritizer = Puppet::Graph::SequentialPrioritizer.new) + ral = compile_to_ral(manifest) + graph = Puppet::Graph::RelationshipGraph.new(prioritizer) + graph.populate_from(ral) + graph + end + + if Puppet.version.to_f >= 3.3 + def apply_compiled_manifest(manifest, prioritizer = Puppet::Graph::SequentialPrioritizer.new) + transaction = Puppet::Transaction.new(compile_to_ral(manifest), + Puppet::Transaction::Report.new("apply"), + prioritizer) + transaction.evaluate + transaction.report.finalize_report + + transaction + end + else + def apply_compiled_manifest(manifest) + transaction = Puppet::Transaction.new(compile_to_ral(manifest), Puppet::Transaction::Report.new("apply")) + transaction.evaluate + transaction.report.finalize_report + + transaction + end + end + + def order_resources_traversed_in(relationships) + order_seen = [] + relationships.traverse { |resource| order_seen << resource.ref } + order_seen + end +end diff --git a/spec/lib/puppet_spec/database.rb b/spec/lib/puppet_spec/database.rb new file mode 100644 index 0000000..069ca15 --- /dev/null +++ b/spec/lib/puppet_spec/database.rb @@ -0,0 +1,29 @@ +# This just makes some nice things available at global scope, and for setup of +# tests to use a real fake database, rather than a fake stubs-that-don't-work +# version of the same. Fun times. +def sqlite? + if $sqlite.nil? + begin + require 'sqlite3' + $sqlite = true + rescue LoadError + $sqlite = false + end + end + $sqlite +end + +def can_use_scratch_database? + sqlite? and Puppet.features.rails? +end + + +# This is expected to be called in your `before :each` block, and will get you +# ready to roll with a serious database and all. Cleanup is handled +# automatically for you. Nothing to do there. +def setup_scratch_database + Puppet[:dbadapter] = 'sqlite3' + Puppet[:dblocation] = ':memory:' + Puppet[:railslog] = PuppetSpec::Files.tmpfile('storeconfigs.log') + Puppet::Rails.init +end diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb new file mode 100755 index 0000000..65b04aa --- /dev/null +++ b/spec/lib/puppet_spec/files.rb @@ -0,0 +1,60 @@ +require 'fileutils' +require 'tempfile' +require 'tmpdir' +require 'pathname' + +# A support module for testing files. +module PuppetSpec::Files + def self.cleanup + $global_tempfiles ||= [] + while path = $global_tempfiles.pop do + begin + Dir.unstub(:entries) + FileUtils.rm_rf path, :secure => true + rescue Errno::ENOENT + # nothing to do + end + end + end + + def make_absolute(path) PuppetSpec::Files.make_absolute(path) end + def self.make_absolute(path) + path = File.expand_path(path) + path[0] = 'c' if Puppet.features.microsoft_windows? + path + end + + def tmpfile(name, dir = nil) PuppetSpec::Files.tmpfile(name, dir) end + def self.tmpfile(name, dir = nil) + # Generate a temporary file, just for the name... + source = dir ? Tempfile.new(name, dir) : Tempfile.new(name) + path = source.path + source.close! + + record_tmp(File.expand_path(path)) + + path + end + + def file_containing(name, contents) PuppetSpec::Files.file_containing(name, contents) end + def self.file_containing(name, contents) + file = tmpfile(name) + File.open(file, 'wb') { |f| f.write(contents) } + file + end + + def tmpdir(name) PuppetSpec::Files.tmpdir(name) end + def self.tmpdir(name) + dir = Dir.mktmpdir(name) + + record_tmp(dir) + + dir + end + + def self.record_tmp(tmp) + # ...record it for cleanup, + $global_tempfiles ||= [] + $global_tempfiles << tmp + end +end diff --git a/spec/lib/puppet_spec/fixtures.rb b/spec/lib/puppet_spec/fixtures.rb new file mode 100755 index 0000000..7f6bc2a --- /dev/null +++ b/spec/lib/puppet_spec/fixtures.rb @@ -0,0 +1,28 @@ +module PuppetSpec::Fixtures + def fixtures(*rest) + File.join(PuppetSpec::FIXTURE_DIR, *rest) + end + def my_fixture_dir + callers = caller + while line = callers.shift do + next unless found = line.match(%r{/spec/(.*)_spec\.rb:}) + return fixtures(found[1]) + end + fail "sorry, I couldn't work out your path from the caller stack!" + end + def my_fixture(name) + file = File.join(my_fixture_dir, name) + unless File.readable? file then + fail Puppet::DevError, "fixture '#{name}' for #{my_fixture_dir} is not readable" + end + return file + end + def my_fixtures(glob = '*', flags = 0) + files = Dir.glob(File.join(my_fixture_dir, glob), flags) + unless files.length > 0 then + fail Puppet::DevError, "fixture '#{glob}' for #{my_fixture_dir} had no files!" + end + block_given? and files.each do |file| yield file end + files + end +end diff --git a/spec/lib/puppet_spec/matchers.rb b/spec/lib/puppet_spec/matchers.rb new file mode 100644 index 0000000..448bd18 --- /dev/null +++ b/spec/lib/puppet_spec/matchers.rb @@ -0,0 +1,120 @@ +require 'stringio' + +######################################################################## +# Backward compatibility for Jenkins outdated environment. +module RSpec + module Matchers + module BlockAliases + alias_method :to, :should unless method_defined? :to + alias_method :to_not, :should_not unless method_defined? :to_not + alias_method :not_to, :should_not unless method_defined? :not_to + end + end +end + + +######################################################################## +# Custom matchers... +RSpec::Matchers.define :have_matching_element do |expected| + match do |actual| + actual.any? { |item| item =~ expected } + end +end + + +RSpec::Matchers.define :exit_with do |expected| + actual = nil + match do |block| + begin + block.call + rescue SystemExit => e + actual = e.status + end + actual and actual == expected + end + failure_message_for_should do |block| + "expected exit with code #{expected} but " + + (actual.nil? ? " exit was not called" : "we exited with #{actual} instead") + end + failure_message_for_should_not do |block| + "expected that exit would not be called with #{expected}" + end + description do + "expect exit with #{expected}" + end +end + +class HavePrintedMatcher + attr_accessor :expected, :actual + + def initialize(expected) + case expected + when String, Regexp + @expected = expected + else + @expected = expected.to_s + end + end + + def matches?(block) + begin + $stderr = $stdout = StringIO.new + $stdout.set_encoding('UTF-8') if $stdout.respond_to?(:set_encoding) + block.call + $stdout.rewind + @actual = $stdout.read + ensure + $stdout = STDOUT + $stderr = STDERR + end + + if @actual then + case @expected + when String + @actual.include? @expected + when Regexp + @expected.match @actual + end + else + false + end + end + + def failure_message_for_should + if @actual.nil? then + "expected #{@expected.inspect}, but nothing was printed" + else + "expected #{@expected.inspect} to be printed; got:\n#{@actual}" + end + end + + def failure_message_for_should_not + "expected #{@expected.inspect} to not be printed; got:\n#{@actual}" + end + + def description + "expect #{@expected.inspect} to be printed" + end +end + +def have_printed(what) + HavePrintedMatcher.new(what) +end + +RSpec::Matchers.define :equal_attributes_of do |expected| + match do |actual| + actual.instance_variables.all? do |attr| + actual.instance_variable_get(attr) == expected.instance_variable_get(attr) + end + end +end + +RSpec::Matchers.define :be_one_of do |*expected| + match do |actual| + expected.include? actual + end + + failure_message_for_should do |actual| + "expected #{actual.inspect} to be one of #{expected.map(&:inspect).join(' or ')}" + end +end diff --git a/spec/lib/puppet_spec/modules.rb b/spec/lib/puppet_spec/modules.rb new file mode 100644 index 0000000..6835e44 --- /dev/null +++ b/spec/lib/puppet_spec/modules.rb @@ -0,0 +1,26 @@ +module PuppetSpec::Modules + class << self + def create(name, dir, options = {}) + module_dir = File.join(dir, name) + FileUtils.mkdir_p(module_dir) + + environment = options[:environment] + + if metadata = options[:metadata] + metadata[:source] ||= 'github' + metadata[:author] ||= 'puppetlabs' + metadata[:version] ||= '9.9.9' + metadata[:license] ||= 'to kill' + metadata[:dependencies] ||= [] + + metadata[:name] = "#{metadata[:author]}/#{name}" + + File.open(File.join(module_dir, 'metadata.json'), 'w') do |f| + f.write(metadata.to_pson) + end + end + + Puppet::Module.new(name, module_dir, environment) + end + end +end diff --git a/spec/lib/puppet_spec/pops.rb b/spec/lib/puppet_spec/pops.rb new file mode 100644 index 0000000..442c85b --- /dev/null +++ b/spec/lib/puppet_spec/pops.rb @@ -0,0 +1,16 @@ +module PuppetSpec::Pops + extend RSpec::Matchers::DSL + + # Checks if an Acceptor has a specific issue in its list of diagnostics + matcher :have_issue do |expected| + match do |actual| + actual.diagnostics.index { |i| i.issue == expected } != nil + end + failure_message_for_should do |actual| + "expected Acceptor[#{actual.diagnostics.collect { |i| i.issue.issue_code }.join(',')}] to contain issue #{expected.issue_code}" + end + failure_message_for_should_not do |actual| + "expected Acceptor[#{actual.diagnostics.collect { |i| i.issue.issue_code }.join(',')}] to not contain issue #{expected.issue_code}" + end + end +end diff --git a/spec/lib/puppet_spec/scope.rb b/spec/lib/puppet_spec/scope.rb new file mode 100644 index 0000000..c14ab47 --- /dev/null +++ b/spec/lib/puppet_spec/scope.rb @@ -0,0 +1,14 @@ + +module PuppetSpec::Scope + # Initialize a new scope suitable for testing. + # + def create_test_scope_for_node(node_name) + node = Puppet::Node.new(node_name) + compiler = Puppet::Parser::Compiler.new(node) + scope = Puppet::Parser::Scope.new(compiler) + scope.source = Puppet::Resource::Type.new(:node, node_name) + scope.parent = compiler.topscope + scope + end + +end \ No newline at end of file diff --git a/spec/lib/puppet_spec/settings.rb b/spec/lib/puppet_spec/settings.rb new file mode 100644 index 0000000..f3dbc42 --- /dev/null +++ b/spec/lib/puppet_spec/settings.rb @@ -0,0 +1,15 @@ +module PuppetSpec::Settings + + # It would probably be preferable to refactor defaults.rb such that the real definitions of + # these settings were available as a variable, which was then accessible for use during tests. + # However, I'm not doing that yet because I don't want to introduce any additional moving parts + # to this already very large changeset. + # Would be nice to clean this up later. --cprice 2012-03-20 + TEST_APP_DEFAULT_DEFINITIONS = { + :name => { :default => "test", :desc => "name" }, + :logdir => { :type => :directory, :default => "test", :desc => "logdir" }, + :confdir => { :type => :directory, :default => "test", :desc => "confdir" }, + :vardir => { :type => :directory, :default => "test", :desc => "vardir" }, + :rundir => { :type => :directory, :default => "test", :desc => "rundir" }, + } +end diff --git a/spec/lib/puppet_spec/verbose.rb b/spec/lib/puppet_spec/verbose.rb new file mode 100755 index 0000000..d9834f2 --- /dev/null +++ b/spec/lib/puppet_spec/verbose.rb @@ -0,0 +1,9 @@ +# Support code for running stuff with warnings disabled. +module Kernel + def with_verbose_disabled + verbose, $VERBOSE = $VERBOSE, nil + result = yield + $VERBOSE = verbose + return result + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 931d35c..cf1981b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,21 +1,31 @@ dir = File.expand_path(File.dirname(__FILE__)) $LOAD_PATH.unshift File.join(dir, 'lib') -# Don't want puppet getting the command line arguments for rake or autotest -ARGV.clear +# So everyone else doesn't have to include this base constant. +module PuppetSpec + FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR) +end require 'puppet' -require 'facter' -require 'mocha' -gem 'rspec', '>=2.0.0' -require 'rspec/expectations' - +require 'rspec-puppet' +require 'simplecov' require 'puppetlabs_spec_helper/module_spec_helper' +require 'puppet_spec/verbose' +require 'puppet_spec/files' +require 'puppet_spec/settings' +require 'puppet_spec/fixtures' +require 'puppet_spec/matchers' +require 'puppet_spec/database' +require 'monkey_patches/alias_should_to_must' +require 'mocha/setup' + + +SimpleCov.start do + add_filter "/spec/" +end + RSpec.configure do |config| - # FIXME REVISIT - We may want to delegate to Facter like we do in - # Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because - # this behavior is a duplication of the spec_helper in Facter. config.before :each do # Ensure that we don't accidentally cache facts and environment between # test cases. This requires each example group to explicitly load the 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 diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb index 65b5d20..c356bd2 100644 --- a/spec/unit/puppet/provider/file_line/ruby_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -1,4 +1,4 @@ -require 'puppet' +require 'spec_helper' require 'tempfile' provider_class = Puppet::Type.type(:file_line).provider(:ruby) describe provider_class do diff --git a/spec/unit/puppet/type/anchor_spec.rb b/spec/unit/puppet/type/anchor_spec.rb index 2030b83..f92065f 100644 --- a/spec/unit/puppet/type/anchor_spec.rb +++ b/spec/unit/puppet/type/anchor_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require 'puppet' +require 'spec_helper' anchor = Puppet::Type.type(:anchor).new(:name => "ntp::begin") diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb index edc64bd..34d5dad 100644 --- a/spec/unit/puppet/type/file_line_spec.rb +++ b/spec/unit/puppet/type/file_line_spec.rb @@ -1,4 +1,4 @@ -require 'puppet' +require 'spec_helper' require 'tempfile' describe Puppet::Type.type(:file_line) do let :file_line do diff --git a/spec/watchr.rb b/spec/watchr.rb deleted file mode 100644 index 885ef1d..0000000 --- a/spec/watchr.rb +++ /dev/null @@ -1,86 +0,0 @@ -ENV['FOG_MOCK'] ||= 'true' -ENV['AUTOTEST'] = 'true' -ENV['WATCHR'] = '1' - -system 'clear' - -def growl(message) - growlnotify = `which growlnotify`.chomp - title = "Watchr Test Results" - image = case message - when /(\d+)\s+?(failure|error)/i - ($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png" - else - '~/.watchr_images/unknown.png' - end - options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'" - system %(#{growlnotify} #{options} &) -end - -def run(cmd) - puts(cmd) - `#{cmd}` -end - -def run_spec_test(file) - if File.exist? file - result = run "rspec --format p --color #{file}" - growl result.split("\n").last - puts result - else - puts "FIXME: No test #{file} [#{Time.now}]" - end -end - -def filter_rspec(data) - data.split("\n").find_all do |l| - l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/ - end.join("\n") -end - -def run_all_tests - system('clear') - files = Dir.glob("spec/**/*_spec.rb").join(" ") - result = run "rspec #{files}" - growl_results = filter_rspec result - growl growl_results - puts result - puts "GROWL: #{growl_results}" -end - -# Ctrl-\ -Signal.trap 'QUIT' do - puts " --- Running all tests ---\n\n" - run_all_tests -end - -@interrupted = false - -# Ctrl-C -Signal.trap 'INT' do - if @interrupted then - @wants_to_quit = true - abort("\n") - else - puts "Interrupt a second time to quit" - @interrupted = true - Kernel.sleep 1.5 - # raise Interrupt, nil # let the run loop catch it - run_suite - end -end - -def file2spec(file) - result = file.sub('lib/puppet/', 'spec/unit/puppet/').gsub(/\.rb$/, '_spec.rb') - result = file.sub('lib/facter/', 'spec/unit/facter/').gsub(/\.rb$/, '_spec.rb') -end - - -watch( 'spec/.*_spec\.rb' ) do |md| - #run_spec_test(md[0]) - run_all_tests -end -watch( 'lib/.*\.rb' ) do |md| - # run_spec_test(file2spec(md[0])) - run_all_tests -end -- cgit v1.2.3 From dbb29980a170623c578c51c471af71ff66e23e9c 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. --- Gemfile | 24 +++++ spec/classes/anchor_spec.rb | 31 ++++++ spec/functions/ensure_packages_spec.rb | 60 +++++++---- spec/functions/ensure_resource_spec.rb | 75 ++++++++----- spec/lib/puppet_spec/compiler.rb | 46 ++++++++ spec/lib/puppet_spec/database.rb | 29 +++++ spec/lib/puppet_spec/files.rb | 60 +++++++++++ spec/lib/puppet_spec/fixtures.rb | 28 +++++ spec/lib/puppet_spec/matchers.rb | 120 +++++++++++++++++++++ spec/lib/puppet_spec/modules.rb | 26 +++++ spec/lib/puppet_spec/pops.rb | 16 +++ spec/lib/puppet_spec/scope.rb | 14 +++ spec/lib/puppet_spec/settings.rb | 15 +++ spec/lib/puppet_spec/verbose.rb | 9 ++ spec/spec_helper.rb | 30 ++++-- spec/unit/puppet/parser/functions/merge_spec.rb | 7 +- .../functions/validate_absolute_path_spec.rb | 4 +- spec/unit/puppet/provider/file_line/ruby_spec.rb | 2 +- spec/unit/puppet/type/anchor_spec.rb | 2 +- spec/unit/puppet/type/file_line_spec.rb | 2 +- spec/watchr.rb | 86 --------------- 21 files changed, 539 insertions(+), 147 deletions(-) create mode 100644 Gemfile create mode 100644 spec/classes/anchor_spec.rb create mode 100644 spec/lib/puppet_spec/compiler.rb create mode 100644 spec/lib/puppet_spec/database.rb create mode 100755 spec/lib/puppet_spec/files.rb create mode 100755 spec/lib/puppet_spec/fixtures.rb create mode 100644 spec/lib/puppet_spec/matchers.rb create mode 100644 spec/lib/puppet_spec/modules.rb create mode 100644 spec/lib/puppet_spec/pops.rb create mode 100644 spec/lib/puppet_spec/scope.rb create mode 100644 spec/lib/puppet_spec/settings.rb create mode 100755 spec/lib/puppet_spec/verbose.rb delete mode 100644 spec/watchr.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..3d6d5ea --- /dev/null +++ b/Gemfile @@ -0,0 +1,24 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +group :development, :test do + gem 'rake', :require => false + gem 'rspec-puppet', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'rspec-system', :require => false + gem 'rspec-system-puppet', :require => false + gem 'rspec-system-serverspec', :require => false + gem 'serverspec', :require => false + gem 'puppet-lint', :require => false + gem 'pry', :require => false + gem 'simplecov', :require => false + gem 'beaker', :require => false + gem 'beaker-rspec', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/spec/classes/anchor_spec.rb b/spec/classes/anchor_spec.rb new file mode 100644 index 0000000..6754811 --- /dev/null +++ b/spec/classes/anchor_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' +require 'puppet_spec/compiler' + +describe "anchorrefresh" do + include PuppetSpec::Compiler + + let :transaction do + apply_compiled_manifest(<<-ANCHORCLASS) + class anchored { + anchor { 'anchored::begin': } + ~> anchor { 'anchored::end': } + } + + class anchorrefresh { + notify { 'first': } + ~> class { 'anchored': } + ~> anchor { 'final': } + } + + include anchorrefresh + ANCHORCLASS + end + + it 'propagates events through the anchored class' do + require 'pry' + binding.pry + resource = transaction.resource_status('Anchor[final]') + + expect(resource.restarted).to eq(true) + end +end diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index 1c2a328..4163d69 100644 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -2,41 +2,65 @@ require 'spec_helper' require 'rspec-puppet' +require 'puppet_spec/compiler' describe 'ensure_packages' do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + 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 - should run.with_params().and_raise_error(Puppet::ParseError) + expect { + scope.function_ensure_packages([]) + }.to raise_error(Puppet::ParseError, /0 for 1/) end - it 'requires an array' do - lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error - end - it 'fails when given a string' do - should run.with_params('foo').and_raise_error(Puppet::ParseError) + + it 'accepts an array of values' do + scope.function_ensure_packages([['foo']]) end end - context 'given a catalog containing Package[puppet]{ensure => absent}' do - let :pre_condition do - 'package { puppet: ensure => absent }' + 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 - # NOTE: should run.with_params has the side effect of making the compiler - # available to the test harness. it 'has no effect on Package[puppet]' do - should run.with_params(['puppet']) - rsrc = compiler.catalog.resource('Package[puppet]') - rsrc.to_hash.should == {:ensure => "absent"} + 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 - should run.with_params(['facter']) - rsrc = compiler.catalog.resource('Package[facter]') - rsrc.to_hash.should == {:name => "facter", :ensure => "present"} + expect(catalog.resource(:package, 'facter')['ensure']).to eq('present') end end end diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb index 611666e..430691c 100644 --- a/spec/functions/ensure_resource_spec.rb +++ b/spec/functions/ensure_resource_spec.rb @@ -1,40 +1,61 @@ -#! /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 do - should run.with_params().and_raise_error(ArgumentError) - should run.with_params(['type']).and_raise_error(ArgumentError) - end + 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 :pre_condition do - 'user { "dan": }' + let :catalog do + compile_to_catalog(<<-EOS + user { "dan": } + ensure_resource('user', 'dan', {}) + EOS + ) end - it do - should run.with_params('user', 'dan', {}) - compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' + + it 'should contain the the ensured resources' do + expect(catalog.resource(:user, 'dan').to_s).to eq('User[dan]') 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 - # these first three should not fail - should run.with_params('User', 'dan', {}) - should run.with_params('User', 'dan', '') - should run.with_params('User', 'dan', {'ensure' => 'present'}) - should run.with_params('User', 'dan', - {'ensure' => 'present', 'managehome' => false} - ) - # test that this fails - should run.with_params('User', 'dan', - {'ensure' => 'absent', 'managehome' => false} - ).and_raise_error(Puppet::Error) + 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 + end diff --git a/spec/lib/puppet_spec/compiler.rb b/spec/lib/puppet_spec/compiler.rb new file mode 100644 index 0000000..22e923d --- /dev/null +++ b/spec/lib/puppet_spec/compiler.rb @@ -0,0 +1,46 @@ +module PuppetSpec::Compiler + def compile_to_catalog(string, node = Puppet::Node.new('foonode')) + Puppet[:code] = string + Puppet::Parser::Compiler.compile(node) + end + + def compile_to_ral(manifest) + catalog = compile_to_catalog(manifest) + ral = catalog.to_ral + ral.finalize + ral + end + + def compile_to_relationship_graph(manifest, prioritizer = Puppet::Graph::SequentialPrioritizer.new) + ral = compile_to_ral(manifest) + graph = Puppet::Graph::RelationshipGraph.new(prioritizer) + graph.populate_from(ral) + graph + end + + if Puppet.version.to_f >= 3.3 + def apply_compiled_manifest(manifest, prioritizer = Puppet::Graph::SequentialPrioritizer.new) + transaction = Puppet::Transaction.new(compile_to_ral(manifest), + Puppet::Transaction::Report.new("apply"), + prioritizer) + transaction.evaluate + transaction.report.finalize_report + + transaction + end + else + def apply_compiled_manifest(manifest) + transaction = Puppet::Transaction.new(compile_to_ral(manifest), Puppet::Transaction::Report.new("apply")) + transaction.evaluate + transaction.report.finalize_report + + transaction + end + end + + def order_resources_traversed_in(relationships) + order_seen = [] + relationships.traverse { |resource| order_seen << resource.ref } + order_seen + end +end diff --git a/spec/lib/puppet_spec/database.rb b/spec/lib/puppet_spec/database.rb new file mode 100644 index 0000000..069ca15 --- /dev/null +++ b/spec/lib/puppet_spec/database.rb @@ -0,0 +1,29 @@ +# This just makes some nice things available at global scope, and for setup of +# tests to use a real fake database, rather than a fake stubs-that-don't-work +# version of the same. Fun times. +def sqlite? + if $sqlite.nil? + begin + require 'sqlite3' + $sqlite = true + rescue LoadError + $sqlite = false + end + end + $sqlite +end + +def can_use_scratch_database? + sqlite? and Puppet.features.rails? +end + + +# This is expected to be called in your `before :each` block, and will get you +# ready to roll with a serious database and all. Cleanup is handled +# automatically for you. Nothing to do there. +def setup_scratch_database + Puppet[:dbadapter] = 'sqlite3' + Puppet[:dblocation] = ':memory:' + Puppet[:railslog] = PuppetSpec::Files.tmpfile('storeconfigs.log') + Puppet::Rails.init +end diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb new file mode 100755 index 0000000..65b04aa --- /dev/null +++ b/spec/lib/puppet_spec/files.rb @@ -0,0 +1,60 @@ +require 'fileutils' +require 'tempfile' +require 'tmpdir' +require 'pathname' + +# A support module for testing files. +module PuppetSpec::Files + def self.cleanup + $global_tempfiles ||= [] + while path = $global_tempfiles.pop do + begin + Dir.unstub(:entries) + FileUtils.rm_rf path, :secure => true + rescue Errno::ENOENT + # nothing to do + end + end + end + + def make_absolute(path) PuppetSpec::Files.make_absolute(path) end + def self.make_absolute(path) + path = File.expand_path(path) + path[0] = 'c' if Puppet.features.microsoft_windows? + path + end + + def tmpfile(name, dir = nil) PuppetSpec::Files.tmpfile(name, dir) end + def self.tmpfile(name, dir = nil) + # Generate a temporary file, just for the name... + source = dir ? Tempfile.new(name, dir) : Tempfile.new(name) + path = source.path + source.close! + + record_tmp(File.expand_path(path)) + + path + end + + def file_containing(name, contents) PuppetSpec::Files.file_containing(name, contents) end + def self.file_containing(name, contents) + file = tmpfile(name) + File.open(file, 'wb') { |f| f.write(contents) } + file + end + + def tmpdir(name) PuppetSpec::Files.tmpdir(name) end + def self.tmpdir(name) + dir = Dir.mktmpdir(name) + + record_tmp(dir) + + dir + end + + def self.record_tmp(tmp) + # ...record it for cleanup, + $global_tempfiles ||= [] + $global_tempfiles << tmp + end +end diff --git a/spec/lib/puppet_spec/fixtures.rb b/spec/lib/puppet_spec/fixtures.rb new file mode 100755 index 0000000..7f6bc2a --- /dev/null +++ b/spec/lib/puppet_spec/fixtures.rb @@ -0,0 +1,28 @@ +module PuppetSpec::Fixtures + def fixtures(*rest) + File.join(PuppetSpec::FIXTURE_DIR, *rest) + end + def my_fixture_dir + callers = caller + while line = callers.shift do + next unless found = line.match(%r{/spec/(.*)_spec\.rb:}) + return fixtures(found[1]) + end + fail "sorry, I couldn't work out your path from the caller stack!" + end + def my_fixture(name) + file = File.join(my_fixture_dir, name) + unless File.readable? file then + fail Puppet::DevError, "fixture '#{name}' for #{my_fixture_dir} is not readable" + end + return file + end + def my_fixtures(glob = '*', flags = 0) + files = Dir.glob(File.join(my_fixture_dir, glob), flags) + unless files.length > 0 then + fail Puppet::DevError, "fixture '#{glob}' for #{my_fixture_dir} had no files!" + end + block_given? and files.each do |file| yield file end + files + end +end diff --git a/spec/lib/puppet_spec/matchers.rb b/spec/lib/puppet_spec/matchers.rb new file mode 100644 index 0000000..448bd18 --- /dev/null +++ b/spec/lib/puppet_spec/matchers.rb @@ -0,0 +1,120 @@ +require 'stringio' + +######################################################################## +# Backward compatibility for Jenkins outdated environment. +module RSpec + module Matchers + module BlockAliases + alias_method :to, :should unless method_defined? :to + alias_method :to_not, :should_not unless method_defined? :to_not + alias_method :not_to, :should_not unless method_defined? :not_to + end + end +end + + +######################################################################## +# Custom matchers... +RSpec::Matchers.define :have_matching_element do |expected| + match do |actual| + actual.any? { |item| item =~ expected } + end +end + + +RSpec::Matchers.define :exit_with do |expected| + actual = nil + match do |block| + begin + block.call + rescue SystemExit => e + actual = e.status + end + actual and actual == expected + end + failure_message_for_should do |block| + "expected exit with code #{expected} but " + + (actual.nil? ? " exit was not called" : "we exited with #{actual} instead") + end + failure_message_for_should_not do |block| + "expected that exit would not be called with #{expected}" + end + description do + "expect exit with #{expected}" + end +end + +class HavePrintedMatcher + attr_accessor :expected, :actual + + def initialize(expected) + case expected + when String, Regexp + @expected = expected + else + @expected = expected.to_s + end + end + + def matches?(block) + begin + $stderr = $stdout = StringIO.new + $stdout.set_encoding('UTF-8') if $stdout.respond_to?(:set_encoding) + block.call + $stdout.rewind + @actual = $stdout.read + ensure + $stdout = STDOUT + $stderr = STDERR + end + + if @actual then + case @expected + when String + @actual.include? @expected + when Regexp + @expected.match @actual + end + else + false + end + end + + def failure_message_for_should + if @actual.nil? then + "expected #{@expected.inspect}, but nothing was printed" + else + "expected #{@expected.inspect} to be printed; got:\n#{@actual}" + end + end + + def failure_message_for_should_not + "expected #{@expected.inspect} to not be printed; got:\n#{@actual}" + end + + def description + "expect #{@expected.inspect} to be printed" + end +end + +def have_printed(what) + HavePrintedMatcher.new(what) +end + +RSpec::Matchers.define :equal_attributes_of do |expected| + match do |actual| + actual.instance_variables.all? do |attr| + actual.instance_variable_get(attr) == expected.instance_variable_get(attr) + end + end +end + +RSpec::Matchers.define :be_one_of do |*expected| + match do |actual| + expected.include? actual + end + + failure_message_for_should do |actual| + "expected #{actual.inspect} to be one of #{expected.map(&:inspect).join(' or ')}" + end +end diff --git a/spec/lib/puppet_spec/modules.rb b/spec/lib/puppet_spec/modules.rb new file mode 100644 index 0000000..6835e44 --- /dev/null +++ b/spec/lib/puppet_spec/modules.rb @@ -0,0 +1,26 @@ +module PuppetSpec::Modules + class << self + def create(name, dir, options = {}) + module_dir = File.join(dir, name) + FileUtils.mkdir_p(module_dir) + + environment = options[:environment] + + if metadata = options[:metadata] + metadata[:source] ||= 'github' + metadata[:author] ||= 'puppetlabs' + metadata[:version] ||= '9.9.9' + metadata[:license] ||= 'to kill' + metadata[:dependencies] ||= [] + + metadata[:name] = "#{metadata[:author]}/#{name}" + + File.open(File.join(module_dir, 'metadata.json'), 'w') do |f| + f.write(metadata.to_pson) + end + end + + Puppet::Module.new(name, module_dir, environment) + end + end +end diff --git a/spec/lib/puppet_spec/pops.rb b/spec/lib/puppet_spec/pops.rb new file mode 100644 index 0000000..442c85b --- /dev/null +++ b/spec/lib/puppet_spec/pops.rb @@ -0,0 +1,16 @@ +module PuppetSpec::Pops + extend RSpec::Matchers::DSL + + # Checks if an Acceptor has a specific issue in its list of diagnostics + matcher :have_issue do |expected| + match do |actual| + actual.diagnostics.index { |i| i.issue == expected } != nil + end + failure_message_for_should do |actual| + "expected Acceptor[#{actual.diagnostics.collect { |i| i.issue.issue_code }.join(',')}] to contain issue #{expected.issue_code}" + end + failure_message_for_should_not do |actual| + "expected Acceptor[#{actual.diagnostics.collect { |i| i.issue.issue_code }.join(',')}] to not contain issue #{expected.issue_code}" + end + end +end diff --git a/spec/lib/puppet_spec/scope.rb b/spec/lib/puppet_spec/scope.rb new file mode 100644 index 0000000..c14ab47 --- /dev/null +++ b/spec/lib/puppet_spec/scope.rb @@ -0,0 +1,14 @@ + +module PuppetSpec::Scope + # Initialize a new scope suitable for testing. + # + def create_test_scope_for_node(node_name) + node = Puppet::Node.new(node_name) + compiler = Puppet::Parser::Compiler.new(node) + scope = Puppet::Parser::Scope.new(compiler) + scope.source = Puppet::Resource::Type.new(:node, node_name) + scope.parent = compiler.topscope + scope + end + +end \ No newline at end of file diff --git a/spec/lib/puppet_spec/settings.rb b/spec/lib/puppet_spec/settings.rb new file mode 100644 index 0000000..f3dbc42 --- /dev/null +++ b/spec/lib/puppet_spec/settings.rb @@ -0,0 +1,15 @@ +module PuppetSpec::Settings + + # It would probably be preferable to refactor defaults.rb such that the real definitions of + # these settings were available as a variable, which was then accessible for use during tests. + # However, I'm not doing that yet because I don't want to introduce any additional moving parts + # to this already very large changeset. + # Would be nice to clean this up later. --cprice 2012-03-20 + TEST_APP_DEFAULT_DEFINITIONS = { + :name => { :default => "test", :desc => "name" }, + :logdir => { :type => :directory, :default => "test", :desc => "logdir" }, + :confdir => { :type => :directory, :default => "test", :desc => "confdir" }, + :vardir => { :type => :directory, :default => "test", :desc => "vardir" }, + :rundir => { :type => :directory, :default => "test", :desc => "rundir" }, + } +end diff --git a/spec/lib/puppet_spec/verbose.rb b/spec/lib/puppet_spec/verbose.rb new file mode 100755 index 0000000..d9834f2 --- /dev/null +++ b/spec/lib/puppet_spec/verbose.rb @@ -0,0 +1,9 @@ +# Support code for running stuff with warnings disabled. +module Kernel + def with_verbose_disabled + verbose, $VERBOSE = $VERBOSE, nil + result = yield + $VERBOSE = verbose + return result + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 931d35c..cf1981b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,21 +1,31 @@ dir = File.expand_path(File.dirname(__FILE__)) $LOAD_PATH.unshift File.join(dir, 'lib') -# Don't want puppet getting the command line arguments for rake or autotest -ARGV.clear +# So everyone else doesn't have to include this base constant. +module PuppetSpec + FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR) +end require 'puppet' -require 'facter' -require 'mocha' -gem 'rspec', '>=2.0.0' -require 'rspec/expectations' - +require 'rspec-puppet' +require 'simplecov' require 'puppetlabs_spec_helper/module_spec_helper' +require 'puppet_spec/verbose' +require 'puppet_spec/files' +require 'puppet_spec/settings' +require 'puppet_spec/fixtures' +require 'puppet_spec/matchers' +require 'puppet_spec/database' +require 'monkey_patches/alias_should_to_must' +require 'mocha/setup' + + +SimpleCov.start do + add_filter "/spec/" +end + RSpec.configure do |config| - # FIXME REVISIT - We may want to delegate to Facter like we do in - # Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because - # this behavior is a duplication of the spec_helper in Facter. config.before :each do # Ensure that we don't accidentally cache facts and environment between # test cases. This requires each example group to explicitly load the diff --git a/spec/unit/puppet/parser/functions/merge_spec.rb b/spec/unit/puppet/parser/functions/merge_spec.rb index db7d837..79079b6 100644 --- a/spec/unit/puppet/parser/functions/merge_spec.rb +++ b/spec/unit/puppet/parser/functions/merge_spec.rb @@ -25,7 +25,12 @@ describe Puppet::Parser::Functions.function(:merge) do describe 'when calling merge on the scope instance' do it 'should require all parameters are hashes' do - expect { new_hash = scope.function_merge([{}, '2'])}.should raise_error(Puppet::ParseError, /unexpected argument type String/) + 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([{}, ''])}.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 diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb index 7857d39..50f5840 100644 --- a/spec/unit/puppet/provider/file_line/ruby_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -1,4 +1,4 @@ -require 'puppet' +require 'spec_helper' require 'tempfile' provider_class = Puppet::Type.type(:file_line).provider(:ruby) describe provider_class do diff --git a/spec/unit/puppet/type/anchor_spec.rb b/spec/unit/puppet/type/anchor_spec.rb index 2030b83..f92065f 100644 --- a/spec/unit/puppet/type/anchor_spec.rb +++ b/spec/unit/puppet/type/anchor_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require 'puppet' +require 'spec_helper' anchor = Puppet::Type.type(:anchor).new(:name => "ntp::begin") diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb index 0cd8a26..37f3861 100644 --- a/spec/unit/puppet/type/file_line_spec.rb +++ b/spec/unit/puppet/type/file_line_spec.rb @@ -1,4 +1,4 @@ -require 'puppet' +require 'spec_helper' require 'tempfile' describe Puppet::Type.type(:file_line) do let :file_line do diff --git a/spec/watchr.rb b/spec/watchr.rb deleted file mode 100644 index 885ef1d..0000000 --- a/spec/watchr.rb +++ /dev/null @@ -1,86 +0,0 @@ -ENV['FOG_MOCK'] ||= 'true' -ENV['AUTOTEST'] = 'true' -ENV['WATCHR'] = '1' - -system 'clear' - -def growl(message) - growlnotify = `which growlnotify`.chomp - title = "Watchr Test Results" - image = case message - when /(\d+)\s+?(failure|error)/i - ($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png" - else - '~/.watchr_images/unknown.png' - end - options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'" - system %(#{growlnotify} #{options} &) -end - -def run(cmd) - puts(cmd) - `#{cmd}` -end - -def run_spec_test(file) - if File.exist? file - result = run "rspec --format p --color #{file}" - growl result.split("\n").last - puts result - else - puts "FIXME: No test #{file} [#{Time.now}]" - end -end - -def filter_rspec(data) - data.split("\n").find_all do |l| - l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/ - end.join("\n") -end - -def run_all_tests - system('clear') - files = Dir.glob("spec/**/*_spec.rb").join(" ") - result = run "rspec #{files}" - growl_results = filter_rspec result - growl growl_results - puts result - puts "GROWL: #{growl_results}" -end - -# Ctrl-\ -Signal.trap 'QUIT' do - puts " --- Running all tests ---\n\n" - run_all_tests -end - -@interrupted = false - -# Ctrl-C -Signal.trap 'INT' do - if @interrupted then - @wants_to_quit = true - abort("\n") - else - puts "Interrupt a second time to quit" - @interrupted = true - Kernel.sleep 1.5 - # raise Interrupt, nil # let the run loop catch it - run_suite - end -end - -def file2spec(file) - result = file.sub('lib/puppet/', 'spec/unit/puppet/').gsub(/\.rb$/, '_spec.rb') - result = file.sub('lib/facter/', 'spec/unit/facter/').gsub(/\.rb$/, '_spec.rb') -end - - -watch( 'spec/.*_spec\.rb' ) do |md| - #run_spec_test(md[0]) - run_all_tests -end -watch( 'lib/.*\.rb' ) do |md| - # run_spec_test(file2spec(md[0])) - run_all_tests -end -- cgit v1.2.3 From 0bf470a71b8e6476645fb241faef12e30b2193ac Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 10 Mar 2014 13:07:43 -0700 Subject: Remove pry, whoops. --- spec/classes/anchor_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/classes/anchor_spec.rb b/spec/classes/anchor_spec.rb index 6754811..2e1fcba 100644 --- a/spec/classes/anchor_spec.rb +++ b/spec/classes/anchor_spec.rb @@ -22,8 +22,6 @@ describe "anchorrefresh" do end it 'propagates events through the anchored class' do - require 'pry' - binding.pry resource = transaction.resource_status('Anchor[final]') expect(resource.restarted).to eq(true) -- cgit v1.2.3 From 0fabaa5f07d52feed34b6d58b586ee937752578c Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 10 Mar 2014 14:56:12 -0700 Subject: Readd location_for location_for is used in Jenkins to transform a passed in git repo into something usable by bundler. --- Gemfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Gemfile b/Gemfile index 3d6d5ea..876beab 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,15 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' +def location_for(place, fake_version = nil) + if place =~ /^(git[:@][^#]*)#(.*)/ + [fake_version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, { :require => false }] + end +end + group :development, :test do gem 'rake', :require => false gem 'rspec-puppet', :require => false -- cgit v1.2.3 From 36dda7b1803a9bfd9a82439f731923e68a208111 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 10 Mar 2014 15:19:03 -0700 Subject: Make sure location_for is used when installing Puppet. --- Gemfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 876beab..4604d1b 100644 --- a/Gemfile +++ b/Gemfile @@ -25,8 +25,10 @@ group :development, :test do gem 'beaker-rspec', :require => false end -if puppetversion = ENV['PUPPET_GEM_VERSION'] - gem 'puppet', puppetversion, :require => false +ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION'] +puppetversion = ENV['GEM_PUPPET_VERSION'] +if puppetversion + gem 'puppet', *location_for(puppetversion) else gem 'puppet', :require => false end -- cgit v1.2.3 From 3feb846cf41d53a6ca7c0f4ea420df56c687a2ec Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 11 Mar 2014 09:21:37 -0700 Subject: Ensure Gemfile retains facilities for Jenkins. --- Gemfile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 3d6d5ea..4604d1b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,15 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' +def location_for(place, fake_version = nil) + if place =~ /^(git[:@][^#]*)#(.*)/ + [fake_version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, { :require => false }] + end +end + group :development, :test do gem 'rake', :require => false gem 'rspec-puppet', :require => false @@ -15,8 +25,10 @@ group :development, :test do gem 'beaker-rspec', :require => false end -if puppetversion = ENV['PUPPET_GEM_VERSION'] - gem 'puppet', puppetversion, :require => false +ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION'] +puppetversion = ENV['GEM_PUPPET_VERSION'] +if puppetversion + gem 'puppet', *location_for(puppetversion) else gem 'puppet', :require => false end -- cgit v1.2.3 From 9a3107fed17a1cfe9d829517ed91c345c6fec774 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 12 Mar 2014 18:22:23 +0000 Subject: Add beaker framework. This prepares the module for beaker acceptance tests. --- spec/acceptance/nodesets/centos-64-x64-pe.yml | 12 ++++++++ spec/acceptance/nodesets/centos-64-x64.yml | 10 +++++++ spec/acceptance/nodesets/centos-65-x64.yml | 10 +++++++ spec/acceptance/nodesets/default.yml | 1 + spec/acceptance/nodesets/fedora-18-x64.yml | 10 +++++++ spec/acceptance/nodesets/sles-11-x64.yml | 10 +++++++ .../nodesets/ubuntu-server-10044-x64.yml | 10 +++++++ .../nodesets/ubuntu-server-12042-x64.yml | 10 +++++++ spec/acceptance/unsupported_spec.rb | 10 +++++++ spec/spec_helper_acceptance.rb | 33 ++++++++++++++++++++++ 10 files changed, 116 insertions(+) create mode 100644 spec/acceptance/nodesets/centos-64-x64-pe.yml create mode 100644 spec/acceptance/nodesets/centos-64-x64.yml create mode 100644 spec/acceptance/nodesets/centos-65-x64.yml create mode 120000 spec/acceptance/nodesets/default.yml create mode 100644 spec/acceptance/nodesets/fedora-18-x64.yml create mode 100644 spec/acceptance/nodesets/sles-11-x64.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-10044-x64.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-12042-x64.yml create mode 100644 spec/acceptance/unsupported_spec.rb create mode 100644 spec/spec_helper_acceptance.rb diff --git a/spec/acceptance/nodesets/centos-64-x64-pe.yml b/spec/acceptance/nodesets/centos-64-x64-pe.yml new file mode 100644 index 0000000..7d9242f --- /dev/null +++ b/spec/acceptance/nodesets/centos-64-x64-pe.yml @@ -0,0 +1,12 @@ +HOSTS: + centos-64-x64: + roles: + - master + - database + - dashboard + platform: el-6-x86_64 + box : centos-64-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box + hypervisor : vagrant +CONFIG: + type: pe diff --git a/spec/acceptance/nodesets/centos-64-x64.yml b/spec/acceptance/nodesets/centos-64-x64.yml new file mode 100644 index 0000000..05540ed --- /dev/null +++ b/spec/acceptance/nodesets/centos-64-x64.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-64-x64: + roles: + - master + platform: el-6-x86_64 + box : centos-64-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box + hypervisor : vagrant +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/centos-65-x64.yml b/spec/acceptance/nodesets/centos-65-x64.yml new file mode 100644 index 0000000..4e2cb80 --- /dev/null +++ b/spec/acceptance/nodesets/centos-65-x64.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-65-x64: + roles: + - master + platform: el-6-x86_64 + box : centos-65-x64-vbox436-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box + hypervisor : vagrant +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 120000 index 0000000..2719644 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1 @@ +centos-64-x64.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/fedora-18-x64.yml b/spec/acceptance/nodesets/fedora-18-x64.yml new file mode 100644 index 0000000..1361649 --- /dev/null +++ b/spec/acceptance/nodesets/fedora-18-x64.yml @@ -0,0 +1,10 @@ +HOSTS: + fedora-18-x64: + roles: + - master + platform: fedora-18-x86_64 + box : fedora-18-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box + hypervisor : vagrant +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/sles-11-x64.yml b/spec/acceptance/nodesets/sles-11-x64.yml new file mode 100644 index 0000000..41abe21 --- /dev/null +++ b/spec/acceptance/nodesets/sles-11-x64.yml @@ -0,0 +1,10 @@ +HOSTS: + sles-11-x64.local: + roles: + - master + platform: sles-11-x64 + box : sles-11sp1-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/sles-11sp1-x64-vbox4210-nocm.box + hypervisor : vagrant +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml b/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml new file mode 100644 index 0000000..5ca1514 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-server-10044-x64: + roles: + - master + platform: ubuntu-10.04-amd64 + box : ubuntu-server-10044-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box + hypervisor : vagrant +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml new file mode 100644 index 0000000..d065b30 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-server-12042-x64: + roles: + - master + platform: ubuntu-12.04-amd64 + box : ubuntu-server-12042-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box + hypervisor : vagrant +CONFIG: + type: foss diff --git a/spec/acceptance/unsupported_spec.rb b/spec/acceptance/unsupported_spec.rb new file mode 100644 index 0000000..449f35a --- /dev/null +++ b/spec/acceptance/unsupported_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper_acceptance' + +describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should fail' do + pp = <<-EOS + class { 'mysql::server': } + EOS + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/unsupported osfamily/i) + end +end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..4cefa75 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,33 @@ +require 'beaker-rspec' + +UNSUPPORTED_PLATFORMS = [] + +unless ENV['RS_PROVISION'] == 'no' + hosts.each do |host| + # Install Puppet + if host.is_pe? + install_pe + else + install_package host, 'rubygems' + on host, 'gem install puppet --no-ri --no-rdoc' + on host, "mkdir -p #{host['distmoduledir']}" + end + end +end + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Readable test descriptions + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + # Install module and dependencies + puppet_module_install(:source => proj_root, :module_name => 'stdlib') + hosts.each do |host| + shell('/bin/touch /etc/puppet/hiera.yaml') + end + end +end -- cgit v1.2.3 From 9aa28f1c100d7703aa1bb9fbe2bcf02bf781b486 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 13 Mar 2014 11:10:01 -0700 Subject: Remove this test. It turns out that in 3.x the refresh functionality doesn't actually exist yet, so testing it makes no sense. --- spec/classes/anchor_spec.rb | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 spec/classes/anchor_spec.rb diff --git a/spec/classes/anchor_spec.rb b/spec/classes/anchor_spec.rb deleted file mode 100644 index 2e1fcba..0000000 --- a/spec/classes/anchor_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'spec_helper' -require 'puppet_spec/compiler' - -describe "anchorrefresh" do - include PuppetSpec::Compiler - - let :transaction do - apply_compiled_manifest(<<-ANCHORCLASS) - class anchored { - anchor { 'anchored::begin': } - ~> anchor { 'anchored::end': } - } - - class anchorrefresh { - notify { 'first': } - ~> class { 'anchored': } - ~> anchor { 'final': } - } - - include anchorrefresh - ANCHORCLASS - end - - it 'propagates events through the anchored class' do - resource = transaction.resource_status('Anchor[final]') - - expect(resource.restarted).to eq(true) - end -end -- cgit v1.2.3 From b6ee24687c420ed92a41cb4f5ce45eb4340e4e7a Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Tue, 25 Mar 2014 09:46:53 -0700 Subject: (maint) Pin rake version to 10.1.0 for 1.8 compat --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 4604d1b..eb5a31c 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ def location_for(place, fake_version = nil) end group :development, :test do - gem 'rake', :require => false + gem 'rake', '~> 10.1.0', :require => false gem 'rspec-puppet', :require => false gem 'puppetlabs_spec_helper', :require => false gem 'rspec-system', :require => false -- cgit v1.2.3 From d20cf4069756866dd96877efe152550be4d9f80d Mon Sep 17 00:00:00 2001 From: GoT Date: Thu, 27 Mar 2014 11:56:17 +0100 Subject: Update README.markdown Add code block for validate_slength. --- README.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index 76c546f..874655c 100644 --- a/README.markdown +++ b/README.markdown @@ -1199,13 +1199,13 @@ to a number. The following values will pass: - validate_slength("discombobulate",17) - validate_slength(["discombobulate","moo"],17) + validate_slength("discombobulate",17) + validate_slength(["discombobulate","moo"],17) -The following valueis will not: +The following values will not: - validate_slength("discombobulate",1) - validate_slength(["discombobulate","thermometer"],5) + validate_slength("discombobulate",1) + validate_slength(["discombobulate","thermometer"],5) -- cgit v1.2.3 From d9b5e912bbb6dffff01e03a0b040fd78888f2578 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Sun, 30 Mar 2014 18:47:36 -0400 Subject: (MODULES-603) Add defaults arguments to ensure_packages() Without this patch one can not specify package resource specific parameters. All the ensure_packages() function does it makes sure the named packages are installed. This patch allows one to pass default as a second argument and allow greater flexibility on packages installations. Use case like the following are now possible : * ensure_packages(['r10k', 'serverspec'], {'provider' => 'gem'}) * ensure_packages(['ntp'], {'require' => 'Exec[foobar]'}) --- README.markdown | 2 ++ lib/puppet/parser/functions/ensure_packages.rb | 16 +++++++++++++--- spec/functions/ensure_packages_spec.rb | 13 ++++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index 874655c..3723173 100644 --- a/README.markdown +++ b/README.markdown @@ -275,6 +275,8 @@ Returns true if the variable is empty. ensure_packages --------------- Takes a list of packages and only installs them if they don't already exist. +It optionally takes a hash as a second parameter that will be passed as the +third argument to the ensure_resource() function. - *Type*: statement diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb index 1e0f225..f1da4aa 100644 --- a/lib/puppet/parser/functions/ensure_packages.rb +++ b/lib/puppet/parser/functions/ensure_packages.rb @@ -5,19 +5,29 @@ module Puppet::Parser::Functions newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS Takes a list of packages and only installs them if they don't already exist. +It optionally takes a hash as a second parameter that will be passed as the +third argument to the ensure_resource() function. EOS ) do |arguments| - if arguments.size != 1 + if arguments.size > 2 or arguments.size == 0 raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") + "given (#{arguments.size} for 1 or 2)") + elsif arguments.size == 2 and !arguments[1].is_a?(Hash) + raise(Puppet::ParseError, 'ensure_packages(): Requires second argument to be a Hash') end packages = Array(arguments[0]) + if arguments[1] + defaults = { 'ensure' => 'present' }.merge(arguments[1]) + else + defaults = { 'ensure' => 'present' } + end + Puppet::Parser::Functions.function(:ensure_resource) packages.each { |package_name| - function_ensure_resource(['package', package_name, {'ensure' => 'present' } ]) + function_ensure_resource(['package', package_name, defaults ]) } end end diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index bf62eff..436be10 100644 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -32,7 +32,7 @@ describe 'ensure_packages' do it 'fails with no arguments' do expect { scope.function_ensure_packages([]) - }.to raise_error(Puppet::ParseError, /0 for 1/) + }.to raise_error(Puppet::ParseError, /0 for 1 or 2/) end it 'accepts an array of values' do @@ -67,4 +67,15 @@ describe 'ensure_packages' 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 -- cgit v1.2.3 From afb78e2b253dfe43816e20afa2f4732eb9dc17eb Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 13 Mar 2014 18:21:38 +0000 Subject: Add some acceptance tests for functions. --- spec/acceptance/abs_spec.rb | 27 +++++++++++++++++ spec/acceptance/any2array_spec.rb | 46 +++++++++++++++++++++++++++++ spec/acceptance/base64_spec.rb | 15 ++++++++++ spec/acceptance/bool2num_spec.rb | 31 +++++++++++++++++++ spec/acceptance/capitalize_spec.rb | 30 +++++++++++++++++++ spec/acceptance/chomp_spec.rb | 18 +++++++++++ spec/acceptance/chop_spec.rb | 42 ++++++++++++++++++++++++++ spec/acceptance/concat_spec.rb | 15 ++++++++++ spec/acceptance/count_spec.rb | 27 +++++++++++++++++ spec/acceptance/deep_merge_spec.rb | 17 +++++++++++ spec/acceptance/defined_with_params_spec.rb | 19 ++++++++++++ spec/acceptance/delete_at_spec.rb | 16 ++++++++++ spec/acceptance/delete_spec.rb | 16 ++++++++++ spec/acceptance/delete_undef_values_spec.rb | 16 ++++++++++ 14 files changed, 335 insertions(+) create mode 100644 spec/acceptance/abs_spec.rb create mode 100644 spec/acceptance/any2array_spec.rb create mode 100644 spec/acceptance/base64_spec.rb create mode 100644 spec/acceptance/bool2num_spec.rb create mode 100644 spec/acceptance/capitalize_spec.rb create mode 100644 spec/acceptance/chomp_spec.rb create mode 100644 spec/acceptance/chop_spec.rb create mode 100644 spec/acceptance/concat_spec.rb create mode 100644 spec/acceptance/count_spec.rb create mode 100644 spec/acceptance/deep_merge_spec.rb create mode 100644 spec/acceptance/defined_with_params_spec.rb create mode 100644 spec/acceptance/delete_at_spec.rb create mode 100644 spec/acceptance/delete_spec.rb create mode 100644 spec/acceptance/delete_undef_values_spec.rb diff --git a/spec/acceptance/abs_spec.rb b/spec/acceptance/abs_spec.rb new file mode 100644 index 0000000..0921497 --- /dev/null +++ b/spec/acceptance/abs_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper_acceptance' + +describe 'abs function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should accept a string' do + pp = <<-EOS + $input = '-34.56' + $output = abs($input) + notify { $output: } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 34.56/) + end + end + + it 'should accept a float' do + pp = <<-EOS + $input = -34.56 + $output = abs($input) + notify { $output: } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 34.56/) + end + end +end diff --git a/spec/acceptance/any2array_spec.rb b/spec/acceptance/any2array_spec.rb new file mode 100644 index 0000000..7d452ed --- /dev/null +++ b/spec/acceptance/any2array_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper_acceptance' + +describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should create an empty array' do + pp = <<-EOS + $input = '' + $output = any2array($input) + validate_array($output) + notify { "Output: ${output}": } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: Output: /) + end + end + + it 'should leave arrays modified' do + pp = <<-EOS + $input = ['test', 'array'] + $output = any2array($input) + validate_array($output) + notify { "Output: ${output}": } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: Output: testarray/) + end + end + + it 'should turn a hash into an array' do + pp = <<-EOS + $input = {'test' => 'array'} + $output = any2array($input) + + validate_array($output) + # Check each element of the array is a plain string. + validate_string($output[0]) + validate_string($output[1]) + notify { "Output: ${output}": } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: Output: testarray/) + end + end +end diff --git a/spec/acceptance/base64_spec.rb b/spec/acceptance/base64_spec.rb new file mode 100644 index 0000000..c29b3a7 --- /dev/null +++ b/spec/acceptance/base64_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper_acceptance' + +describe 'base64 function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should encode then decode a string' do + pp = <<-EOS + $encodestring = base64('encode', 'thestring') + $decodestring = base64('decode', $encodestring) + notify { $decodestring: } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/thestring/) + end + end +end diff --git a/spec/acceptance/bool2num_spec.rb b/spec/acceptance/bool2num_spec.rb new file mode 100644 index 0000000..5bdb452 --- /dev/null +++ b/spec/acceptance/bool2num_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper_acceptance' + +describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + ['false', 'f', '0', 'n', 'no'].each do |bool| + it 'should convert a given boolean, #{bool}, to 0' do + pp = <<-EOS + $input = #{bool} + $output = bool2num($input) + notify { $output: } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 0/) + end + end + end + + ['true', 't', '1', 'y', 'yes'].each do |bool| + it 'should convert a given boolean, #{bool}, to 1' do + pp = <<-EOS + $input = #{bool} + $output = bool2num($input) + notify { $output: } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 1/) + end + end + end +end diff --git a/spec/acceptance/capitalize_spec.rb b/spec/acceptance/capitalize_spec.rb new file mode 100644 index 0000000..41e16e9 --- /dev/null +++ b/spec/acceptance/capitalize_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper_acceptance' + +describe 'capitalize function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should capitalize the first letter of a string' do + pp = <<-EOS + $input = 'this is a string' + $output = capitalize($input) + notify { $output: } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: This is a string/) + end + end + + it 'should capitalize the first letter of an array of strings' do + pp = <<-EOS + $input = ['this', 'is', 'a', 'string'] + $output = capitalize($input) + notify { $output: } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: This/) + expect(r.stdout).to match(/Notice: Is/) + expect(r.stdout).to match(/Notice: A/) + expect(r.stdout).to match(/Notice: String/) + end + end +end diff --git a/spec/acceptance/chomp_spec.rb b/spec/acceptance/chomp_spec.rb new file mode 100644 index 0000000..052226f --- /dev/null +++ b/spec/acceptance/chomp_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper_acceptance' + +describe 'chomp function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should eat the newline' do + pp = <<-EOS + $input = "test\n" + if size($input) != 5 { + fail("Size of ${input} is not 5.") + } + $output = chomp($input) + if size($output) != 4 { + fail("Size of ${input} is not 4.") + } + EOS + + apply_manifest(pp, :catch_failures => true) + end +end diff --git a/spec/acceptance/chop_spec.rb b/spec/acceptance/chop_spec.rb new file mode 100644 index 0000000..f1183a1 --- /dev/null +++ b/spec/acceptance/chop_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper_acceptance' + +describe 'chop function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should eat the last character' do + pp = <<-EOS + $input = "test" + if size($input) != 4 { + fail("Size of ${input} is not 4.") + } + $output = chop($input) + if size($output) != 3 { + fail("Size of ${input} is not 3.") + } + EOS + + apply_manifest(pp, :catch_failures => true) + end + + it 'should eat the last two characters of \r\n' do + pp = <<-EOS + $input = "test\r\n" + if size($input) != 6 { + fail("Size of ${input} is not 6.") + } + $output = chop($input) + if size($output) != 4 { + fail("Size of ${input} is not 4.") + } + EOS + + apply_manifest(pp, :catch_failures => true) + end + + it 'should not fail on empty strings' do + pp = <<-EOS + $input = "" + $output = chop($input) + EOS + + apply_manifest(pp, :catch_failures => true) + end +end diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb new file mode 100644 index 0000000..1fe7729 --- /dev/null +++ b/spec/acceptance/concat_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper_acceptance' + +describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should concat one array to another' do + pp = <<-EOS + $output = concat(['1','2','3'],['4','5','6']) + validate_array($output) + if size($output) != 6 { + fail("${output} should have 6 elements.") + } + EOS + + apply_manifest(pp, :catch_failures => true) + end +end diff --git a/spec/acceptance/count_spec.rb b/spec/acceptance/count_spec.rb new file mode 100644 index 0000000..cc46be0 --- /dev/null +++ b/spec/acceptance/count_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper_acceptance' + +describe 'count function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should count elements in an array' do + pp = <<-EOS + $input = [1,2,3,4] + $output = count($input) + notify { $output: } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 4/) + end + end + + it 'should count elements in an array that match a second argument' do + pp = <<-EOS + $input = [1,1,1,2] + $output = count($input, 1) + notify { $output: } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 3/) + end + end +end diff --git a/spec/acceptance/deep_merge_spec.rb b/spec/acceptance/deep_merge_spec.rb new file mode 100644 index 0000000..c7f35be --- /dev/null +++ b/spec/acceptance/deep_merge_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper_acceptance' + +describe 'deep_merge function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should deep merge two hashes' do + pp = <<-EOS + $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } } + $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } } + $merged_hash = deep_merge($hash1, $hash2) + + if $merged_hash != { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } { + fail("Hash was incorrectly merged.") + } + EOS + + apply_manifest(pp, :catch_failures => true) + end +end diff --git a/spec/acceptance/defined_with_params_spec.rb b/spec/acceptance/defined_with_params_spec.rb new file mode 100644 index 0000000..eb549e5 --- /dev/null +++ b/spec/acceptance/defined_with_params_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper_acceptance' + +describe 'defined_with_params function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should successfully notify' do + pp = <<-EOS + user { 'dan': + ensure => present, + } + + if defined_with_params(User[dan], {'ensure' => 'present' }) { + notify { 'User defined with ensure=>present': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: User defined with ensure=>present/) + end + end +end diff --git a/spec/acceptance/delete_at_spec.rb b/spec/acceptance/delete_at_spec.rb new file mode 100644 index 0000000..42d7a77 --- /dev/null +++ b/spec/acceptance/delete_at_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper_acceptance' + +describe 'delete_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should delete elements of the array' do + pp = <<-EOS + $output = delete_at(['a','b','c','b'], 1) + if $output == ['a','c','b'] { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end +end diff --git a/spec/acceptance/delete_spec.rb b/spec/acceptance/delete_spec.rb new file mode 100644 index 0000000..63804bc --- /dev/null +++ b/spec/acceptance/delete_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper_acceptance' + +describe 'delete function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should delete elements of the array' do + pp = <<-EOS + $output = delete(['a','b','c','b'], 'b') + if $output == ['a','c'] { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end +end diff --git a/spec/acceptance/delete_undef_values_spec.rb b/spec/acceptance/delete_undef_values_spec.rb new file mode 100644 index 0000000..1ecdf4c --- /dev/null +++ b/spec/acceptance/delete_undef_values_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper_acceptance' + +describe 'delete_undef_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + it 'should delete elements of the array' do + pp = <<-EOS + $output = delete_undef_values({a=>'A', b=>'', c=>undef, d => false}) + if $output == { a => 'A', b => '', d => false } { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end +end -- cgit v1.2.3 From fcbc4b59a69c62239d15aa11ce7fccaeb93da9cf Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 14 Mar 2014 18:17:12 -0700 Subject: First set of tests --- spec/acceptance/validate_array_spec.rb | 36 ++++++++++++++++ spec/acceptance/validate_augeas_spec.rb | 39 +++++++++++++++++ spec/acceptance/validate_bool_spec.rb | 36 ++++++++++++++++ spec/acceptance/validate_cmd_spec.rb | 49 +++++++++++++++++++++ spec/acceptance/validate_hash_spec.rb | 36 ++++++++++++++++ spec/acceptance/validate_re_spec.rb | 46 ++++++++++++++++++++ spec/acceptance/validate_slength_spec.rb | 71 +++++++++++++++++++++++++++++++ spec/acceptance/validate_string_spec.rb | 35 +++++++++++++++ spec/acceptance/values_at_spec.rb | 71 +++++++++++++++++++++++++++++++ spec/acceptance/values_spec.rb | 30 +++++++++++++ spec/acceptance/zip_spec.rb | 73 ++++++++++++++++++++++++++++++++ 11 files changed, 522 insertions(+) create mode 100644 spec/acceptance/validate_array_spec.rb create mode 100644 spec/acceptance/validate_augeas_spec.rb create mode 100644 spec/acceptance/validate_bool_spec.rb create mode 100644 spec/acceptance/validate_cmd_spec.rb create mode 100644 spec/acceptance/validate_hash_spec.rb create mode 100644 spec/acceptance/validate_re_spec.rb create mode 100644 spec/acceptance/validate_slength_spec.rb create mode 100644 spec/acceptance/validate_string_spec.rb create mode 100644 spec/acceptance/values_at_spec.rb create mode 100644 spec/acceptance/values_spec.rb create mode 100644 spec/acceptance/zip_spec.rb diff --git a/spec/acceptance/validate_array_spec.rb b/spec/acceptance/validate_array_spec.rb new file mode 100644 index 0000000..da9f465 --- /dev/null +++ b/spec/acceptance/validate_array_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper_acceptance' + +describe 'validate_array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'validates a single argument' do + pp = <<-EOS + $one = ['a', 'b'] + validate_array($one) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates an multiple arguments' do + pp = <<-EOS + $one = ['a', 'b'] + $two = [['c'], 'd'] + validate_array($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates a non-array' do + { + %{validate_array({'a' => 'hash' })} => "Hash", + %{validate_array('string')} => "String", + %{validate_array(false)} => "FalseClass", + %{validate_array(undef)} => "String" + }.each do |pp,type| + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) + end + end + end + describe 'failure' do + it 'handles improper number of arguments' + end +end diff --git a/spec/acceptance/validate_augeas_spec.rb b/spec/acceptance/validate_augeas_spec.rb new file mode 100644 index 0000000..8b904f5 --- /dev/null +++ b/spec/acceptance/validate_augeas_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper_acceptance' + +describe 'validate_augeas function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'prep' do + it 'installs augeas for tests' + end + describe 'success' do + it 'validates a single argument' do + pp = <<-EOS + $one = { 'a' => 1 } + validate_hash($one) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates an multiple arguments' do + pp = <<-EOS + $one = { 'a' => 1 } + $two = { 'b' => 2 } + validate_hash($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates a non-hash' do + { + %{validate_hash('{ "not" => "hash" }')} => "String", + %{validate_hash('string')} => "String", + %{validate_hash(["array"])} => "Array", + %{validate_hash(undef)} => "String", + }.each do |pp,type| + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) + end + end + end + describe 'failure' do + it 'handles improper number of arguments' + end +end diff --git a/spec/acceptance/validate_bool_spec.rb b/spec/acceptance/validate_bool_spec.rb new file mode 100644 index 0000000..4e77da2 --- /dev/null +++ b/spec/acceptance/validate_bool_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper_acceptance' + +describe 'validate_bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'validates a single argument' do + pp = <<-EOS + $one = true + validate_bool($one) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates an multiple arguments' do + pp = <<-EOS + $one = true + $two = false + validate_bool($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates a non-bool' do + { + %{validate_bool('true')} => "String", + %{validate_bool('false')} => "String", + %{validate_bool([true])} => "Array", + %{validate_bool(undef)} => "String", + }.each do |pp,type| + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) + end + end + end + describe 'failure' do + it 'handles improper number of arguments' + end +end diff --git a/spec/acceptance/validate_cmd_spec.rb b/spec/acceptance/validate_cmd_spec.rb new file mode 100644 index 0000000..b4d6575 --- /dev/null +++ b/spec/acceptance/validate_cmd_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper_acceptance' + +describe 'validate_cmd function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'validates a true command' do + pp = <<-EOS + $one = 'foo' + if $::osfamily == 'windows' { + $two = 'echo' #shell built-in + } else { + $two = '/bin/echo' + } + validate_cmd($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates a fail command' do + pp = <<-EOS + $one = 'foo' + if $::osfamily == 'windows' { + $two = 'C:/aoeu' + } else { + $two = '/bin/aoeu' + } + validate_cmd($one,$two) + EOS + + apply_manifest(pp, :expect_failures => true) + end + it 'validates a fail command with a custom error message' do + pp = <<-EOS + $one = 'foo' + if $::osfamily == 'windows' { + $two = 'C:/aoeu' + } else { + $two = '/bin/aoeu' + } + validate_cmd($one,$two,"aoeu is dvorak) + EOS + + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/aoeu is dvorak/) + end + end + describe 'failure' do + it 'handles improper number of arguments' + it 'handles improper argument types' + end +end diff --git a/spec/acceptance/validate_hash_spec.rb b/spec/acceptance/validate_hash_spec.rb new file mode 100644 index 0000000..d26c9e7 --- /dev/null +++ b/spec/acceptance/validate_hash_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper_acceptance' + +describe 'validate_hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'validates a single argument' do + pp = <<-EOS + $one = { 'a' => 1 } + validate_hash($one) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates an multiple arguments' do + pp = <<-EOS + $one = { 'a' => 1 } + $two = { 'b' => 2 } + validate_hash($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates a non-hash' do + { + %{validate_hash('{ "not" => "hash" }')} => "String", + %{validate_hash('string')} => "String", + %{validate_hash(["array"])} => "Array", + %{validate_hash(undef)} => "String", + }.each do |pp,type| + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) + end + end + end + describe 'failure' do + it 'handles improper number of arguments' + end +end diff --git a/spec/acceptance/validate_re_spec.rb b/spec/acceptance/validate_re_spec.rb new file mode 100644 index 0000000..8d7e634 --- /dev/null +++ b/spec/acceptance/validate_re_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper_acceptance' + +describe 'validate_re function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'validates a string' do + pp = <<-EOS + $one = 'one' + $two = '^one$' + validate_re($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates an array' do + pp = <<-EOS + $one = 'one' + $two = ['^one$', '^two'] + validate_re($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates a failed array' do + pp = <<-EOS + $one = 'one' + $two = ['^two$', '^three'] + validate_re($one,$two) + EOS + + apply_manifest(pp, :expect_failures => true) + end + it 'validates a failed array with a custom error message' do + pp = <<-EOS + $one = '3.4.3' + $two = '^2.7' + validate_re($one,$two,"The $puppetversion fact does not match 2.7") + EOS + + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/does not match/) + end + end + describe 'failure' do + it 'handles improper number of arguments' + it 'handles improper argument types' + end +end diff --git a/spec/acceptance/validate_slength_spec.rb b/spec/acceptance/validate_slength_spec.rb new file mode 100644 index 0000000..96b2a6f --- /dev/null +++ b/spec/acceptance/validate_slength_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper_acceptance' + +describe 'validate_slength function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'validates a single string max' do + pp = <<-EOS + $one = 'discombobulate' + $two = 17 + validate_slength($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates multiple string maxes' do + pp = <<-EOS + $one = ['discombobulate', 'moo'] + $two = 17 + validate_slength($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates min/max of strings in array' do + pp = <<-EOS + $one = ['discombobulate', 'moo'] + $two = 17 + $three = 3 + validate_slength($one,$two,$three) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates a single string max of incorrect length' do + pp = <<-EOS + $one = 'discombobulate' + $two = 1 + validate_slength($one,$two) + EOS + + apply_manifest(pp, :expect_failures => true) + end + it 'validates multiple string maxes of incorrect length' do + pp = <<-EOS + $one = ['discombobulate', 'moo'] + $two = 3 + validate_slength($one,$two) + EOS + + apply_manifest(pp, :expect_failures => true) + end + it 'validates multiple strings min/maxes of incorrect length' do + pp = <<-EOS + $one = ['discombobulate', 'moo'] + $two = 17 + $three = 10 + validate_slength($one,$two,$three) + EOS + + apply_manifest(pp, :expect_failures => true) + end + end + describe 'failure' do + it 'handles improper number of arguments' + it 'handles improper first argument type' + it 'handles non-strings in array of first argument' + it 'handles improper second argument type' + it 'handles improper third argument type' + it 'handles negative ranges' + it 'handles improper ranges' + end +end diff --git a/spec/acceptance/validate_string_spec.rb b/spec/acceptance/validate_string_spec.rb new file mode 100644 index 0000000..f8658c5 --- /dev/null +++ b/spec/acceptance/validate_string_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_acceptance' + +describe 'validate_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'validates a single argument' do + pp = <<-EOS + $one = 'string' + validate_string($one) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates an multiple arguments' do + pp = <<-EOS + $one = 'string' + $two = 'also string' + validate_string($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates a non-string' do + { + %{validate_string({ 'a' => 'hash' })} => "Hash", + %{validate_string(['array'])} => "Array", + %{validate_string(false)} => "FalseClass", + }.each do |pp,type| + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) + end + end + end + describe 'failure' do + it 'handles improper number of arguments' + end +end diff --git a/spec/acceptance/values_at_spec.rb b/spec/acceptance/values_at_spec.rb new file mode 100644 index 0000000..fb661dd --- /dev/null +++ b/spec/acceptance/values_at_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper_acceptance' + +describe 'values_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'returns a specific value' do + pp = <<-EOS + $one = ['a','b','c','d','e'] + $two = 1 + $output = values_at($one,$two) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b"\]/) + end + it 'returns a specific negative index value' do + pp = <<-EOS + $one = ['a','b','c','d','e'] + $two = "-1" + $output = values_at($one,$two) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["e"\]/) + end + it 'returns a range of values' do + pp = <<-EOS + $one = ['a','b','c','d','e'] + $two = "1-3" + $output = values_at($one,$two) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b", "c", "d"\]/) + end + it 'returns a negative specific value and range of values' do + pp = <<-EOS + $one = ['a','b','c','d','e'] + $two = ["1-3",0] + $output = values_at($one,$two) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b", "c", "d", "a"\]/) + end + end + describe 'failure' do + it 'handles improper number of arguments' do + pp = <<-EOS + $one = ['a','b','c','d','e'] + $output = values_at($one) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Wrong number of arguments/) + end + it 'handles non-indicies arguments' do + pp = <<-EOS + $one = ['a','b','c','d','e'] + $two = [] + $output = values_at($one,$two) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/at least one positive index/) + end + + it 'detects index ranges smaller than the start range' + it 'handles index ranges larger than array' + it 'handles non-integer indicies' + end +end diff --git a/spec/acceptance/values_spec.rb b/spec/acceptance/values_spec.rb new file mode 100644 index 0000000..0c12702 --- /dev/null +++ b/spec/acceptance/values_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper_acceptance' + +describe 'values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'returns an array of values' do + pp = <<-EOS + $arg = { + 'a' => 1, + 'b' => 2, + 'c' => 3, + } + $output = values($arg) + notice(inline_template('<%= @output.sort.inspect %>')) + EOS + + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "2", "3"\]/) + end + end + describe 'failure' do + it 'handles non-hash arguments' do + pp = <<-EOS + $arg = "foo" + $output = values($arg) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Requires hash/) + end + end +end diff --git a/spec/acceptance/zip_spec.rb b/spec/acceptance/zip_spec.rb new file mode 100644 index 0000000..a551b80 --- /dev/null +++ b/spec/acceptance/zip_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper_acceptance' +require 'puppet' + +describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'zips two arrays of numbers together' do + pp = <<-EOS + $one = [1,2,3,4] + $two = [5,6,7,8] + $output = zip($one,$two) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/) + end + it 'zips two arrays of numbers & bools together' do + pp = <<-EOS + $one = [1,2,"three",4] + $two = [true,true,false,false] + $output = zip($one,$two) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/) + end + it 'zips two arrays of numbers together and flattens them' do + # XXX This only tests the argument `true`, even though the following are valid: + # 1 t y true yes + # 0 f n false no + # undef undefined + pp = <<-EOS + $one = [1,2,3,4] + $two = [5,6,7,8] + $output = zip($one,$two,true) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/) + end + it 'handles unmatched length' do + # XXX Is this expected behavior? + pp = <<-EOS + $one = [1,2] + $two = [5,6,7,8] + $output = zip($one,$two) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/) + end + end + describe 'failure' do + it 'handles improper number of arguments' do + pp = <<-EOS + $one = [1,2] + $output = zip($one) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Wrong number of arguments/) + end + it 'handles improper argument types' do + pp = <<-EOS + $one = "a string" + $two = [5,6,7,8] + $output = zip($one,$two) + notice(inline_template('<%= @output.inspect %>')) + EOS + + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Requires array/) + end + end +end -- cgit v1.2.3 From f8f147e794ad305bb8f2dbf5e3a612f0659834ba Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 8 Apr 2014 15:04:55 -0700 Subject: Add success/fail groups --- Gemfile | 3 -- spec/acceptance/abs_spec.rb | 36 +++++++------- spec/acceptance/any2array_spec.rb | 66 +++++++++++++------------ spec/acceptance/base64_spec.rb | 18 ++++--- spec/acceptance/bool2num_spec.rb | 40 +++++++-------- spec/acceptance/capitalize_spec.rb | 42 ++++++++-------- spec/acceptance/chomp_spec.rb | 26 +++++----- spec/acceptance/chop_spec.rb | 66 +++++++++++++------------ spec/acceptance/concat_spec.rb | 20 ++++---- spec/acceptance/count_spec.rb | 36 +++++++------- spec/acceptance/deep_merge_spec.rb | 22 +++++---- spec/acceptance/defined_with_params_spec.rb | 24 ++++----- spec/acceptance/delete_at_spec.rb | 20 ++++---- spec/acceptance/delete_spec.rb | 20 ++++---- spec/acceptance/delete_undef_values_spec.rb | 20 ++++---- spec/acceptance/num2bool_spec.rb | 75 +++++++++++++++++++++++++++++ 16 files changed, 317 insertions(+), 217 deletions(-) create mode 100644 spec/acceptance/num2bool_spec.rb diff --git a/Gemfile b/Gemfile index eb5a31c..bbef720 100644 --- a/Gemfile +++ b/Gemfile @@ -14,9 +14,6 @@ group :development, :test do gem 'rake', '~> 10.1.0', :require => false gem 'rspec-puppet', :require => false gem 'puppetlabs_spec_helper', :require => false - gem 'rspec-system', :require => false - gem 'rspec-system-puppet', :require => false - gem 'rspec-system-serverspec', :require => false gem 'serverspec', :require => false gem 'puppet-lint', :require => false gem 'pry', :require => false diff --git a/spec/acceptance/abs_spec.rb b/spec/acceptance/abs_spec.rb index 0921497..eeae89b 100644 --- a/spec/acceptance/abs_spec.rb +++ b/spec/acceptance/abs_spec.rb @@ -1,27 +1,29 @@ require 'spec_helper_acceptance' describe 'abs function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should accept a string' do - pp = <<-EOS - $input = '-34.56' - $output = abs($input) - notify { $output: } - EOS + describe 'success' do + it 'should accept a string' do + pp = <<-EOS + $input = '-34.56' + $output = abs($input) + notify { $output: } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: 34.56/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 34.56/) + end end - end - it 'should accept a float' do - pp = <<-EOS - $input = -34.56 - $output = abs($input) - notify { $output: } - EOS + it 'should accept a float' do + pp = <<-EOS + $input = -34.56 + $output = abs($input) + notify { $output: } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: 34.56/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 34.56/) + end end end end diff --git a/spec/acceptance/any2array_spec.rb b/spec/acceptance/any2array_spec.rb index 7d452ed..0127303 100644 --- a/spec/acceptance/any2array_spec.rb +++ b/spec/acceptance/any2array_spec.rb @@ -1,46 +1,48 @@ require 'spec_helper_acceptance' describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should create an empty array' do - pp = <<-EOS - $input = '' - $output = any2array($input) - validate_array($output) - notify { "Output: ${output}": } - EOS + describe 'success' do + it 'should create an empty array' do + pp = <<-EOS + $input = '' + $output = any2array($input) + validate_array($output) + notify { "Output: ${output}": } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: Output: /) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: Output: /) + end end - end - it 'should leave arrays modified' do - pp = <<-EOS - $input = ['test', 'array'] - $output = any2array($input) - validate_array($output) - notify { "Output: ${output}": } - EOS + it 'should leave arrays modified' do + pp = <<-EOS + $input = ['test', 'array'] + $output = any2array($input) + validate_array($output) + notify { "Output: ${output}": } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: Output: testarray/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: Output: testarray/) + end end - end - it 'should turn a hash into an array' do - pp = <<-EOS - $input = {'test' => 'array'} - $output = any2array($input) + it 'should turn a hash into an array' do + pp = <<-EOS + $input = {'test' => 'array'} + $output = any2array($input) - validate_array($output) - # Check each element of the array is a plain string. - validate_string($output[0]) - validate_string($output[1]) - notify { "Output: ${output}": } - EOS + validate_array($output) + # Check each element of the array is a plain string. + validate_string($output[0]) + validate_string($output[1]) + notify { "Output: ${output}": } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: Output: testarray/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: Output: testarray/) + end end end end diff --git a/spec/acceptance/base64_spec.rb b/spec/acceptance/base64_spec.rb index c29b3a7..30ba689 100644 --- a/spec/acceptance/base64_spec.rb +++ b/spec/acceptance/base64_spec.rb @@ -1,15 +1,17 @@ require 'spec_helper_acceptance' describe 'base64 function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should encode then decode a string' do - pp = <<-EOS - $encodestring = base64('encode', 'thestring') - $decodestring = base64('decode', $encodestring) - notify { $decodestring: } - EOS + describe 'success' do + it 'should encode then decode a string' do + pp = <<-EOS + $encodestring = base64('encode', 'thestring') + $decodestring = base64('decode', $encodestring) + notify { $decodestring: } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/thestring/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/thestring/) + end end end end diff --git a/spec/acceptance/bool2num_spec.rb b/spec/acceptance/bool2num_spec.rb index 5bdb452..1cbd88d 100644 --- a/spec/acceptance/bool2num_spec.rb +++ b/spec/acceptance/bool2num_spec.rb @@ -1,30 +1,32 @@ require 'spec_helper_acceptance' describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - ['false', 'f', '0', 'n', 'no'].each do |bool| - it 'should convert a given boolean, #{bool}, to 0' do - pp = <<-EOS - $input = #{bool} - $output = bool2num($input) - notify { $output: } - EOS + describe 'success' do + ['false', 'f', '0', 'n', 'no'].each do |bool| + it 'should convert a given boolean, #{bool}, to 0' do + pp = <<-EOS + $input = #{bool} + $output = bool2num($input) + notify { $output: } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: 0/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 0/) + end end end - end - ['true', 't', '1', 'y', 'yes'].each do |bool| - it 'should convert a given boolean, #{bool}, to 1' do - pp = <<-EOS - $input = #{bool} - $output = bool2num($input) - notify { $output: } - EOS + ['true', 't', '1', 'y', 'yes'].each do |bool| + it 'should convert a given boolean, #{bool}, to 1' do + pp = <<-EOS + $input = #{bool} + $output = bool2num($input) + notify { $output: } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: 1/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 1/) + end end end end diff --git a/spec/acceptance/capitalize_spec.rb b/spec/acceptance/capitalize_spec.rb index 41e16e9..c04b401 100644 --- a/spec/acceptance/capitalize_spec.rb +++ b/spec/acceptance/capitalize_spec.rb @@ -1,30 +1,32 @@ require 'spec_helper_acceptance' describe 'capitalize function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should capitalize the first letter of a string' do - pp = <<-EOS - $input = 'this is a string' - $output = capitalize($input) - notify { $output: } - EOS + describe 'success' do + it 'should capitalize the first letter of a string' do + pp = <<-EOS + $input = 'this is a string' + $output = capitalize($input) + notify { $output: } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: This is a string/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: This is a string/) + end end - end - it 'should capitalize the first letter of an array of strings' do - pp = <<-EOS - $input = ['this', 'is', 'a', 'string'] - $output = capitalize($input) - notify { $output: } - EOS + it 'should capitalize the first letter of an array of strings' do + pp = <<-EOS + $input = ['this', 'is', 'a', 'string'] + $output = capitalize($input) + notify { $output: } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: This/) - expect(r.stdout).to match(/Notice: Is/) - expect(r.stdout).to match(/Notice: A/) - expect(r.stdout).to match(/Notice: String/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: This/) + expect(r.stdout).to match(/Notice: Is/) + expect(r.stdout).to match(/Notice: A/) + expect(r.stdout).to match(/Notice: String/) + end end end end diff --git a/spec/acceptance/chomp_spec.rb b/spec/acceptance/chomp_spec.rb index 052226f..c4af9d9 100644 --- a/spec/acceptance/chomp_spec.rb +++ b/spec/acceptance/chomp_spec.rb @@ -1,18 +1,20 @@ require 'spec_helper_acceptance' describe 'chomp function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should eat the newline' do - pp = <<-EOS - $input = "test\n" - if size($input) != 5 { - fail("Size of ${input} is not 5.") - } - $output = chomp($input) - if size($output) != 4 { - fail("Size of ${input} is not 4.") - } - EOS + describe 'success' do + it 'should eat the newline' do + pp = <<-EOS + $input = "test\n" + if size($input) != 5 { + fail("Size of ${input} is not 5.") + } + $output = chomp($input) + if size($output) != 4 { + fail("Size of ${input} is not 4.") + } + EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_failures => true) + end end end diff --git a/spec/acceptance/chop_spec.rb b/spec/acceptance/chop_spec.rb index f1183a1..8774390 100644 --- a/spec/acceptance/chop_spec.rb +++ b/spec/acceptance/chop_spec.rb @@ -1,42 +1,44 @@ require 'spec_helper_acceptance' describe 'chop function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should eat the last character' do - pp = <<-EOS - $input = "test" - if size($input) != 4 { - fail("Size of ${input} is not 4.") - } - $output = chop($input) - if size($output) != 3 { - fail("Size of ${input} is not 3.") - } - EOS + describe 'success' do + it 'should eat the last character' do + pp = <<-EOS + $input = "test" + if size($input) != 4 { + fail("Size of ${input} is not 4.") + } + $output = chop($input) + if size($output) != 3 { + fail("Size of ${input} is not 3.") + } + EOS - apply_manifest(pp, :catch_failures => true) - end + apply_manifest(pp, :catch_failures => true) + end - it 'should eat the last two characters of \r\n' do - pp = <<-EOS - $input = "test\r\n" - if size($input) != 6 { - fail("Size of ${input} is not 6.") - } - $output = chop($input) - if size($output) != 4 { - fail("Size of ${input} is not 4.") - } - EOS + it 'should eat the last two characters of \r\n' do + pp = <<-EOS + $input = "test\r\n" + if size($input) != 6 { + fail("Size of ${input} is not 6.") + } + $output = chop($input) + if size($output) != 4 { + fail("Size of ${input} is not 4.") + } + EOS - apply_manifest(pp, :catch_failures => true) - end + apply_manifest(pp, :catch_failures => true) + end - it 'should not fail on empty strings' do - pp = <<-EOS - $input = "" - $output = chop($input) - EOS + it 'should not fail on empty strings' do + pp = <<-EOS + $input = "" + $output = chop($input) + EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_failures => true) + end end end diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index 1fe7729..24b5955 100644 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -1,15 +1,17 @@ require 'spec_helper_acceptance' describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should concat one array to another' do - pp = <<-EOS - $output = concat(['1','2','3'],['4','5','6']) - validate_array($output) - if size($output) != 6 { - fail("${output} should have 6 elements.") - } - EOS + describe 'success' do + it 'should concat one array to another' do + pp = <<-EOS + $output = concat(['1','2','3'],['4','5','6']) + validate_array($output) + if size($output) != 6 { + fail("${output} should have 6 elements.") + } + EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_failures => true) + end end end diff --git a/spec/acceptance/count_spec.rb b/spec/acceptance/count_spec.rb index cc46be0..0a0f5d7 100644 --- a/spec/acceptance/count_spec.rb +++ b/spec/acceptance/count_spec.rb @@ -1,27 +1,29 @@ require 'spec_helper_acceptance' describe 'count function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should count elements in an array' do - pp = <<-EOS - $input = [1,2,3,4] - $output = count($input) - notify { $output: } - EOS + describe 'success' do + it 'should count elements in an array' do + pp = <<-EOS + $input = [1,2,3,4] + $output = count($input) + notify { $output: } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: 4/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 4/) + end end - end - it 'should count elements in an array that match a second argument' do - pp = <<-EOS - $input = [1,1,1,2] - $output = count($input, 1) - notify { $output: } - EOS + it 'should count elements in an array that match a second argument' do + pp = <<-EOS + $input = [1,1,1,2] + $output = count($input, 1) + notify { $output: } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: 3/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: 3/) + end end end end diff --git a/spec/acceptance/deep_merge_spec.rb b/spec/acceptance/deep_merge_spec.rb index c7f35be..676d23d 100644 --- a/spec/acceptance/deep_merge_spec.rb +++ b/spec/acceptance/deep_merge_spec.rb @@ -1,17 +1,19 @@ require 'spec_helper_acceptance' describe 'deep_merge function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should deep merge two hashes' do - pp = <<-EOS - $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } } - $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } } - $merged_hash = deep_merge($hash1, $hash2) + describe 'success' do + it 'should deep merge two hashes' do + pp = <<-EOS + $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } } + $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } } + $merged_hash = deep_merge($hash1, $hash2) - if $merged_hash != { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } { - fail("Hash was incorrectly merged.") - } - EOS + if $merged_hash != { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } { + fail("Hash was incorrectly merged.") + } + EOS - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_failures => true) + end end end diff --git a/spec/acceptance/defined_with_params_spec.rb b/spec/acceptance/defined_with_params_spec.rb index eb549e5..7477453 100644 --- a/spec/acceptance/defined_with_params_spec.rb +++ b/spec/acceptance/defined_with_params_spec.rb @@ -1,19 +1,21 @@ require 'spec_helper_acceptance' describe 'defined_with_params function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should successfully notify' do - pp = <<-EOS - user { 'dan': - ensure => present, - } + describe 'success' do + it 'should successfully notify' do + pp = <<-EOS + user { 'dan': + ensure => present, + } - if defined_with_params(User[dan], {'ensure' => 'present' }) { - notify { 'User defined with ensure=>present': } - } - EOS + if defined_with_params(User[dan], {'ensure' => 'present' }) { + notify { 'User defined with ensure=>present': } + } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: User defined with ensure=>present/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: User defined with ensure=>present/) + end end end end diff --git a/spec/acceptance/delete_at_spec.rb b/spec/acceptance/delete_at_spec.rb index 42d7a77..f2c5cfe 100644 --- a/spec/acceptance/delete_at_spec.rb +++ b/spec/acceptance/delete_at_spec.rb @@ -1,16 +1,18 @@ require 'spec_helper_acceptance' describe 'delete_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should delete elements of the array' do - pp = <<-EOS - $output = delete_at(['a','b','c','b'], 1) - if $output == ['a','c','b'] { - notify { 'output correct': } - } - EOS + describe 'success' do + it 'should delete elements of the array' do + pp = <<-EOS + $output = delete_at(['a','b','c','b'], 1) + if $output == ['a','c','b'] { + notify { 'output correct': } + } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: output correct/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end end end end diff --git a/spec/acceptance/delete_spec.rb b/spec/acceptance/delete_spec.rb index 63804bc..e54d816 100644 --- a/spec/acceptance/delete_spec.rb +++ b/spec/acceptance/delete_spec.rb @@ -1,16 +1,18 @@ require 'spec_helper_acceptance' describe 'delete function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should delete elements of the array' do - pp = <<-EOS - $output = delete(['a','b','c','b'], 'b') - if $output == ['a','c'] { - notify { 'output correct': } - } - EOS + describe 'success' do + it 'should delete elements of the array' do + pp = <<-EOS + $output = delete(['a','b','c','b'], 'b') + if $output == ['a','c'] { + notify { 'output correct': } + } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: output correct/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end end end end diff --git a/spec/acceptance/delete_undef_values_spec.rb b/spec/acceptance/delete_undef_values_spec.rb index 1ecdf4c..c2ac931 100644 --- a/spec/acceptance/delete_undef_values_spec.rb +++ b/spec/acceptance/delete_undef_values_spec.rb @@ -1,16 +1,18 @@ require 'spec_helper_acceptance' describe 'delete_undef_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - it 'should delete elements of the array' do - pp = <<-EOS - $output = delete_undef_values({a=>'A', b=>'', c=>undef, d => false}) - if $output == { a => 'A', b => '', d => false } { - notify { 'output correct': } - } - EOS + describe 'success' do + it 'should delete elements of the array' do + pp = <<-EOS + $output = delete_undef_values({a=>'A', b=>'', c=>undef, d => false}) + if $output == { a => 'A', b => '', d => false } { + notify { 'output correct': } + } + EOS - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: output correct/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end end end end diff --git a/spec/acceptance/num2bool_spec.rb b/spec/acceptance/num2bool_spec.rb new file mode 100644 index 0000000..cdfbc70 --- /dev/null +++ b/spec/acceptance/num2bool_spec.rb @@ -0,0 +1,75 @@ +require 'spec_helper_acceptance' + +describe 'num2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'bools positive numbers and numeric strings as true' do + pp = <<-EOS + $a = 1 + $b = "1" + $c = "50" + $ao = num2bool($a) + $bo = num2bool($b) + $co = num2bool($c) + notice(inline_template('a is <%= @ao.inspect %>')) + notice(inline_template('b is <%= @bo.inspect %>')) + notice(inline_template('c is <%= @co.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/a is true/) + expect(r.stdout).to match(/b is true/) + expect(r.stdout).to match(/c is true/) + end + end + it 'bools negative numbers as false' do + pp = <<-EOS + $a = 0 + $b = -0.1 + $c = ["-50","1"] + $ao = num2bool($a) + $bo = num2bool($b) + $co = num2bool($c) + notice(inline_template('a is <%= @ao.inspect %>')) + notice(inline_template('b is <%= @bo.inspect %>')) + notice(inline_template('c is <%= @co.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/a is false/) + expect(r.stdout).to match(/b is false/) + expect(r.stdout).to match(/c is false/) + end + end + end + describe 'failure' do + it 'fails on words' do + pp = <<-EOS + $a = "a" + $ao = num2bool($a) + notice(inline_template('a is <%= @ao.inspect %>')) + EOS + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/) + end + + it 'fails on numberwords' do + pp = <<-EOS + $b = "1b" + $bo = num2bool($b) + notice(inline_template('b is <%= @bo.inspect %>')) + EOS + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not look like a number/) + + end + + it 'fails on non-numeric/strings' do + pending "The function will call .to_s.to_i on anything not a Numeric or + String, and results in 0. Is this intended?" + pp = <<-EOS + $c = {"c" => "-50"} + $co = num2bool($c) + notice(inline_template('c is <%= @co.inspect %>')) + EOS + expect(apply_manifest(ppc :expect_failures => true).stderr).to match(/Unable to parse/) + end + end +end -- cgit v1.2.3 From 8a269c6722594611cb981f1a97d4288e5acc9fd7 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 8 Apr 2014 16:38:33 -0700 Subject: Add build_csv --- spec/acceptance/build_csv.rb | 69 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 spec/acceptance/build_csv.rb diff --git a/spec/acceptance/build_csv.rb b/spec/acceptance/build_csv.rb new file mode 100644 index 0000000..556d1f8 --- /dev/null +++ b/spec/acceptance/build_csv.rb @@ -0,0 +1,69 @@ +#!/usr/bin/env ruby +# vim: set sw=2 sts=2 et tw=80 : +require 'rspec' +require 'pry' + +#XXX Super ugly hack to keep from starting beaker nodes +module Kernel + # make an alias of the original require + alias_method :original_require, :require + # rewrite require + def require name + original_require name if name != 'spec_helper_acceptance' + end +end +UNSUPPORTED_PLATFORMS = [] +def fact(*args) [] end +#XXX End hax + +# Get a list of functions for test coverage +function_list = Dir[File.join(File.dirname(__FILE__),"..","..","lib","puppet","parser","functions","*.rb")].collect do |function_rb| + File.basename(function_rb,".rb") +end + +## Configure rspec to parse tests +options = RSpec::Core::ConfigurationOptions.new(['spec/acceptance']) +configuration = RSpec::configuration +world = RSpec::world +options.parse_options +options.configure(configuration) +configuration.load_spec_files + +## Collect up tests and example groups into a hash +def get_tests(children) + children.inject({}) do |memo,c| + memo[c.description] = Hash.new + memo[c.description]["groups"] = get_tests(c.children) unless c.children.empty? + memo[c.description]["tests"] = c.examples.collect { |e| + e.description unless e.pending? + }.compact unless c.examples.empty? + memo[c.description]["pending_tests"] = c.examples.collect { |e| + e.description if e.pending? + }.compact unless c.examples.empty? + memo + end +end + +# Convert tests hash to csv format +def to_csv(function_list,tests) + function_list.collect do |function_name| + if v = tests["#{function_name} function"] + positive_tests = v["groups"]["success"] ? v["groups"]["success"]["tests"].length : 0 + negative_tests = v["groups"]["failure"] ? v["groups"]["failure"]["tests"].length : 0 + pending_tests = + (v["groups"]["failure"] ? v["groups"]["success"]["pending_tests"].length : 0) + + (v["groups"]["failure"] ? v["groups"]["failure"]["pending_tests"].length : 0) + else + positive_tests = 0 + negative_tests = 0 + pending_tests = 0 + end + sprintf("%-25s, %-9d, %-9d, %-9d", function_name,positive_tests,negative_tests,pending_tests) + end.compact +end + +tests = get_tests(world.example_groups) +csv = to_csv(function_list,tests) +percentage_tested = "#{tests.count*100/function_list.count}%" +printf("%-25s, %-9s, %-9s, %-9s\n","#{percentage_tested} have tests.","Positive","Negative","Pending") +puts csv -- cgit v1.2.3 From 90222959b14a10c3519c88f74e244b13b07fd78b Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Wed, 9 Apr 2014 14:35:34 -0700 Subject: Adding more tests --- spec/acceptance/parsejson_spec.rb | 33 ++++++++++++++++++++++++ spec/acceptance/parseyaml_spec.rb | 34 ++++++++++++++++++++++++ spec/acceptance/pick_spec.rb | 43 +++++++++++++++++++++++++++++++ spec/acceptance/prefix_spec.rb | 41 +++++++++++++++++++++++++++++ spec/acceptance/reject_spec.rb | 41 +++++++++++++++++++++++++++++ spec/acceptance/size_spec.rb | 54 +++++++++++++++++++++++++++++++++++++++ spec/acceptance/sort_spec.rb | 33 ++++++++++++++++++++++++ spec/spec_helper_acceptance.rb | 2 +- 8 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 spec/acceptance/parsejson_spec.rb create mode 100644 spec/acceptance/parseyaml_spec.rb create mode 100644 spec/acceptance/pick_spec.rb create mode 100644 spec/acceptance/prefix_spec.rb create mode 100644 spec/acceptance/reject_spec.rb create mode 100644 spec/acceptance/size_spec.rb create mode 100644 spec/acceptance/sort_spec.rb diff --git a/spec/acceptance/parsejson_spec.rb b/spec/acceptance/parsejson_spec.rb new file mode 100644 index 0000000..b2ae030 --- /dev/null +++ b/spec/acceptance/parsejson_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper_acceptance' + +describe 'parsejson function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'parses valid json' do + pp = <<-EOS + $a = '{"hunter": "washere", "tests": "passing"}' + $ao = parsejson($a) + $tests = $ao['tests'] + notice(inline_template('tests are <%= @tests.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/tests are "passing"/) + end + end + end + describe 'failure' do + it 'raises error on incorrect json' do + pp = <<-EOS + $a = '{"hunter": "washere", "tests": "passing",}' + $ao = parsejson($a) + notice(inline_template('a is <%= @ao.inspect %>')) + EOS + + apply_manifest(pp, :expect_failures => true) do |r| + expect(r.stderr).to match(/expected next name/) + end + end + + it 'raises error on incorrect number of arguments' + end +end diff --git a/spec/acceptance/parseyaml_spec.rb b/spec/acceptance/parseyaml_spec.rb new file mode 100644 index 0000000..01e0988 --- /dev/null +++ b/spec/acceptance/parseyaml_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper_acceptance' + +describe 'parseyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'parses valid yaml' do + pp = <<-EOS + $a = "---\nhunter: washere\ntests: passing\n" + $o = parseyaml($a) + $tests = $o['tests'] + notice(inline_template('tests are <%= @tests.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/tests are "passing"/) + end + end + end + describe 'failure' do + it 'raises error on incorrect yaml' do + pp = <<-EOS + $a = "---\nhunter: washere\ntests: passing\n:" + $o = parseyaml($a) + $tests = $o['tests'] + notice(inline_template('tests are <%= @tests.inspect %>')) + EOS + + apply_manifest(pp, :expect_failures => true) do |r| + expect(r.stderr).to match(/syntax error/) + end + end + + it 'raises error on incorrect number of arguments' + end +end diff --git a/spec/acceptance/pick_spec.rb b/spec/acceptance/pick_spec.rb new file mode 100644 index 0000000..8a768a9 --- /dev/null +++ b/spec/acceptance/pick_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper_acceptance' + +describe 'pick function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'picks a default value' do + pp = <<-EOS + $a = undef + $o = pick($a, 'default') + notice(inline_template('picked is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/picked is "default"/) + end + end + it 'picks the first set value' do + pp = <<-EOS + $a = "something" + $b = "long" + $o = pick($a, $b, 'default') + notice(inline_template('picked is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/picked is "something"/) + end + end + end + describe 'failure' do + it 'raises error with all undef values' do + pp = <<-EOS + $a = undef + $b = undef + $o = pick($a, $b) + notice(inline_template('picked is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :expect_failures => true) do |r| + expect(r.stderr).to match(/must receive at least one non empty value/) + end + end + end +end diff --git a/spec/acceptance/prefix_spec.rb b/spec/acceptance/prefix_spec.rb new file mode 100644 index 0000000..d7b80a8 --- /dev/null +++ b/spec/acceptance/prefix_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper_acceptance' + +describe 'prefix function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'prefixes array of values' do + pp = <<-EOS + $o = prefix(['a','b','c'],'p') + notice(inline_template('prefix is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/prefix is \["pa", "pb", "pc"\]/) + end + end + it 'prefixs with empty array' do + pp = <<-EOS + $o = prefix([],'p') + notice(inline_template('prefix is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/prefix is \[\]/) + end + end + it 'prefixs array of values with undef' do + pp = <<-EOS + $o = prefix(['a','b','c'], undef) + notice(inline_template('prefix is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/prefix is \["a", "b", "c"\]/) + end + end + end + describe 'failure' do + it 'fails with no arguments' + it 'fails when first argument is not array' + it 'fails when second argument is not string' + end +end diff --git a/spec/acceptance/reject_spec.rb b/spec/acceptance/reject_spec.rb new file mode 100644 index 0000000..5333f36 --- /dev/null +++ b/spec/acceptance/reject_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper_acceptance' + +describe 'reject function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'rejects array of values' do + pp = <<-EOS + $o = reject(['aaa','bbb','ccc','aaaddd'], 'aaa') + notice(inline_template('reject is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/reject is \["bbb", "ccc"\]/) + end + end + it 'rejects with empty array' do + pp = <<-EOS + $o = reject([],'aaa') + notice(inline_template('reject is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/reject is \[\]/) + end + end + it 'rejects array of values with undef' do + pp = <<-EOS + $o = reject(['aaa','bbb','ccc','aaaddd'], undef) + notice(inline_template('reject is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/reject is \["aaa", "bbb", "ccc", "aaaddd"\]/) + end + end + end + describe 'failure' do + it 'fails with no arguments' + it 'fails when first argument is not array' + it 'fails when second argument is not string' + end +end diff --git a/spec/acceptance/size_spec.rb b/spec/acceptance/size_spec.rb new file mode 100644 index 0000000..2aacf0b --- /dev/null +++ b/spec/acceptance/size_spec.rb @@ -0,0 +1,54 @@ +require 'spec_helper_acceptance' + +describe 'size function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'single string size' do + pp = <<-EOS + $a = 'discombobulate' + $o =size($a) + notice(inline_template('size is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/size is 14/) + end + end + it 'with empty string' do + pp = <<-EOS + $a = '' + $o =size($a) + notice(inline_template('size is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/size is 0/) + end + end + it 'with undef' do + pp = <<-EOS + $a = undef + $o =size($a) + notice(inline_template('size is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/size is 0/) + end + end + it 'strings in array' do + pp = <<-EOS + $a = ['discombobulate', 'moo'] + $o =size($a) + notice(inline_template('size is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/size is 2/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/acceptance/sort_spec.rb b/spec/acceptance/sort_spec.rb new file mode 100644 index 0000000..1868a03 --- /dev/null +++ b/spec/acceptance/sort_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper_acceptance' + +describe 'sort function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'sorts arrays' do + pp = <<-EOS + $a = ["the","public","art","galleries"] + # Anagram: Large picture halls, I bet + $o =sort($a) + notice(inline_template('sort is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/sort is \["art", "galleries", "public", "the"\]/) + end + end + it 'sorts strings' do + pp = <<-EOS + $a = "blowzy night-frumps vex'd jack q" + $o =sort($a) + notice(inline_template('sort is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/sort is " '-abcdefghijklmnopqrstuvwxyz"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 4cefa75..e9d0be8 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -2,7 +2,7 @@ require 'beaker-rspec' UNSUPPORTED_PLATFORMS = [] -unless ENV['RS_PROVISION'] == 'no' +unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' hosts.each do |host| # Install Puppet if host.is_pe? -- cgit v1.2.3 From b691be7ea965af9fab501b31817be57f04b89243 Mon Sep 17 00:00:00 2001 From: Kylo Ginsberg Date: Tue, 8 Apr 2014 16:21:37 -0700 Subject: (maint) Remove facter versions test This test attempts to emulate various versions of facter, but is still dependent on the version of facter it is running against. The immediate symptom was that the test breaks with facter 2.0.1 because it adds another external facts search directory. I tried a couple ways to stub this but allowing it to pretend to run against one set of facters, while actually running against one real facter (which might itself be one of several versions) eluded me. So this patch just removes the test. --- spec/unit/facter/pe_required_facts_spec.rb | 70 ------------------------------ 1 file changed, 70 deletions(-) delete mode 100644 spec/unit/facter/pe_required_facts_spec.rb diff --git a/spec/unit/facter/pe_required_facts_spec.rb b/spec/unit/facter/pe_required_facts_spec.rb deleted file mode 100644 index 85ff6ab..0000000 --- a/spec/unit/facter/pe_required_facts_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -# Puppet Enterprise requires the following facts to be set in order to operate. -# These facts are set using the file ???? and the two facts are -# `fact_stomp_port`, and `fact_stomp_server`. -# - -require 'spec_helper' - -describe "External facts in /etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt" do - context "With Facter 1.6.17 which does not have external facts support" do - before :each do - Facter.stubs(:version).returns("1.6.17") - Facter::Util::Root.stubs(:root?).returns(true) - # Stub out the filesystem for stdlib - Dir.stubs(:entries).with("/etc/puppetlabs/facter/facts.d"). - returns(['puppet_enterprise_installer.txt']) - Dir.stubs(:entries).with("/etc/facter/facts.d").returns([]) - File.stubs(:readlines).with('/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt'). - returns([ - "fact_stomp_port=61613\n", - "fact_stomp_server=puppetmaster.acme.com\n", - "fact_is_puppetagent=true\n", - "fact_is_puppetmaster=false\n", - "fact_is_puppetca=false\n", - "fact_is_puppetconsole=false\n", - ]) - if Facter.collection.respond_to? :load - Facter.collection.load(:facter_dot_d) - else - Facter.collection.loader.load(:facter_dot_d) - end - end - - it 'defines fact_stomp_port' do - Facter.fact(:fact_stomp_port).value.should == '61613' - end - it 'defines fact_stomp_server' do - Facter.fact(:fact_stomp_server).value.should == 'puppetmaster.acme.com' - end - it 'defines fact_is_puppetagent' do - Facter.fact(:fact_is_puppetagent).value.should == 'true' - end - it 'defines fact_is_puppetmaster' do - Facter.fact(:fact_is_puppetmaster).value.should == 'false' - end - it 'defines fact_is_puppetca' do - Facter.fact(:fact_is_puppetca).value.should == 'false' - end - it 'defines fact_is_puppetconsole' do - Facter.fact(:fact_is_puppetconsole).value.should == 'false' - end - end - - [ '1.7.1', '2.0.1' ].each do |v| - context "With Facter #{v} which has external facts support" do - before :each do - Facter.stubs(:version).returns(v) - end - - it 'does not call Facter::Util::DotD.new' do - Facter::Util::DotD.expects(:new).never - - if Facter.collection.respond_to? :load - Facter.collection.load(:facter_dot_d) - else - Facter.collection.loader.load(:facter_dot_d) - end - end - end - end -end -- cgit v1.2.3 From 68acb59bf77d8d818489b1e2a97491cb7f327a0a Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 22 Apr 2014 23:14:16 +0200 Subject: Adjust the regular expression for facts. Previously this was incorrectly handling facts that were of the form foo=1+1=2 due to the ='s in the actual fact contents. Fix this and add tests to try and prevent regressions. --- lib/facter/facter_dot_d.rb | 2 +- spec/unit/facter/facter_dot_d_spec.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 spec/unit/facter/facter_dot_d_spec.rb diff --git a/lib/facter/facter_dot_d.rb b/lib/facter/facter_dot_d.rb index e414b20..2c096b0 100644 --- a/lib/facter/facter_dot_d.rb +++ b/lib/facter/facter_dot_d.rb @@ -40,7 +40,7 @@ class Facter::Util::DotD def txt_parser(file) File.readlines(file).each do |line| - if line =~ /^(.+)=(.+)$/ + if line =~ /^([^=]+)=(.+)$/ var = $1; val = $2 Facter.add(var) do diff --git a/spec/unit/facter/facter_dot_d_spec.rb b/spec/unit/facter/facter_dot_d_spec.rb new file mode 100644 index 0000000..1ecffc8 --- /dev/null +++ b/spec/unit/facter/facter_dot_d_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' +require 'facter/facter_dot_d' + +describe Facter::Util::DotD do + + context 'returns a simple fact' do + before :each do + Facter.stubs(:version).returns('1.6.1') + subject.stubs(:entries).returns(['/etc/facter/facts.d/fake_fact.txt']) + File.stubs(:readlines).with('/etc/facter/facts.d/fake_fact.txt').returns(['fake_fact=fake fact']) + subject.create + end + + it 'should return successfully' do + Facter.fact(:fake_fact).value.should == 'fake fact' + end + end + + context 'returns a fact with equals signs' do + before :each do + Facter.stubs(:version).returns('1.6.1') + subject.stubs(:entries).returns(['/etc/facter/facts.d/foo.txt']) + File.stubs(:readlines).with('/etc/facter/facts.d/foo.txt').returns(['foo=1+1=2']) + subject.create + end + + it 'should return successfully' do + Facter.fact(:foo).value.should == '1+1=2' + end + end +end -- cgit v1.2.3 From 80590a9bfe2a8c0d288125d17cfb9f01c8563a7a Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 28 Apr 2014 17:28:22 -0700 Subject: Add more specs --- spec/acceptance/pick_default_spec.rb | 53 +++++++++++++++++ spec/acceptance/range_spec.rb | 35 ++++++++++++ spec/acceptance/reject_spec.rb | 2 +- spec/acceptance/reverse_spec.rb | 22 ++++++++ spec/acceptance/rstrip_spec.rb | 33 +++++++++++ spec/acceptance/shuffle_spec.rb | 33 +++++++++++ spec/acceptance/size_spec.rb | 8 +-- spec/acceptance/sort_spec.rb | 4 +- spec/acceptance/squeeze_spec.rb | 46 +++++++++++++++ spec/acceptance/str2bool_spec.rb | 30 ++++++++++ spec/acceptance/str2saltedsha512_spec.rb | 21 +++++++ spec/acceptance/strftime_spec.rb | 21 +++++++ spec/acceptance/strip_spec.rb | 33 +++++++++++ spec/acceptance/suffix_spec.rb | 41 ++++++++++++++ spec/acceptance/swapcase_spec.rb | 21 +++++++ spec/acceptance/time_spec.rb | 35 ++++++++++++ spec/acceptance/to_bytes_spec.rb | 26 +++++++++ spec/acceptance/type_spec.rb | 36 ++++++++++++ spec/acceptance/union_spec.rb | 23 ++++++++ spec/acceptance/unique_spec.rb | 32 +++++++++++ spec/acceptance/upcase_spec.rb | 32 +++++++++++ spec/acceptance/uriescape_spec.rb | 22 ++++++++ spec/acceptance/validate_absolute_path_spec.rb | 30 ++++++++++ spec/acceptance/validate_augeas_spec.rb | 78 +++++++++++++------------- spec/acceptance/validate_ipv4_address_spec.rb | 30 ++++++++++ spec/acceptance/validate_ipv6_address_spec.rb | 30 ++++++++++ spec/acceptance/values_at_spec.rb | 3 +- 27 files changed, 733 insertions(+), 47 deletions(-) create mode 100644 spec/acceptance/pick_default_spec.rb create mode 100644 spec/acceptance/range_spec.rb create mode 100644 spec/acceptance/reverse_spec.rb create mode 100644 spec/acceptance/rstrip_spec.rb create mode 100644 spec/acceptance/shuffle_spec.rb create mode 100644 spec/acceptance/squeeze_spec.rb create mode 100644 spec/acceptance/str2bool_spec.rb create mode 100644 spec/acceptance/str2saltedsha512_spec.rb create mode 100644 spec/acceptance/strftime_spec.rb create mode 100644 spec/acceptance/strip_spec.rb create mode 100644 spec/acceptance/suffix_spec.rb create mode 100644 spec/acceptance/swapcase_spec.rb create mode 100644 spec/acceptance/time_spec.rb create mode 100644 spec/acceptance/to_bytes_spec.rb create mode 100644 spec/acceptance/type_spec.rb create mode 100644 spec/acceptance/union_spec.rb create mode 100644 spec/acceptance/unique_spec.rb create mode 100644 spec/acceptance/upcase_spec.rb create mode 100644 spec/acceptance/uriescape_spec.rb create mode 100644 spec/acceptance/validate_absolute_path_spec.rb create mode 100644 spec/acceptance/validate_ipv4_address_spec.rb create mode 100644 spec/acceptance/validate_ipv6_address_spec.rb diff --git a/spec/acceptance/pick_default_spec.rb b/spec/acceptance/pick_default_spec.rb new file mode 100644 index 0000000..e94a999 --- /dev/null +++ b/spec/acceptance/pick_default_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper_acceptance' + +describe 'pick_default function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'pick_defaults a default value' do + pp = <<-EOS + $a = undef + $o = pick_default($a, 'default') + notice(inline_template('picked is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/picked is "default"/) + end + end + it 'pick_defaults with no value' do + pp = <<-EOS + $a = undef + $b = undef + $o = pick_default($a,$b) + notice(inline_template('picked is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/picked is ""/) + end + end + it 'pick_defaults the first set value' do + pp = <<-EOS + $a = "something" + $b = "long" + $o = pick_default($a, $b, 'default') + notice(inline_template('picked is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/picked is "something"/) + end + end + end + describe 'failure' do + it 'raises error with no values' do + pp = <<-EOS + $o = pick_default() + notice(inline_template('picked is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :expect_failures => true) do |r| + expect(r.stderr).to match(/Must receive at least one argument/) + end + end + end +end diff --git a/spec/acceptance/range_spec.rb b/spec/acceptance/range_spec.rb new file mode 100644 index 0000000..0387e4e --- /dev/null +++ b/spec/acceptance/range_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_acceptance' + +describe 'range function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'ranges letters' do + pp = <<-EOS + $o = range('a','d') + notice(inline_template('range is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/range is \["a", "b", "c", "d"\]/) + end + end + it 'ranges letters with a step' do + pp = <<-EOS + $o = range('a','d', '2') + notice(inline_template('range is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/range is \["a", "c"\]/) + end + end + it 'ranges letters with a negative step' + it 'ranges numbers' + it 'ranges numbers with a step' + it 'ranges numbers with a negative step' + it 'ranges numeric strings' + it 'ranges zero padded numbers' + end + describe 'failure' do + it 'fails with no arguments' + end +end diff --git a/spec/acceptance/reject_spec.rb b/spec/acceptance/reject_spec.rb index 5333f36..52b8755 100644 --- a/spec/acceptance/reject_spec.rb +++ b/spec/acceptance/reject_spec.rb @@ -29,7 +29,7 @@ describe 'reject function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('oper EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/reject is \["aaa", "bbb", "ccc", "aaaddd"\]/) + expect(r.stdout).to match(/reject is \[\]/) end end end diff --git a/spec/acceptance/reverse_spec.rb b/spec/acceptance/reverse_spec.rb new file mode 100644 index 0000000..29bdc25 --- /dev/null +++ b/spec/acceptance/reverse_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper_acceptance' + +describe 'reverse function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'reverses strings' do + pp = <<-EOS + $a = "the public art galleries" + # Anagram: Large picture halls, I bet + $o = reverse($a) + notice(inline_template('reverse is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/reverse is "seirellag tra cilbup eht"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/acceptance/rstrip_spec.rb b/spec/acceptance/rstrip_spec.rb new file mode 100644 index 0000000..11ed60a --- /dev/null +++ b/spec/acceptance/rstrip_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper_acceptance' + +describe 'rstrip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'rstrips arrays' do + pp = <<-EOS + $a = [" the "," public "," art","galleries "] + # Anagram: Large picture halls, I bet + $o = rstrip($a) + notice(inline_template('rstrip is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/rstrip is \[" the", " public", " art", "galleries"\]/) + end + end + it 'rstrips strings' do + pp = <<-EOS + $a = " blowzy night-frumps vex'd jack q " + $o = rstrip($a) + notice(inline_template('rstrip is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/rstrip is " blowzy night-frumps vex'd jack q"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/acceptance/shuffle_spec.rb b/spec/acceptance/shuffle_spec.rb new file mode 100644 index 0000000..e22171f --- /dev/null +++ b/spec/acceptance/shuffle_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper_acceptance' + +describe 'shuffle function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'shuffles arrays' do + pp = <<-EOS + $a = ["the","public","art","galleries"] + # Anagram: Large picture halls, I bet + $o = shuffle($a) + notice(inline_template('shuffle is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to_not match(/shuffle is \["the", "public", "art", "galleries"\]/) + end + end + it 'shuffles strings' do + pp = <<-EOS + $a = "blowzy night-frumps vex'd jack q" + $o = shuffle($a) + notice(inline_template('shuffle is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to_not match(/shuffle is "blowzy night-frumps vex'd jack q"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/acceptance/size_spec.rb b/spec/acceptance/size_spec.rb index 2aacf0b..d79140e 100644 --- a/spec/acceptance/size_spec.rb +++ b/spec/acceptance/size_spec.rb @@ -5,7 +5,7 @@ describe 'size function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operat it 'single string size' do pp = <<-EOS $a = 'discombobulate' - $o =size($a) + $o = size($a) notice(inline_template('size is <%= @o.inspect %>')) EOS @@ -16,7 +16,7 @@ describe 'size function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operat it 'with empty string' do pp = <<-EOS $a = '' - $o =size($a) + $o = size($a) notice(inline_template('size is <%= @o.inspect %>')) EOS @@ -27,7 +27,7 @@ describe 'size function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operat it 'with undef' do pp = <<-EOS $a = undef - $o =size($a) + $o = size($a) notice(inline_template('size is <%= @o.inspect %>')) EOS @@ -38,7 +38,7 @@ describe 'size function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operat it 'strings in array' do pp = <<-EOS $a = ['discombobulate', 'moo'] - $o =size($a) + $o = size($a) notice(inline_template('size is <%= @o.inspect %>')) EOS diff --git a/spec/acceptance/sort_spec.rb b/spec/acceptance/sort_spec.rb index 1868a03..ae7c9db 100644 --- a/spec/acceptance/sort_spec.rb +++ b/spec/acceptance/sort_spec.rb @@ -6,7 +6,7 @@ describe 'sort function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operat pp = <<-EOS $a = ["the","public","art","galleries"] # Anagram: Large picture halls, I bet - $o =sort($a) + $o = sort($a) notice(inline_template('sort is <%= @o.inspect %>')) EOS @@ -17,7 +17,7 @@ describe 'sort function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operat it 'sorts strings' do pp = <<-EOS $a = "blowzy night-frumps vex'd jack q" - $o =sort($a) + $o = sort($a) notice(inline_template('sort is <%= @o.inspect %>')) EOS diff --git a/spec/acceptance/squeeze_spec.rb b/spec/acceptance/squeeze_spec.rb new file mode 100644 index 0000000..82e3233 --- /dev/null +++ b/spec/acceptance/squeeze_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper_acceptance' + +describe 'squeeze function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'squeezes arrays' do + pp = <<-EOS + # Real words! + $a = ["wallless", "laparohysterosalpingooophorectomy", "brrr", "goddessship"] + $o = squeeze($a) + notice(inline_template('squeeze is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/squeeze is \["wales", "laparohysterosalpingophorectomy", "br", "godeship"\]/) + end + end + it 'squeezez arrays with an argument' + it 'squeezes strings' do + pp = <<-EOS + $a = "wallless laparohysterosalpingooophorectomy brrr goddessship" + $o = squeeze($a) + notice(inline_template('squeeze is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/squeeze is "wales laparohysterosalpingophorectomy br godeship"/) + end + end + + it 'squeezes strings with an argument' do + pp = <<-EOS + $a = "countessship duchessship governessship hostessship" + $o = squeeze($a, 's') + notice(inline_template('squeeze is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/squeeze is "counteship ducheship governeship hosteship"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/acceptance/str2bool_spec.rb b/spec/acceptance/str2bool_spec.rb new file mode 100644 index 0000000..a3ba5fe --- /dev/null +++ b/spec/acceptance/str2bool_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper_acceptance' + +describe 'str2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'works with "y"' do + pp = <<-EOS + $o = str2bool('y') + notice(inline_template('str2bool is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/str2bool is true/) + end + end + it 'works with "Y"' + it 'works with "yes"' + it 'works with "1"' + it 'works with "true"' + it 'works with "n"' + it 'works with "N"' + it 'works with "no"' + it 'works with "0"' + it 'works with "false"' + it 'works with undef' + end + describe 'failure' do + it 'handles no arguments' + it 'handles non arrays or strings' + end +end diff --git a/spec/acceptance/str2saltedsha512_spec.rb b/spec/acceptance/str2saltedsha512_spec.rb new file mode 100644 index 0000000..d353e22 --- /dev/null +++ b/spec/acceptance/str2saltedsha512_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper_acceptance' + +describe 'str2saltedsha512 function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'works with "y"' do + pp = <<-EOS + $o = str2saltedsha512('password') + notice(inline_template('str2saltedsha512 is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/str2saltedsha512 is "[a-f0-9]{136}"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles more than one argument' + it 'handles non strings' + end +end diff --git a/spec/acceptance/strftime_spec.rb b/spec/acceptance/strftime_spec.rb new file mode 100644 index 0000000..73a01c0 --- /dev/null +++ b/spec/acceptance/strftime_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper_acceptance' + +describe 'strftime function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'gives the Century' do + pp = <<-EOS + $o = strftime('%C') + notice(inline_template('strftime is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/strftime is "20"/) + end + end + it 'takes a timezone argument' + end + describe 'failure' do + it 'handles no arguments' + it 'handles invalid format strings' + end +end diff --git a/spec/acceptance/strip_spec.rb b/spec/acceptance/strip_spec.rb new file mode 100644 index 0000000..fe0c7e9 --- /dev/null +++ b/spec/acceptance/strip_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper_acceptance' + +describe 'strip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'strips arrays' do + pp = <<-EOS + $a = [" the "," public "," art","galleries "] + # Anagram: Large picture halls, I bet + $o = strip($a) + notice(inline_template('strip is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/strip is \["the", "public", "art", "galleries"\]/) + end + end + it 'strips strings' do + pp = <<-EOS + $a = " blowzy night-frumps vex'd jack q " + $o = strip($a) + notice(inline_template('strip is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/strip is "blowzy night-frumps vex'd jack q"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/acceptance/suffix_spec.rb b/spec/acceptance/suffix_spec.rb new file mode 100644 index 0000000..493bc2b --- /dev/null +++ b/spec/acceptance/suffix_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper_acceptance' + +describe 'suffix function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'suffixes array of values' do + pp = <<-EOS + $o = suffix(['a','b','c'],'p') + notice(inline_template('suffix is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/suffix is \["ap", "bp", "cp"\]/) + end + end + it 'suffixs with empty array' do + pp = <<-EOS + $o = suffix([],'p') + notice(inline_template('suffix is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/suffix is \[\]/) + end + end + it 'suffixs array of values with undef' do + pp = <<-EOS + $o = suffix(['a','b','c'], undef) + notice(inline_template('suffix is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/suffix is \["a", "b", "c"\]/) + end + end + end + describe 'failure' do + it 'fails with no arguments' + it 'fails when first argument is not array' + it 'fails when second argument is not string' + end +end diff --git a/spec/acceptance/swapcase_spec.rb b/spec/acceptance/swapcase_spec.rb new file mode 100644 index 0000000..d4ae0dd --- /dev/null +++ b/spec/acceptance/swapcase_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper_acceptance' + +describe 'swapcase function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'works with strings' do + pp = <<-EOS + $o = swapcase('aBcD') + notice(inline_template('swapcase is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/swapcase is "AbCd"/) + end + end + it 'works with arrays' + end + describe 'failure' do + it 'handles no arguments' + it 'handles non arrays or strings' + end +end diff --git a/spec/acceptance/time_spec.rb b/spec/acceptance/time_spec.rb new file mode 100644 index 0000000..2a5e52a --- /dev/null +++ b/spec/acceptance/time_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_acceptance' + +describe 'time function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'gives the time' do + pp = <<-EOS + $o = time() + notice(inline_template('time is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + m = r.stdout.match(/time is (\d+)\D/) + + # When I wrote this test + expect(Integer(m[1])).to be > 1398894170 + end + end + it 'takes a timezone argument' do + pp = <<-EOS + $o = time('UTC') + notice(inline_template('time is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + m = r.stdout.match(/time is (\d+)\D/) + + expect(Integer(m[1])).to be > 1398894170 + end + end + end + describe 'failure' do + it 'handles more arguments' + it 'handles invalid timezones' + end +end diff --git a/spec/acceptance/to_bytes_spec.rb b/spec/acceptance/to_bytes_spec.rb new file mode 100644 index 0000000..34f3647 --- /dev/null +++ b/spec/acceptance/to_bytes_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper_acceptance' + +describe 'to_bytes function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'converts kB to B' do + pp = <<-EOS + $o = to_bytes('4 kB') + notice(inline_template('to_bytes is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + m = r.stdout.match(/to_bytes is (\d+)\D/) + expect(m[1]).to eq("4096") + end + end + it 'works without the B in unit' + it 'works without a space before unit' + it 'works without a unit' + it 'converts fractions' + end + describe 'failure' do + it 'handles no arguments' + it 'handles non integer arguments' + it 'handles unknown units like uB' + end +end diff --git a/spec/acceptance/type_spec.rb b/spec/acceptance/type_spec.rb new file mode 100644 index 0000000..dc72f74 --- /dev/null +++ b/spec/acceptance/type_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper_acceptance' + +describe 'type function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'types arrays' do + pp = <<-EOS + $a = ["the","public","art","galleries"] + # Anagram: Large picture halls, I bet + $o = type($a) + notice(inline_template('type is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/type is "array"/) + end + end + it 'types strings' do + pp = <<-EOS + $a = "blowzy night-frumps vex'd jack q" + $o = type($a) + notice(inline_template('type is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/type is "string"/) + end + end + it 'types hashes' + it 'types integers' + it 'types floats' + it 'types booleans' + end + describe 'failure' do + it 'handles no arguments' + end +end diff --git a/spec/acceptance/union_spec.rb b/spec/acceptance/union_spec.rb new file mode 100644 index 0000000..f413d9a --- /dev/null +++ b/spec/acceptance/union_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_acceptance' + +describe 'union function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'unions arrays' do + pp = <<-EOS + $a = ["the","public"] + $b = ["art","galleries"] + # Anagram: Large picture halls, I bet + $o = union($a,$b) + notice(inline_template('union is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/union is \["the", "public", "art", "galleries"\]/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non arrays' + end +end diff --git a/spec/acceptance/unique_spec.rb b/spec/acceptance/unique_spec.rb new file mode 100644 index 0000000..ea63cb4 --- /dev/null +++ b/spec/acceptance/unique_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper_acceptance' + +describe 'unique function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'uniques arrays' do + pp = <<-EOS + $a = ["wallless", "wallless", "brrr", "goddessship"] + $o = unique($a) + notice(inline_template('unique is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/unique is \["wallless", "brrr", "goddessship"\]/) + end + end + it 'uniques strings' do + pp = <<-EOS + $a = "wallless laparohysterosalpingooophorectomy brrr goddessship" + $o = unique($a) + notice(inline_template('unique is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/unique is "wales prohytingcmbd"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/acceptance/upcase_spec.rb b/spec/acceptance/upcase_spec.rb new file mode 100644 index 0000000..50e6302 --- /dev/null +++ b/spec/acceptance/upcase_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper_acceptance' + +describe 'upcase function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'upcases arrays' do + pp = <<-EOS + $a = ["wallless", "laparohysterosalpingooophorectomy", "brrr", "goddessship"] + $o = upcase($a) + notice(inline_template('upcase is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/upcase is \["WALLLESS", "LAPAROHYSTEROSALPINGOOOPHORECTOMY", "BRRR", "GODDESSSHIP"\]/) + end + end + it 'upcases strings' do + pp = <<-EOS + $a = "wallless laparohysterosalpingooophorectomy brrr goddessship" + $o = upcase($a) + notice(inline_template('upcase is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/upcase is "WALLLESS LAPAROHYSTEROSALPINGOOOPHORECTOMY BRRR GODDESSSHIP"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/acceptance/uriescape_spec.rb b/spec/acceptance/uriescape_spec.rb new file mode 100644 index 0000000..0b8a549 --- /dev/null +++ b/spec/acceptance/uriescape_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper_acceptance' + +describe 'uriescape function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'uriescape strings' do + pp = <<-EOS + $a = ":/?#[]@!$&'()*+,;= \\\"{}" + $o = uriescape($a) + notice(inline_template('uriescape is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/uriescape is ":\/\?%23\[\]@!\$&'\(\)\*\+,;=%20%22%7B%7D"/) + end + end + it 'does nothing if a string is already safe' + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/acceptance/validate_absolute_path_spec.rb b/spec/acceptance/validate_absolute_path_spec.rb new file mode 100644 index 0000000..35ee974 --- /dev/null +++ b/spec/acceptance/validate_absolute_path_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper_acceptance' + +describe 'validate_absolute_path function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + %w{ + C:/ + C:\\\\ + C:\\\\WINDOWS\\\\System32 + C:/windows/system32 + X:/foo/bar + X:\\\\foo\\\\bar + /var/tmp + /var/lib/puppet + /var/opt/../lib/puppet + }.each do |path| + it "validates a single argument #{path}" do + pp = <<-EOS + $one = '#{path}' + validate_absolute_path($one) + EOS + + apply_manifest(pp, :catch_failures => true) + end + end + end + describe 'failure' do + it 'handles improper number of arguments' + it 'handles relative paths' + end +end diff --git a/spec/acceptance/validate_augeas_spec.rb b/spec/acceptance/validate_augeas_spec.rb index 8b904f5..2175ada 100644 --- a/spec/acceptance/validate_augeas_spec.rb +++ b/spec/acceptance/validate_augeas_spec.rb @@ -1,39 +1,39 @@ -require 'spec_helper_acceptance' - -describe 'validate_augeas function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do - describe 'prep' do - it 'installs augeas for tests' - end - describe 'success' do - it 'validates a single argument' do - pp = <<-EOS - $one = { 'a' => 1 } - validate_hash($one) - EOS - - apply_manifest(pp, :catch_failures => true) - end - it 'validates an multiple arguments' do - pp = <<-EOS - $one = { 'a' => 1 } - $two = { 'b' => 2 } - validate_hash($one,$two) - EOS - - apply_manifest(pp, :catch_failures => true) - end - it 'validates a non-hash' do - { - %{validate_hash('{ "not" => "hash" }')} => "String", - %{validate_hash('string')} => "String", - %{validate_hash(["array"])} => "Array", - %{validate_hash(undef)} => "String", - }.each do |pp,type| - expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) - end - end - end - describe 'failure' do - it 'handles improper number of arguments' - end -end +#require 'spec_helper_acceptance' +# +#describe 'validate_augeas function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +# describe 'prep' do +# it 'installs augeas for tests' +# end +# describe 'success' do +# it 'validates a single argument' do +# pp = <<-EOS +# $one = { 'a' => 1 } +# validate_hash($one) +# EOS +# +# apply_manifest(pp, :catch_failures => true) +# end +# it 'validates an multiple arguments' do +# pp = <<-EOS +# $one = { 'a' => 1 } +# $two = { 'b' => 2 } +# validate_hash($one,$two) +# EOS +# +# apply_manifest(pp, :catch_failures => true) +# end +# it 'validates a non-hash' do +# { +# %{validate_hash('{ "not" => "hash" }')} => "String", +# %{validate_hash('string')} => "String", +# %{validate_hash(["array"])} => "Array", +# %{validate_hash(undef)} => "String", +# }.each do |pp,type| +# expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) +# end +# end +# end +# describe 'failure' do +# it 'handles improper number of arguments' +# end +#end diff --git a/spec/acceptance/validate_ipv4_address_spec.rb b/spec/acceptance/validate_ipv4_address_spec.rb new file mode 100644 index 0000000..b98b81c --- /dev/null +++ b/spec/acceptance/validate_ipv4_address_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper_acceptance' + +describe 'validate_ipv4_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'validates a single argument' do + pp = <<-EOS + $one = '1.2.3.4' + validate_ipv4_address($one) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates an multiple arguments' do + pp = <<-EOS + $one = '1.2.3.4' + $two = '5.6.7.8' + validate_ipv4_address($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + end + describe 'failure' do + it 'handles improper number of arguments' + it 'handles ipv6 addresses' + it 'handles non-ipv4 strings' + it 'handles numbers' + it 'handles no arguments' + end +end diff --git a/spec/acceptance/validate_ipv6_address_spec.rb b/spec/acceptance/validate_ipv6_address_spec.rb new file mode 100644 index 0000000..3e73a82 --- /dev/null +++ b/spec/acceptance/validate_ipv6_address_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper_acceptance' + +describe 'validate_ipv6_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'validates a single argument' do + pp = <<-EOS + $one = '3ffe:0505:0002::' + validate_ipv6_address($one) + EOS + + apply_manifest(pp, :catch_failures => true) + end + it 'validates an multiple arguments' do + pp = <<-EOS + $one = '3ffe:0505:0002::' + $two = '3ffe:0505:0001::' + validate_ipv6_address($one,$two) + EOS + + apply_manifest(pp, :catch_failures => true) + end + end + describe 'failure' do + it 'handles improper number of arguments' + it 'handles ipv6 addresses' + it 'handles non-ipv6 strings' + it 'handles numbers' + it 'handles no arguments' + end +end diff --git a/spec/acceptance/values_at_spec.rb b/spec/acceptance/values_at_spec.rb index fb661dd..f341e3d 100644 --- a/spec/acceptance/values_at_spec.rb +++ b/spec/acceptance/values_at_spec.rb @@ -13,9 +13,10 @@ describe 'values_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["b"\]/) end it 'returns a specific negative index value' do + pending("negative numbers don't work") pp = <<-EOS $one = ['a','b','c','d','e'] - $two = "-1" + $two = -1 $output = values_at($one,$two) notice(inline_template('<%= @output.inspect %>')) EOS -- cgit v1.2.3 From af49ef4ca2e4c2219c1c547bdc7f368d3eb777eb Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 2 May 2014 12:56:22 -0700 Subject: Fix the validate_augeas beaker tests --- spec/acceptance/validate_augeas_spec.rb | 101 ++++++++++++++++++++------------ spec/spec_helper_acceptance.rb | 3 +- 2 files changed, 63 insertions(+), 41 deletions(-) diff --git a/spec/acceptance/validate_augeas_spec.rb b/spec/acceptance/validate_augeas_spec.rb index 2175ada..98ee6d1 100644 --- a/spec/acceptance/validate_augeas_spec.rb +++ b/spec/acceptance/validate_augeas_spec.rb @@ -1,39 +1,62 @@ -#require 'spec_helper_acceptance' -# -#describe 'validate_augeas function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do -# describe 'prep' do -# it 'installs augeas for tests' -# end -# describe 'success' do -# it 'validates a single argument' do -# pp = <<-EOS -# $one = { 'a' => 1 } -# validate_hash($one) -# EOS -# -# apply_manifest(pp, :catch_failures => true) -# end -# it 'validates an multiple arguments' do -# pp = <<-EOS -# $one = { 'a' => 1 } -# $two = { 'b' => 2 } -# validate_hash($one,$two) -# EOS -# -# apply_manifest(pp, :catch_failures => true) -# end -# it 'validates a non-hash' do -# { -# %{validate_hash('{ "not" => "hash" }')} => "String", -# %{validate_hash('string')} => "String", -# %{validate_hash(["array"])} => "Array", -# %{validate_hash(undef)} => "String", -# }.each do |pp,type| -# expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) -# end -# end -# end -# describe 'failure' do -# it 'handles improper number of arguments' -# end -#end +require 'spec_helper_acceptance' + +describe 'validate_augeas function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'prep' do + it 'installs augeas for tests' + end + describe 'success' do + context 'valid inputs with no 3rd argument' do + { + 'root:x:0:0:root:/root:/bin/bash\n' => 'Passwd.lns', + 'proc /proc proc nodev,noexec,nosuid 0 0\n' => 'Fstab.lns' + }.each do |line,lens| + it "validates a single argument for #{lens}" do + pp = <<-EOS + $line = "#{line}" + $lens = "#{lens}" + validate_augeas($line, $lens) + EOS + + apply_manifest(pp, :catch_failures => true) + end + end + end + context 'valid inputs with 3rd and 4th arguments' do + it "validates a restricted value" do + line = 'root:x:0:0:root:/root:/bin/barsh\n' + lens = 'Passwd.lns' + restriction = '$file/*[shell="/bin/barsh"]' + pp = <<-EOS + $line = "#{line}" + $lens = "#{lens}" + $restriction = ['#{restriction}'] + validate_augeas($line, $lens, $restriction, "my custom failure message") + EOS + + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/my custom failure message/) + end + end + context 'invalid inputs' do + { + 'root:x:0:0:root' => 'Passwd.lns', + '127.0.1.1' => 'Hosts.lns' + }.each do |line,lens| + it "validates a single argument for #{lens}" do + pp = <<-EOS + $line = "#{line}" + $lens = "#{lens}" + validate_augeas($line, $lens) + EOS + + apply_manifest(pp, :expect_failures => true) + end + end + end + context 'garbage inputs' do + it 'raises an error on invalid inputs' + end + end + describe 'failure' do + it 'handles improper number of arguments' + end +end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index e9d0be8..1a0bba0 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -8,8 +8,7 @@ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' if host.is_pe? install_pe else - install_package host, 'rubygems' - on host, 'gem install puppet --no-ri --no-rdoc' + install_puppet on host, "mkdir -p #{host['distmoduledir']}" end end -- cgit v1.2.3 From 226cc7653c468afecf70ca3cdc8594ba874998db Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 2 May 2014 13:42:25 -0700 Subject: Update build_csv to understand contexts --- spec/acceptance/build_csv.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/spec/acceptance/build_csv.rb b/spec/acceptance/build_csv.rb index 556d1f8..62ecbf1 100644 --- a/spec/acceptance/build_csv.rb +++ b/spec/acceptance/build_csv.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby # vim: set sw=2 sts=2 et tw=80 : require 'rspec' -require 'pry' #XXX Super ugly hack to keep from starting beaker nodes module Kernel @@ -44,15 +43,30 @@ def get_tests(children) end end +def count_test_types_in(type,group) + return 0 if group.nil? + group.inject(0) do |m,(k,v)| + m += v.length if k == type + m += count_tests_in(v) if v.is_a?(Hash) + m + end +end +def count_tests_in(group) + count_test_types_in('tests',group) +end +def count_pending_tests_in(group) + count_test_types_in('pending_tests',group) +end + # Convert tests hash to csv format def to_csv(function_list,tests) function_list.collect do |function_name| if v = tests["#{function_name} function"] - positive_tests = v["groups"]["success"] ? v["groups"]["success"]["tests"].length : 0 - negative_tests = v["groups"]["failure"] ? v["groups"]["failure"]["tests"].length : 0 + positive_tests = count_tests_in(v["groups"]["success"]) + negative_tests = count_tests_in(v["groups"]["failure"]) pending_tests = - (v["groups"]["failure"] ? v["groups"]["success"]["pending_tests"].length : 0) + - (v["groups"]["failure"] ? v["groups"]["failure"]["pending_tests"].length : 0) + count_pending_tests_in(v["groups"]["failure"]) + + count_pending_tests_in(v["groups"]["failure"]) else positive_tests = 0 negative_tests = 0 -- 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/acceptance/abs_spec.rb | 1 + spec/acceptance/any2array_spec.rb | 1 + spec/acceptance/base64_spec.rb | 1 + spec/acceptance/bool2num_spec.rb | 1 + spec/acceptance/capitalize_spec.rb | 1 + spec/acceptance/chomp_spec.rb | 1 + spec/acceptance/chop_spec.rb | 1 + spec/acceptance/concat_spec.rb | 1 + spec/acceptance/count_spec.rb | 1 + spec/acceptance/deep_merge_spec.rb | 1 + spec/acceptance/defined_with_params_spec.rb | 1 + spec/acceptance/delete_at_spec.rb | 1 + spec/acceptance/delete_spec.rb | 1 + spec/acceptance/delete_undef_values_spec.rb | 1 + spec/acceptance/num2bool_spec.rb | 1 + spec/acceptance/parsejson_spec.rb | 1 + spec/acceptance/parseyaml_spec.rb | 1 + spec/acceptance/pick_default_spec.rb | 1 + spec/acceptance/pick_spec.rb | 1 + spec/acceptance/prefix_spec.rb | 1 + spec/acceptance/range_spec.rb | 1 + spec/acceptance/reject_spec.rb | 1 + spec/acceptance/reverse_spec.rb | 1 + spec/acceptance/rstrip_spec.rb | 1 + spec/acceptance/shuffle_spec.rb | 1 + spec/acceptance/size_spec.rb | 1 + spec/acceptance/sort_spec.rb | 1 + spec/acceptance/squeeze_spec.rb | 1 + spec/acceptance/str2bool_spec.rb | 1 + spec/acceptance/str2saltedsha512_spec.rb | 1 + spec/acceptance/strftime_spec.rb | 1 + spec/acceptance/strip_spec.rb | 1 + spec/acceptance/suffix_spec.rb | 1 + spec/acceptance/swapcase_spec.rb | 1 + spec/acceptance/time_spec.rb | 1 + spec/acceptance/to_bytes_spec.rb | 1 + spec/acceptance/type_spec.rb | 1 + spec/acceptance/union_spec.rb | 1 + spec/acceptance/unique_spec.rb | 1 + spec/acceptance/unsupported_spec.rb | 1 + spec/acceptance/upcase_spec.rb | 1 + spec/acceptance/uriescape_spec.rb | 1 + spec/acceptance/validate_absolute_path_spec.rb | 1 + spec/acceptance/validate_array_spec.rb | 1 + spec/acceptance/validate_augeas_spec.rb | 1 + spec/acceptance/validate_bool_spec.rb | 1 + spec/acceptance/validate_cmd_spec.rb | 1 + spec/acceptance/validate_hash_spec.rb | 1 + spec/acceptance/validate_ipv4_address_spec.rb | 1 + spec/acceptance/validate_ipv6_address_spec.rb | 1 + spec/acceptance/validate_re_spec.rb | 1 + spec/acceptance/validate_slength_spec.rb | 1 + spec/acceptance/validate_string_spec.rb | 1 + spec/acceptance/values_at_spec.rb | 1 + spec/acceptance/values_spec.rb | 1 + spec/acceptance/zip_spec.rb | 1 + spec/classes/anchor_spec.rb | 1 + spec/functions/ensure_resource_spec.rb | 1 + spec/functions/getparam_spec.rb | 1 + spec/lib/puppet_spec/compiler.rb | 1 + spec/lib/puppet_spec/database.rb | 1 + spec/lib/puppet_spec/files.rb | 1 + spec/lib/puppet_spec/fixtures.rb | 1 + spec/lib/puppet_spec/matchers.rb | 1 + spec/lib/puppet_spec/modules.rb | 1 + spec/lib/puppet_spec/pops.rb | 1 + spec/lib/puppet_spec/scope.rb | 1 + spec/lib/puppet_spec/settings.rb | 1 + spec/lib/puppet_spec/verbose.rb | 1 + spec/monkey_patches/alias_should_to_must.rb | 1 + spec/monkey_patches/publicize_methods.rb | 1 + spec/spec_helper.rb | 1 + spec/spec_helper_acceptance.rb | 1 + spec/unit/facter/facter_dot_d_spec.rb | 1 + spec/unit/facter/root_home_spec.rb | 1 + spec/unit/facter/util/puppet_settings_spec.rb | 1 + 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 + spec/unit/puppet/provider/file_line/ruby_spec.rb | 1 + spec/unit/puppet/type/file_line_spec.rb | 1 + 85 files changed, 85 insertions(+), 3 deletions(-) diff --git a/spec/acceptance/abs_spec.rb b/spec/acceptance/abs_spec.rb index eeae89b..8e05642 100644 --- a/spec/acceptance/abs_spec.rb +++ b/spec/acceptance/abs_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'abs function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/any2array_spec.rb b/spec/acceptance/any2array_spec.rb index 0127303..467d6af 100644 --- a/spec/acceptance/any2array_spec.rb +++ b/spec/acceptance/any2array_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/base64_spec.rb b/spec/acceptance/base64_spec.rb index 30ba689..97e1738 100644 --- a/spec/acceptance/base64_spec.rb +++ b/spec/acceptance/base64_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'base64 function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/bool2num_spec.rb b/spec/acceptance/bool2num_spec.rb index 1cbd88d..7a70311 100644 --- a/spec/acceptance/bool2num_spec.rb +++ b/spec/acceptance/bool2num_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/capitalize_spec.rb b/spec/acceptance/capitalize_spec.rb index c04b401..e5e7b7b 100644 --- a/spec/acceptance/capitalize_spec.rb +++ b/spec/acceptance/capitalize_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'capitalize function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/chomp_spec.rb b/spec/acceptance/chomp_spec.rb index c4af9d9..f6c1595 100644 --- a/spec/acceptance/chomp_spec.rb +++ b/spec/acceptance/chomp_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'chomp function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/chop_spec.rb b/spec/acceptance/chop_spec.rb index 8774390..dbc28da 100644 --- a/spec/acceptance/chop_spec.rb +++ b/spec/acceptance/chop_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'chop function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index 24b5955..7bda365 100644 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/count_spec.rb b/spec/acceptance/count_spec.rb index 0a0f5d7..51a40ba 100644 --- a/spec/acceptance/count_spec.rb +++ b/spec/acceptance/count_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'count function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/deep_merge_spec.rb b/spec/acceptance/deep_merge_spec.rb index 676d23d..c0f9b12 100644 --- a/spec/acceptance/deep_merge_spec.rb +++ b/spec/acceptance/deep_merge_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'deep_merge function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/defined_with_params_spec.rb b/spec/acceptance/defined_with_params_spec.rb index 7477453..fc54450 100644 --- a/spec/acceptance/defined_with_params_spec.rb +++ b/spec/acceptance/defined_with_params_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'defined_with_params function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/delete_at_spec.rb b/spec/acceptance/delete_at_spec.rb index f2c5cfe..db0c01f 100644 --- a/spec/acceptance/delete_at_spec.rb +++ b/spec/acceptance/delete_at_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'delete_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/delete_spec.rb b/spec/acceptance/delete_spec.rb index e54d816..a28604c 100644 --- a/spec/acceptance/delete_spec.rb +++ b/spec/acceptance/delete_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'delete function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/delete_undef_values_spec.rb b/spec/acceptance/delete_undef_values_spec.rb index c2ac931..b7eda19 100644 --- a/spec/acceptance/delete_undef_values_spec.rb +++ b/spec/acceptance/delete_undef_values_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'delete_undef_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/num2bool_spec.rb b/spec/acceptance/num2bool_spec.rb index cdfbc70..1d99ba0 100644 --- a/spec/acceptance/num2bool_spec.rb +++ b/spec/acceptance/num2bool_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'num2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/parsejson_spec.rb b/spec/acceptance/parsejson_spec.rb index b2ae030..5097810 100644 --- a/spec/acceptance/parsejson_spec.rb +++ b/spec/acceptance/parsejson_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'parsejson function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/parseyaml_spec.rb b/spec/acceptance/parseyaml_spec.rb index 01e0988..4b4bf3d 100644 --- a/spec/acceptance/parseyaml_spec.rb +++ b/spec/acceptance/parseyaml_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'parseyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/pick_default_spec.rb b/spec/acceptance/pick_default_spec.rb index e94a999..a663f54 100644 --- a/spec/acceptance/pick_default_spec.rb +++ b/spec/acceptance/pick_default_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'pick_default function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/pick_spec.rb b/spec/acceptance/pick_spec.rb index 8a768a9..46cf63f 100644 --- a/spec/acceptance/pick_spec.rb +++ b/spec/acceptance/pick_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'pick function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/prefix_spec.rb b/spec/acceptance/prefix_spec.rb index d7b80a8..de55530 100644 --- a/spec/acceptance/prefix_spec.rb +++ b/spec/acceptance/prefix_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'prefix function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/range_spec.rb b/spec/acceptance/range_spec.rb index 0387e4e..a3ccd33 100644 --- a/spec/acceptance/range_spec.rb +++ b/spec/acceptance/range_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'range function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/reject_spec.rb b/spec/acceptance/reject_spec.rb index 52b8755..7f16a00 100644 --- a/spec/acceptance/reject_spec.rb +++ b/spec/acceptance/reject_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'reject function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/reverse_spec.rb b/spec/acceptance/reverse_spec.rb index 29bdc25..c3f0156 100644 --- a/spec/acceptance/reverse_spec.rb +++ b/spec/acceptance/reverse_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'reverse function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/rstrip_spec.rb b/spec/acceptance/rstrip_spec.rb index 11ed60a..b57a8b0 100644 --- a/spec/acceptance/rstrip_spec.rb +++ b/spec/acceptance/rstrip_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'rstrip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/shuffle_spec.rb b/spec/acceptance/shuffle_spec.rb index e22171f..02d1201 100644 --- a/spec/acceptance/shuffle_spec.rb +++ b/spec/acceptance/shuffle_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'shuffle function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/size_spec.rb b/spec/acceptance/size_spec.rb index d79140e..a52b778 100644 --- a/spec/acceptance/size_spec.rb +++ b/spec/acceptance/size_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'size function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/sort_spec.rb b/spec/acceptance/sort_spec.rb index ae7c9db..c85bfab 100644 --- a/spec/acceptance/sort_spec.rb +++ b/spec/acceptance/sort_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'sort function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/squeeze_spec.rb b/spec/acceptance/squeeze_spec.rb index 82e3233..400a458 100644 --- a/spec/acceptance/squeeze_spec.rb +++ b/spec/acceptance/squeeze_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'squeeze function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/str2bool_spec.rb b/spec/acceptance/str2bool_spec.rb index a3ba5fe..cf549da 100644 --- a/spec/acceptance/str2bool_spec.rb +++ b/spec/acceptance/str2bool_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'str2bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/str2saltedsha512_spec.rb b/spec/acceptance/str2saltedsha512_spec.rb index d353e22..993e63b 100644 --- a/spec/acceptance/str2saltedsha512_spec.rb +++ b/spec/acceptance/str2saltedsha512_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'str2saltedsha512 function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/strftime_spec.rb b/spec/acceptance/strftime_spec.rb index 73a01c0..53b7f90 100644 --- a/spec/acceptance/strftime_spec.rb +++ b/spec/acceptance/strftime_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'strftime function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/strip_spec.rb b/spec/acceptance/strip_spec.rb index fe0c7e9..906fd7a 100644 --- a/spec/acceptance/strip_spec.rb +++ b/spec/acceptance/strip_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'strip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/suffix_spec.rb b/spec/acceptance/suffix_spec.rb index 493bc2b..630f866 100644 --- a/spec/acceptance/suffix_spec.rb +++ b/spec/acceptance/suffix_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'suffix function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/swapcase_spec.rb b/spec/acceptance/swapcase_spec.rb index d4ae0dd..b7894fb 100644 --- a/spec/acceptance/swapcase_spec.rb +++ b/spec/acceptance/swapcase_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'swapcase function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/time_spec.rb b/spec/acceptance/time_spec.rb index 2a5e52a..cdb2960 100644 --- a/spec/acceptance/time_spec.rb +++ b/spec/acceptance/time_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'time function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/to_bytes_spec.rb b/spec/acceptance/to_bytes_spec.rb index 34f3647..2b4c61f 100644 --- a/spec/acceptance/to_bytes_spec.rb +++ b/spec/acceptance/to_bytes_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'to_bytes function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/type_spec.rb b/spec/acceptance/type_spec.rb index dc72f74..0043aad 100644 --- a/spec/acceptance/type_spec.rb +++ b/spec/acceptance/type_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'type function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/union_spec.rb b/spec/acceptance/union_spec.rb index f413d9a..6db8d0c 100644 --- a/spec/acceptance/union_spec.rb +++ b/spec/acceptance/union_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'union function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/unique_spec.rb b/spec/acceptance/unique_spec.rb index ea63cb4..bfadad1 100644 --- a/spec/acceptance/unique_spec.rb +++ b/spec/acceptance/unique_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'unique function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/unsupported_spec.rb b/spec/acceptance/unsupported_spec.rb index 449f35a..1c559f6 100644 --- a/spec/acceptance/unsupported_spec.rb +++ b/spec/acceptance/unsupported_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/upcase_spec.rb b/spec/acceptance/upcase_spec.rb index 50e6302..3d2906d 100644 --- a/spec/acceptance/upcase_spec.rb +++ b/spec/acceptance/upcase_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'upcase function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/uriescape_spec.rb b/spec/acceptance/uriescape_spec.rb index 0b8a549..7e30205 100644 --- a/spec/acceptance/uriescape_spec.rb +++ b/spec/acceptance/uriescape_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'uriescape function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_absolute_path_spec.rb b/spec/acceptance/validate_absolute_path_spec.rb index 35ee974..7082e84 100644 --- a/spec/acceptance/validate_absolute_path_spec.rb +++ b/spec/acceptance/validate_absolute_path_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_absolute_path function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_array_spec.rb b/spec/acceptance/validate_array_spec.rb index da9f465..b53e98c 100644 --- a/spec/acceptance/validate_array_spec.rb +++ b/spec/acceptance/validate_array_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_augeas_spec.rb b/spec/acceptance/validate_augeas_spec.rb index 98ee6d1..aeec67a 100644 --- a/spec/acceptance/validate_augeas_spec.rb +++ b/spec/acceptance/validate_augeas_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_augeas function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_bool_spec.rb b/spec/acceptance/validate_bool_spec.rb index 4e77da2..c837f08 100644 --- a/spec/acceptance/validate_bool_spec.rb +++ b/spec/acceptance/validate_bool_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_cmd_spec.rb b/spec/acceptance/validate_cmd_spec.rb index b4d6575..385676d 100644 --- a/spec/acceptance/validate_cmd_spec.rb +++ b/spec/acceptance/validate_cmd_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_cmd function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_hash_spec.rb b/spec/acceptance/validate_hash_spec.rb index d26c9e7..52fb615 100644 --- a/spec/acceptance/validate_hash_spec.rb +++ b/spec/acceptance/validate_hash_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_ipv4_address_spec.rb b/spec/acceptance/validate_ipv4_address_spec.rb index b98b81c..64841c3 100644 --- a/spec/acceptance/validate_ipv4_address_spec.rb +++ b/spec/acceptance/validate_ipv4_address_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_ipv4_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_ipv6_address_spec.rb b/spec/acceptance/validate_ipv6_address_spec.rb index 3e73a82..6426d1a 100644 --- a/spec/acceptance/validate_ipv6_address_spec.rb +++ b/spec/acceptance/validate_ipv6_address_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_ipv6_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_re_spec.rb b/spec/acceptance/validate_re_spec.rb index 8d7e634..22f6d47 100644 --- a/spec/acceptance/validate_re_spec.rb +++ b/spec/acceptance/validate_re_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_re function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_slength_spec.rb b/spec/acceptance/validate_slength_spec.rb index 96b2a6f..1ab2bb9 100644 --- a/spec/acceptance/validate_slength_spec.rb +++ b/spec/acceptance/validate_slength_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_slength function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/validate_string_spec.rb b/spec/acceptance/validate_string_spec.rb index f8658c5..8956f48 100644 --- a/spec/acceptance/validate_string_spec.rb +++ b/spec/acceptance/validate_string_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'validate_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/values_at_spec.rb b/spec/acceptance/values_at_spec.rb index f341e3d..da63cf3 100644 --- a/spec/acceptance/values_at_spec.rb +++ b/spec/acceptance/values_at_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'values_at function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/values_spec.rb b/spec/acceptance/values_spec.rb index 0c12702..7ef956e 100644 --- a/spec/acceptance/values_spec.rb +++ b/spec/acceptance/values_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' describe 'values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do diff --git a/spec/acceptance/zip_spec.rb b/spec/acceptance/zip_spec.rb index a551b80..0e924e8 100644 --- a/spec/acceptance/zip_spec.rb +++ b/spec/acceptance/zip_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' require 'puppet' diff --git a/spec/classes/anchor_spec.rb b/spec/classes/anchor_spec.rb index 2e1fcba..2d4455e 100644 --- a/spec/classes/anchor_spec.rb +++ b/spec/classes/anchor_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' require 'puppet_spec/compiler' diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb index 459d917..33bcac0 100644 --- a/spec/functions/ensure_resource_spec.rb +++ b/spec/functions/ensure_resource_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' require 'rspec-puppet' require 'puppet_spec/compiler' diff --git a/spec/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb index 7f5ad1a..bf024af 100644 --- a/spec/functions/getparam_spec.rb +++ b/spec/functions/getparam_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' require 'rspec-puppet' require 'puppet_spec/compiler' diff --git a/spec/lib/puppet_spec/compiler.rb b/spec/lib/puppet_spec/compiler.rb index 22e923d..2f0ae4d 100644 --- a/spec/lib/puppet_spec/compiler.rb +++ b/spec/lib/puppet_spec/compiler.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec module PuppetSpec::Compiler def compile_to_catalog(string, node = Puppet::Node.new('foonode')) Puppet[:code] = string diff --git a/spec/lib/puppet_spec/database.rb b/spec/lib/puppet_spec/database.rb index 069ca15..f5c2341 100644 --- a/spec/lib/puppet_spec/database.rb +++ b/spec/lib/puppet_spec/database.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec # This just makes some nice things available at global scope, and for setup of # tests to use a real fake database, rather than a fake stubs-that-don't-work # version of the same. Fun times. diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb index 65b04aa..71b38ff 100755 --- a/spec/lib/puppet_spec/files.rb +++ b/spec/lib/puppet_spec/files.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'fileutils' require 'tempfile' require 'tmpdir' diff --git a/spec/lib/puppet_spec/fixtures.rb b/spec/lib/puppet_spec/fixtures.rb index 7f6bc2a..81e9775 100755 --- a/spec/lib/puppet_spec/fixtures.rb +++ b/spec/lib/puppet_spec/fixtures.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec module PuppetSpec::Fixtures def fixtures(*rest) File.join(PuppetSpec::FIXTURE_DIR, *rest) diff --git a/spec/lib/puppet_spec/matchers.rb b/spec/lib/puppet_spec/matchers.rb index 448bd18..093d77c 100644 --- a/spec/lib/puppet_spec/matchers.rb +++ b/spec/lib/puppet_spec/matchers.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'stringio' ######################################################################## diff --git a/spec/lib/puppet_spec/modules.rb b/spec/lib/puppet_spec/modules.rb index 6835e44..910c6d9 100644 --- a/spec/lib/puppet_spec/modules.rb +++ b/spec/lib/puppet_spec/modules.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec module PuppetSpec::Modules class << self def create(name, dir, options = {}) diff --git a/spec/lib/puppet_spec/pops.rb b/spec/lib/puppet_spec/pops.rb index 442c85b..e056a52 100644 --- a/spec/lib/puppet_spec/pops.rb +++ b/spec/lib/puppet_spec/pops.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec module PuppetSpec::Pops extend RSpec::Matchers::DSL diff --git a/spec/lib/puppet_spec/scope.rb b/spec/lib/puppet_spec/scope.rb index c14ab47..3847ede 100644 --- a/spec/lib/puppet_spec/scope.rb +++ b/spec/lib/puppet_spec/scope.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec module PuppetSpec::Scope # Initialize a new scope suitable for testing. diff --git a/spec/lib/puppet_spec/settings.rb b/spec/lib/puppet_spec/settings.rb index f3dbc42..8ddcb97 100644 --- a/spec/lib/puppet_spec/settings.rb +++ b/spec/lib/puppet_spec/settings.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec module PuppetSpec::Settings # It would probably be preferable to refactor defaults.rb such that the real definitions of diff --git a/spec/lib/puppet_spec/verbose.rb b/spec/lib/puppet_spec/verbose.rb index d9834f2..b2683df 100755 --- a/spec/lib/puppet_spec/verbose.rb +++ b/spec/lib/puppet_spec/verbose.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec # Support code for running stuff with warnings disabled. module Kernel def with_verbose_disabled diff --git a/spec/monkey_patches/alias_should_to_must.rb b/spec/monkey_patches/alias_should_to_must.rb index 1a11117..505e240 100755 --- a/spec/monkey_patches/alias_should_to_must.rb +++ b/spec/monkey_patches/alias_should_to_must.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'rspec' class Object diff --git a/spec/monkey_patches/publicize_methods.rb b/spec/monkey_patches/publicize_methods.rb index f3a1abf..3ae59f9 100755 --- a/spec/monkey_patches/publicize_methods.rb +++ b/spec/monkey_patches/publicize_methods.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec # Some monkey-patching to allow us to test private methods. class Class def publicize_methods(*methods) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cf1981b..78925fd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec dir = File.expand_path(File.dirname(__FILE__)) $LOAD_PATH.unshift File.join(dir, 'lib') diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 1a0bba0..f388729 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'beaker-rspec' UNSUPPORTED_PLATFORMS = [] diff --git a/spec/unit/facter/facter_dot_d_spec.rb b/spec/unit/facter/facter_dot_d_spec.rb index 1ecffc8..2fb72b2 100644 --- a/spec/unit/facter/facter_dot_d_spec.rb +++ b/spec/unit/facter/facter_dot_d_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' require 'facter/facter_dot_d' diff --git a/spec/unit/facter/root_home_spec.rb b/spec/unit/facter/root_home_spec.rb index 532fae1..73eb3ea 100644 --- a/spec/unit/facter/root_home_spec.rb +++ b/spec/unit/facter/root_home_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' require 'facter/root_home' diff --git a/spec/unit/facter/util/puppet_settings_spec.rb b/spec/unit/facter/util/puppet_settings_spec.rb index c3ce6ea..e77779b 100644 --- a/spec/unit/facter/util/puppet_settings_spec.rb +++ b/spec/unit/facter/util/puppet_settings_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' require 'facter/util/puppet_settings' 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 diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb index c356bd2..a016b68 100644 --- a/spec/unit/puppet/provider/file_line/ruby_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' require 'tempfile' provider_class = Puppet::Type.type(:file_line).provider(:ruby) diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb index 34d5dad..ab5b81b 100644 --- a/spec/unit/puppet/type/file_line_spec.rb +++ b/spec/unit/puppet/type/file_line_spec.rb @@ -1,3 +1,4 @@ +#! /usr/bin/env ruby -S rspec require 'spec_helper' require 'tempfile' describe Puppet::Type.type(:file_line) do -- cgit v1.2.3 From 890ef5c471027eb164e0296d4fd172a0115319d6 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 6 May 2014 18:48:59 -0700 Subject: Adding more spec coverage --- spec/acceptance/delete_values_spec.rb | 25 +++++++ spec/acceptance/difference_spec.rb | 26 +++++++ spec/acceptance/dirname_spec.rb | 42 +++++++++++ spec/acceptance/downcase_spec.rb | 39 ++++++++++ spec/acceptance/empty_spec.rb | 39 ++++++++++ spec/acceptance/ensure_packages_spec.rb | 24 ++++++ spec/acceptance/ensure_resource_spec.rb | 24 ++++++ spec/acceptance/flatten_spec.rb | 39 ++++++++++ spec/acceptance/floor_spec.rb | 39 ++++++++++ spec/acceptance/fqdn_rotate_spec.rb | 33 +++++++++ spec/acceptance/get_module_path_spec.rb | 41 +++++++++++ spec/acceptance/getparam_spec.rb | 25 +++++++ spec/acceptance/getvar_spec.rb | 26 +++++++ spec/acceptance/grep_spec.rb | 26 +++++++ spec/acceptance/has_interface_with_spec.rb | 44 +++++++++++ spec/acceptance/has_ip_address_spec.rb | 33 +++++++++ spec/acceptance/has_ip_network_spec.rb | 33 +++++++++ spec/acceptance/has_key_spec.rb | 41 +++++++++++ spec/acceptance/hash_spec.rb | 26 +++++++ spec/acceptance/intersection_spec.rb | 27 +++++++ spec/acceptance/is_array_spec.rb | 67 +++++++++++++++++ spec/acceptance/is_bool_spec.rb | 81 ++++++++++++++++++++ spec/acceptance/is_domain_name_spec.rb | 83 +++++++++++++++++++++ spec/acceptance/is_float_spec.rb | 86 ++++++++++++++++++++++ spec/acceptance/is_function_available_spec.rb | 58 +++++++++++++++ spec/acceptance/is_hash_spec.rb | 63 ++++++++++++++++ spec/acceptance/is_integer_spec.rb | 95 ++++++++++++++++++++++++ spec/acceptance/is_ip_address_spec.rb | 80 ++++++++++++++++++++ spec/acceptance/is_mac_address_spec.rb | 38 ++++++++++ spec/acceptance/is_numeric_spec.rb | 95 ++++++++++++++++++++++++ spec/acceptance/is_string_spec.rb | 102 ++++++++++++++++++++++++++ spec/acceptance/join_keys_to_values_spec.rb | 24 ++++++ spec/acceptance/join_spec.rb | 26 +++++++ spec/acceptance/keys_spec.rb | 23 ++++++ spec/acceptance/loadyaml_spec.rb | 31 ++++++++ spec/acceptance/lstrip_spec.rb | 34 +++++++++ spec/acceptance/max_spec.rb | 20 +++++ spec/acceptance/member_spec.rb | 26 +++++++ spec/acceptance/merge_spec.rb | 23 ++++++ spec/acceptance/min_spec.rb | 20 +++++ spec/acceptance/nodesets/centos-6-vcloud.yml | 15 ++++ spec/spec_helper_acceptance.rb | 20 +++-- 42 files changed, 1751 insertions(+), 11 deletions(-) create mode 100644 spec/acceptance/delete_values_spec.rb create mode 100644 spec/acceptance/difference_spec.rb create mode 100644 spec/acceptance/dirname_spec.rb create mode 100644 spec/acceptance/downcase_spec.rb create mode 100644 spec/acceptance/empty_spec.rb create mode 100644 spec/acceptance/ensure_packages_spec.rb create mode 100755 spec/acceptance/ensure_resource_spec.rb create mode 100644 spec/acceptance/flatten_spec.rb create mode 100644 spec/acceptance/floor_spec.rb create mode 100644 spec/acceptance/fqdn_rotate_spec.rb create mode 100644 spec/acceptance/get_module_path_spec.rb create mode 100755 spec/acceptance/getparam_spec.rb create mode 100644 spec/acceptance/getvar_spec.rb create mode 100644 spec/acceptance/grep_spec.rb create mode 100644 spec/acceptance/has_interface_with_spec.rb create mode 100755 spec/acceptance/has_ip_address_spec.rb create mode 100755 spec/acceptance/has_ip_network_spec.rb create mode 100644 spec/acceptance/has_key_spec.rb create mode 100644 spec/acceptance/hash_spec.rb create mode 100644 spec/acceptance/intersection_spec.rb create mode 100644 spec/acceptance/is_array_spec.rb create mode 100644 spec/acceptance/is_bool_spec.rb create mode 100644 spec/acceptance/is_domain_name_spec.rb create mode 100644 spec/acceptance/is_float_spec.rb create mode 100644 spec/acceptance/is_function_available_spec.rb create mode 100644 spec/acceptance/is_hash_spec.rb create mode 100644 spec/acceptance/is_integer_spec.rb create mode 100644 spec/acceptance/is_ip_address_spec.rb create mode 100644 spec/acceptance/is_mac_address_spec.rb create mode 100644 spec/acceptance/is_numeric_spec.rb create mode 100644 spec/acceptance/is_string_spec.rb create mode 100644 spec/acceptance/join_keys_to_values_spec.rb create mode 100644 spec/acceptance/join_spec.rb create mode 100644 spec/acceptance/keys_spec.rb create mode 100644 spec/acceptance/loadyaml_spec.rb create mode 100644 spec/acceptance/lstrip_spec.rb create mode 100644 spec/acceptance/max_spec.rb create mode 100644 spec/acceptance/member_spec.rb create mode 100644 spec/acceptance/merge_spec.rb create mode 100644 spec/acceptance/min_spec.rb create mode 100644 spec/acceptance/nodesets/centos-6-vcloud.yml diff --git a/spec/acceptance/delete_values_spec.rb b/spec/acceptance/delete_values_spec.rb new file mode 100644 index 0000000..6d2369c --- /dev/null +++ b/spec/acceptance/delete_values_spec.rb @@ -0,0 +1,25 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'delete_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'should delete elements of the hash' do + pp = <<-EOS + $a = { 'a' => 'A', 'b' => 'B', 'B' => 'C', 'd' => 'B' } + $b = { 'a' => 'A', 'B' => 'C' } + $o = delete_values($a, 'B') + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles non-hash arguments' + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/difference_spec.rb b/spec/acceptance/difference_spec.rb new file mode 100644 index 0000000..2fae5c4 --- /dev/null +++ b/spec/acceptance/difference_spec.rb @@ -0,0 +1,26 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'difference function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'returns non-duplicates in the first array' do + pp = <<-EOS + $a = ['a','b','c'] + $b = ['b','c','d'] + $c = ['a'] + $o = difference($a, $b) + if $o == $c { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles non-array arguments' + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/dirname_spec.rb b/spec/acceptance/dirname_spec.rb new file mode 100644 index 0000000..97913dd --- /dev/null +++ b/spec/acceptance/dirname_spec.rb @@ -0,0 +1,42 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'dirname function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + context 'absolute path' do + it 'returns the dirname' do + pp = <<-EOS + $a = '/path/to/a/file.txt' + $b = '/path/to/a' + $o = dirname($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + context 'relative path' do + it 'returns the dirname' do + pp = <<-EOS + $a = 'path/to/a/file.txt' + $b = 'path/to/a' + $o = dirname($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + end + describe 'failure' do + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/downcase_spec.rb b/spec/acceptance/downcase_spec.rb new file mode 100644 index 0000000..bc4e706 --- /dev/null +++ b/spec/acceptance/downcase_spec.rb @@ -0,0 +1,39 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'downcase function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'returns the downcase' do + pp = <<-EOS + $a = 'AOEU' + $b = 'aoeu' + $o = downcase($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'doesn\'t affect lowercase words' do + pp = <<-EOS + $a = 'aoeu aoeu' + $b = 'aoeu aoeu' + $o = downcase($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-strings' + end +end diff --git a/spec/acceptance/empty_spec.rb b/spec/acceptance/empty_spec.rb new file mode 100644 index 0000000..8b46aac --- /dev/null +++ b/spec/acceptance/empty_spec.rb @@ -0,0 +1,39 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'empty function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'recognizes empty strings' do + pp = <<-EOS + $a = '' + $b = true + $o = empty($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'recognizes non-empty strings' do + pp = <<-EOS + $a = 'aoeu' + $b = false + $o = empty($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-strings' + end +end diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb new file mode 100644 index 0000000..145bdc5 --- /dev/null +++ b/spec/acceptance/ensure_packages_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'ensure_packages function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'ensure_packages a package' do + apply_manifest('package { "zsh": ensure => absent, }') + pp = <<-EOS + $a = "zsh" + ensure_packages($a) + EOS + + apply_manifest(pp, :expect_changes => true) do |r| + expect(r.stdout).to match(/Package\[zsh\]\/ensure: created/) + end + end + it 'ensures a package already declared' + it 'takes defaults arguments' + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings' + end +end diff --git a/spec/acceptance/ensure_resource_spec.rb b/spec/acceptance/ensure_resource_spec.rb new file mode 100755 index 0000000..c4d8887 --- /dev/null +++ b/spec/acceptance/ensure_resource_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'ensure_resource function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'ensure_resource a package' do + apply_manifest('package { "zsh": ensure => absent, }') + pp = <<-EOS + $a = "zsh" + ensure_resource('package', $a) + EOS + + apply_manifest(pp, :expect_changes => true) do |r| + expect(r.stdout).to match(/Package\[zsh\]\/ensure: created/) + end + end + it 'ensures a resource already declared' + it 'takes defaults arguments' + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings' + end +end diff --git a/spec/acceptance/flatten_spec.rb b/spec/acceptance/flatten_spec.rb new file mode 100644 index 0000000..c4d66e0 --- /dev/null +++ b/spec/acceptance/flatten_spec.rb @@ -0,0 +1,39 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'flatten function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'flattens arrays' do + pp = <<-EOS + $a = ["a","b",["c",["d","e"],"f","g"]] + $b = ["a","b","c","d","e","f","g"] + $o = flatten($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'does not affect flat arrays' do + pp = <<-EOS + $a = ["a","b","c","d","e","f","g"] + $b = ["a","b","c","d","e","f","g"] + $o = flatten($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-strings' + end +end diff --git a/spec/acceptance/floor_spec.rb b/spec/acceptance/floor_spec.rb new file mode 100644 index 0000000..0dcdad9 --- /dev/null +++ b/spec/acceptance/floor_spec.rb @@ -0,0 +1,39 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'floor function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'floors floats' do + pp = <<-EOS + $a = 12.8 + $b = 12 + $o = floor($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'floors integers' do + pp = <<-EOS + $a = 7 + $b = 7 + $o = floor($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-numbers' + end +end diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb new file mode 100644 index 0000000..b7f8bf8 --- /dev/null +++ b/spec/acceptance/fqdn_rotate_spec.rb @@ -0,0 +1,33 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + let(:facts_d) do + if fact('is_pe') == "true" + '/etc/puppetlabs/facter/facts.d' + else + '/etc/facter/facts.d' + end + end + after :each do + shell("if [ -f #{facts_d}/fqdn.txt ] ; then rm #{facts_d}/fqdn.txt ; fi") + end + it 'fqdn_rotates floats' do + shell("echo 'fqdn=fakehost.localdomain' > #{facts_d}/fqdn.txt") + pp = <<-EOS + $a = ['a','b','c','d'] + $o = fqdn_rotate($a) + notice(inline_template('fqdn_rotate is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rotate is \["c", "d", "a", "b"\]/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-numbers' + end +end diff --git a/spec/acceptance/get_module_path_spec.rb b/spec/acceptance/get_module_path_spec.rb new file mode 100644 index 0000000..34d91fa --- /dev/null +++ b/spec/acceptance/get_module_path_spec.rb @@ -0,0 +1,41 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'get_module_path function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'get_module_paths stdlib' do + pp = <<-EOS + $a = $::is_pe ? { + 'true' => '/opt/puppet/share/puppet/modules/stdlib', + 'false' => '/etc/puppet/modules/stdlib', + } + $o = get_module_path('stdlib') + if $o == $a { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'get_module_paths dne' do + pp = <<-EOS + $a = $::is_pe ? { + 'true' => '/etc/puppetlabs/puppet/modules/dne', + 'false' => '/etc/puppet/modules/dne', + } + $o = get_module_path('dne') + if $o == $a { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :expect_failures => true) + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-numbers' + end +end diff --git a/spec/acceptance/getparam_spec.rb b/spec/acceptance/getparam_spec.rb new file mode 100755 index 0000000..a84b2d1 --- /dev/null +++ b/spec/acceptance/getparam_spec.rb @@ -0,0 +1,25 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'getparam function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'getparam a package' do + pp = <<-EOS + user { "rspec": + ensure => present, + managehome => true, + } + $o = getparam(User['rspec'], 'managehome') + notice(inline_template('getparam is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :expect_changes => true) do |r| + expect(r.stdout).to match(/getparam is true/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings' + end +end diff --git a/spec/acceptance/getvar_spec.rb b/spec/acceptance/getvar_spec.rb new file mode 100644 index 0000000..333c467 --- /dev/null +++ b/spec/acceptance/getvar_spec.rb @@ -0,0 +1,26 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'getvar function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'getvars from classes' do + pp = <<-EOS + class a::data { $foo = 'aoeu' } + include a::data + $b = 'aoeu' + $o = getvar("a::data::foo") + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-numbers' + end +end diff --git a/spec/acceptance/grep_spec.rb b/spec/acceptance/grep_spec.rb new file mode 100644 index 0000000..b39d48e --- /dev/null +++ b/spec/acceptance/grep_spec.rb @@ -0,0 +1,26 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'grep function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'greps arrays' do + pp = <<-EOS + $a = ['aaabbb','bbbccc','dddeee'] + $b = 'bbb' + $c = ['aaabbb','bbbccc'] + $o = grep($a,$b) + if $o == $c { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-arrays' + end +end diff --git a/spec/acceptance/has_interface_with_spec.rb b/spec/acceptance/has_interface_with_spec.rb new file mode 100644 index 0000000..41ae19f --- /dev/null +++ b/spec/acceptance/has_interface_with_spec.rb @@ -0,0 +1,44 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'has_interface_with function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'has_interface_with existing ipaddress' do + pp = <<-EOS + $a = '127.0.0.1' + $o = has_interface_with('ipaddress', $a) + notice(inline_template('has_interface_with is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/has_interface_with is true/) + end + end + it 'has_interface_with absent ipaddress' do + pp = <<-EOS + $a = '128.0.0.1' + $o = has_interface_with('ipaddress', $a) + notice(inline_template('has_interface_with is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/has_interface_with is false/) + end + end + it 'has_interface_with existing interface' do + pp = <<-EOS + $a = 'lo' + $o = has_interface_with($a) + notice(inline_template('has_interface_with is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/has_interface_with is true/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings' + end +end diff --git a/spec/acceptance/has_ip_address_spec.rb b/spec/acceptance/has_ip_address_spec.rb new file mode 100755 index 0000000..7d5fd87 --- /dev/null +++ b/spec/acceptance/has_ip_address_spec.rb @@ -0,0 +1,33 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'has_ip_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'has_ip_address existing ipaddress' do + pp = <<-EOS + $a = '127.0.0.1' + $o = has_ip_address($a) + notice(inline_template('has_ip_address is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/has_ip_address is true/) + end + end + it 'has_ip_address absent ipaddress' do + pp = <<-EOS + $a = '128.0.0.1' + $o = has_ip_address($a) + notice(inline_template('has_ip_address is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/has_ip_address is false/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings' + end +end diff --git a/spec/acceptance/has_ip_network_spec.rb b/spec/acceptance/has_ip_network_spec.rb new file mode 100755 index 0000000..692eaf9 --- /dev/null +++ b/spec/acceptance/has_ip_network_spec.rb @@ -0,0 +1,33 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'has_ip_network function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'has_ip_network existing ipaddress' do + pp = <<-EOS + $a = '127.0.0.0' + $o = has_ip_network($a) + notice(inline_template('has_ip_network is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/has_ip_network is true/) + end + end + it 'has_ip_network absent ipaddress' do + pp = <<-EOS + $a = '128.0.0.0' + $o = has_ip_network($a) + notice(inline_template('has_ip_network is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/has_ip_network is false/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings' + end +end diff --git a/spec/acceptance/has_key_spec.rb b/spec/acceptance/has_key_spec.rb new file mode 100644 index 0000000..c8557cb --- /dev/null +++ b/spec/acceptance/has_key_spec.rb @@ -0,0 +1,41 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'has_key function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'has_keys in hashes' do + pp = <<-EOS + $a = { 'aaa' => 'bbb','bbb' => 'ccc','ddd' => 'eee' } + $b = 'bbb' + $c = true + $o = has_key($a,$b) + if $o == $c { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'has_keys not in hashes' do + pp = <<-EOS + $a = { 'aaa' => 'bbb','bbb' => 'ccc','ddd' => 'eee' } + $b = 'ccc' + $c = false + $o = has_key($a,$b) + if $o == $c { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-hashes' + end +end diff --git a/spec/acceptance/hash_spec.rb b/spec/acceptance/hash_spec.rb new file mode 100644 index 0000000..ed53834 --- /dev/null +++ b/spec/acceptance/hash_spec.rb @@ -0,0 +1,26 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'hashs arrays' do + pp = <<-EOS + $a = ['aaa','bbb','bbb','ccc','ddd','eee'] + $b = { 'aaa' => 'bbb', 'bbb' => 'ccc', 'ddd' => 'eee' } + $o = hash($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'handles odd-length arrays' + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-arrays' + end +end diff --git a/spec/acceptance/intersection_spec.rb b/spec/acceptance/intersection_spec.rb new file mode 100644 index 0000000..66b8652 --- /dev/null +++ b/spec/acceptance/intersection_spec.rb @@ -0,0 +1,27 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'intersection function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'intersections arrays' do + pp = <<-EOS + $a = ['aaa','bbb','ccc'] + $b = ['bbb','ccc','ddd','eee'] + $c = ['bbb','ccc'] + $o = intersection($a,$b) + if $o == $c { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'intersections empty arrays' + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-arrays' + end +end diff --git a/spec/acceptance/is_array_spec.rb b/spec/acceptance/is_array_spec.rb new file mode 100644 index 0000000..9c6bad7 --- /dev/null +++ b/spec/acceptance/is_array_spec.rb @@ -0,0 +1,67 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_arrays arrays' do + pp = <<-EOS + $a = ['aaa','bbb','ccc'] + $b = true + $o = is_array($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_arrays empty arrays' do + pp = <<-EOS + $a = [] + $b = true + $o = is_array($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_arrays strings' do + pp = <<-EOS + $a = "aoeu" + $b = false + $o = is_array($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_arrays hashes' do + pp = <<-EOS + $a = {'aaa'=>'bbb'} + $b = false + $o = is_array($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-arrays' + end +end diff --git a/spec/acceptance/is_bool_spec.rb b/spec/acceptance/is_bool_spec.rb new file mode 100644 index 0000000..60079f9 --- /dev/null +++ b/spec/acceptance/is_bool_spec.rb @@ -0,0 +1,81 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_bools arrays' do + pp = <<-EOS + $a = ['aaa','bbb','ccc'] + $b = false + $o = is_bool($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_bools true' do + pp = <<-EOS + $a = true + $b = true + $o = is_bool($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_bools false' do + pp = <<-EOS + $a = false + $b = true + $o = is_bool($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_bools strings' do + pp = <<-EOS + $a = "true" + $b = false + $o = is_bool($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_bools hashes' do + pp = <<-EOS + $a = {'aaa'=>'bbb'} + $b = false + $o = is_bool($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-arrays' + end +end diff --git a/spec/acceptance/is_domain_name_spec.rb b/spec/acceptance/is_domain_name_spec.rb new file mode 100644 index 0000000..e0f03fa --- /dev/null +++ b/spec/acceptance/is_domain_name_spec.rb @@ -0,0 +1,83 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_domain_name function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_domain_names arrays' do + pp = <<-EOS + $a = ['aaa.com','bbb','ccc'] + $o = is_domain_name($a) + notice(inline_template('is_domain_name is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_domain_name is false/) + end + end + it 'is_domain_names true' do + pp = <<-EOS + $a = true + $o = is_domain_name($a) + notice(inline_template('is_domain_name is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_domain_name is false/) + end + end + it 'is_domain_names false' do + pp = <<-EOS + $a = false + $o = is_domain_name($a) + notice(inline_template('is_domain_name is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_domain_name is false/) + end + end + it 'is_domain_names strings with hyphens' do + pp = <<-EOS + $a = "3foo-bar.2bar-fuzz.com" + $b = true + $o = is_domain_name($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_domain_names strings beginning with hyphens' do + pp = <<-EOS + $a = "-bar.2bar-fuzz.com" + $b = false + $o = is_domain_name($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_domain_names hashes' do + pp = <<-EOS + $a = {'aaa'=>'www.com'} + $o = is_domain_name($a) + notice(inline_template('is_domain_name is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_domain_name is false/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-arrays' + end +end diff --git a/spec/acceptance/is_float_spec.rb b/spec/acceptance/is_float_spec.rb new file mode 100644 index 0000000..79b01f0 --- /dev/null +++ b/spec/acceptance/is_float_spec.rb @@ -0,0 +1,86 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_floats arrays' do + pp = <<-EOS + $a = ['aaa.com','bbb','ccc'] + $o = is_float($a) + notice(inline_template('is_floats is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_float is false/) + end + end + it 'is_floats true' do + pp = <<-EOS + $a = true + $o = is_float($a) + notice(inline_template('is_floats is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_float is false/) + end + end + it 'is_floats strings' do + pp = <<-EOS + $a = "3.5" + $b = true + $o = is_float($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_floats floats' do + pp = <<-EOS + $a = 3.5 + $b = true + $o = is_float($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_floats integers' do + pp = <<-EOS + $a = 3 + $b = false + $o = is_float($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_floats hashes' do + pp = <<-EOS + $a = {'aaa'=>'www.com'} + $o = is_float($a) + notice(inline_template('is_float is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_floats is false/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-arrays' + end +end diff --git a/spec/acceptance/is_function_available_spec.rb b/spec/acceptance/is_function_available_spec.rb new file mode 100644 index 0000000..2b5dd6d --- /dev/null +++ b/spec/acceptance/is_function_available_spec.rb @@ -0,0 +1,58 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_function_available function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_function_availables arrays' do + pp = <<-EOS + $a = ['fail','include','require'] + $o = is_function_available($a) + notice(inline_template('is_function_available is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_function_available is false/) + end + end + it 'is_function_availables true' do + pp = <<-EOS + $a = true + $o = is_function_available($a) + notice(inline_template('is_function_available is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_function_available is false/) + end + end + it 'is_function_availables strings' do + pp = <<-EOS + $a = "fail" + $b = true + $o = is_function_available($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_function_availables function_availables' do + pp = <<-EOS + $a = "is_function_available" + $o = is_function_available($a) + notice(inline_template('is_function_available is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_function_available is true/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-arrays' + end +end diff --git a/spec/acceptance/is_hash_spec.rb b/spec/acceptance/is_hash_spec.rb new file mode 100644 index 0000000..2ef310a --- /dev/null +++ b/spec/acceptance/is_hash_spec.rb @@ -0,0 +1,63 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_hashs arrays' do + pp = <<-EOS + $a = ['aaa','bbb','ccc'] + $o = is_hash($a) + notice(inline_template('is_hash is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_hash is false/) + end + end + it 'is_hashs empty hashs' do + pp = <<-EOS + $a = {} + $b = true + $o = is_hash($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_hashs strings' do + pp = <<-EOS + $a = "aoeu" + $b = false + $o = is_hash($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_hashs hashes' do + pp = <<-EOS + $a = {'aaa'=>'bbb'} + $b = true + $o = is_hash($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/is_integer_spec.rb b/spec/acceptance/is_integer_spec.rb new file mode 100644 index 0000000..bf6902b --- /dev/null +++ b/spec/acceptance/is_integer_spec.rb @@ -0,0 +1,95 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_integer function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_integers arrays' do + pp = <<-EOS + $a = ['aaa.com','bbb','ccc'] + $b = false + $o = is_integer($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_integers true' do + pp = <<-EOS + $a = true + $b = false + $o = is_integer($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_integers strings' do + pp = <<-EOS + $a = "3" + $b = true + $o = is_integer($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_integers floats' do + pp = <<-EOS + $a = 3.5 + $b = false + $o = is_integer($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_integers integers' do + pp = <<-EOS + $a = 3 + $b = true + $o = is_integer($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_integers hashes' do + pp = <<-EOS + $a = {'aaa'=>'www.com'} + $b = false + $o = is_integer($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-arrays' + end +end diff --git a/spec/acceptance/is_ip_address_spec.rb b/spec/acceptance/is_ip_address_spec.rb new file mode 100644 index 0000000..ed7a854 --- /dev/null +++ b/spec/acceptance/is_ip_address_spec.rb @@ -0,0 +1,80 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_ip_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_ip_addresss ipv4' do + pp = <<-EOS + $a = '1.2.3.4' + $b = true + $o = is_ip_address($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_ip_addresss ipv6' do + pp = <<-EOS + $a = "fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74" + $b = true + $o = is_ip_address($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_ip_addresss ipv6 compressed' do + pp = <<-EOS + $a = "fe00::1" + $b = true + $o = is_ip_address($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_ip_addresss strings' do + pp = <<-EOS + $a = "aoeu" + $b = false + $o = is_ip_address($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_ip_addresss ipv4 out of range' do + pp = <<-EOS + $a = '1.2.3.400' + $b = false + $o = is_ip_address($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/is_mac_address_spec.rb b/spec/acceptance/is_mac_address_spec.rb new file mode 100644 index 0000000..a2c892f --- /dev/null +++ b/spec/acceptance/is_mac_address_spec.rb @@ -0,0 +1,38 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_mac_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_mac_addresss a mac' do + pp = <<-EOS + $a = '00:a0:1f:12:7f:a0' + $b = true + $o = is_mac_address($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_mac_addresss a mac out of range' do + pp = <<-EOS + $a = '00:a0:1f:12:7f:g0' + $b = false + $o = is_mac_address($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/is_numeric_spec.rb b/spec/acceptance/is_numeric_spec.rb new file mode 100644 index 0000000..21c8988 --- /dev/null +++ b/spec/acceptance/is_numeric_spec.rb @@ -0,0 +1,95 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_numeric function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_numerics arrays' do + pp = <<-EOS + $a = ['aaa.com','bbb','ccc'] + $b = false + $o = is_numeric($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_numerics true' do + pp = <<-EOS + $a = true + $b = false + $o = is_numeric($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_numerics strings' do + pp = <<-EOS + $a = "3" + $b = true + $o = is_numeric($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_numerics floats' do + pp = <<-EOS + $a = 3.5 + $b = true + $o = is_numeric($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_numerics integers' do + pp = <<-EOS + $a = 3 + $b = true + $o = is_numeric($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_numerics hashes' do + pp = <<-EOS + $a = {'aaa'=>'www.com'} + $b = false + $o = is_numeric($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-arrays' + end +end diff --git a/spec/acceptance/is_string_spec.rb b/spec/acceptance/is_string_spec.rb new file mode 100644 index 0000000..bda6cd7 --- /dev/null +++ b/spec/acceptance/is_string_spec.rb @@ -0,0 +1,102 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'is_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'is_strings arrays' do + pp = <<-EOS + $a = ['aaa.com','bbb','ccc'] + $b = false + $o = is_string($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_strings true' do + pp = <<-EOS + $a = true + $b = false + $o = is_string($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_strings strings' do + pp = <<-EOS + $a = "aoeu" + $o = is_string($a) + notice(inline_template('is_string is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_string is true/) + end + end + it 'is_strings number strings' do + pp = <<-EOS + $a = "3" + $o = is_string($a) + notice(inline_template('is_string is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/is_string is true/) + end + end + it 'is_strings floats' do + pp = <<-EOS + $a = 3.5 + $b = false + $o = is_string($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_strings integers' do + pp = <<-EOS + $a = 3 + $b = false + $o = is_string($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'is_strings hashes' do + pp = <<-EOS + $a = {'aaa'=>'www.com'} + $b = false + $o = is_string($a) + if $o == $b { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/join_keys_to_values_spec.rb b/spec/acceptance/join_keys_to_values_spec.rb new file mode 100644 index 0000000..70493fd --- /dev/null +++ b/spec/acceptance/join_keys_to_values_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'join_keys_to_values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'join_keys_to_valuess hashes' do + pp = <<-EOS + $a = {'aaa'=>'bbb','ccc'=>'ddd'} + $b = ':' + $o = join_keys_to_values($a,$b) + notice(inline_template('join_keys_to_values is <%= @o.sort.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/join_keys_to_values is \["aaa:bbb", "ccc:ddd"\]/) + end + end + it 'handles non hashes' + it 'handles empty hashes' + end + describe 'failure' do + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/join_spec.rb b/spec/acceptance/join_spec.rb new file mode 100644 index 0000000..5397ce2 --- /dev/null +++ b/spec/acceptance/join_spec.rb @@ -0,0 +1,26 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'join function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'joins arrays' do + pp = <<-EOS + $a = ['aaa','bbb','ccc'] + $b = ':' + $c = 'aaa:bbb:ccc' + $o = join($a,$b) + if $o == $c { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'handles non arrays' + end + describe 'failure' do + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/keys_spec.rb b/spec/acceptance/keys_spec.rb new file mode 100644 index 0000000..176918e --- /dev/null +++ b/spec/acceptance/keys_spec.rb @@ -0,0 +1,23 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'keys function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'keyss hashes' do + pp = <<-EOS + $a = {'aaa'=>'bbb','ccc'=>'ddd'} + $o = keys($a) + notice(inline_template('keys is <%= @o.sort.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/keys is \["aaa", "ccc"\]/) + end + end + it 'handles non hashes' + it 'handles empty hashes' + end + describe 'failure' do + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/loadyaml_spec.rb b/spec/acceptance/loadyaml_spec.rb new file mode 100644 index 0000000..944a727 --- /dev/null +++ b/spec/acceptance/loadyaml_spec.rb @@ -0,0 +1,31 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'loadyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'loadyamls array of values' do + shell('echo "--- + aaa: 1 + bbb: 2 + ccc: 3 + ddd: 4" > /testyaml.yaml') + pp = <<-EOS + $o = loadyaml('/testyaml.yaml') + notice(inline_template('loadyaml[aaa] is <%= @o["aaa"].inspect %>')) + notice(inline_template('loadyaml[bbb] is <%= @o["bbb"].inspect %>')) + notice(inline_template('loadyaml[ccc] is <%= @o["ccc"].inspect %>')) + notice(inline_template('loadyaml[ddd] is <%= @o["ddd"].inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/loadyaml\[aaa\] is 1/) + expect(r.stdout).to match(/loadyaml\[bbb\] is 2/) + expect(r.stdout).to match(/loadyaml\[ccc\] is 3/) + expect(r.stdout).to match(/loadyaml\[ddd\] is 4/) + end + end + end + describe 'failure' do + it 'fails with no arguments' + end +end diff --git a/spec/acceptance/lstrip_spec.rb b/spec/acceptance/lstrip_spec.rb new file mode 100644 index 0000000..3dc952f --- /dev/null +++ b/spec/acceptance/lstrip_spec.rb @@ -0,0 +1,34 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'lstrip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'lstrips arrays' do + pp = <<-EOS + $a = [" the "," public "," art","galleries "] + # Anagram: Large picture halls, I bet + $o = lstrip($a) + notice(inline_template('lstrip is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/lstrip is \["the ", "public ", "art", "galleries "\]/) + end + end + it 'lstrips strings' do + pp = <<-EOS + $a = " blowzy night-frumps vex'd jack q " + $o = lstrip($a) + notice(inline_template('lstrip is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/lstrip is "blowzy night-frumps vex'd jack q "/) + end + end + end + describe 'failure' do + it 'handles no arguments' + it 'handles non strings or arrays' + end +end diff --git a/spec/acceptance/max_spec.rb b/spec/acceptance/max_spec.rb new file mode 100644 index 0000000..f04e3d2 --- /dev/null +++ b/spec/acceptance/max_spec.rb @@ -0,0 +1,20 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'max function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'maxs arrays' do + pp = <<-EOS + $o = max("the","public","art","galleries") + notice(inline_template('max is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/max is "the"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + end +end diff --git a/spec/acceptance/member_spec.rb b/spec/acceptance/member_spec.rb new file mode 100644 index 0000000..b467dbb --- /dev/null +++ b/spec/acceptance/member_spec.rb @@ -0,0 +1,26 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'member function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'members arrays' do + pp = <<-EOS + $a = ['aaa','bbb','ccc'] + $b = 'ccc' + $c = true + $o = member($a,$b) + if $o == $c { + notify { 'output correct': } + } + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + it 'members arrays without members' + end + describe 'failure' do + it 'handles improper argument counts' + end +end diff --git a/spec/acceptance/merge_spec.rb b/spec/acceptance/merge_spec.rb new file mode 100644 index 0000000..a60e784 --- /dev/null +++ b/spec/acceptance/merge_spec.rb @@ -0,0 +1,23 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'merge function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'should merge two hashes' do + pp = <<-EOS + $a = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } } + $b = {'two' => 'dos', 'three' => { 'five' => 5 } } + $o = merge($a, $b) + notice(inline_template('merge[one] is <%= @o["one"].inspect %>')) + notice(inline_template('merge[two] is <%= @o["two"].inspect %>')) + notice(inline_template('merge[three] is <%= @o["three"].inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/merge\[one\] is "1"/) + expect(r.stdout).to match(/merge\[two\] is "dos"/) + expect(r.stdout).to match(/merge\[three\] is {"five"=>"5"}/) + end + end + end +end diff --git a/spec/acceptance/min_spec.rb b/spec/acceptance/min_spec.rb new file mode 100644 index 0000000..509092d --- /dev/null +++ b/spec/acceptance/min_spec.rb @@ -0,0 +1,20 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'min function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + describe 'success' do + it 'mins arrays' do + pp = <<-EOS + $o = min("the","public","art","galleries") + notice(inline_template('min is <%= @o.inspect %>')) + EOS + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/min is "art"/) + end + end + end + describe 'failure' do + it 'handles no arguments' + end +end diff --git a/spec/acceptance/nodesets/centos-6-vcloud.yml b/spec/acceptance/nodesets/centos-6-vcloud.yml new file mode 100644 index 0000000..ca9c1d3 --- /dev/null +++ b/spec/acceptance/nodesets/centos-6-vcloud.yml @@ -0,0 +1,15 @@ +HOSTS: + 'centos-6-vcloud': + roles: + - master + platform: el-6-x86_64 + hypervisor: vcloud + template: centos-6-x86_64 +CONFIG: + type: foss + ssh: + keys: "~/.ssh/id_rsa-acceptance" + datastore: instance0 + folder: Delivery/Quality Assurance/Enterprise/Dynamic + resourcepool: delivery/Quality Assurance/Enterprise/Dynamic + pooling_api: http://vcloud.delivery.puppetlabs.net/ diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index f388729..8e56daa 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -4,14 +4,16 @@ require 'beaker-rspec' UNSUPPORTED_PLATFORMS = [] unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' + if hosts.first.is_pe? + install_pe + on hosts, 'mkdir -p /etc/puppetlabs/facter/facts.d' + else + install_puppet + on hosts, 'mkdir -p /etc/facter/facts.d' + on hosts, '/bin/touch /etc/puppet/hiera.yaml' + end hosts.each do |host| - # Install Puppet - if host.is_pe? - install_pe - else - install_puppet - on host, "mkdir -p #{host['distmoduledir']}" - end + on host, "mkdir -p #{host['distmoduledir']}" end end @@ -24,10 +26,6 @@ RSpec.configure do |c| # Configure all nodes in nodeset c.before :suite do - # Install module and dependencies puppet_module_install(:source => proj_root, :module_name => 'stdlib') - hosts.each do |host| - shell('/bin/touch /etc/puppet/hiera.yaml') - end end end -- 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 --- spec/functions/defined_with_params_spec.rb | 37 ------- spec/functions/ensure_packages_spec.rb | 81 --------------- spec/functions/ensure_resource_spec.rb | 113 --------------------- spec/functions/getparam_spec.rb | 76 -------------- .../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 ++++++++++++++ 8 files changed, 307 insertions(+), 307 deletions(-) delete mode 100644 spec/functions/defined_with_params_spec.rb delete mode 100644 spec/functions/ensure_packages_spec.rb delete mode 100644 spec/functions/ensure_resource_spec.rb delete mode 100644 spec/functions/getparam_spec.rb 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 diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb deleted file mode 100644 index 28dbab3..0000000 --- a/spec/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/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb deleted file mode 100644 index 436be10..0000000 --- a/spec/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/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb deleted file mode 100644 index 33bcac0..0000000 --- a/spec/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/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb deleted file mode 100644 index bf024af..0000000 --- a/spec/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/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/acceptance/abs_spec.rb | 0 spec/acceptance/any2array_spec.rb | 0 spec/acceptance/base64_spec.rb | 0 spec/acceptance/bool2num_spec.rb | 0 spec/acceptance/build_csv.rb | 0 spec/acceptance/capitalize_spec.rb | 0 spec/acceptance/chomp_spec.rb | 0 spec/acceptance/chop_spec.rb | 0 spec/acceptance/concat_spec.rb | 0 spec/acceptance/count_spec.rb | 0 spec/acceptance/deep_merge_spec.rb | 0 spec/acceptance/defined_with_params_spec.rb | 0 spec/acceptance/delete_at_spec.rb | 0 spec/acceptance/delete_spec.rb | 0 spec/acceptance/delete_undef_values_spec.rb | 0 spec/acceptance/delete_values_spec.rb | 0 spec/acceptance/difference_spec.rb | 0 spec/acceptance/dirname_spec.rb | 0 spec/acceptance/downcase_spec.rb | 0 spec/acceptance/empty_spec.rb | 0 spec/acceptance/ensure_packages_spec.rb | 0 spec/acceptance/flatten_spec.rb | 0 spec/acceptance/floor_spec.rb | 0 spec/acceptance/fqdn_rotate_spec.rb | 0 spec/acceptance/get_module_path_spec.rb | 0 spec/acceptance/getvar_spec.rb | 0 spec/acceptance/grep_spec.rb | 0 spec/acceptance/has_interface_with_spec.rb | 0 spec/acceptance/has_key_spec.rb | 0 spec/acceptance/hash_spec.rb | 0 spec/acceptance/intersection_spec.rb | 0 spec/acceptance/is_array_spec.rb | 0 spec/acceptance/is_bool_spec.rb | 0 spec/acceptance/is_domain_name_spec.rb | 0 spec/acceptance/is_float_spec.rb | 0 spec/acceptance/is_function_available_spec.rb | 0 spec/acceptance/is_hash_spec.rb | 0 spec/acceptance/is_integer_spec.rb | 0 spec/acceptance/is_ip_address_spec.rb | 0 spec/acceptance/is_mac_address_spec.rb | 0 spec/acceptance/is_numeric_spec.rb | 0 spec/acceptance/is_string_spec.rb | 0 spec/acceptance/join_keys_to_values_spec.rb | 0 spec/acceptance/join_spec.rb | 0 spec/acceptance/keys_spec.rb | 0 spec/acceptance/lstrip_spec.rb | 0 spec/acceptance/max_spec.rb | 0 spec/acceptance/member_spec.rb | 0 spec/acceptance/merge_spec.rb | 0 spec/acceptance/min_spec.rb | 0 spec/acceptance/num2bool_spec.rb | 0 spec/acceptance/parsejson_spec.rb | 0 spec/acceptance/parseyaml_spec.rb | 0 spec/acceptance/pick_default_spec.rb | 0 spec/acceptance/pick_spec.rb | 0 spec/acceptance/prefix_spec.rb | 0 spec/acceptance/range_spec.rb | 0 spec/acceptance/reject_spec.rb | 0 spec/acceptance/reverse_spec.rb | 0 spec/acceptance/rstrip_spec.rb | 0 spec/acceptance/shuffle_spec.rb | 0 spec/acceptance/size_spec.rb | 0 spec/acceptance/sort_spec.rb | 0 spec/acceptance/squeeze_spec.rb | 0 spec/acceptance/str2bool_spec.rb | 0 spec/acceptance/str2saltedsha512_spec.rb | 0 spec/acceptance/strftime_spec.rb | 0 spec/acceptance/strip_spec.rb | 0 spec/acceptance/suffix_spec.rb | 0 spec/acceptance/swapcase_spec.rb | 0 spec/acceptance/time_spec.rb | 0 spec/acceptance/to_bytes_spec.rb | 0 spec/acceptance/type_spec.rb | 0 spec/acceptance/union_spec.rb | 0 spec/acceptance/unique_spec.rb | 0 spec/acceptance/unsupported_spec.rb | 0 spec/acceptance/upcase_spec.rb | 0 spec/acceptance/uriescape_spec.rb | 0 spec/acceptance/validate_absolute_path_spec.rb | 0 spec/acceptance/validate_array_spec.rb | 0 spec/acceptance/validate_augeas_spec.rb | 0 spec/acceptance/validate_bool_spec.rb | 0 spec/acceptance/validate_cmd_spec.rb | 0 spec/acceptance/validate_hash_spec.rb | 0 spec/acceptance/validate_ipv4_address_spec.rb | 0 spec/acceptance/validate_ipv6_address_spec.rb | 0 spec/acceptance/validate_re_spec.rb | 0 spec/acceptance/validate_slength_spec.rb | 0 spec/acceptance/validate_string_spec.rb | 0 spec/acceptance/values_at_spec.rb | 0 spec/acceptance/values_spec.rb | 0 spec/acceptance/zip_spec.rb | 0 spec/classes/anchor_spec.rb | 0 spec/lib/puppet_spec/compiler.rb | 0 spec/lib/puppet_spec/database.rb | 0 spec/lib/puppet_spec/matchers.rb | 0 spec/lib/puppet_spec/modules.rb | 0 spec/lib/puppet_spec/pops.rb | 0 spec/lib/puppet_spec/scope.rb | 0 spec/lib/puppet_spec/settings.rb | 0 spec/spec_helper.rb | 0 spec/spec_helper_acceptance.rb | 0 spec/unit/facter/facter_dot_d_spec.rb | 0 spec/unit/facter/pe_version_spec.rb | 0 spec/unit/facter/root_home_spec.rb | 0 spec/unit/facter/util/puppet_settings_spec.rb | 0 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 spec/unit/puppet/provider/file_line/ruby_spec.rb | 0 spec/unit/puppet/type/anchor_spec.rb | 0 spec/unit/puppet/type/file_line_spec.rb | 0 182 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 spec/acceptance/abs_spec.rb mode change 100644 => 100755 spec/acceptance/any2array_spec.rb mode change 100644 => 100755 spec/acceptance/base64_spec.rb mode change 100644 => 100755 spec/acceptance/bool2num_spec.rb mode change 100644 => 100755 spec/acceptance/build_csv.rb mode change 100644 => 100755 spec/acceptance/capitalize_spec.rb mode change 100644 => 100755 spec/acceptance/chomp_spec.rb mode change 100644 => 100755 spec/acceptance/chop_spec.rb mode change 100644 => 100755 spec/acceptance/concat_spec.rb mode change 100644 => 100755 spec/acceptance/count_spec.rb mode change 100644 => 100755 spec/acceptance/deep_merge_spec.rb mode change 100644 => 100755 spec/acceptance/defined_with_params_spec.rb mode change 100644 => 100755 spec/acceptance/delete_at_spec.rb mode change 100644 => 100755 spec/acceptance/delete_spec.rb mode change 100644 => 100755 spec/acceptance/delete_undef_values_spec.rb mode change 100644 => 100755 spec/acceptance/delete_values_spec.rb mode change 100644 => 100755 spec/acceptance/difference_spec.rb mode change 100644 => 100755 spec/acceptance/dirname_spec.rb mode change 100644 => 100755 spec/acceptance/downcase_spec.rb mode change 100644 => 100755 spec/acceptance/empty_spec.rb mode change 100644 => 100755 spec/acceptance/ensure_packages_spec.rb mode change 100644 => 100755 spec/acceptance/flatten_spec.rb mode change 100644 => 100755 spec/acceptance/floor_spec.rb mode change 100644 => 100755 spec/acceptance/fqdn_rotate_spec.rb mode change 100644 => 100755 spec/acceptance/get_module_path_spec.rb mode change 100644 => 100755 spec/acceptance/getvar_spec.rb mode change 100644 => 100755 spec/acceptance/grep_spec.rb mode change 100644 => 100755 spec/acceptance/has_interface_with_spec.rb mode change 100644 => 100755 spec/acceptance/has_key_spec.rb mode change 100644 => 100755 spec/acceptance/hash_spec.rb mode change 100644 => 100755 spec/acceptance/intersection_spec.rb mode change 100644 => 100755 spec/acceptance/is_array_spec.rb mode change 100644 => 100755 spec/acceptance/is_bool_spec.rb mode change 100644 => 100755 spec/acceptance/is_domain_name_spec.rb mode change 100644 => 100755 spec/acceptance/is_float_spec.rb mode change 100644 => 100755 spec/acceptance/is_function_available_spec.rb mode change 100644 => 100755 spec/acceptance/is_hash_spec.rb mode change 100644 => 100755 spec/acceptance/is_integer_spec.rb mode change 100644 => 100755 spec/acceptance/is_ip_address_spec.rb mode change 100644 => 100755 spec/acceptance/is_mac_address_spec.rb mode change 100644 => 100755 spec/acceptance/is_numeric_spec.rb mode change 100644 => 100755 spec/acceptance/is_string_spec.rb mode change 100644 => 100755 spec/acceptance/join_keys_to_values_spec.rb mode change 100644 => 100755 spec/acceptance/join_spec.rb mode change 100644 => 100755 spec/acceptance/keys_spec.rb mode change 100644 => 100755 spec/acceptance/lstrip_spec.rb mode change 100644 => 100755 spec/acceptance/max_spec.rb mode change 100644 => 100755 spec/acceptance/member_spec.rb mode change 100644 => 100755 spec/acceptance/merge_spec.rb mode change 100644 => 100755 spec/acceptance/min_spec.rb mode change 100644 => 100755 spec/acceptance/num2bool_spec.rb mode change 100644 => 100755 spec/acceptance/parsejson_spec.rb mode change 100644 => 100755 spec/acceptance/parseyaml_spec.rb mode change 100644 => 100755 spec/acceptance/pick_default_spec.rb mode change 100644 => 100755 spec/acceptance/pick_spec.rb mode change 100644 => 100755 spec/acceptance/prefix_spec.rb mode change 100644 => 100755 spec/acceptance/range_spec.rb mode change 100644 => 100755 spec/acceptance/reject_spec.rb mode change 100644 => 100755 spec/acceptance/reverse_spec.rb mode change 100644 => 100755 spec/acceptance/rstrip_spec.rb mode change 100644 => 100755 spec/acceptance/shuffle_spec.rb mode change 100644 => 100755 spec/acceptance/size_spec.rb mode change 100644 => 100755 spec/acceptance/sort_spec.rb mode change 100644 => 100755 spec/acceptance/squeeze_spec.rb mode change 100644 => 100755 spec/acceptance/str2bool_spec.rb mode change 100644 => 100755 spec/acceptance/str2saltedsha512_spec.rb mode change 100644 => 100755 spec/acceptance/strftime_spec.rb mode change 100644 => 100755 spec/acceptance/strip_spec.rb mode change 100644 => 100755 spec/acceptance/suffix_spec.rb mode change 100644 => 100755 spec/acceptance/swapcase_spec.rb mode change 100644 => 100755 spec/acceptance/time_spec.rb mode change 100644 => 100755 spec/acceptance/to_bytes_spec.rb mode change 100644 => 100755 spec/acceptance/type_spec.rb mode change 100644 => 100755 spec/acceptance/union_spec.rb mode change 100644 => 100755 spec/acceptance/unique_spec.rb mode change 100644 => 100755 spec/acceptance/unsupported_spec.rb mode change 100644 => 100755 spec/acceptance/upcase_spec.rb mode change 100644 => 100755 spec/acceptance/uriescape_spec.rb mode change 100644 => 100755 spec/acceptance/validate_absolute_path_spec.rb mode change 100644 => 100755 spec/acceptance/validate_array_spec.rb mode change 100644 => 100755 spec/acceptance/validate_augeas_spec.rb mode change 100644 => 100755 spec/acceptance/validate_bool_spec.rb mode change 100644 => 100755 spec/acceptance/validate_cmd_spec.rb mode change 100644 => 100755 spec/acceptance/validate_hash_spec.rb mode change 100644 => 100755 spec/acceptance/validate_ipv4_address_spec.rb mode change 100644 => 100755 spec/acceptance/validate_ipv6_address_spec.rb mode change 100644 => 100755 spec/acceptance/validate_re_spec.rb mode change 100644 => 100755 spec/acceptance/validate_slength_spec.rb mode change 100644 => 100755 spec/acceptance/validate_string_spec.rb mode change 100644 => 100755 spec/acceptance/values_at_spec.rb mode change 100644 => 100755 spec/acceptance/values_spec.rb mode change 100644 => 100755 spec/acceptance/zip_spec.rb mode change 100644 => 100755 spec/classes/anchor_spec.rb mode change 100644 => 100755 spec/lib/puppet_spec/compiler.rb mode change 100644 => 100755 spec/lib/puppet_spec/database.rb mode change 100644 => 100755 spec/lib/puppet_spec/matchers.rb mode change 100644 => 100755 spec/lib/puppet_spec/modules.rb mode change 100644 => 100755 spec/lib/puppet_spec/pops.rb mode change 100644 => 100755 spec/lib/puppet_spec/scope.rb mode change 100644 => 100755 spec/lib/puppet_spec/settings.rb mode change 100644 => 100755 spec/spec_helper.rb mode change 100644 => 100755 spec/spec_helper_acceptance.rb mode change 100644 => 100755 spec/unit/facter/facter_dot_d_spec.rb mode change 100644 => 100755 spec/unit/facter/pe_version_spec.rb mode change 100644 => 100755 spec/unit/facter/root_home_spec.rb mode change 100644 => 100755 spec/unit/facter/util/puppet_settings_spec.rb 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 mode change 100644 => 100755 spec/unit/puppet/provider/file_line/ruby_spec.rb mode change 100644 => 100755 spec/unit/puppet/type/anchor_spec.rb mode change 100644 => 100755 spec/unit/puppet/type/file_line_spec.rb diff --git a/spec/acceptance/abs_spec.rb b/spec/acceptance/abs_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/any2array_spec.rb b/spec/acceptance/any2array_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/base64_spec.rb b/spec/acceptance/base64_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/bool2num_spec.rb b/spec/acceptance/bool2num_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/build_csv.rb b/spec/acceptance/build_csv.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/capitalize_spec.rb b/spec/acceptance/capitalize_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/chomp_spec.rb b/spec/acceptance/chomp_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/chop_spec.rb b/spec/acceptance/chop_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/count_spec.rb b/spec/acceptance/count_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/deep_merge_spec.rb b/spec/acceptance/deep_merge_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/defined_with_params_spec.rb b/spec/acceptance/defined_with_params_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/delete_at_spec.rb b/spec/acceptance/delete_at_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/delete_spec.rb b/spec/acceptance/delete_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/delete_undef_values_spec.rb b/spec/acceptance/delete_undef_values_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/delete_values_spec.rb b/spec/acceptance/delete_values_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/difference_spec.rb b/spec/acceptance/difference_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/dirname_spec.rb b/spec/acceptance/dirname_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/downcase_spec.rb b/spec/acceptance/downcase_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/empty_spec.rb b/spec/acceptance/empty_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/flatten_spec.rb b/spec/acceptance/flatten_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/floor_spec.rb b/spec/acceptance/floor_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/get_module_path_spec.rb b/spec/acceptance/get_module_path_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/getvar_spec.rb b/spec/acceptance/getvar_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/grep_spec.rb b/spec/acceptance/grep_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/has_interface_with_spec.rb b/spec/acceptance/has_interface_with_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/has_key_spec.rb b/spec/acceptance/has_key_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/hash_spec.rb b/spec/acceptance/hash_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/intersection_spec.rb b/spec/acceptance/intersection_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_array_spec.rb b/spec/acceptance/is_array_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_bool_spec.rb b/spec/acceptance/is_bool_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_domain_name_spec.rb b/spec/acceptance/is_domain_name_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_float_spec.rb b/spec/acceptance/is_float_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_function_available_spec.rb b/spec/acceptance/is_function_available_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_hash_spec.rb b/spec/acceptance/is_hash_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_integer_spec.rb b/spec/acceptance/is_integer_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_ip_address_spec.rb b/spec/acceptance/is_ip_address_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_mac_address_spec.rb b/spec/acceptance/is_mac_address_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_numeric_spec.rb b/spec/acceptance/is_numeric_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/is_string_spec.rb b/spec/acceptance/is_string_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/join_keys_to_values_spec.rb b/spec/acceptance/join_keys_to_values_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/join_spec.rb b/spec/acceptance/join_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/keys_spec.rb b/spec/acceptance/keys_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/lstrip_spec.rb b/spec/acceptance/lstrip_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/max_spec.rb b/spec/acceptance/max_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/member_spec.rb b/spec/acceptance/member_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/merge_spec.rb b/spec/acceptance/merge_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/min_spec.rb b/spec/acceptance/min_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/num2bool_spec.rb b/spec/acceptance/num2bool_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/parsejson_spec.rb b/spec/acceptance/parsejson_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/parseyaml_spec.rb b/spec/acceptance/parseyaml_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/pick_default_spec.rb b/spec/acceptance/pick_default_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/pick_spec.rb b/spec/acceptance/pick_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/prefix_spec.rb b/spec/acceptance/prefix_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/range_spec.rb b/spec/acceptance/range_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/reject_spec.rb b/spec/acceptance/reject_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/reverse_spec.rb b/spec/acceptance/reverse_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/rstrip_spec.rb b/spec/acceptance/rstrip_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/shuffle_spec.rb b/spec/acceptance/shuffle_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/size_spec.rb b/spec/acceptance/size_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/sort_spec.rb b/spec/acceptance/sort_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/squeeze_spec.rb b/spec/acceptance/squeeze_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/str2bool_spec.rb b/spec/acceptance/str2bool_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/str2saltedsha512_spec.rb b/spec/acceptance/str2saltedsha512_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/strftime_spec.rb b/spec/acceptance/strftime_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/strip_spec.rb b/spec/acceptance/strip_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/suffix_spec.rb b/spec/acceptance/suffix_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/swapcase_spec.rb b/spec/acceptance/swapcase_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/time_spec.rb b/spec/acceptance/time_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/to_bytes_spec.rb b/spec/acceptance/to_bytes_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/type_spec.rb b/spec/acceptance/type_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/union_spec.rb b/spec/acceptance/union_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/unique_spec.rb b/spec/acceptance/unique_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/unsupported_spec.rb b/spec/acceptance/unsupported_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/upcase_spec.rb b/spec/acceptance/upcase_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/uriescape_spec.rb b/spec/acceptance/uriescape_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_absolute_path_spec.rb b/spec/acceptance/validate_absolute_path_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_array_spec.rb b/spec/acceptance/validate_array_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_augeas_spec.rb b/spec/acceptance/validate_augeas_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_bool_spec.rb b/spec/acceptance/validate_bool_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_cmd_spec.rb b/spec/acceptance/validate_cmd_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_hash_spec.rb b/spec/acceptance/validate_hash_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_ipv4_address_spec.rb b/spec/acceptance/validate_ipv4_address_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_ipv6_address_spec.rb b/spec/acceptance/validate_ipv6_address_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_re_spec.rb b/spec/acceptance/validate_re_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_slength_spec.rb b/spec/acceptance/validate_slength_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/validate_string_spec.rb b/spec/acceptance/validate_string_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/values_at_spec.rb b/spec/acceptance/values_at_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/values_spec.rb b/spec/acceptance/values_spec.rb old mode 100644 new mode 100755 diff --git a/spec/acceptance/zip_spec.rb b/spec/acceptance/zip_spec.rb old mode 100644 new mode 100755 diff --git a/spec/classes/anchor_spec.rb b/spec/classes/anchor_spec.rb old mode 100644 new mode 100755 diff --git a/spec/lib/puppet_spec/compiler.rb b/spec/lib/puppet_spec/compiler.rb old mode 100644 new mode 100755 diff --git a/spec/lib/puppet_spec/database.rb b/spec/lib/puppet_spec/database.rb old mode 100644 new mode 100755 diff --git a/spec/lib/puppet_spec/matchers.rb b/spec/lib/puppet_spec/matchers.rb old mode 100644 new mode 100755 diff --git a/spec/lib/puppet_spec/modules.rb b/spec/lib/puppet_spec/modules.rb old mode 100644 new mode 100755 diff --git a/spec/lib/puppet_spec/pops.rb b/spec/lib/puppet_spec/pops.rb old mode 100644 new mode 100755 diff --git a/spec/lib/puppet_spec/scope.rb b/spec/lib/puppet_spec/scope.rb old mode 100644 new mode 100755 diff --git a/spec/lib/puppet_spec/settings.rb b/spec/lib/puppet_spec/settings.rb old mode 100644 new mode 100755 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb old mode 100644 new mode 100755 diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb old mode 100644 new mode 100755 diff --git a/spec/unit/facter/facter_dot_d_spec.rb b/spec/unit/facter/facter_dot_d_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/facter/pe_version_spec.rb b/spec/unit/facter/pe_version_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/facter/root_home_spec.rb b/spec/unit/facter/root_home_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/facter/util/puppet_settings_spec.rb b/spec/unit/facter/util/puppet_settings_spec.rb old mode 100644 new mode 100755 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 diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/type/anchor_spec.rb b/spec/unit/puppet/type/anchor_spec.rb old mode 100644 new mode 100755 diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_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/functions/abs_spec.rb | 25 +++++ spec/functions/any2array_spec.rb | 55 ++++++++++ spec/functions/base64_spec.rb | 34 ++++++ spec/functions/bool2num_spec.rb | 24 +++++ spec/functions/capitalize_spec.rb | 19 ++++ spec/functions/chomp_spec.rb | 19 ++++ spec/functions/chop_spec.rb | 19 ++++ spec/functions/concat_spec.rb | 30 ++++++ spec/functions/count_spec.rb | 31 ++++++ spec/functions/deep_merge_spec.rb | 105 ++++++++++++++++++ spec/functions/defined_with_params_spec.rb | 37 +++++++ spec/functions/delete_at_spec.rb | 25 +++++ spec/functions/delete_spec.rb | 56 ++++++++++ spec/functions/delete_undef_values_spec.rb | 41 +++++++ spec/functions/delete_values_spec.rb | 36 +++++++ spec/functions/difference_spec.rb | 19 ++++ spec/functions/dirname_spec.rb | 24 +++++ spec/functions/downcase_spec.rb | 24 +++++ spec/functions/empty_spec.rb | 23 ++++ spec/functions/ensure_packages_spec.rb | 81 ++++++++++++++ spec/functions/ensure_resource_spec.rb | 113 +++++++++++++++++++ spec/functions/flatten_spec.rb | 27 +++++ spec/functions/floor_spec.rb | 39 +++++++ spec/functions/fqdn_rotate_spec.rb | 33 ++++++ spec/functions/get_module_path_spec.rb | 46 ++++++++ spec/functions/getparam_spec.rb | 76 +++++++++++++ spec/functions/getvar_spec.rb | 37 +++++++ spec/functions/grep_spec.rb | 19 ++++ spec/functions/has_interface_with_spec.rb | 64 +++++++++++ spec/functions/has_ip_address_spec.rb | 39 +++++++ spec/functions/has_ip_network_spec.rb | 36 +++++++ spec/functions/has_key_spec.rb | 42 ++++++++ spec/functions/hash_spec.rb | 19 ++++ spec/functions/intersection_spec.rb | 19 ++++ spec/functions/is_array_spec.rb | 29 +++++ spec/functions/is_bool_spec.rb | 44 ++++++++ spec/functions/is_domain_name_spec.rb | 64 +++++++++++ spec/functions/is_float_spec.rb | 33 ++++++ spec/functions/is_function_available.rb | 31 ++++++ spec/functions/is_hash_spec.rb | 29 +++++ spec/functions/is_integer_spec.rb | 69 ++++++++++++ spec/functions/is_ip_address_spec.rb | 39 +++++++ spec/functions/is_mac_address_spec.rb | 29 +++++ spec/functions/is_numeric_spec.rb | 119 +++++++++++++++++++++ spec/functions/is_string_spec.rb | 34 ++++++ spec/functions/join_keys_to_values_spec.rb | 40 +++++++ spec/functions/join_spec.rb | 19 ++++ spec/functions/keys_spec.rb | 21 ++++ spec/functions/loadyaml_spec.rb | 25 +++++ spec/functions/lstrip_spec.rb | 19 ++++ spec/functions/max_spec.rb | 27 +++++ spec/functions/member_spec.rb | 24 +++++ spec/functions/merge_spec.rb | 52 +++++++++ spec/functions/min_spec.rb | 27 +++++ spec/functions/num2bool_spec.rb | 67 ++++++++++++ spec/functions/parsejson_spec.rb | 22 ++++ spec/functions/parseyaml_spec.rb | 24 +++++ spec/functions/pick_default_spec.rb | 58 ++++++++++ spec/functions/pick_spec.rb | 34 ++++++ spec/functions/prefix_spec.rb | 28 +++++ spec/functions/range_spec.rb | 70 ++++++++++++ spec/functions/reject_spec.rb | 20 ++++ spec/functions/reverse_spec.rb | 19 ++++ spec/functions/rstrip_spec.rb | 24 +++++ spec/functions/shuffle_spec.rb | 24 +++++ spec/functions/size_spec.rb | 24 +++++ spec/functions/sort_spec.rb | 24 +++++ spec/functions/squeeze_spec.rb | 24 +++++ spec/functions/str2bool_spec.rb | 31 ++++++ spec/functions/str2saltedsha512_spec.rb | 45 ++++++++ spec/functions/strftime_spec.rb | 29 +++++ spec/functions/strip_spec.rb | 18 ++++ spec/functions/suffix_spec.rb | 27 +++++ spec/functions/swapcase_spec.rb | 19 ++++ spec/functions/time_spec.rb | 29 +++++ spec/functions/to_bytes_spec.rb | 58 ++++++++++ spec/functions/type_spec.rb | 43 ++++++++ spec/functions/union_spec.rb | 19 ++++ spec/functions/unique_spec.rb | 24 +++++ spec/functions/upcase_spec.rb | 24 +++++ spec/functions/uriescape_spec.rb | 24 +++++ spec/functions/validate_absolute_path_spec.rb | 84 +++++++++++++++ spec/functions/validate_array_spec.rb | 38 +++++++ spec/functions/validate_augeas_spec.rb | 103 ++++++++++++++++++ spec/functions/validate_bool_spec.rb | 51 +++++++++ spec/functions/validate_cmd_spec.rb | 48 +++++++++ spec/functions/validate_hash_spec.rb | 43 ++++++++ spec/functions/validate_ipv4_address_spec.rb | 64 +++++++++++ spec/functions/validate_ipv6_address_spec.rb | 67 ++++++++++++ spec/functions/validate_re_spec.rb | 77 +++++++++++++ spec/functions/validate_slength_spec.rb | 67 ++++++++++++ spec/functions/validate_string_spec.rb | 60 +++++++++++ spec/functions/values_at_spec.rb | 38 +++++++ spec/functions/values_spec.rb | 31 ++++++ spec/functions/zip_spec.rb | 15 +++ 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 --- 190 files changed, 3748 insertions(+), 3748 deletions(-) create mode 100755 spec/functions/abs_spec.rb create mode 100755 spec/functions/any2array_spec.rb create mode 100755 spec/functions/base64_spec.rb create mode 100755 spec/functions/bool2num_spec.rb create mode 100755 spec/functions/capitalize_spec.rb create mode 100755 spec/functions/chomp_spec.rb create mode 100755 spec/functions/chop_spec.rb create mode 100755 spec/functions/concat_spec.rb create mode 100755 spec/functions/count_spec.rb create mode 100755 spec/functions/deep_merge_spec.rb create mode 100755 spec/functions/defined_with_params_spec.rb create mode 100755 spec/functions/delete_at_spec.rb create mode 100755 spec/functions/delete_spec.rb create mode 100755 spec/functions/delete_undef_values_spec.rb create mode 100755 spec/functions/delete_values_spec.rb create mode 100755 spec/functions/difference_spec.rb create mode 100755 spec/functions/dirname_spec.rb create mode 100755 spec/functions/downcase_spec.rb create mode 100755 spec/functions/empty_spec.rb create mode 100755 spec/functions/ensure_packages_spec.rb create mode 100755 spec/functions/ensure_resource_spec.rb create mode 100755 spec/functions/flatten_spec.rb create mode 100755 spec/functions/floor_spec.rb create mode 100755 spec/functions/fqdn_rotate_spec.rb create mode 100755 spec/functions/get_module_path_spec.rb create mode 100755 spec/functions/getparam_spec.rb create mode 100755 spec/functions/getvar_spec.rb create mode 100755 spec/functions/grep_spec.rb create mode 100755 spec/functions/has_interface_with_spec.rb create mode 100755 spec/functions/has_ip_address_spec.rb create mode 100755 spec/functions/has_ip_network_spec.rb create mode 100755 spec/functions/has_key_spec.rb create mode 100755 spec/functions/hash_spec.rb create mode 100755 spec/functions/intersection_spec.rb create mode 100755 spec/functions/is_array_spec.rb create mode 100755 spec/functions/is_bool_spec.rb create mode 100755 spec/functions/is_domain_name_spec.rb create mode 100755 spec/functions/is_float_spec.rb create mode 100755 spec/functions/is_function_available.rb create mode 100755 spec/functions/is_hash_spec.rb create mode 100755 spec/functions/is_integer_spec.rb create mode 100755 spec/functions/is_ip_address_spec.rb create mode 100755 spec/functions/is_mac_address_spec.rb create mode 100755 spec/functions/is_numeric_spec.rb create mode 100755 spec/functions/is_string_spec.rb create mode 100755 spec/functions/join_keys_to_values_spec.rb create mode 100755 spec/functions/join_spec.rb create mode 100755 spec/functions/keys_spec.rb create mode 100755 spec/functions/loadyaml_spec.rb create mode 100755 spec/functions/lstrip_spec.rb create mode 100755 spec/functions/max_spec.rb create mode 100755 spec/functions/member_spec.rb create mode 100755 spec/functions/merge_spec.rb create mode 100755 spec/functions/min_spec.rb create mode 100755 spec/functions/num2bool_spec.rb create mode 100755 spec/functions/parsejson_spec.rb create mode 100755 spec/functions/parseyaml_spec.rb create mode 100755 spec/functions/pick_default_spec.rb create mode 100755 spec/functions/pick_spec.rb create mode 100755 spec/functions/prefix_spec.rb create mode 100755 spec/functions/range_spec.rb create mode 100755 spec/functions/reject_spec.rb create mode 100755 spec/functions/reverse_spec.rb create mode 100755 spec/functions/rstrip_spec.rb create mode 100755 spec/functions/shuffle_spec.rb create mode 100755 spec/functions/size_spec.rb create mode 100755 spec/functions/sort_spec.rb create mode 100755 spec/functions/squeeze_spec.rb create mode 100755 spec/functions/str2bool_spec.rb create mode 100755 spec/functions/str2saltedsha512_spec.rb create mode 100755 spec/functions/strftime_spec.rb create mode 100755 spec/functions/strip_spec.rb create mode 100755 spec/functions/suffix_spec.rb create mode 100755 spec/functions/swapcase_spec.rb create mode 100755 spec/functions/time_spec.rb create mode 100755 spec/functions/to_bytes_spec.rb create mode 100755 spec/functions/type_spec.rb create mode 100755 spec/functions/union_spec.rb create mode 100755 spec/functions/unique_spec.rb create mode 100755 spec/functions/upcase_spec.rb create mode 100755 spec/functions/uriescape_spec.rb create mode 100755 spec/functions/validate_absolute_path_spec.rb create mode 100755 spec/functions/validate_array_spec.rb create mode 100755 spec/functions/validate_augeas_spec.rb create mode 100755 spec/functions/validate_bool_spec.rb create mode 100755 spec/functions/validate_cmd_spec.rb create mode 100755 spec/functions/validate_hash_spec.rb create mode 100755 spec/functions/validate_ipv4_address_spec.rb create mode 100755 spec/functions/validate_ipv6_address_spec.rb create mode 100755 spec/functions/validate_re_spec.rb create mode 100755 spec/functions/validate_slength_spec.rb create mode 100755 spec/functions/validate_string_spec.rb create mode 100755 spec/functions/values_at_spec.rb create mode 100755 spec/functions/values_spec.rb create mode 100755 spec/functions/zip_spec.rb 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 diff --git a/spec/functions/abs_spec.rb b/spec/functions/abs_spec.rb new file mode 100755 index 0000000..c0b4297 --- /dev/null +++ b/spec/functions/abs_spec.rb @@ -0,0 +1,25 @@ +#! /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/functions/any2array_spec.rb b/spec/functions/any2array_spec.rb new file mode 100755 index 0000000..b266e84 --- /dev/null +++ b/spec/functions/any2array_spec.rb @@ -0,0 +1,55 @@ +#! /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/functions/base64_spec.rb b/spec/functions/base64_spec.rb new file mode 100755 index 0000000..5faa5e6 --- /dev/null +++ b/spec/functions/base64_spec.rb @@ -0,0 +1,34 @@ +#! /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/functions/bool2num_spec.rb b/spec/functions/bool2num_spec.rb new file mode 100755 index 0000000..518ac85 --- /dev/null +++ b/spec/functions/bool2num_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/capitalize_spec.rb b/spec/functions/capitalize_spec.rb new file mode 100755 index 0000000..69c9758 --- /dev/null +++ b/spec/functions/capitalize_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/chomp_spec.rb b/spec/functions/chomp_spec.rb new file mode 100755 index 0000000..e425365 --- /dev/null +++ b/spec/functions/chomp_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/chop_spec.rb b/spec/functions/chop_spec.rb new file mode 100755 index 0000000..9e466de --- /dev/null +++ b/spec/functions/chop_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/concat_spec.rb b/spec/functions/concat_spec.rb new file mode 100755 index 0000000..6e67620 --- /dev/null +++ b/spec/functions/concat_spec.rb @@ -0,0 +1,30 @@ +#! /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/functions/count_spec.rb b/spec/functions/count_spec.rb new file mode 100755 index 0000000..2453815 --- /dev/null +++ b/spec/functions/count_spec.rb @@ -0,0 +1,31 @@ +#! /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/functions/deep_merge_spec.rb b/spec/functions/deep_merge_spec.rb new file mode 100755 index 0000000..f134701 --- /dev/null +++ b/spec/functions/deep_merge_spec.rb @@ -0,0 +1,105 @@ +#! /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/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb new file mode 100755 index 0000000..28dbab3 --- /dev/null +++ b/spec/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/functions/delete_at_spec.rb b/spec/functions/delete_at_spec.rb new file mode 100755 index 0000000..593cf45 --- /dev/null +++ b/spec/functions/delete_at_spec.rb @@ -0,0 +1,25 @@ +#! /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/functions/delete_spec.rb b/spec/functions/delete_spec.rb new file mode 100755 index 0000000..1508a63 --- /dev/null +++ b/spec/functions/delete_spec.rb @@ -0,0 +1,56 @@ +#! /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/functions/delete_undef_values_spec.rb b/spec/functions/delete_undef_values_spec.rb new file mode 100755 index 0000000..b341d88 --- /dev/null +++ b/spec/functions/delete_undef_values_spec.rb @@ -0,0 +1,41 @@ +#! /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/functions/delete_values_spec.rb b/spec/functions/delete_values_spec.rb new file mode 100755 index 0000000..8d7f231 --- /dev/null +++ b/spec/functions/delete_values_spec.rb @@ -0,0 +1,36 @@ +#! /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/functions/difference_spec.rb b/spec/functions/difference_spec.rb new file mode 100755 index 0000000..9feff09 --- /dev/null +++ b/spec/functions/difference_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/dirname_spec.rb b/spec/functions/dirname_spec.rb new file mode 100755 index 0000000..fb3b4fe --- /dev/null +++ b/spec/functions/dirname_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/downcase_spec.rb b/spec/functions/downcase_spec.rb new file mode 100755 index 0000000..acef1f0 --- /dev/null +++ b/spec/functions/downcase_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/empty_spec.rb b/spec/functions/empty_spec.rb new file mode 100755 index 0000000..7745875 --- /dev/null +++ b/spec/functions/empty_spec.rb @@ -0,0 +1,23 @@ +#! /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/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb new file mode 100755 index 0000000..436be10 --- /dev/null +++ b/spec/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/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb new file mode 100755 index 0000000..33bcac0 --- /dev/null +++ b/spec/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/functions/flatten_spec.rb b/spec/functions/flatten_spec.rb new file mode 100755 index 0000000..dba7a6b --- /dev/null +++ b/spec/functions/flatten_spec.rb @@ -0,0 +1,27 @@ +#! /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/functions/floor_spec.rb b/spec/functions/floor_spec.rb new file mode 100755 index 0000000..dbc8c77 --- /dev/null +++ b/spec/functions/floor_spec.rb @@ -0,0 +1,39 @@ +#! /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/functions/fqdn_rotate_spec.rb b/spec/functions/fqdn_rotate_spec.rb new file mode 100755 index 0000000..2577723 --- /dev/null +++ b/spec/functions/fqdn_rotate_spec.rb @@ -0,0 +1,33 @@ +#! /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/functions/get_module_path_spec.rb b/spec/functions/get_module_path_spec.rb new file mode 100755 index 0000000..486bef6 --- /dev/null +++ b/spec/functions/get_module_path_spec.rb @@ -0,0 +1,46 @@ +#! /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/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb new file mode 100755 index 0000000..bf024af --- /dev/null +++ b/spec/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 diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb new file mode 100755 index 0000000..5ff834e --- /dev/null +++ b/spec/functions/getvar_spec.rb @@ -0,0 +1,37 @@ +#! /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/functions/grep_spec.rb b/spec/functions/grep_spec.rb new file mode 100755 index 0000000..a93b842 --- /dev/null +++ b/spec/functions/grep_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/has_interface_with_spec.rb b/spec/functions/has_interface_with_spec.rb new file mode 100755 index 0000000..c5264e4 --- /dev/null +++ b/spec/functions/has_interface_with_spec.rb @@ -0,0 +1,64 @@ +#!/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/functions/has_ip_address_spec.rb b/spec/functions/has_ip_address_spec.rb new file mode 100755 index 0000000..5a68460 --- /dev/null +++ b/spec/functions/has_ip_address_spec.rb @@ -0,0 +1,39 @@ +#!/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/functions/has_ip_network_spec.rb b/spec/functions/has_ip_network_spec.rb new file mode 100755 index 0000000..c3a289e --- /dev/null +++ b/spec/functions/has_ip_network_spec.rb @@ -0,0 +1,36 @@ +#!/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/functions/has_key_spec.rb b/spec/functions/has_key_spec.rb new file mode 100755 index 0000000..490daea --- /dev/null +++ b/spec/functions/has_key_spec.rb @@ -0,0 +1,42 @@ +#! /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/functions/hash_spec.rb b/spec/functions/hash_spec.rb new file mode 100755 index 0000000..7c91be9 --- /dev/null +++ b/spec/functions/hash_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/intersection_spec.rb b/spec/functions/intersection_spec.rb new file mode 100755 index 0000000..fd44f7f --- /dev/null +++ b/spec/functions/intersection_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/is_array_spec.rb b/spec/functions/is_array_spec.rb new file mode 100755 index 0000000..e7f4bcd --- /dev/null +++ b/spec/functions/is_array_spec.rb @@ -0,0 +1,29 @@ +#! /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/functions/is_bool_spec.rb b/spec/functions/is_bool_spec.rb new file mode 100755 index 0000000..c94e83a --- /dev/null +++ b/spec/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 diff --git a/spec/functions/is_domain_name_spec.rb b/spec/functions/is_domain_name_spec.rb new file mode 100755 index 0000000..f2ea76d --- /dev/null +++ b/spec/functions/is_domain_name_spec.rb @@ -0,0 +1,64 @@ +#! /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/functions/is_float_spec.rb b/spec/functions/is_float_spec.rb new file mode 100755 index 0000000..b7d73b0 --- /dev/null +++ b/spec/functions/is_float_spec.rb @@ -0,0 +1,33 @@ +#! /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/functions/is_function_available.rb b/spec/functions/is_function_available.rb new file mode 100755 index 0000000..d5669a7 --- /dev/null +++ b/spec/functions/is_function_available.rb @@ -0,0 +1,31 @@ +#!/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/functions/is_hash_spec.rb b/spec/functions/is_hash_spec.rb new file mode 100755 index 0000000..bbebf39 --- /dev/null +++ b/spec/functions/is_hash_spec.rb @@ -0,0 +1,29 @@ +#! /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/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb new file mode 100755 index 0000000..24141cc --- /dev/null +++ b/spec/functions/is_integer_spec.rb @@ -0,0 +1,69 @@ +#! /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/functions/is_ip_address_spec.rb b/spec/functions/is_ip_address_spec.rb new file mode 100755 index 0000000..c0debb3 --- /dev/null +++ b/spec/functions/is_ip_address_spec.rb @@ -0,0 +1,39 @@ +#! /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/functions/is_mac_address_spec.rb b/spec/functions/is_mac_address_spec.rb new file mode 100755 index 0000000..ca9c590 --- /dev/null +++ b/spec/functions/is_mac_address_spec.rb @@ -0,0 +1,29 @@ +#! /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/functions/is_numeric_spec.rb b/spec/functions/is_numeric_spec.rb new file mode 100755 index 0000000..1df1497 --- /dev/null +++ b/spec/functions/is_numeric_spec.rb @@ -0,0 +1,119 @@ +#! /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/functions/is_string_spec.rb b/spec/functions/is_string_spec.rb new file mode 100755 index 0000000..3756bea --- /dev/null +++ b/spec/functions/is_string_spec.rb @@ -0,0 +1,34 @@ +#! /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/functions/join_keys_to_values_spec.rb b/spec/functions/join_keys_to_values_spec.rb new file mode 100755 index 0000000..a52fb71 --- /dev/null +++ b/spec/functions/join_keys_to_values_spec.rb @@ -0,0 +1,40 @@ +#! /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/functions/join_spec.rb b/spec/functions/join_spec.rb new file mode 100755 index 0000000..aafa1a7 --- /dev/null +++ b/spec/functions/join_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/keys_spec.rb b/spec/functions/keys_spec.rb new file mode 100755 index 0000000..fdd7a70 --- /dev/null +++ b/spec/functions/keys_spec.rb @@ -0,0 +1,21 @@ +#! /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/functions/loadyaml_spec.rb b/spec/functions/loadyaml_spec.rb new file mode 100755 index 0000000..fe16318 --- /dev/null +++ b/spec/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 diff --git a/spec/functions/lstrip_spec.rb b/spec/functions/lstrip_spec.rb new file mode 100755 index 0000000..b280ae7 --- /dev/null +++ b/spec/functions/lstrip_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/max_spec.rb b/spec/functions/max_spec.rb new file mode 100755 index 0000000..ff6f2b3 --- /dev/null +++ b/spec/functions/max_spec.rb @@ -0,0 +1,27 @@ +#! /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/functions/member_spec.rb b/spec/functions/member_spec.rb new file mode 100755 index 0000000..6e9a023 --- /dev/null +++ b/spec/functions/member_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/merge_spec.rb b/spec/functions/merge_spec.rb new file mode 100755 index 0000000..15a5d94 --- /dev/null +++ b/spec/functions/merge_spec.rb @@ -0,0 +1,52 @@ +#! /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/functions/min_spec.rb b/spec/functions/min_spec.rb new file mode 100755 index 0000000..71d593e --- /dev/null +++ b/spec/functions/min_spec.rb @@ -0,0 +1,27 @@ +#! /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/functions/num2bool_spec.rb b/spec/functions/num2bool_spec.rb new file mode 100755 index 0000000..b56196d --- /dev/null +++ b/spec/functions/num2bool_spec.rb @@ -0,0 +1,67 @@ +#! /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/functions/parsejson_spec.rb b/spec/functions/parsejson_spec.rb new file mode 100755 index 0000000..f179ac1 --- /dev/null +++ b/spec/functions/parsejson_spec.rb @@ -0,0 +1,22 @@ +#! /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/functions/parseyaml_spec.rb b/spec/functions/parseyaml_spec.rb new file mode 100755 index 0000000..0c7aea8 --- /dev/null +++ b/spec/functions/parseyaml_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/pick_default_spec.rb b/spec/functions/pick_default_spec.rb new file mode 100755 index 0000000..c9235b5 --- /dev/null +++ b/spec/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 diff --git a/spec/functions/pick_spec.rb b/spec/functions/pick_spec.rb new file mode 100755 index 0000000..f53fa80 --- /dev/null +++ b/spec/functions/pick_spec.rb @@ -0,0 +1,34 @@ +#!/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/functions/prefix_spec.rb b/spec/functions/prefix_spec.rb new file mode 100755 index 0000000..6e8ddc5 --- /dev/null +++ b/spec/functions/prefix_spec.rb @@ -0,0 +1,28 @@ +#! /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/functions/range_spec.rb b/spec/functions/range_spec.rb new file mode 100755 index 0000000..0e1ad37 --- /dev/null +++ b/spec/functions/range_spec.rb @@ -0,0 +1,70 @@ +#! /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/functions/reject_spec.rb b/spec/functions/reject_spec.rb new file mode 100755 index 0000000..f2cb741 --- /dev/null +++ b/spec/functions/reject_spec.rb @@ -0,0 +1,20 @@ +#!/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/functions/reverse_spec.rb b/spec/functions/reverse_spec.rb new file mode 100755 index 0000000..1b59206 --- /dev/null +++ b/spec/functions/reverse_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/rstrip_spec.rb b/spec/functions/rstrip_spec.rb new file mode 100755 index 0000000..d90de1d --- /dev/null +++ b/spec/functions/rstrip_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/shuffle_spec.rb b/spec/functions/shuffle_spec.rb new file mode 100755 index 0000000..93346d5 --- /dev/null +++ b/spec/functions/shuffle_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/size_spec.rb b/spec/functions/size_spec.rb new file mode 100755 index 0000000..b1c435a --- /dev/null +++ b/spec/functions/size_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/sort_spec.rb b/spec/functions/sort_spec.rb new file mode 100755 index 0000000..3187a5a --- /dev/null +++ b/spec/functions/sort_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/squeeze_spec.rb b/spec/functions/squeeze_spec.rb new file mode 100755 index 0000000..60e5a30 --- /dev/null +++ b/spec/functions/squeeze_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/str2bool_spec.rb b/spec/functions/str2bool_spec.rb new file mode 100755 index 0000000..73c09c7 --- /dev/null +++ b/spec/functions/str2bool_spec.rb @@ -0,0 +1,31 @@ +#! /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/functions/str2saltedsha512_spec.rb b/spec/functions/str2saltedsha512_spec.rb new file mode 100755 index 0000000..df8fb8e --- /dev/null +++ b/spec/functions/str2saltedsha512_spec.rb @@ -0,0 +1,45 @@ +#! /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/functions/strftime_spec.rb b/spec/functions/strftime_spec.rb new file mode 100755 index 0000000..df42b6f --- /dev/null +++ b/spec/functions/strftime_spec.rb @@ -0,0 +1,29 @@ +#! /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/functions/strip_spec.rb b/spec/functions/strip_spec.rb new file mode 100755 index 0000000..fccdd26 --- /dev/null +++ b/spec/functions/strip_spec.rb @@ -0,0 +1,18 @@ +#! /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/functions/suffix_spec.rb b/spec/functions/suffix_spec.rb new file mode 100755 index 0000000..89ba3b8 --- /dev/null +++ b/spec/functions/suffix_spec.rb @@ -0,0 +1,27 @@ +#! /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/functions/swapcase_spec.rb b/spec/functions/swapcase_spec.rb new file mode 100755 index 0000000..808b415 --- /dev/null +++ b/spec/functions/swapcase_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/time_spec.rb b/spec/functions/time_spec.rb new file mode 100755 index 0000000..e9fb76e --- /dev/null +++ b/spec/functions/time_spec.rb @@ -0,0 +1,29 @@ +#! /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/functions/to_bytes_spec.rb b/spec/functions/to_bytes_spec.rb new file mode 100755 index 0000000..d1ea4c8 --- /dev/null +++ b/spec/functions/to_bytes_spec.rb @@ -0,0 +1,58 @@ +#! /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/functions/type_spec.rb b/spec/functions/type_spec.rb new file mode 100755 index 0000000..8fec88f --- /dev/null +++ b/spec/functions/type_spec.rb @@ -0,0 +1,43 @@ +#! /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/functions/union_spec.rb b/spec/functions/union_spec.rb new file mode 100755 index 0000000..0d282ca --- /dev/null +++ b/spec/functions/union_spec.rb @@ -0,0 +1,19 @@ +#! /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/functions/unique_spec.rb b/spec/functions/unique_spec.rb new file mode 100755 index 0000000..5d48d49 --- /dev/null +++ b/spec/functions/unique_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/upcase_spec.rb b/spec/functions/upcase_spec.rb new file mode 100755 index 0000000..5db5513 --- /dev/null +++ b/spec/functions/upcase_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/uriescape_spec.rb b/spec/functions/uriescape_spec.rb new file mode 100755 index 0000000..7211c88 --- /dev/null +++ b/spec/functions/uriescape_spec.rb @@ -0,0 +1,24 @@ +#! /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/functions/validate_absolute_path_spec.rb b/spec/functions/validate_absolute_path_spec.rb new file mode 100755 index 0000000..342ae84 --- /dev/null +++ b/spec/functions/validate_absolute_path_spec.rb @@ -0,0 +1,84 @@ +#! /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/functions/validate_array_spec.rb b/spec/functions/validate_array_spec.rb new file mode 100755 index 0000000..4b31cfd --- /dev/null +++ b/spec/functions/validate_array_spec.rb @@ -0,0 +1,38 @@ +#! /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/functions/validate_augeas_spec.rb b/spec/functions/validate_augeas_spec.rb new file mode 100755 index 0000000..c695ba2 --- /dev/null +++ b/spec/functions/validate_augeas_spec.rb @@ -0,0 +1,103 @@ +#! /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/functions/validate_bool_spec.rb b/spec/functions/validate_bool_spec.rb new file mode 100755 index 0000000..a352d3b --- /dev/null +++ b/spec/functions/validate_bool_spec.rb @@ -0,0 +1,51 @@ +#! /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/functions/validate_cmd_spec.rb b/spec/functions/validate_cmd_spec.rb new file mode 100755 index 0000000..a6e68df --- /dev/null +++ b/spec/functions/validate_cmd_spec.rb @@ -0,0 +1,48 @@ +#! /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/functions/validate_hash_spec.rb b/spec/functions/validate_hash_spec.rb new file mode 100755 index 0000000..a0c35c2 --- /dev/null +++ b/spec/functions/validate_hash_spec.rb @@ -0,0 +1,43 @@ +#! /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/functions/validate_ipv4_address_spec.rb b/spec/functions/validate_ipv4_address_spec.rb new file mode 100755 index 0000000..45401a4 --- /dev/null +++ b/spec/functions/validate_ipv4_address_spec.rb @@ -0,0 +1,64 @@ +#! /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/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb new file mode 100755 index 0000000..a839d90 --- /dev/null +++ b/spec/functions/validate_ipv6_address_spec.rb @@ -0,0 +1,67 @@ +#! /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/functions/validate_re_spec.rb b/spec/functions/validate_re_spec.rb new file mode 100755 index 0000000..d29988b --- /dev/null +++ b/spec/functions/validate_re_spec.rb @@ -0,0 +1,77 @@ +#! /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/functions/validate_slength_spec.rb b/spec/functions/validate_slength_spec.rb new file mode 100755 index 0000000..851835f --- /dev/null +++ b/spec/functions/validate_slength_spec.rb @@ -0,0 +1,67 @@ +#! /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/functions/validate_string_spec.rb b/spec/functions/validate_string_spec.rb new file mode 100755 index 0000000..3b4fb3e --- /dev/null +++ b/spec/functions/validate_string_spec.rb @@ -0,0 +1,60 @@ +#! /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/functions/values_at_spec.rb b/spec/functions/values_at_spec.rb new file mode 100755 index 0000000..08e95a5 --- /dev/null +++ b/spec/functions/values_at_spec.rb @@ -0,0 +1,38 @@ +#! /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/functions/values_spec.rb b/spec/functions/values_spec.rb new file mode 100755 index 0000000..14ae417 --- /dev/null +++ b/spec/functions/values_spec.rb @@ -0,0 +1,31 @@ +#! /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/functions/zip_spec.rb b/spec/functions/zip_spec.rb new file mode 100755 index 0000000..f45ab17 --- /dev/null +++ b/spec/functions/zip_spec.rb @@ -0,0 +1,15 @@ +#! /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 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 0804121719e4bde856723e19e8ff8bf6f9c2d55d Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 8 May 2014 14:43:06 -0700 Subject: Fix the stdlib functions that fail tests --- lib/puppet/parser/functions/floor.rb | 7 ++++++- lib/puppet/parser/functions/is_domain_name.rb | 3 +++ lib/puppet/parser/functions/is_float.rb | 3 +++ lib/puppet/parser/functions/is_function_available.rb | 3 +++ spec/acceptance/getparam_spec.rb | 2 +- spec/acceptance/is_float_spec.rb | 6 +++--- spec/acceptance/is_string_spec.rb | 2 +- 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/puppet/parser/functions/floor.rb b/lib/puppet/parser/functions/floor.rb index a401923..9a6f014 100644 --- a/lib/puppet/parser/functions/floor.rb +++ b/lib/puppet/parser/functions/floor.rb @@ -8,7 +8,12 @@ module Puppet::Parser::Functions raise(Puppet::ParseError, "floor(): Wrong number of arguments " + "given (#{arguments.size} for 1)") if arguments.size != 1 - arg = arguments[0] + begin + arg = Float(arguments[0]) + rescue TypeError, ArgumentError => e + raise(Puppet::ParseError, "floor(): Wrong argument type " + + "given (#{arguments[0]} for Numeric)") + end raise(Puppet::ParseError, "floor(): Wrong argument type " + "given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false diff --git a/lib/puppet/parser/functions/is_domain_name.rb b/lib/puppet/parser/functions/is_domain_name.rb index 5826dc0..b3fee96 100644 --- a/lib/puppet/parser/functions/is_domain_name.rb +++ b/lib/puppet/parser/functions/is_domain_name.rb @@ -20,6 +20,9 @@ Returns true if the string passed to this function is a syntactically correct do label_min_length=1 label_max_length=63 + # Only allow string types + return false unless domain.is_a?(String) + # Allow ".", it is the top level domain return true if domain == '.' diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb index 911f3c2..a2da943 100644 --- a/lib/puppet/parser/functions/is_float.rb +++ b/lib/puppet/parser/functions/is_float.rb @@ -15,6 +15,9 @@ Returns true if the variable passed to this function is a float. value = arguments[0] + # Only allow Numeric or String types + return false unless value.is_a?(Numeric) or value.is_a?(String) + if value != value.to_f.to_s and !value.is_a? Float then return false else diff --git a/lib/puppet/parser/functions/is_function_available.rb b/lib/puppet/parser/functions/is_function_available.rb index 6cbd35c..6da82c8 100644 --- a/lib/puppet/parser/functions/is_function_available.rb +++ b/lib/puppet/parser/functions/is_function_available.rb @@ -15,6 +15,9 @@ true if the function exists, false if not. "given #{arguments.size} for 1") end + # Only allow String types + return false unless arguments[0].is_a?(String) + function = Puppet::Parser::Functions.function(arguments[0].to_sym) function.is_a?(String) and not function.empty? end diff --git a/spec/acceptance/getparam_spec.rb b/spec/acceptance/getparam_spec.rb index a84b2d1..91fc9a0 100755 --- a/spec/acceptance/getparam_spec.rb +++ b/spec/acceptance/getparam_spec.rb @@ -13,7 +13,7 @@ describe 'getparam function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op notice(inline_template('getparam is <%= @o.inspect %>')) EOS - apply_manifest(pp, :expect_changes => true) do |r| + apply_manifest(pp, :catch_failures => true) do |r| expect(r.stdout).to match(/getparam is true/) end end diff --git a/spec/acceptance/is_float_spec.rb b/spec/acceptance/is_float_spec.rb index 79b01f0..338ba58 100755 --- a/spec/acceptance/is_float_spec.rb +++ b/spec/acceptance/is_float_spec.rb @@ -7,7 +7,7 @@ describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op pp = <<-EOS $a = ['aaa.com','bbb','ccc'] $o = is_float($a) - notice(inline_template('is_floats is <%= @o.inspect %>')) + notice(inline_template('is_float is <%= @o.inspect %>')) EOS apply_manifest(pp, :catch_failures => true) do |r| @@ -18,7 +18,7 @@ describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op pp = <<-EOS $a = true $o = is_float($a) - notice(inline_template('is_floats is <%= @o.inspect %>')) + notice(inline_template('is_float is <%= @o.inspect %>')) EOS apply_manifest(pp, :catch_failures => true) do |r| @@ -75,7 +75,7 @@ describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/is_floats is false/) + expect(r.stdout).to match(/is_float is false/) end end end diff --git a/spec/acceptance/is_string_spec.rb b/spec/acceptance/is_string_spec.rb index bda6cd7..94d8e96 100755 --- a/spec/acceptance/is_string_spec.rb +++ b/spec/acceptance/is_string_spec.rb @@ -50,7 +50,7 @@ describe 'is_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/is_string is true/) + expect(r.stdout).to match(/is_string is false/) end end it 'is_strings floats' do -- cgit v1.2.3 From f3be3b625a2260d74530b2308ec8409ba810509f Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 8 May 2014 15:18:36 -0700 Subject: Release - 4.2.0 Summary ======== This release adds many new functions and fixes, and continues to be backwards compatible with stdlib 3.x Features ------- - New `base64()` function - New `deep_merge()` function - New `delete_undef_values()` function - New `delete_values()` function - New `difference()` function - New `intersection()` function - New `is_bool()` function - New `pick_default()` function - New `union()` function - New `validate_ipv4_address` function - New `validate_ipv6_address` function - Update `ensure_packages()` to take an option hash as a second parameter. - Update `range()` to take an optional third argument for range step - Update `validate_slength()` to take an optional third argument for minimum length - Update `file_line` resource to take `after` and `multiple` attributes Bugfixes -------- - Correct `is_string`, `is_domain_name`, `is_array`, `is_float`, and `is_function_available` for parsing odd types such as bools and hashes. - Allow facts.d facts to contain `=` in the value - Fix `root_home` fact on darwin systems - Fix `concat()` to work with a second non-array argument - Fix `floor()` to work with integer strings - Fix `is_integer()` to return true if passed integer strings - Fix `is_numeric()` to return true if passed integer strings - Fix `merge()` to work with empty strings - Fix `pick()` to raise the correct error type - Fix `uriescape()` to use the default URI.escape list - Add/update unit & acceptance tests. --- CHANGELOG.md | 35 +++++++++++++++++++++++++++++++++++ Modulefile | 2 +- metadata.json | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f132649..cc581ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,38 @@ +## 2014-05-08 - Release - 4.2.0 +### Summary +This release adds many new functions and fixes, and continues to be backwards compatible with stdlib 3.x + +#### Features +- New `base64()` function +- New `deep_merge()` function +- New `delete_undef_values()` function +- New `delete_values()` function +- New `difference()` function +- New `intersection()` function +- New `is_bool()` function +- New `pick_default()` function +- New `union()` function +- New `validate_ipv4_address` function +- New `validate_ipv6_address` function +- Update `ensure_packages()` to take an option hash as a second parameter. +- Update `range()` to take an optional third argument for range step +- Update `validate_slength()` to take an optional third argument for minimum length +- Update `file_line` resource to take `after` and `multiple` attributes + +#### Bugfixes +- Correct `is_string`, `is_domain_name`, `is_array`, `is_float`, and `is_function_available` for parsing odd types such as bools and hashes. +- Allow facts.d facts to contain `=` in the value +- Fix `root_home` fact on darwin systems +- Fix `concat()` to work with a second non-array argument +- Fix `floor()` to work with integer strings +- Fix `is_integer()` to return true if passed integer strings +- Fix `is_numeric()` to return true if passed integer strings +- Fix `merge()` to work with empty strings +- Fix `pick()` to raise the correct error type +- Fix `uriescape()` to use the default URI.escape list +- Add/update unit & acceptance tests. + + ##2014-03-04 - Supported Release - 3.2.1 ###Summary This is a supported release diff --git a/Modulefile b/Modulefile index 9d2e8c2..a685348 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'puppetlabs-stdlib' -version '4.1.0' +version '4.2.0' source 'git://github.com/puppetlabs/puppetlabs-stdlib.git' author 'puppetlabs' license 'Apache 2.0' diff --git a/metadata.json b/metadata.json index 5e9fb0e..46ea7ac 100644 --- a/metadata.json +++ b/metadata.json @@ -92,7 +92,7 @@ } ], "name": "puppetlabs-stdlib", - "version": "3.2.1", + "version": "4.2.0", "source": "git://github.com/puppetlabs/puppetlabs-stdlib", "author": "puppetlabs", "license": "Apache 2.0", -- cgit v1.2.3 From 14c9155745fe4b472e530da6965c0866b6f2640d Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 9 May 2014 16:57:32 +0200 Subject: Prepare a 4.2.1 release. --- CHANGELOG.md | 4 ++++ Modulefile | 2 +- metadata.json | 2 +- spec/acceptance/nodesets/centos-65-x64.yml | 10 ---------- spec/acceptance/nodesets/default.yml | 11 ++++++++++- 5 files changed, 16 insertions(+), 13 deletions(-) delete mode 100644 spec/acceptance/nodesets/centos-65-x64.yml mode change 120000 => 100644 spec/acceptance/nodesets/default.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index cc581ee..5a3597e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2014-05-08 - Release - 4.2.1 +### Summary +This release moves a stray symlink that can cause problems. + ## 2014-05-08 - Release - 4.2.0 ### Summary This release adds many new functions and fixes, and continues to be backwards compatible with stdlib 3.x diff --git a/Modulefile b/Modulefile index a685348..c5da72d 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'puppetlabs-stdlib' -version '4.2.0' +version '4.2.1' source 'git://github.com/puppetlabs/puppetlabs-stdlib.git' author 'puppetlabs' license 'Apache 2.0' diff --git a/metadata.json b/metadata.json index 46ea7ac..9d3847b 100644 --- a/metadata.json +++ b/metadata.json @@ -92,7 +92,7 @@ } ], "name": "puppetlabs-stdlib", - "version": "4.2.0", + "version": "4.2.1", "source": "git://github.com/puppetlabs/puppetlabs-stdlib", "author": "puppetlabs", "license": "Apache 2.0", diff --git a/spec/acceptance/nodesets/centos-65-x64.yml b/spec/acceptance/nodesets/centos-65-x64.yml deleted file mode 100644 index 4e2cb80..0000000 --- a/spec/acceptance/nodesets/centos-65-x64.yml +++ /dev/null @@ -1,10 +0,0 @@ -HOSTS: - centos-65-x64: - roles: - - master - platform: el-6-x86_64 - box : centos-65-x64-vbox436-nocm - box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box - hypervisor : vagrant -CONFIG: - type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml deleted file mode 120000 index 2719644..0000000 --- a/spec/acceptance/nodesets/default.yml +++ /dev/null @@ -1 +0,0 @@ -centos-64-x64.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..4e2cb80 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-65-x64: + roles: + - master + platform: el-6-x86_64 + box : centos-65-x64-vbox436-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box + hypervisor : vagrant +CONFIG: + type: foss -- cgit v1.2.3 From 42743614cb13541a2973f28251b1f79a33019d77 Mon Sep 17 00:00:00 2001 From: Ryan McKern Date: Tue, 13 May 2014 15:01:44 -0700 Subject: (MODULES-905) Add bool2str() and camelcase() for string manipulation Python likes to have its constants Capitalized, and the capitalize function only understands strings... so I shave a yak. bool2str will convert a boolean to its equivalent string value, and camelcase extends on uppercase & downcase to convert an underscore delimited string into a camelcased string. --- lib/puppet/parser/functions/bool2str.rb | 30 +++++++++++++++++++++++++++++ lib/puppet/parser/functions/camelcase.rb | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 lib/puppet/parser/functions/bool2str.rb create mode 100644 lib/puppet/parser/functions/camelcase.rb diff --git a/lib/puppet/parser/functions/bool2str.rb b/lib/puppet/parser/functions/bool2str.rb new file mode 100644 index 0000000..a97d356 --- /dev/null +++ b/lib/puppet/parser/functions/bool2str.rb @@ -0,0 +1,30 @@ +# +# bool2str.rb +# + +module Puppet::Parser::Functions + newfunction(:bool2str, :type => :rvalue, :doc => <<-EOS + Converts a boolean to a string. + Requires a single boolean or string as an input. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "bool2str(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + # We can have either true or false, or string which resembles boolean ... + unless [FalseClass, TrueClass, String].include?(klass) + raise(Puppet::ParseError, 'bool2str(): Requires either ' + + 'boolean or string to work with') + end + + result = value.is_a?(String) ? value : value.to_s + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/camelcase.rb b/lib/puppet/parser/functions/camelcase.rb new file mode 100644 index 0000000..d7f43f7 --- /dev/null +++ b/lib/puppet/parser/functions/camelcase.rb @@ -0,0 +1,33 @@ +# +# camelcase.rb +# + +module Puppet::Parser::Functions + newfunction(:camelcase, :type => :rvalue, :doc => <<-EOS +Converts the case of a string or all strings in an array to camel case. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "camelcase(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'camelcase(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.split('_').map{|e| e.capitalize}.join : i } + else + result = value.split('_').map{|e| e.capitalize}.join + end + + return result + end +end + +# vim: set ts=2 sw=2 et : -- 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 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 6eaa592cd8d5af097a4624b3d1cead74408aabf2 Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Wed, 14 May 2014 20:33:57 +0200 Subject: (PUP-2571) add 'before' functionality to file_line file_line supports adding lines after a match, but there are use cases when having "before" would be useful. For example, in Debian-based OS's, the last line of /etc/rc.local is "exit 0" it's an incredible pain to deal with that scenario today. This commit adds a 'before' parameter to the file_line type, and implements it for the ruby provider. --- lib/puppet/provider/file_line/ruby.rb | 16 ++++--- lib/puppet/type/file_line.rb | 4 ++ spec/unit/puppet/provider/file_line/ruby_spec.rb | 59 ++++++++++++++++++++++++ spec/unit/puppet/type/file_line_spec.rb | 8 ++++ 4 files changed, 80 insertions(+), 7 deletions(-) diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb index 94e7fac..2cbd172 100644 --- a/lib/puppet/provider/file_line/ruby.rb +++ b/lib/puppet/provider/file_line/ruby.rb @@ -9,7 +9,9 @@ Puppet::Type.type(:file_line).provide(:ruby) do if resource[:match] handle_create_with_match elsif resource[:after] - handle_create_with_after + handle_create_with_position :after + elsif resource[:before] + handle_create_with_position :before else append_line end @@ -49,29 +51,29 @@ Puppet::Type.type(:file_line).provide(:ruby) do end end - def handle_create_with_after - regex = Regexp.new(resource[:after]) + def handle_create_with_position(position) + regex = resource[position] ? Regexp.new(resource[position]) : nil count = lines.count {|l| l.match(regex)} case count - when 1 # find the line to put our line after + when 1 # find the line to put our line before/after File.open(resource[:path], 'w') do |fh| lines.each do |l| - fh.puts(l) + fh.puts(l) if position == :after if regex.match(l) then fh.puts(resource[:line]) end + fh.puts(l) if position == :before end end when 0 # append the line to the end of the file append_line else - raise Puppet::Error, "#{count} lines match pattern '#{resource[:after]}' in file '#{resource[:path]}'. One or no line must match the pattern." + raise Puppet::Error, "#{count} lines match pattern '#{resource[position]}' in file '#{resource[:path]}'. One or no line must match the pattern." end end - ## # append the line to the file. # # @api private diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb index 323fc4c..bc6745f 100644 --- a/lib/puppet/type/file_line.rb +++ b/lib/puppet/type/file_line.rb @@ -46,6 +46,10 @@ Puppet::Type.newtype(:file_line) do desc 'An optional value used to specify the line after which we will add any new lines. (Existing lines are added in place)' end + newparam(:before) do + desc 'An optional value used to specify the line before which we will add any new lines. (Existing lines are added in place)' + end + newparam(:line) do desc 'The line to be appended to the file located by the path parameter.' end diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb index a016b68..d004af4 100755 --- a/spec/unit/puppet/provider/file_line/ruby_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -183,6 +183,65 @@ describe provider_class do end end end + + describe 'using before' do + let :resource do + Puppet::Type::File_line.new( + { + :name => 'foo', + :path => @tmpfile, + :line => 'inserted = line', + :before => '^foo1', + } + ) + end + + let :provider do + provider_class.new(resource) + end + + context 'with one line matching the before expression' do + before :each do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo = blah\nfoo2\nfoo = baz") + end + end + + it 'inserts the specified line before the line matching the "before" expression' do + provider.create + File.read(@tmpfile).chomp.should eql("inserted = line\nfoo1\nfoo = blah\nfoo2\nfoo = baz") + end + end + + context 'with two lines matching the before expression' do + before :each do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo = blah\nfoo2\nfoo1\nfoo = baz") + end + end + + it 'errors out stating "One or no line must match the pattern"' do + expect { provider.create }.to raise_error(Puppet::Error, /One or no line must match the pattern/) + end + end + + context 'with no lines matching the after expression' do + let :content do + "foo3\nfoo = blah\nfoo2\nfoo = baz\n" + end + + before :each do + File.open(@tmpfile, 'w') do |fh| + fh.write(content) + end + end + + it 'appends the specified line to the file' do + provider.create + File.read(@tmpfile).should eq(content << resource[:line] << "\n") + end + end + end end context "when removing" do diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb index ab5b81b..b85b9f4 100755 --- a/spec/unit/puppet/type/file_line_spec.rb +++ b/spec/unit/puppet/type/file_line_spec.rb @@ -15,6 +15,14 @@ describe Puppet::Type.type(:file_line) do file_line[:match] = '^foo.*$' file_line[:match].should == '^foo.*$' end + it 'should accept an after regex' do + file_line[:after] = '^foo.*$' + file_line[:after].should == '^foo.*$' + end + it 'should accept a before regex' do + file_line[:before] = '^foo.*$' + file_line[:before].should == '^foo.*$' + end it 'should not accept a match regex that does not match the specified line' do expect { Puppet::Type.type(:file_line).new( -- cgit v1.2.3 From 1155d66381103e64ecbf2753372f138283fe3b3e Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 14 May 2014 16:37:48 -0400 Subject: Prepare a 4.3.0 release. --- CHANGELOG.md | 5 +++++ Modulefile | 2 +- metadata.json | 15 ++++++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a3597e..f160002 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +##2014-05-14 - Supported Release 4.3.0 +### Summary + +This is a supported release of the code released as 4.2.1. + ## 2014-05-08 - Release - 4.2.1 ### Summary This release moves a stray symlink that can cause problems. diff --git a/Modulefile b/Modulefile index c5da72d..3375491 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'puppetlabs-stdlib' -version '4.2.1' +version '4.3.0' source 'git://github.com/puppetlabs/puppetlabs-stdlib.git' author 'puppetlabs' license 'Apache 2.0' diff --git a/metadata.json b/metadata.json index 9d3847b..45508e6 100644 --- a/metadata.json +++ b/metadata.json @@ -5,7 +5,8 @@ "operatingsystemrelease": [ "4", "5", - "6" + "6", + "7" ] }, { @@ -13,7 +14,8 @@ "operatingsystemrelease": [ "4", "5", - "6" + "6", + "7" ] }, { @@ -21,7 +23,8 @@ "operatingsystemrelease": [ "4", "5", - "6" + "6", + "7" ] }, { @@ -29,7 +32,8 @@ "operatingsystemrelease": [ "4", "5", - "6" + "6", + "7" ] }, { @@ -49,7 +53,8 @@ "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "10.04", - "12.04" + "12.04", + "14.04" ] }, { -- cgit v1.2.3 From fa45d594ade2f460ec59b35932d04cbca0ee1a84 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 15 May 2014 14:59:37 -0400 Subject: Claim PE3.3 support. --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 45508e6..638e36d 100644 --- a/metadata.json +++ b/metadata.json @@ -89,7 +89,7 @@ "requirements": [ { "name": "pe", - "version_requirement": "3.2.x" + "version_requirement": "3.3.x" }, { "name": "puppet", -- cgit v1.2.3 From c5b06f9bbca7acc491560c92a73d7e2a153fe0a7 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 15 May 2014 17:28:59 -0400 Subject: Revert "Merge pull request #256 from stbenjam/2571-before" This reverts commit 8499ebdb7f892f2623295058649c67a5553d4732, reversing changes made to 08b00d9229961d7b3c3cba997bfb35c8d47e4c4b. --- lib/puppet/provider/file_line/ruby.rb | 16 +++---- lib/puppet/type/file_line.rb | 4 -- spec/unit/puppet/provider/file_line/ruby_spec.rb | 59 ------------------------ spec/unit/puppet/type/file_line_spec.rb | 8 ---- 4 files changed, 7 insertions(+), 80 deletions(-) diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb index 2cbd172..94e7fac 100644 --- a/lib/puppet/provider/file_line/ruby.rb +++ b/lib/puppet/provider/file_line/ruby.rb @@ -9,9 +9,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do if resource[:match] handle_create_with_match elsif resource[:after] - handle_create_with_position :after - elsif resource[:before] - handle_create_with_position :before + handle_create_with_after else append_line end @@ -51,29 +49,29 @@ Puppet::Type.type(:file_line).provide(:ruby) do end end - def handle_create_with_position(position) - regex = resource[position] ? Regexp.new(resource[position]) : nil + def handle_create_with_after + regex = Regexp.new(resource[:after]) count = lines.count {|l| l.match(regex)} case count - when 1 # find the line to put our line before/after + when 1 # find the line to put our line after File.open(resource[:path], 'w') do |fh| lines.each do |l| - fh.puts(l) if position == :after + fh.puts(l) if regex.match(l) then fh.puts(resource[:line]) end - fh.puts(l) if position == :before end end when 0 # append the line to the end of the file append_line else - raise Puppet::Error, "#{count} lines match pattern '#{resource[position]}' in file '#{resource[:path]}'. One or no line must match the pattern." + raise Puppet::Error, "#{count} lines match pattern '#{resource[:after]}' in file '#{resource[:path]}'. One or no line must match the pattern." end end + ## # append the line to the file. # # @api private diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb index bc6745f..323fc4c 100644 --- a/lib/puppet/type/file_line.rb +++ b/lib/puppet/type/file_line.rb @@ -46,10 +46,6 @@ Puppet::Type.newtype(:file_line) do desc 'An optional value used to specify the line after which we will add any new lines. (Existing lines are added in place)' end - newparam(:before) do - desc 'An optional value used to specify the line before which we will add any new lines. (Existing lines are added in place)' - end - newparam(:line) do desc 'The line to be appended to the file located by the path parameter.' end diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb index d004af4..a016b68 100755 --- a/spec/unit/puppet/provider/file_line/ruby_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -183,65 +183,6 @@ describe provider_class do end end end - - describe 'using before' do - let :resource do - Puppet::Type::File_line.new( - { - :name => 'foo', - :path => @tmpfile, - :line => 'inserted = line', - :before => '^foo1', - } - ) - end - - let :provider do - provider_class.new(resource) - end - - context 'with one line matching the before expression' do - before :each do - File.open(@tmpfile, 'w') do |fh| - fh.write("foo1\nfoo = blah\nfoo2\nfoo = baz") - end - end - - it 'inserts the specified line before the line matching the "before" expression' do - provider.create - File.read(@tmpfile).chomp.should eql("inserted = line\nfoo1\nfoo = blah\nfoo2\nfoo = baz") - end - end - - context 'with two lines matching the before expression' do - before :each do - File.open(@tmpfile, 'w') do |fh| - fh.write("foo1\nfoo = blah\nfoo2\nfoo1\nfoo = baz") - end - end - - it 'errors out stating "One or no line must match the pattern"' do - expect { provider.create }.to raise_error(Puppet::Error, /One or no line must match the pattern/) - end - end - - context 'with no lines matching the after expression' do - let :content do - "foo3\nfoo = blah\nfoo2\nfoo = baz\n" - end - - before :each do - File.open(@tmpfile, 'w') do |fh| - fh.write(content) - end - end - - it 'appends the specified line to the file' do - provider.create - File.read(@tmpfile).should eq(content << resource[:line] << "\n") - end - end - end end context "when removing" do diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb index b85b9f4..ab5b81b 100755 --- a/spec/unit/puppet/type/file_line_spec.rb +++ b/spec/unit/puppet/type/file_line_spec.rb @@ -15,14 +15,6 @@ describe Puppet::Type.type(:file_line) do file_line[:match] = '^foo.*$' file_line[:match].should == '^foo.*$' end - it 'should accept an after regex' do - file_line[:after] = '^foo.*$' - file_line[:after].should == '^foo.*$' - end - it 'should accept a before regex' do - file_line[:before] = '^foo.*$' - file_line[:before].should == '^foo.*$' - end it 'should not accept a match regex that does not match the specified line' do expect { Puppet::Type.type(:file_line).new( -- cgit v1.2.3 From 93c4151edfedb28a0cafa60011c57eb6d76ca6be Mon Sep 17 00:00:00 2001 From: Ryan McKern Date: Thu, 15 May 2014 15:01:14 -0700 Subject: (MODULES-905) Narrow the confinement in bool2str Previously, bool2str() accepted a broad array of boolean values and bare strings, without any attempt to validate that the strings in any way resembled "true" or "false" (or any of the other values bool2num() accepts). This commit narrows the input confinement to TrueClass and FalseClass, which means that bool2str() will only interpolate strict boolean values now. --- lib/puppet/parser/functions/bool2str.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/puppet/parser/functions/bool2str.rb b/lib/puppet/parser/functions/bool2str.rb index a97d356..fcd3791 100644 --- a/lib/puppet/parser/functions/bool2str.rb +++ b/lib/puppet/parser/functions/bool2str.rb @@ -5,7 +5,7 @@ module Puppet::Parser::Functions newfunction(:bool2str, :type => :rvalue, :doc => <<-EOS Converts a boolean to a string. - Requires a single boolean or string as an input. + Requires a single boolean as an input. EOS ) do |arguments| @@ -15,15 +15,12 @@ module Puppet::Parser::Functions value = arguments[0] klass = value.class - # We can have either true or false, or string which resembles boolean ... - unless [FalseClass, TrueClass, String].include?(klass) - raise(Puppet::ParseError, 'bool2str(): Requires either ' + - 'boolean or string to work with') + # We can have either true or false, and nothing else + unless [FalseClass, TrueClass].include?(klass) + raise(Puppet::ParseError, 'bool2str(): Requires a boolean to work with') end - result = value.is_a?(String) ? value : value.to_s - - return result + return value.to_s 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(+) 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 08f7553fb66621fb816400609a034582c44c91e4 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 3 Jun 2014 11:11:08 -0400 Subject: Fixes for PE3.3. --- spec/acceptance/fqdn_rotate_spec.rb | 1 + spec/acceptance/parseyaml_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb index b7f8bf8..fc8bea2 100755 --- a/spec/acceptance/fqdn_rotate_spec.rb +++ b/spec/acceptance/fqdn_rotate_spec.rb @@ -14,6 +14,7 @@ describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact( shell("if [ -f #{facts_d}/fqdn.txt ] ; then rm #{facts_d}/fqdn.txt ; fi") end it 'fqdn_rotates floats' do + shell("mkdir -p #{facts_d}") shell("echo 'fqdn=fakehost.localdomain' > #{facts_d}/fqdn.txt") pp = <<-EOS $a = ['a','b','c','d'] diff --git a/spec/acceptance/parseyaml_spec.rb b/spec/acceptance/parseyaml_spec.rb index 4b4bf3d..5819837 100755 --- a/spec/acceptance/parseyaml_spec.rb +++ b/spec/acceptance/parseyaml_spec.rb @@ -26,7 +26,7 @@ describe 'parseyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o EOS apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/syntax error/) + expect(r.stderr).to match(/(syntax error|did not find expected key)/) end end -- cgit v1.2.3 From a364605f3b71b8a0857bbc2c47388f7bb9e11f82 Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Tue, 3 Jun 2014 11:13:35 -0400 Subject: Merge pull request #264 from apenney/fixes-for-tests Fixes for PE3.3. --- spec/acceptance/fqdn_rotate_spec.rb | 1 + spec/acceptance/parseyaml_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb index b7f8bf8..fc8bea2 100755 --- a/spec/acceptance/fqdn_rotate_spec.rb +++ b/spec/acceptance/fqdn_rotate_spec.rb @@ -14,6 +14,7 @@ describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact( shell("if [ -f #{facts_d}/fqdn.txt ] ; then rm #{facts_d}/fqdn.txt ; fi") end it 'fqdn_rotates floats' do + shell("mkdir -p #{facts_d}") shell("echo 'fqdn=fakehost.localdomain' > #{facts_d}/fqdn.txt") pp = <<-EOS $a = ['a','b','c','d'] diff --git a/spec/acceptance/parseyaml_spec.rb b/spec/acceptance/parseyaml_spec.rb index 4b4bf3d..5819837 100755 --- a/spec/acceptance/parseyaml_spec.rb +++ b/spec/acceptance/parseyaml_spec.rb @@ -26,7 +26,7 @@ describe 'parseyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o EOS apply_manifest(pp, :expect_failures => true) do |r| - expect(r.stderr).to match(/syntax error/) + expect(r.stderr).to match(/(syntax error|did not find expected key)/) end end -- cgit v1.2.3 From 6010e9bd932560a61ffb5f955af1e3226fb8d934 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 3 Jun 2014 14:52:10 -0400 Subject: Further fixes to tests for 14.04. --- spec/acceptance/ensure_packages_spec.rb | 2 +- spec/acceptance/shuffle_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb index 145bdc5..aa7b14c 100755 --- a/spec/acceptance/ensure_packages_spec.rb +++ b/spec/acceptance/ensure_packages_spec.rb @@ -11,7 +11,7 @@ describe 'ensure_packages function', :unless => UNSUPPORTED_PLATFORMS.include?(f EOS apply_manifest(pp, :expect_changes => true) do |r| - expect(r.stdout).to match(/Package\[zsh\]\/ensure: created/) + expect(r.stdout).to match(/Package\[zsh\]\/ensure: (created|ensure changed 'purged' to 'present')/) end end it 'ensures a package already declared' diff --git a/spec/acceptance/shuffle_spec.rb b/spec/acceptance/shuffle_spec.rb index 02d1201..b840d1f 100755 --- a/spec/acceptance/shuffle_spec.rb +++ b/spec/acceptance/shuffle_spec.rb @@ -5,14 +5,14 @@ describe 'shuffle function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('ope describe 'success' do it 'shuffles arrays' do pp = <<-EOS - $a = ["the","public","art","galleries"] + $a = ["1", "2", "3", "4", "5", "6", "7", "8", "the","public","art","galleries"] # Anagram: Large picture halls, I bet $o = shuffle($a) notice(inline_template('shuffle is <%= @o.inspect %>')) EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to_not match(/shuffle is \["the", "public", "art", "galleries"\]/) + expect(r.stdout).to_not match(/shuffle is \["1", "2", "3", "4", "5", "6", "7", "8", "the", "public", "art", "galleries"\]/) end end it 'shuffles strings' do -- cgit v1.2.3 From af71faa247043e01fc31ef8248304e8e20a25d6f Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Tue, 3 Jun 2014 14:53:04 -0400 Subject: Merge pull request #265 from apenney/fix-tests Further fixes to tests for 14.04. --- spec/acceptance/ensure_packages_spec.rb | 2 +- spec/acceptance/shuffle_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb index 145bdc5..aa7b14c 100755 --- a/spec/acceptance/ensure_packages_spec.rb +++ b/spec/acceptance/ensure_packages_spec.rb @@ -11,7 +11,7 @@ describe 'ensure_packages function', :unless => UNSUPPORTED_PLATFORMS.include?(f EOS apply_manifest(pp, :expect_changes => true) do |r| - expect(r.stdout).to match(/Package\[zsh\]\/ensure: created/) + expect(r.stdout).to match(/Package\[zsh\]\/ensure: (created|ensure changed 'purged' to 'present')/) end end it 'ensures a package already declared' diff --git a/spec/acceptance/shuffle_spec.rb b/spec/acceptance/shuffle_spec.rb index 02d1201..b840d1f 100755 --- a/spec/acceptance/shuffle_spec.rb +++ b/spec/acceptance/shuffle_spec.rb @@ -5,14 +5,14 @@ describe 'shuffle function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('ope describe 'success' do it 'shuffles arrays' do pp = <<-EOS - $a = ["the","public","art","galleries"] + $a = ["1", "2", "3", "4", "5", "6", "7", "8", "the","public","art","galleries"] # Anagram: Large picture halls, I bet $o = shuffle($a) notice(inline_template('shuffle is <%= @o.inspect %>')) EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to_not match(/shuffle is \["the", "public", "art", "galleries"\]/) + expect(r.stdout).to_not match(/shuffle is \["1", "2", "3", "4", "5", "6", "7", "8", "the", "public", "art", "galleries"\]/) end end it 'shuffles strings' do -- cgit v1.2.3 From e7b27205c4fdc9162f11ee606be93865c1a080ea Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 4 Jun 2014 14:15:14 -0400 Subject: Prepare a 4.2.2 release. --- CHANGELOG.md | 4 ++-- Modulefile | 2 +- metadata.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f160002..97979bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ -##2014-05-14 - Supported Release 4.3.0 +##2014-06-04 - Release 4.2.2 ### Summary -This is a supported release of the code released as 4.2.1. +This release adds PE3.3 support in the metadata and fixes a few tests. ## 2014-05-08 - Release - 4.2.1 ### Summary diff --git a/Modulefile b/Modulefile index 3375491..bf80e3b 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'puppetlabs-stdlib' -version '4.3.0' +version '4.2.2' source 'git://github.com/puppetlabs/puppetlabs-stdlib.git' author 'puppetlabs' license 'Apache 2.0' diff --git a/metadata.json b/metadata.json index 638e36d..acb880f 100644 --- a/metadata.json +++ b/metadata.json @@ -89,7 +89,7 @@ "requirements": [ { "name": "pe", - "version_requirement": "3.3.x" + "version_requirement": ">= 3.2.0 < 3.4.0" }, { "name": "puppet", @@ -97,7 +97,7 @@ } ], "name": "puppetlabs-stdlib", - "version": "4.2.1", + "version": "4.2.2", "source": "git://github.com/puppetlabs/puppetlabs-stdlib", "author": "puppetlabs", "license": "Apache 2.0", -- 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/facter/facter_dot_d_spec.rb | 4 +-- spec/unit/facter/pe_version_spec.rb | 20 ++++++------ spec/unit/facter/root_home_spec.rb | 8 ++--- spec/unit/facter/util/puppet_settings_spec.rb | 6 ++-- spec/unit/puppet/parser/functions/bool2str_spec.rb | 18 +++++------ .../unit/puppet/parser/functions/camelcase_spec.rb | 8 ++--- spec/unit/puppet/provider/file_line/ruby_spec.rb | 36 +++++++++++----------- spec/unit/puppet/type/anchor_spec.rb | 2 +- spec/unit/puppet/type/file_line_spec.rb | 14 ++++----- 9 files changed, 58 insertions(+), 58 deletions(-) diff --git a/spec/unit/facter/facter_dot_d_spec.rb b/spec/unit/facter/facter_dot_d_spec.rb index 2fb72b2..0afadb2 100755 --- a/spec/unit/facter/facter_dot_d_spec.rb +++ b/spec/unit/facter/facter_dot_d_spec.rb @@ -13,7 +13,7 @@ describe Facter::Util::DotD do end it 'should return successfully' do - Facter.fact(:fake_fact).value.should == 'fake fact' + expect(Facter.fact(:fake_fact).value).to eq('fake fact') end end @@ -26,7 +26,7 @@ describe Facter::Util::DotD do end it 'should return successfully' do - Facter.fact(:foo).value.should == '1+1=2' + expect(Facter.fact(:foo).value).to eq('1+1=2') end end end diff --git a/spec/unit/facter/pe_version_spec.rb b/spec/unit/facter/pe_version_spec.rb index 931c6d4..4d0349e 100755 --- a/spec/unit/facter/pe_version_spec.rb +++ b/spec/unit/facter/pe_version_spec.rb @@ -26,23 +26,23 @@ describe "PE Version specs" do (major,minor,patch) = version.split(".") it "Should return true" do - Facter.fact(:is_pe).value.should == true + expect(Facter.fact(:is_pe).value).to eq(true) end it "Should have a version of #{version}" do - Facter.fact(:pe_version).value.should == version + expect(Facter.fact(:pe_version).value).to eq(version) end it "Should have a major version of #{major}" do - Facter.fact(:pe_major_version).value.should == major + expect(Facter.fact(:pe_major_version).value).to eq(major) end it "Should have a minor version of #{minor}" do - Facter.fact(:pe_minor_version).value.should == minor + expect(Facter.fact(:pe_minor_version).value).to eq(minor) end it "Should have a patch version of #{patch}" do - Facter.fact(:pe_patch_version).value.should == patch + expect(Facter.fact(:pe_patch_version).value).to eq(patch) end end end @@ -54,23 +54,23 @@ describe "PE Version specs" do end it "is_pe is false" do - Facter.fact(:is_pe).value.should == false + expect(Facter.fact(:is_pe).value).to eq(false) end it "pe_version is nil" do - Facter.fact(:pe_version).value.should be_nil + expect(Facter.fact(:pe_version).value).to be_nil end it "pe_major_version is nil" do - Facter.fact(:pe_major_version).value.should be_nil + expect(Facter.fact(:pe_major_version).value).to be_nil end it "pe_minor_version is nil" do - Facter.fact(:pe_minor_version).value.should be_nil + expect(Facter.fact(:pe_minor_version).value).to be_nil end it "Should have a patch version" do - Facter.fact(:pe_patch_version).value.should be_nil + expect(Facter.fact(:pe_patch_version).value).to be_nil end end end diff --git a/spec/unit/facter/root_home_spec.rb b/spec/unit/facter/root_home_spec.rb index 73eb3ea..98fe141 100755 --- a/spec/unit/facter/root_home_spec.rb +++ b/spec/unit/facter/root_home_spec.rb @@ -9,7 +9,7 @@ describe Facter::Util::RootHome do it "should return /" do Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent) - Facter::Util::RootHome.get_root_home.should == expected_root_home + expect(Facter::Util::RootHome.get_root_home).to eq(expected_root_home) end end context "linux" do @@ -18,7 +18,7 @@ describe Facter::Util::RootHome do it "should return /root" do Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent) - Facter::Util::RootHome.get_root_home.should == expected_root_home + expect(Facter::Util::RootHome.get_root_home).to eq(expected_root_home) end end context "windows" do @@ -26,7 +26,7 @@ describe Facter::Util::RootHome do Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil) end it "should be nil on windows" do - Facter::Util::RootHome.get_root_home.should be_nil + expect(Facter::Util::RootHome.get_root_home).to be_nil end end end @@ -45,7 +45,7 @@ describe 'root_home', :type => :fact do it "should return /var/root" do Facter::Util::Resolution.stubs(:exec).with("dscacheutil -q user -a name root").returns(sample_dscacheutil) - Facter.fact(:root_home).value.should == expected_root_home + expect(Facter.fact(:root_home).value).to eq(expected_root_home) end end diff --git a/spec/unit/facter/util/puppet_settings_spec.rb b/spec/unit/facter/util/puppet_settings_spec.rb index e77779b..c06137d 100755 --- a/spec/unit/facter/util/puppet_settings_spec.rb +++ b/spec/unit/facter/util/puppet_settings_spec.rb @@ -11,11 +11,11 @@ describe Facter::Util::PuppetSettings do end it 'should be nil' do - subject.with_puppet { Puppet[:vardir] }.should be_nil + expect(subject.with_puppet { Puppet[:vardir] }).to be_nil end it 'should not yield to the block' do Puppet.expects(:[]).never - subject.with_puppet { Puppet[:vardir] }.should be_nil + expect(subject.with_puppet { Puppet[:vardir] }).to be_nil end end context "With Puppet loaded" do @@ -29,7 +29,7 @@ describe Facter::Util::PuppetSettings do subject.with_puppet { Puppet[:vardir] } end it 'should return the nodes vardir' do - subject.with_puppet { Puppet[:vardir] }.should eq vardir + expect(subject.with_puppet { Puppet[:vardir] }).to eq vardir end end end 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 diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb index a016b68..d2a129c 100755 --- a/spec/unit/puppet/provider/file_line/ruby_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -23,17 +23,17 @@ describe provider_class do File.open(tmpfile, 'w') do |fh| fh.write('foo') end - provider.exists?.should be_true + expect(provider.exists?).to be_truthy end it 'should detect if the line does not exist in the file' do File.open(tmpfile, 'w') do |fh| fh.write('foo1') end - provider.exists?.should be_nil + expect(provider.exists?).to be_nil end it 'should append to an existing file when creating' do provider.create - File.read(tmpfile).chomp.should == 'foo' + expect(File.read(tmpfile).chomp).to eq('foo') end end @@ -61,9 +61,9 @@ describe provider_class do File.open(@tmpfile, 'w') do |fh| fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") end - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/) - File.read(@tmpfile).should eql("foo1\nfoo=blah\nfoo2\nfoo=baz") + expect(File.read(@tmpfile)).to eql("foo1\nfoo=blah\nfoo2\nfoo=baz") end it 'should replace all lines that matches' do @@ -80,9 +80,9 @@ describe provider_class do File.open(@tmpfile, 'w') do |fh| fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") end - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil @provider.create - File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2\nfoo = bar") + expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2\nfoo = bar") end it 'should raise an error with invalid values' do @@ -103,25 +103,25 @@ describe provider_class do File.open(@tmpfile, 'w') do |fh| fh.write("foo1\nfoo=blah\nfoo2") end - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil @provider.create - File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2") + expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2") end it 'should add a new line if no lines match' do File.open(@tmpfile, 'w') do |fh| fh.write("foo1\nfoo2") end - @provider.exists?.should be_nil + expect(@provider.exists?).to be_nil @provider.create - File.read(@tmpfile).should eql("foo1\nfoo2\nfoo = bar\n") + expect(File.read(@tmpfile)).to eql("foo1\nfoo2\nfoo = bar\n") end it 'should do nothing if the exact line already exists' do File.open(@tmpfile, 'w') do |fh| fh.write("foo1\nfoo = bar\nfoo2") end - @provider.exists?.should be_true + expect(@provider.exists?).to be_truthy @provider.create - File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2") + expect(File.read(@tmpfile).chomp).to eql("foo1\nfoo = bar\nfoo2") end end @@ -150,7 +150,7 @@ describe provider_class do it 'inserts the specified line after the line matching the "after" expression' do provider.create - File.read(@tmpfile).chomp.should eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo = baz") + expect(File.read(@tmpfile).chomp).to eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo = baz") end end @@ -179,7 +179,7 @@ describe provider_class do it 'appends the specified line to the file' do provider.create - File.read(@tmpfile).should eq(content << resource[:line] << "\n") + expect(File.read(@tmpfile)).to eq(content << resource[:line] << "\n") end end end @@ -203,7 +203,7 @@ describe provider_class do fh.write("foo1\nfoo\nfoo2") end @provider.destroy - File.read(@tmpfile).should eql("foo1\nfoo2") + expect(File.read(@tmpfile)).to eql("foo1\nfoo2") end it 'should remove the line without touching the last new line' do @@ -211,7 +211,7 @@ describe provider_class do fh.write("foo1\nfoo\nfoo2\n") end @provider.destroy - File.read(@tmpfile).should eql("foo1\nfoo2\n") + expect(File.read(@tmpfile)).to eql("foo1\nfoo2\n") end it 'should remove any occurence of the line' do @@ -219,7 +219,7 @@ describe provider_class do fh.write("foo1\nfoo\nfoo2\nfoo\nfoo") end @provider.destroy - File.read(@tmpfile).should eql("foo1\nfoo2\n") + expect(File.read(@tmpfile)).to eql("foo1\nfoo2\n") end end end diff --git a/spec/unit/puppet/type/anchor_spec.rb b/spec/unit/puppet/type/anchor_spec.rb index f92065f..c738a27 100755 --- a/spec/unit/puppet/type/anchor_spec.rb +++ b/spec/unit/puppet/type/anchor_spec.rb @@ -6,6 +6,6 @@ anchor = Puppet::Type.type(:anchor).new(:name => "ntp::begin") describe anchor do it "should stringify normally" do - anchor.to_s.should == "Anchor[ntp::begin]" + expect(anchor.to_s).to eq("Anchor[ntp::begin]") end end diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb index ab5b81b..9ef49ef 100755 --- a/spec/unit/puppet/type/file_line_spec.rb +++ b/spec/unit/puppet/type/file_line_spec.rb @@ -7,13 +7,13 @@ describe Puppet::Type.type(:file_line) do end it 'should accept a line and path' do file_line[:line] = 'my_line' - file_line[:line].should == 'my_line' + expect(file_line[:line]).to eq('my_line') file_line[:path] = '/my/path' - file_line[:path].should == '/my/path' + expect(file_line[:path]).to eq('/my/path') end it 'should accept a match regex' do file_line[:match] = '^foo.*$' - file_line[:match].should == '^foo.*$' + expect(file_line[:match]).to eq('^foo.*$') end it 'should not accept a match regex that does not match the specified line' do expect { @@ -35,7 +35,7 @@ describe Puppet::Type.type(:file_line) do end it 'should accept posix filenames' do file_line[:path] = '/tmp/path' - file_line[:path].should == '/tmp/path' + expect(file_line[:path]).to eq('/tmp/path') end it 'should not accept unqualified path' do expect { file_line[:path] = 'file' }.to raise_error(Puppet::Error, /File paths must be fully qualified/) @@ -47,7 +47,7 @@ describe Puppet::Type.type(:file_line) do expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /Both line and path are required attributes/) end it 'should default to ensure => present' do - file_line[:ensure].should eq :present + expect(file_line[:ensure]).to eq :present end it "should autorequire the file it manages" do @@ -59,12 +59,12 @@ describe Puppet::Type.type(:file_line) do relationship = file_line.autorequire.find do |rel| (rel.source.to_s == "File[/tmp/path]") and (rel.target.to_s == file_line.to_s) end - relationship.should be_a Puppet::Relationship + expect(relationship).to be_a Puppet::Relationship end it "should not autorequire the file it manages if it is not managed" do catalog = Puppet::Resource::Catalog.new catalog.add_resource file_line - file_line.autorequire.should be_empty + expect(file_line.autorequire).to be_empty end end -- cgit v1.2.3 From 6287a200af558d277f83b919e8409f6c798eef39 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 4 Jun 2014 14:38:37 -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/functions * 345 conversions from: obj.should to: expect(obj).to * 122 conversions from: == expected to: eq(expected) * 85 conversions from: lambda { }.should to: expect { }.to * 22 conversions from: be_true to: be_truthy * 16 conversions from: be_false to: be_falsey * 11 conversions from: pending to: skip * 9 conversions from: it { should ... } to: it { is_expected.to ... } * 5 conversions from: =~ [1, 2] to: match_array([1, 2]) * 2 conversions from: =~ /pattern/ to: match(/pattern/) * 2 conversions from: obj.should_not to: expect(obj).not_to For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/functions/abs_spec.rb | 8 ++--- spec/functions/any2array_spec.rb | 20 ++++++------ spec/functions/base64_spec.rb | 6 ++-- spec/functions/bool2num_spec.rb | 8 ++--- spec/functions/capitalize_spec.rb | 6 ++-- spec/functions/chomp_spec.rb | 6 ++-- spec/functions/chop_spec.rb | 6 ++-- spec/functions/concat_spec.rb | 10 +++--- spec/functions/count_spec.rb | 10 +++--- spec/functions/deep_merge_spec.rb | 52 +++++++++++++++--------------- spec/functions/defined_with_params_spec.rb | 18 +++++------ spec/functions/delete_at_spec.rb | 8 ++--- spec/functions/delete_spec.rb | 20 ++++++------ spec/functions/delete_undef_values_spec.rb | 16 ++++----- spec/functions/delete_values_spec.rb | 16 ++++----- spec/functions/difference_spec.rb | 6 ++-- spec/functions/dirname_spec.rb | 8 ++--- spec/functions/downcase_spec.rb | 8 ++--- spec/functions/empty_spec.rb | 8 ++--- spec/functions/flatten_spec.rb | 10 +++--- spec/functions/floor_spec.rb | 14 ++++---- spec/functions/fqdn_rotate_spec.rb | 10 +++--- spec/functions/get_module_path_spec.rb | 8 ++--- spec/functions/getparam_spec.rb | 2 +- spec/functions/getvar_spec.rb | 6 ++-- spec/functions/grep_spec.rb | 6 ++-- spec/functions/has_interface_with_spec.rb | 20 ++++++------ spec/functions/has_ip_address_spec.rb | 8 ++--- spec/functions/has_ip_network_spec.rb | 6 ++-- spec/functions/has_key_spec.rb | 10 +++--- spec/functions/hash_spec.rb | 6 ++-- spec/functions/intersection_spec.rb | 6 ++-- spec/functions/is_array_spec.rb | 10 +++--- spec/functions/is_bool_spec.rb | 16 ++++----- spec/functions/is_domain_name_spec.rb | 24 +++++++------- spec/functions/is_float_spec.rb | 12 +++---- spec/functions/is_function_available.rb | 8 ++--- spec/functions/is_hash_spec.rb | 10 +++--- spec/functions/is_integer_spec.rb | 26 +++++++-------- spec/functions/is_ip_address_spec.rb | 14 ++++---- spec/functions/is_mac_address_spec.rb | 10 +++--- spec/functions/is_numeric_spec.rb | 28 ++++++++-------- spec/functions/is_string_spec.rb | 12 +++---- spec/functions/join_keys_to_values_spec.rb | 16 ++++----- spec/functions/join_spec.rb | 6 ++-- spec/functions/keys_spec.rb | 6 ++-- spec/functions/loadyaml_spec.rb | 4 +-- spec/functions/lstrip_spec.rb | 6 ++-- spec/functions/max_spec.rb | 10 +++--- spec/functions/member_spec.rb | 8 ++--- spec/functions/merge_spec.rb | 14 ++++---- spec/functions/min_spec.rb | 10 +++--- spec/functions/num2bool_spec.rb | 26 +++++++-------- spec/functions/parsejson_spec.rb | 6 ++-- spec/functions/parseyaml_spec.rb | 6 ++-- spec/functions/pick_default_spec.rb | 24 +++++++------- spec/functions/pick_spec.rb | 12 +++---- spec/functions/prefix_spec.rb | 2 +- spec/functions/range_spec.rb | 22 ++++++------- spec/functions/reject_spec.rb | 6 ++-- spec/functions/reverse_spec.rb | 6 ++-- spec/functions/rstrip_spec.rb | 8 ++--- spec/functions/shuffle_spec.rb | 8 ++--- spec/functions/size_spec.rb | 8 ++--- spec/functions/sort_spec.rb | 8 ++--- spec/functions/squeeze_spec.rb | 8 ++--- spec/functions/str2bool_spec.rb | 12 +++---- spec/functions/str2saltedsha512_spec.rb | 6 ++-- spec/functions/strftime_spec.rb | 10 +++--- spec/functions/strip_spec.rb | 6 ++-- spec/functions/suffix_spec.rb | 2 +- spec/functions/swapcase_spec.rb | 6 ++-- spec/functions/time_spec.rb | 10 +++--- spec/functions/to_bytes_spec.rb | 22 ++++++------- spec/functions/type_spec.rb | 16 ++++----- spec/functions/union_spec.rb | 6 ++-- spec/functions/unique_spec.rb | 8 ++--- spec/functions/upcase_spec.rb | 8 ++--- spec/functions/uriescape_spec.rb | 8 ++--- spec/functions/validate_slength_spec.rb | 2 +- spec/functions/values_at_spec.rb | 14 ++++---- spec/functions/values_spec.rb | 12 +++---- spec/functions/zip_spec.rb | 4 +-- 83 files changed, 452 insertions(+), 452 deletions(-) diff --git a/spec/functions/abs_spec.rb b/spec/functions/abs_spec.rb index c0b4297..3c25ce2 100755 --- a/spec/functions/abs_spec.rb +++ b/spec/functions/abs_spec.rb @@ -6,20 +6,20 @@ describe "the abs function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("abs").should == "function_abs" + expect(Puppet::Parser::Functions.function("abs")).to eq("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)) + expect { scope.function_abs([]) }.to( raise_error(Puppet::ParseError)) end it "should convert a negative number into a positive" do result = scope.function_abs(["-34"]) - result.should(eq(34)) + expect(result).to(eq(34)) end it "should do nothing with a positive number" do result = scope.function_abs(["5678"]) - result.should(eq(5678)) + expect(result).to(eq(5678)) end end diff --git a/spec/functions/any2array_spec.rb b/spec/functions/any2array_spec.rb index b266e84..87cd04b 100755 --- a/spec/functions/any2array_spec.rb +++ b/spec/functions/any2array_spec.rb @@ -5,51 +5,51 @@ describe "the any2array function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("any2array").should == "function_any2array" + expect(Puppet::Parser::Functions.function("any2array")).to eq("function_any2array") end it "should return an empty array if there is less than 1 argument" do result = scope.function_any2array([]) - result.should(eq([])) + expect(result).to(eq([])) end it "should convert boolean true to [ true ] " do result = scope.function_any2array([true]) - result.should(eq([true])) + expect(result).to(eq([true])) end it "should convert one object to [object]" do result = scope.function_any2array(['one']) - result.should(eq(['one'])) + expect(result).to(eq(['one'])) end it "should convert multiple objects to [objects]" do result = scope.function_any2array(['one', 'two']) - result.should(eq(['one', 'two'])) + expect(result).to(eq(['one', 'two'])) end it "should return empty array it was called with" do result = scope.function_any2array([[]]) - result.should(eq([])) + expect(result).to(eq([])) end it "should return one-member array it was called with" do result = scope.function_any2array([['string']]) - result.should(eq(['string'])) + expect(result).to(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'])) + expect(result).to(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'])) + expect(result).to(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([])) + expect(result).to(eq([])) end end diff --git a/spec/functions/base64_spec.rb b/spec/functions/base64_spec.rb index 5faa5e6..e93fafc 100755 --- a/spec/functions/base64_spec.rb +++ b/spec/functions/base64_spec.rb @@ -6,7 +6,7 @@ describe "the base64 function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("base64").should == "function_base64" + expect(Puppet::Parser::Functions.function("base64")).to eq("function_base64") end it "should raise a ParseError if there are other than 2 arguments" do @@ -25,10 +25,10 @@ describe "the base64 function" do it "should encode a encoded string" do result = scope.function_base64(["encode",'thestring']) - result.should =~ /\AdGhlc3RyaW5n\n\Z/ + expect(result).to match(/\AdGhlc3RyaW5n\n\Z/) end it "should decode a base64 encoded string" do result = scope.function_base64(["decode",'dGhlc3RyaW5n']) - result.should == 'thestring' + expect(result).to eq('thestring') end end diff --git a/spec/functions/bool2num_spec.rb b/spec/functions/bool2num_spec.rb index 518ac85..fbf461b 100755 --- a/spec/functions/bool2num_spec.rb +++ b/spec/functions/bool2num_spec.rb @@ -5,20 +5,20 @@ describe "the bool2num function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("bool2num").should == "function_bool2num" + expect(Puppet::Parser::Functions.function("bool2num")).to eq("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)) + expect { scope.function_bool2num([]) }.to( raise_error(Puppet::ParseError)) end it "should convert true to 1" do result = scope.function_bool2num([true]) - result.should(eq(1)) + expect(result).to(eq(1)) end it "should convert false to 0" do result = scope.function_bool2num([false]) - result.should(eq(0)) + expect(result).to(eq(0)) end end diff --git a/spec/functions/capitalize_spec.rb b/spec/functions/capitalize_spec.rb index 69c9758..0cc2d76 100755 --- a/spec/functions/capitalize_spec.rb +++ b/spec/functions/capitalize_spec.rb @@ -5,15 +5,15 @@ describe "the capitalize function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("capitalize").should == "function_capitalize" + expect(Puppet::Parser::Functions.function("capitalize")).to eq("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)) + expect { scope.function_capitalize([]) }.to( raise_error(Puppet::ParseError)) end it "should capitalize the beginning of a string" do result = scope.function_capitalize(["abc"]) - result.should(eq("Abc")) + expect(result).to(eq("Abc")) end end diff --git a/spec/functions/chomp_spec.rb b/spec/functions/chomp_spec.rb index e425365..d2ae287 100755 --- a/spec/functions/chomp_spec.rb +++ b/spec/functions/chomp_spec.rb @@ -5,15 +5,15 @@ describe "the chomp function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("chomp").should == "function_chomp" + expect(Puppet::Parser::Functions.function("chomp")).to eq("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)) + expect { scope.function_chomp([]) }.to( raise_error(Puppet::ParseError)) end it "should chomp the end of a string" do result = scope.function_chomp(["abc\n"]) - result.should(eq("abc")) + expect(result).to(eq("abc")) end end diff --git a/spec/functions/chop_spec.rb b/spec/functions/chop_spec.rb index 9e466de..d9dbb88 100755 --- a/spec/functions/chop_spec.rb +++ b/spec/functions/chop_spec.rb @@ -5,15 +5,15 @@ describe "the chop function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("chop").should == "function_chop" + expect(Puppet::Parser::Functions.function("chop")).to eq("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)) + expect { scope.function_chop([]) }.to( raise_error(Puppet::ParseError)) end it "should chop the end of a string" do result = scope.function_chop(["asdf\n"]) - result.should(eq("asdf")) + expect(result).to(eq("asdf")) end end diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index 6e67620..b853b4c 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -5,26 +5,26 @@ 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)) + expect { scope.function_concat([]) }.to(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)) + expect { scope.function_concat([1, []])}.to(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'])) + expect(result).to(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'])) + expect(result).to(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'])) + expect(result).to(eq(['1','2','3',['4','5'],'6'])) end end diff --git a/spec/functions/count_spec.rb b/spec/functions/count_spec.rb index 2453815..f8f1d48 100755 --- a/spec/functions/count_spec.rb +++ b/spec/functions/count_spec.rb @@ -6,23 +6,23 @@ describe "the count function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("count").should == "function_count" + expect(Puppet::Parser::Functions.function("count")).to eq("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)) + expect { scope.function_count(['foo', 'bar', 'baz']) }.to( raise_error(ArgumentError)) end it "should be able to count arrays" do - scope.function_count([["1","2","3"]]).should(eq(3)) + expect(scope.function_count([["1","2","3"]])).to(eq(3)) end it "should be able to count matching elements in arrays" do - scope.function_count([["1", "2", "2"], "2"]).should(eq(2)) + expect(scope.function_count([["1", "2", "2"], "2"])).to(eq(2)) end it "should not count nil or empty strings" do - scope.function_count([["foo","bar",nil,""]]).should(eq(2)) + expect(scope.function_count([["foo","bar",nil,""]])).to(eq(2)) end it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do diff --git a/spec/functions/deep_merge_spec.rb b/spec/functions/deep_merge_spec.rb index f134701..7087904 100755 --- a/spec/functions/deep_merge_spec.rb +++ b/spec/functions/deep_merge_spec.rb @@ -7,7 +7,7 @@ describe Puppet::Parser::Functions.function(:deep_merge) do 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\./ + skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = '$x = deep_merge()' expect { scope.compiler.compile @@ -15,7 +15,7 @@ describe Puppet::Parser::Functions.function(:deep_merge) do 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\./ + skip("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 @@ -35,71 +35,71 @@ describe Puppet::Parser::Functions.function(:deep_merge) do 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' + expect(new_hash['one']).to eq('1') + expect(new_hash['two']).to eq('2') + expect(new_hash['three']).to eq('2') end it 'should deep_merge multiple hashes' do hash = scope.function_deep_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) - hash['one'].should == '3' + expect(hash['one']).to eq('3') end it 'should accept empty hashes' do - scope.function_deep_merge([{},{},{}]).should == {} + expect(scope.function_deep_merge([{},{},{}])).to eq({}) 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 } + expect(hash['one']).to eq(1) + expect(hash['two']).to eq(2) + expect(hash['three']).to eq({ '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 } + expect(hash['one']).to eq({ '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 } + expect(hash['one']).to eq(1) + expect(hash['two']).to eq('dos') + expect(hash['three']).to eq({ '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 } + expect(hash['key1']).to eq({ 'a' => 1, 'b' => 99 }) + expect(hash['key2']).to eq({ '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 } + expect(hash1).to eq({'one' => { 'two' => 2 } }) + expect(hash2).to eq({ 'one' => { 'three' => 3 } }) + expect(hash['one']).to eq({ '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 } + expect(hash1).to eq({'one' => { 'two' => [1,2] } }) + expect(hash2).to eq({ 'one' => { 'three' => 3 } }) + expect(hash['one']).to eq({ '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}] + expect(hash1).to eq({'one' => { 'two' => [1,2, {'two' => 2}] } }) + expect(hash2).to eq({ 'one' => { 'three' => 3 } }) + expect(hash['one']).to eq({ 'two' => [1,2, {'two' => 2} ], 'three' => 3 }) + expect(hash['one']['two']).to eq([1,2, {'two' => 2}]) end end end diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index 28dbab3..3590304 100755 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -4,16 +4,16 @@ 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) } + it { is_expected.to 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) + is_expected.to run.with_params('User[dan]', {}).and_return(true) + is_expected.to run.with_params('User[bob]', {}).and_return(false) + is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) end end @@ -22,14 +22,14 @@ describe 'defined_with_params' 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'} + is_expected.to run.with_params('User[dan]', {}).and_return(true) + is_expected.to run.with_params('User[dan]', '').and_return(true) + is_expected.to run.with_params('User[dan]', {'ensure' => 'present'} ).and_return(true) - should run.with_params('User[dan]', + is_expected.to run.with_params('User[dan]', {'ensure' => 'present', 'managehome' => false} ).and_return(true) - should run.with_params('User[dan]', + is_expected.to run.with_params('User[dan]', {'ensure' => 'absent', 'managehome' => false} ).and_return(false) end diff --git a/spec/functions/delete_at_spec.rb b/spec/functions/delete_at_spec.rb index 593cf45..7c20aec 100755 --- a/spec/functions/delete_at_spec.rb +++ b/spec/functions/delete_at_spec.rb @@ -5,21 +5,21 @@ 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" + expect(Puppet::Parser::Functions.function("delete_at")).to eq("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)) + expect { scope.function_delete_at([]) }.to( 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'])) + expect(result).to(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'])) + expect(origin_array).to(eq(['a','b','c','d'])) end end diff --git a/spec/functions/delete_spec.rb b/spec/functions/delete_spec.rb index 1508a63..39b3176 100755 --- a/spec/functions/delete_spec.rb +++ b/spec/functions/delete_spec.rb @@ -5,52 +5,52 @@ describe "the delete function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("delete").should == "function_delete" + expect(Puppet::Parser::Functions.function("delete")).to eq("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)) + expect { scope.function_delete([]) }.to( 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)) + expect { scope.function_delete([[], 'foo', 'bar']) }.to( 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)) + expect { scope.function_delete([1, 'bar']) }.to( 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'])) + expect(result).to(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')) + expect(result).to(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 })) + expect(result).to(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'])) + expect(origin_array).to(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')) + expect(origin_string).to(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 })) + expect(origin_hash).to(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) end end diff --git a/spec/functions/delete_undef_values_spec.rb b/spec/functions/delete_undef_values_spec.rb index b341d88..dc67953 100755 --- a/spec/functions/delete_undef_values_spec.rb +++ b/spec/functions/delete_undef_values_spec.rb @@ -5,37 +5,37 @@ 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" + expect(Puppet::Parser::Functions.function("delete_undef_values")).to eq("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)) + expect { scope.function_delete_undef_values([]) }.to( 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)) + expect { scope.function_delete_undef_values(['']) }.to( raise_error(Puppet::ParseError)) + expect { scope.function_delete_undef_values([nil]) }.to( 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'])) + expect(result).to(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'})) + expect(result).to(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'])) + expect(origin_array).to(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' })) + expect(origin_hash).to(eq({ 'a' => 1, 'b' => :undef, 'c' => 'undef' })) end end diff --git a/spec/functions/delete_values_spec.rb b/spec/functions/delete_values_spec.rb index 8d7f231..4f4d411 100755 --- a/spec/functions/delete_values_spec.rb +++ b/spec/functions/delete_values_spec.rb @@ -5,32 +5,32 @@ 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" + expect(Puppet::Parser::Functions.function("delete_values")).to eq("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)) + expect { scope.function_delete_values([]) }.to( 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)) + expect { scope.function_delete_values([[], 'foo', 'bar']) }.to( 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)) + expect { scope.function_delete_values([1,'bar']) }.to( raise_error(TypeError)) + expect { scope.function_delete_values(['foo','bar']) }.to( raise_error(TypeError)) + expect { scope.function_delete_values([[],'bar']) }.to( 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' })) + expect(result).to(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 })) + expect(origin_hash).to(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) end end diff --git a/spec/functions/difference_spec.rb b/spec/functions/difference_spec.rb index 9feff09..24b2b1b 100755 --- a/spec/functions/difference_spec.rb +++ b/spec/functions/difference_spec.rb @@ -5,15 +5,15 @@ describe "the difference function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("difference").should == "function_difference" + expect(Puppet::Parser::Functions.function("difference")).to eq("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) ) + expect { scope.function_difference([]) }.to( 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"])) + expect(result).to(eq(["a"])) end end diff --git a/spec/functions/dirname_spec.rb b/spec/functions/dirname_spec.rb index fb3b4fe..8a3bcab 100755 --- a/spec/functions/dirname_spec.rb +++ b/spec/functions/dirname_spec.rb @@ -5,20 +5,20 @@ describe "the dirname function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("dirname").should == "function_dirname" + expect(Puppet::Parser::Functions.function("dirname")).to eq("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)) + expect { scope.function_dirname([]) }.to( 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')) + expect(result).to(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')) + expect(result).to(eq('path/to/a')) end end diff --git a/spec/functions/downcase_spec.rb b/spec/functions/downcase_spec.rb index acef1f0..a844780 100755 --- a/spec/functions/downcase_spec.rb +++ b/spec/functions/downcase_spec.rb @@ -5,20 +5,20 @@ describe "the downcase function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("downcase").should == "function_downcase" + expect(Puppet::Parser::Functions.function("downcase")).to eq("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)) + expect { scope.function_downcase([]) }.to( raise_error(Puppet::ParseError)) end it "should downcase a string" do result = scope.function_downcase(["ASFD"]) - result.should(eq("asfd")) + expect(result).to(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")) + expect(result).to(eq("asdf asdf")) end end diff --git a/spec/functions/empty_spec.rb b/spec/functions/empty_spec.rb index 7745875..1f2ace4 100755 --- a/spec/functions/empty_spec.rb +++ b/spec/functions/empty_spec.rb @@ -4,20 +4,20 @@ 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" + expect(Puppet::Parser::Functions.function("empty")).to eq("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)) + expect { scope.function_empty([]) }.to( raise_error(Puppet::ParseError)) end it "should return a true for an empty string" do result = scope.function_empty(['']) - result.should(eq(true)) + expect(result).to(eq(true)) end it "should return a false for a non-empty string" do result = scope.function_empty(['asdf']) - result.should(eq(false)) + expect(result).to(eq(false)) end end diff --git a/spec/functions/flatten_spec.rb b/spec/functions/flatten_spec.rb index dba7a6b..de8c66d 100755 --- a/spec/functions/flatten_spec.rb +++ b/spec/functions/flatten_spec.rb @@ -4,24 +4,24 @@ 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" + expect(Puppet::Parser::Functions.function("flatten")).to eq("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)) + expect { scope.function_flatten([]) }.to( 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)) + expect { scope.function_flatten([[], []]) }.to( 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"])) + expect(result).to(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"])) + expect(result).to(eq(["a","b","c","d"])) end end diff --git a/spec/functions/floor_spec.rb b/spec/functions/floor_spec.rb index dbc8c77..12a6917 100755 --- a/spec/functions/floor_spec.rb +++ b/spec/functions/floor_spec.rb @@ -6,34 +6,34 @@ describe "the floor function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("floor").should == "function_floor" + expect(Puppet::Parser::Functions.function("floor")).to eq("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/)) + expect { scope.function_floor([]) }.to( 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/)) + expect { scope.function_floor(["foo"]) }.to( 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/)) + expect { scope.function_floor([true]) }.to( 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)) + expect(result.is_a?(Integer)).to(eq(true)) end it "should return the input when an integer is passed" do result = scope.function_floor([7]) - result.should(eq(7)) + expect(result).to(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)) + expect(result).to(eq(3)) end end diff --git a/spec/functions/fqdn_rotate_spec.rb b/spec/functions/fqdn_rotate_spec.rb index 2577723..b2dc1f5 100755 --- a/spec/functions/fqdn_rotate_spec.rb +++ b/spec/functions/fqdn_rotate_spec.rb @@ -5,22 +5,22 @@ 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" + expect(Puppet::Parser::Functions.function("fqdn_rotate")).to eq("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)) + expect { scope.function_fqdn_rotate([]) }.to( 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)) + expect(result.size).to(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"])) + expect(scope.function_fqdn_rotate(["abcdefg"])).to eql(scope.function_fqdn_rotate(["abcdefg"])) end it "should rotate a string to give different values on different hosts" do @@ -28,6 +28,6 @@ describe "the fqdn_rotate function" do 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) + expect(val1).not_to eql(val2) end end diff --git a/spec/functions/get_module_path_spec.rb b/spec/functions/get_module_path_spec.rb index 486bef6..38ce645 100755 --- a/spec/functions/get_module_path_spec.rb +++ b/spec/functions/get_module_path_spec.rb @@ -29,18 +29,18 @@ describe Puppet::Parser::Functions.function(:get_module_path) do 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 + expect(scope.function_get_module_path(['foo'])).to eq(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 + expect(scope.function_get_module_path(['foo'])).to eq(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/ + skip("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 + expect(scope('danstestenv').function_get_module_path(['foo'])).to eq(path_of_module_foo.path) end end end diff --git a/spec/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb index bf024af..833c4d4 100755 --- a/spec/functions/getparam_spec.rb +++ b/spec/functions/getparam_spec.rb @@ -25,7 +25,7 @@ describe 'getparam' do end it "should exist" do - Puppet::Parser::Functions.function("getparam").should == "function_getparam" + expect(Puppet::Parser::Functions.function("getparam")).to eq("function_getparam") end describe 'when a resource is not specified' do diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb index 5ff834e..87ab9b5 100755 --- a/spec/functions/getvar_spec.rb +++ b/spec/functions/getvar_spec.rb @@ -6,7 +6,7 @@ describe Puppet::Parser::Functions.function(:getvar) do 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\./ + skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = '$foo = getvar()' expect { scope.compiler.compile @@ -14,7 +14,7 @@ describe Puppet::Parser::Functions.function(:getvar) do 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\./ + skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = '$foo = getvar("foo::bar", "baz")' expect { scope.compiler.compile @@ -22,7 +22,7 @@ describe Puppet::Parser::Functions.function(:getvar) do end it "should lookup variables in other namespaces" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = <<-'ENDofPUPPETcode' class site::data { $foo = 'baz' } include site::data diff --git a/spec/functions/grep_spec.rb b/spec/functions/grep_spec.rb index a93b842..9c671dd 100755 --- a/spec/functions/grep_spec.rb +++ b/spec/functions/grep_spec.rb @@ -5,15 +5,15 @@ describe "the grep function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("grep").should == "function_grep" + expect(Puppet::Parser::Functions.function("grep")).to eq("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)) + expect { scope.function_grep([]) }.to( 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"])) + expect(result).to(eq(["aaabbb","bbbccc"])) end end diff --git a/spec/functions/has_interface_with_spec.rb b/spec/functions/has_interface_with_spec.rb index c5264e4..23e09a9 100755 --- a/spec/functions/has_interface_with_spec.rb +++ b/spec/functions/has_interface_with_spec.rb @@ -20,10 +20,10 @@ describe Puppet::Parser::Functions.function(:has_interface_with) 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 + expect(subject.call(['lo0'])).to be_truthy end it 'should not have loopback (lo)' do - subject.call(['lo']).should be_false + expect(subject.call(['lo'])).to be_falsey end end context "On Linux Systems" do @@ -37,28 +37,28 @@ describe Puppet::Parser::Functions.function(:has_interface_with) do scope.stubs(:lookupvar).with('muppet_eth0').returns('kermit') end it 'should have loopback (lo)' do - subject.call(['lo']).should be_true + expect(subject.call(['lo'])).to be_truthy end it 'should not have loopback (lo0)' do - subject.call(['lo0']).should be_false + expect(subject.call(['lo0'])).to be_falsey end it 'should have ipaddress with 127.0.0.1' do - subject.call(['ipaddress', '127.0.0.1']).should be_true + expect(subject.call(['ipaddress', '127.0.0.1'])).to be_truthy end it 'should have ipaddress with 10.0.0.1' do - subject.call(['ipaddress', '10.0.0.1']).should be_true + expect(subject.call(['ipaddress', '10.0.0.1'])).to be_truthy end it 'should not have ipaddress with 10.0.0.2' do - subject.call(['ipaddress', '10.0.0.2']).should be_false + expect(subject.call(['ipaddress', '10.0.0.2'])).to be_falsey end it 'should have muppet named kermit' do - subject.call(['muppet', 'kermit']).should be_true + expect(subject.call(['muppet', 'kermit'])).to be_truthy end it 'should have muppet named mspiggy' do - subject.call(['muppet', 'mspiggy']).should be_true + expect(subject.call(['muppet', 'mspiggy'])).to be_truthy end it 'should not have muppet named bigbird' do - subject.call(['muppet', 'bigbird']).should be_false + expect(subject.call(['muppet', 'bigbird'])).to be_falsey end end end diff --git a/spec/functions/has_ip_address_spec.rb b/spec/functions/has_ip_address_spec.rb index 5a68460..0df12a7 100755 --- a/spec/functions/has_ip_address_spec.rb +++ b/spec/functions/has_ip_address_spec.rb @@ -21,19 +21,19 @@ describe Puppet::Parser::Functions.function(:has_ip_address) do end it 'should have primary address (10.0.2.15)' do - subject.call(['10.0.2.15']).should be_true + expect(subject.call(['10.0.2.15'])).to be_truthy end it 'should have lookupback address (127.0.0.1)' do - subject.call(['127.0.0.1']).should be_true + expect(subject.call(['127.0.0.1'])).to be_truthy end it 'should not have other address' do - subject.call(['192.1681.1.1']).should be_false + expect(subject.call(['192.1681.1.1'])).to be_falsey end it 'should not have "mspiggy" on an interface' do - subject.call(['mspiggy']).should be_false + expect(subject.call(['mspiggy'])).to be_falsey end end end diff --git a/spec/functions/has_ip_network_spec.rb b/spec/functions/has_ip_network_spec.rb index c3a289e..2a2578e 100755 --- a/spec/functions/has_ip_network_spec.rb +++ b/spec/functions/has_ip_network_spec.rb @@ -21,15 +21,15 @@ describe Puppet::Parser::Functions.function(:has_ip_network) do end it 'should have primary network (10.0.2.0)' do - subject.call(['10.0.2.0']).should be_true + expect(subject.call(['10.0.2.0'])).to be_truthy end it 'should have loopback network (127.0.0.0)' do - subject.call(['127.0.0.1']).should be_true + expect(subject.call(['127.0.0.1'])).to be_truthy end it 'should not have other network' do - subject.call(['192.168.1.0']).should be_false + expect(subject.call(['192.168.1.0'])).to be_falsey end end end diff --git a/spec/functions/has_key_spec.rb b/spec/functions/has_key_spec.rb index 490daea..6b71800 100755 --- a/spec/functions/has_key_spec.rb +++ b/spec/functions/has_key_spec.rb @@ -6,7 +6,7 @@ describe Puppet::Parser::Functions.function(:has_key) do 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\./ + skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = '$x = has_key()' expect { scope.compiler.compile @@ -14,7 +14,7 @@ describe Puppet::Parser::Functions.function(:has_key) do 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\./ + skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = "$x = has_key('foo')" expect { scope.compiler.compile @@ -22,7 +22,7 @@ describe Puppet::Parser::Functions.function(:has_key) do 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\./ + skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = "$x = has_key('foo', 'bar')" expect { scope.compiler.compile @@ -32,11 +32,11 @@ describe Puppet::Parser::Functions.function(:has_key) do 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 + expect(scope.function_has_key([{'one' => 1}, 'one'])).to be_truthy end it 'should detect existing keys' do - scope.function_has_key([{'one' => 1}, 'two']).should be_false + expect(scope.function_has_key([{'one' => 1}, 'two'])).to be_falsey end end end diff --git a/spec/functions/hash_spec.rb b/spec/functions/hash_spec.rb index 7c91be9..ec2988b 100755 --- a/spec/functions/hash_spec.rb +++ b/spec/functions/hash_spec.rb @@ -5,15 +5,15 @@ describe "the hash function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("hash").should == "function_hash" + expect(Puppet::Parser::Functions.function("hash")).to eq("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)) + expect { scope.function_hash([]) }.to( 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})) + expect(result).to(eq({'a'=>1,'b'=>2,'c'=>3})) end end diff --git a/spec/functions/intersection_spec.rb b/spec/functions/intersection_spec.rb index fd44f7f..6361304 100755 --- a/spec/functions/intersection_spec.rb +++ b/spec/functions/intersection_spec.rb @@ -5,15 +5,15 @@ describe "the intersection function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("intersection").should == "function_intersection" + expect(Puppet::Parser::Functions.function("intersection")).to eq("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) ) + expect { scope.function_intersection([]) }.to( 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"])) + expect(result).to(eq(["b","c"])) end end diff --git a/spec/functions/is_array_spec.rb b/spec/functions/is_array_spec.rb index e7f4bcd..94920a4 100755 --- a/spec/functions/is_array_spec.rb +++ b/spec/functions/is_array_spec.rb @@ -5,25 +5,25 @@ 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" + expect(Puppet::Parser::Functions.function("is_array")).to eq("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)) + expect { scope.function_is_array([]) }.to( 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)) + expect(result).to(eq(true)) end it "should return false if passed a hash" do result = scope.function_is_array([{'a'=>1}]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if passed a string" do result = scope.function_is_array(["asdf"]) - result.should(eq(false)) + expect(result).to(eq(false)) end end diff --git a/spec/functions/is_bool_spec.rb b/spec/functions/is_bool_spec.rb index c94e83a..4a342ba 100755 --- a/spec/functions/is_bool_spec.rb +++ b/spec/functions/is_bool_spec.rb @@ -5,40 +5,40 @@ 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" + expect(Puppet::Parser::Functions.function("is_bool")).to eq("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)) + expect { scope.function_is_bool([]) }.to( raise_error(Puppet::ParseError)) end it "should return true if passed a TrueClass" do result = scope.function_is_bool([true]) - result.should(eq(true)) + expect(result).to(eq(true)) end it "should return true if passed a FalseClass" do result = scope.function_is_bool([false]) - result.should(eq(true)) + expect(result).to(eq(true)) end it "should return false if passed the string 'true'" do result = scope.function_is_bool(['true']) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if passed the string 'false'" do result = scope.function_is_bool(['false']) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if passed an array" do result = scope.function_is_bool([["a","b"]]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if passed a hash" do result = scope.function_is_bool([{"a" => "b"}]) - result.should(eq(false)) + expect(result).to(eq(false)) end end diff --git a/spec/functions/is_domain_name_spec.rb b/spec/functions/is_domain_name_spec.rb index f2ea76d..4d05f5c 100755 --- a/spec/functions/is_domain_name_spec.rb +++ b/spec/functions/is_domain_name_spec.rb @@ -5,60 +5,60 @@ 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" + expect(Puppet::Parser::Functions.function("is_domain_name")).to eq("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)) + expect { scope.function_is_domain_name([]) }.to( 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) + expect(result).to(be_truthy) end it "should return true if the domain is ." do result = scope.function_is_domain_name(["."]) - result.should(be_true) + expect(result).to(be_truthy) end it "should return true if the domain is x.com." do result = scope.function_is_domain_name(["x.com."]) - result.should(be_true) + expect(result).to(be_truthy) end it "should return true if a valid domain name" do result = scope.function_is_domain_name(["foo.bar.com"]) - result.should(be_true) + expect(result).to(be_truthy) end it "should allow domain parts to start with numbers" do result = scope.function_is_domain_name(["3foo.2bar.com"]) - result.should(be_true) + expect(result).to(be_truthy) end it "should allow domain to end with a dot" do result = scope.function_is_domain_name(["3foo.2bar.com."]) - result.should(be_true) + expect(result).to(be_truthy) end it "should allow a single part domain" do result = scope.function_is_domain_name(["orange"]) - result.should(be_true) + expect(result).to(be_truthy) 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) + expect(result).to(be_falsey) 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) + expect(result).to(be_truthy) end it "should return false if domain name contains spaces" do result = scope.function_is_domain_name(["not valid"]) - result.should(be_false) + expect(result).to(be_falsey) end end diff --git a/spec/functions/is_float_spec.rb b/spec/functions/is_float_spec.rb index b7d73b0..d926634 100755 --- a/spec/functions/is_float_spec.rb +++ b/spec/functions/is_float_spec.rb @@ -5,29 +5,29 @@ 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" + expect(Puppet::Parser::Functions.function("is_float")).to eq("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)) + expect { scope.function_is_float([]) }.to( raise_error(Puppet::ParseError)) end it "should return true if a float" do result = scope.function_is_float(["0.12"]) - result.should(eq(true)) + expect(result).to(eq(true)) end it "should return false if a string" do result = scope.function_is_float(["asdf"]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if an integer" do result = scope.function_is_float(["3"]) - result.should(eq(false)) + expect(result).to(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)) + expect(result).to(eq(true)) end end diff --git a/spec/functions/is_function_available.rb b/spec/functions/is_function_available.rb index d5669a7..3a9aa1b 100755 --- a/spec/functions/is_function_available.rb +++ b/spec/functions/is_function_available.rb @@ -11,21 +11,21 @@ describe "the is_function_available function" do end it "should exist" do - Puppet::Parser::Functions.function("is_function_available").should == "function_is_function_available" + expect(Puppet::Parser::Functions.function("is_function_available")).to eq("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)) + expect { @scope.function_is_function_available([]) }.to( 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)) + expect(result).to(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)) + expect(result).to(eq(true)) end end diff --git a/spec/functions/is_hash_spec.rb b/spec/functions/is_hash_spec.rb index bbebf39..a849411 100755 --- a/spec/functions/is_hash_spec.rb +++ b/spec/functions/is_hash_spec.rb @@ -5,25 +5,25 @@ 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" + expect(Puppet::Parser::Functions.function("is_hash")).to eq("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)) + expect { scope.function_is_hash([]) }.to( 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)) + expect(result).to(eq(true)) end it "should return false if passed an array" do result = scope.function_is_hash([["a","b"]]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if passed a string" do result = scope.function_is_hash(["asdf"]) - result.should(eq(false)) + expect(result).to(eq(false)) end end diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb index 24141cc..f0cbca8 100755 --- a/spec/functions/is_integer_spec.rb +++ b/spec/functions/is_integer_spec.rb @@ -5,65 +5,65 @@ 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" + expect(Puppet::Parser::Functions.function("is_integer")).to eq("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)) + expect { scope.function_is_integer([]) }.to( raise_error(Puppet::ParseError)) end it "should return true if an integer" do result = scope.function_is_integer(["3"]) - result.should(eq(true)) + expect(result).to(eq(true)) end it "should return true if a negative integer" do result = scope.function_is_integer(["-7"]) - result.should(eq(true)) + expect(result).to(eq(true)) end it "should return false if a float" do result = scope.function_is_integer(["3.2"]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if a string" do result = scope.function_is_integer(["asdf"]) - result.should(eq(false)) + expect(result).to(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)) + expect(result).to(eq(true)) end it "should return false if an array" do result = scope.function_is_numeric([["asdf"]]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if a hash" do result = scope.function_is_numeric([{"asdf" => false}]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if a boolean" do result = scope.function_is_numeric([true]) - result.should(eq(false)) + expect(result).to(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)) + expect(result).to(eq(false)) end it "should return false if it is zero prefixed" do result = scope.function_is_numeric(["0001234"]) - result.should(eq(false)) + expect(result).to(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)) + expect(result).to(eq(false)) end end diff --git a/spec/functions/is_ip_address_spec.rb b/spec/functions/is_ip_address_spec.rb index c0debb3..c16d12b 100755 --- a/spec/functions/is_ip_address_spec.rb +++ b/spec/functions/is_ip_address_spec.rb @@ -5,35 +5,35 @@ 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" + expect(Puppet::Parser::Functions.function("is_ip_address")).to eq("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)) + expect { scope.function_is_ip_address([]) }.to( 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)) + expect(result).to(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)) + expect(result).to(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)) + expect(result).to(eq(true)) end it "should return false if not valid" do result = scope.function_is_ip_address(["asdf"]) - result.should(eq(false)) + expect(result).to(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)) + expect(result).to(eq(false)) end end diff --git a/spec/functions/is_mac_address_spec.rb b/spec/functions/is_mac_address_spec.rb index ca9c590..66edd19 100755 --- a/spec/functions/is_mac_address_spec.rb +++ b/spec/functions/is_mac_address_spec.rb @@ -5,25 +5,25 @@ 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" + expect(Puppet::Parser::Functions.function("is_mac_address")).to eq("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)) + expect { scope.function_is_mac_address([]) }.to( 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)) + expect(result).to(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)) + expect(result).to(eq(false)) end it "should return false if not valid" do result = scope.function_is_mac_address(["not valid"]) - result.should(eq(false)) + expect(result).to(eq(false)) end end diff --git a/spec/functions/is_numeric_spec.rb b/spec/functions/is_numeric_spec.rb index 1df1497..4176961 100755 --- a/spec/functions/is_numeric_spec.rb +++ b/spec/functions/is_numeric_spec.rb @@ -5,71 +5,71 @@ 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" + expect(Puppet::Parser::Functions.function("is_numeric")).to eq("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)) + expect { scope.function_is_numeric([]) }.to( raise_error(Puppet::ParseError)) end it "should return true if an integer" do result = scope.function_is_numeric(["3"]) - result.should(eq(true)) + expect(result).to(eq(true)) end it "should return true if a float" do result = scope.function_is_numeric(["3.2"]) - result.should(eq(true)) + expect(result).to(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)) + expect(result).to(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)) + expect(result).to(eq(true)) end it "should return false if a string" do result = scope.function_is_numeric(["asdf"]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if an array" do result = scope.function_is_numeric([["asdf"]]) - result.should(eq(false)) + expect(result).to(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)) + expect(result).to(eq(false)) end it "should return false if a hash" do result = scope.function_is_numeric([{"asdf" => false}]) - result.should(eq(false)) + expect(result).to(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)) + expect(result).to(eq(false)) end it "should return false if a boolean" do result = scope.function_is_numeric([true]) - result.should(eq(false)) + expect(result).to(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)) + expect(result).to(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)) + expect(result).to(eq(false)) end # it "should return true if a hexadecimal" do diff --git a/spec/functions/is_string_spec.rb b/spec/functions/is_string_spec.rb index 3756bea..6a0801a 100755 --- a/spec/functions/is_string_spec.rb +++ b/spec/functions/is_string_spec.rb @@ -5,30 +5,30 @@ 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" + expect(Puppet::Parser::Functions.function("is_string")).to eq("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)) + expect { scope.function_is_string([]) }.to( raise_error(Puppet::ParseError)) end it "should return true if a string" do result = scope.function_is_string(["asdf"]) - result.should(eq(true)) + expect(result).to(eq(true)) end it "should return false if an integer" do result = scope.function_is_string(["3"]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if a float" do result = scope.function_is_string(["3.23"]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return false if an array" do result = scope.function_is_string([["a","b","c"]]) - result.should(eq(false)) + expect(result).to(eq(false)) end end diff --git a/spec/functions/join_keys_to_values_spec.rb b/spec/functions/join_keys_to_values_spec.rb index a52fb71..4a9ae87 100755 --- a/spec/functions/join_keys_to_values_spec.rb +++ b/spec/functions/join_keys_to_values_spec.rb @@ -5,36 +5,36 @@ 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" + expect(Puppet::Parser::Functions.function("join_keys_to_values")).to eq("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 + expect { scope.function_join_keys_to_values([{}]) }.to 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 + expect { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.to 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 + expect { scope.function_join_keys_to_values([[1,2], ',']) }.to 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 + expect { scope.function_join_keys_to_values([{}, [1,2]]) }.to 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 + expect { scope.function_join_keys_to_values([{}, 1]) }.to raise_error TypeError end it "should return an empty array given an empty hash" do result = scope.function_join_keys_to_values([{}, ":"]) - result.should == [] + expect(result).to eq([]) 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:'] + expect(result).to match_array(['a:1','2:foo','b:']) end end diff --git a/spec/functions/join_spec.rb b/spec/functions/join_spec.rb index aafa1a7..793c36f 100755 --- a/spec/functions/join_spec.rb +++ b/spec/functions/join_spec.rb @@ -5,15 +5,15 @@ describe "the join function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("join").should == "function_join" + expect(Puppet::Parser::Functions.function("join")).to eq("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)) + expect { scope.function_join([]) }.to( 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")) + expect(result).to(eq("a:b:c")) end end diff --git a/spec/functions/keys_spec.rb b/spec/functions/keys_spec.rb index fdd7a70..f2e7d42 100755 --- a/spec/functions/keys_spec.rb +++ b/spec/functions/keys_spec.rb @@ -5,17 +5,17 @@ describe "the keys function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("keys").should == "function_keys" + expect(Puppet::Parser::Functions.function("keys")).to eq("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)) + expect { scope.function_keys([]) }.to( 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'] + expect(result).to match_array(['a','b']) end end diff --git a/spec/functions/loadyaml_spec.rb b/spec/functions/loadyaml_spec.rb index fe16318..cdc3d6f 100755 --- a/spec/functions/loadyaml_spec.rb +++ b/spec/functions/loadyaml_spec.rb @@ -7,7 +7,7 @@ describe "the loadyaml function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("loadyaml").should == "function_loadyaml" + expect(Puppet::Parser::Functions.function("loadyaml")).to eq("function_loadyaml") end it "should raise a ParseError if there is less than 1 arguments" do @@ -20,6 +20,6 @@ describe "the loadyaml function" do 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 } + expect(result).to eq({"aaa" => 1, "bbb" => 2, "ccc" => 3, "ddd" => 4 }) end end diff --git a/spec/functions/lstrip_spec.rb b/spec/functions/lstrip_spec.rb index b280ae7..7025f97 100755 --- a/spec/functions/lstrip_spec.rb +++ b/spec/functions/lstrip_spec.rb @@ -5,15 +5,15 @@ describe "the lstrip function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("lstrip").should == "function_lstrip" + expect(Puppet::Parser::Functions.function("lstrip")).to eq("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)) + expect { scope.function_lstrip([]) }.to( raise_error(Puppet::ParseError)) end it "should lstrip a string" do result = scope.function_lstrip([" asdf"]) - result.should(eq('asdf')) + expect(result).to(eq('asdf')) end end diff --git a/spec/functions/max_spec.rb b/spec/functions/max_spec.rb index ff6f2b3..c3d8a13 100755 --- a/spec/functions/max_spec.rb +++ b/spec/functions/max_spec.rb @@ -6,22 +6,22 @@ describe "the max function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("max").should == "function_max" + expect(Puppet::Parser::Functions.function("max")).to eq("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)) + expect { scope.function_max([]) }.to( raise_error(Puppet::ParseError)) end it "should be able to compare strings" do - scope.function_max(["albatross","dog","horse"]).should(eq("horse")) + expect(scope.function_max(["albatross","dog","horse"])).to(eq("horse")) end it "should be able to compare numbers" do - scope.function_max([6,8,4]).should(eq(8)) + expect(scope.function_max([6,8,4])).to(eq(8)) end it "should be able to compare a number with a stringified number" do - scope.function_max([1,"2"]).should(eq("2")) + expect(scope.function_max([1,"2"])).to(eq("2")) end end diff --git a/spec/functions/member_spec.rb b/spec/functions/member_spec.rb index 6e9a023..cee6110 100755 --- a/spec/functions/member_spec.rb +++ b/spec/functions/member_spec.rb @@ -5,20 +5,20 @@ describe "the member function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("member").should == "function_member" + expect(Puppet::Parser::Functions.function("member")).to eq("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)) + expect { scope.function_member([]) }.to( 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)) + expect(result).to(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)) + expect(result).to(eq(false)) end end diff --git a/spec/functions/merge_spec.rb b/spec/functions/merge_spec.rb index 15a5d94..2abf976 100755 --- a/spec/functions/merge_spec.rb +++ b/spec/functions/merge_spec.rb @@ -7,7 +7,7 @@ describe Puppet::Parser::Functions.function(:merge) do 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\./ + skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = '$x = merge()' expect { scope.compiler.compile @@ -15,7 +15,7 @@ describe Puppet::Parser::Functions.function(:merge) do 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\./ + skip("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 @@ -35,18 +35,18 @@ describe Puppet::Parser::Functions.function(:merge) do 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' + expect(new_hash['one']).to eq('1') + expect(new_hash['two']).to eq('2') + expect(new_hash['three']).to eq('2') end it 'should merge multiple hashes' do hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) - hash['one'].should == '3' + expect(hash['one']).to eq('3') end it 'should accept empty hashes' do - scope.function_merge([{},{},{}]).should == {} + expect(scope.function_merge([{},{},{}])).to eq({}) end end end diff --git a/spec/functions/min_spec.rb b/spec/functions/min_spec.rb index 71d593e..35a0890 100755 --- a/spec/functions/min_spec.rb +++ b/spec/functions/min_spec.rb @@ -6,22 +6,22 @@ describe "the min function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("min").should == "function_min" + expect(Puppet::Parser::Functions.function("min")).to eq("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)) + expect { scope.function_min([]) }.to( raise_error(Puppet::ParseError)) end it "should be able to compare strings" do - scope.function_min(["albatross","dog","horse"]).should(eq("albatross")) + expect(scope.function_min(["albatross","dog","horse"])).to(eq("albatross")) end it "should be able to compare numbers" do - scope.function_min([6,8,4]).should(eq(4)) + expect(scope.function_min([6,8,4])).to(eq(4)) end it "should be able to compare a number with a stringified number" do - scope.function_min([1,"2"]).should(eq(1)) + expect(scope.function_min([1,"2"])).to(eq(1)) end end diff --git a/spec/functions/num2bool_spec.rb b/spec/functions/num2bool_spec.rb index b56196d..d0ba935 100755 --- a/spec/functions/num2bool_spec.rb +++ b/spec/functions/num2bool_spec.rb @@ -5,63 +5,63 @@ describe "the num2bool function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("num2bool").should == "function_num2bool" + expect(Puppet::Parser::Functions.function("num2bool")).to eq("function_num2bool") end it "should raise a ParseError if there are no arguments" do - lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_num2bool([]) }.to( 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)) + expect { scope.function_num2bool(["foo","bar"]) }.to( 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)) + expect { scope.function_num2bool(["xyzzy"]) }.to( raise_error(Puppet::ParseError)) end it "should return true if passed string 1" do result = scope.function_num2bool(["1"]) - result.should(be_true) + expect(result).to(be_truthy) end it "should return true if passed string 1.5" do result = scope.function_num2bool(["1.5"]) - result.should(be_true) + expect(result).to(be_truthy) end it "should return true if passed number 1" do result = scope.function_num2bool([1]) - result.should(be_true) + expect(result).to(be_truthy) end it "should return false if passed string 0" do result = scope.function_num2bool(["0"]) - result.should(be_false) + expect(result).to(be_falsey) end it "should return false if passed number 0" do result = scope.function_num2bool([0]) - result.should(be_false) + expect(result).to(be_falsey) end it "should return false if passed string -1" do result = scope.function_num2bool(["-1"]) - result.should(be_false) + expect(result).to(be_falsey) end it "should return false if passed string -1.5" do result = scope.function_num2bool(["-1.5"]) - result.should(be_false) + expect(result).to(be_falsey) end it "should return false if passed number -1" do result = scope.function_num2bool([-1]) - result.should(be_false) + expect(result).to(be_falsey) end it "should return false if passed float -1.5" do result = scope.function_num2bool([-1.5]) - result.should(be_false) + expect(result).to(be_falsey) end end diff --git a/spec/functions/parsejson_spec.rb b/spec/functions/parsejson_spec.rb index f179ac1..1dd41b9 100755 --- a/spec/functions/parsejson_spec.rb +++ b/spec/functions/parsejson_spec.rb @@ -5,11 +5,11 @@ describe "the parsejson function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("parsejson").should == "function_parsejson" + expect(Puppet::Parser::Functions.function("parsejson")).to eq("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)) + expect { scope.function_parsejson([]) }.to( raise_error(Puppet::ParseError)) end it "should convert JSON to a data structure" do @@ -17,6 +17,6 @@ describe "the parsejson function" do ["aaa","bbb","ccc"] EOS result = scope.function_parsejson([json]) - result.should(eq(['aaa','bbb','ccc'])) + expect(result).to(eq(['aaa','bbb','ccc'])) end end diff --git a/spec/functions/parseyaml_spec.rb b/spec/functions/parseyaml_spec.rb index 0c7aea8..e5f145b 100755 --- a/spec/functions/parseyaml_spec.rb +++ b/spec/functions/parseyaml_spec.rb @@ -5,11 +5,11 @@ describe "the parseyaml function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml" + expect(Puppet::Parser::Functions.function("parseyaml")).to eq("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)) + expect { scope.function_parseyaml([]) }.to( raise_error(Puppet::ParseError)) end it "should convert YAML to a data structure" do @@ -19,6 +19,6 @@ describe "the parseyaml function" do - ccc EOS result = scope.function_parseyaml([yaml]) - result.should(eq(['aaa','bbb','ccc'])) + expect(result).to(eq(['aaa','bbb','ccc'])) end end diff --git a/spec/functions/pick_default_spec.rb b/spec/functions/pick_default_spec.rb index c9235b5..db10cc3 100755 --- a/spec/functions/pick_default_spec.rb +++ b/spec/functions/pick_default_spec.rb @@ -5,51 +5,51 @@ 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" + expect(Puppet::Parser::Functions.function("pick_default")).to eq("function_pick_default") end it 'should return the correct value' do - scope.function_pick_default(['first', 'second']).should == 'first' + expect(scope.function_pick_default(['first', 'second'])).to eq('first') end it 'should return the correct value if the first value is empty' do - scope.function_pick_default(['', 'second']).should == 'second' + expect(scope.function_pick_default(['', 'second'])).to eq('second') end it 'should skip empty string values' do - scope.function_pick_default(['', 'first']).should == 'first' + expect(scope.function_pick_default(['', 'first'])).to eq('first') end it 'should skip :undef values' do - scope.function_pick_default([:undef, 'first']).should == 'first' + expect(scope.function_pick_default([:undef, 'first'])).to eq('first') end it 'should skip :undefined values' do - scope.function_pick_default([:undefined, 'first']).should == 'first' + expect(scope.function_pick_default([:undefined, 'first'])).to eq('first') end it 'should return the empty string if it is the last possibility' do - scope.function_pick_default([:undef, :undefined, '']).should == '' + expect(scope.function_pick_default([:undef, :undefined, ''])).to eq('') end it 'should return :undef if it is the last possibility' do - scope.function_pick_default(['', :undefined, :undef]).should == :undef + expect(scope.function_pick_default(['', :undefined, :undef])).to eq(:undef) end it 'should return :undefined if it is the last possibility' do - scope.function_pick_default([:undef, '', :undefined]).should == :undefined + expect(scope.function_pick_default([:undef, '', :undefined])).to eq(:undefined) end it 'should return the empty string if it is the only possibility' do - scope.function_pick_default(['']).should == '' + expect(scope.function_pick_default([''])).to eq('') end it 'should return :undef if it is the only possibility' do - scope.function_pick_default([:undef]).should == :undef + expect(scope.function_pick_default([:undef])).to eq(:undef) end it 'should return :undefined if it is the only possibility' do - scope.function_pick_default([:undefined]).should == :undefined + expect(scope.function_pick_default([:undefined])).to eq(:undefined) end it 'should error if no values are passed' do diff --git a/spec/functions/pick_spec.rb b/spec/functions/pick_spec.rb index f53fa80..8be8f58 100755 --- a/spec/functions/pick_spec.rb +++ b/spec/functions/pick_spec.rb @@ -5,27 +5,27 @@ describe "the pick function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("pick").should == "function_pick" + expect(Puppet::Parser::Functions.function("pick")).to eq("function_pick") end it 'should return the correct value' do - scope.function_pick(['first', 'second']).should == 'first' + expect(scope.function_pick(['first', 'second'])).to eq('first') end it 'should return the correct value if the first value is empty' do - scope.function_pick(['', 'second']).should == 'second' + expect(scope.function_pick(['', 'second'])).to eq('second') end it 'should remove empty string values' do - scope.function_pick(['', 'first']).should == 'first' + expect(scope.function_pick(['', 'first'])).to eq('first') end it 'should remove :undef values' do - scope.function_pick([:undef, 'first']).should == 'first' + expect(scope.function_pick([:undef, 'first'])).to eq('first') end it 'should remove :undefined values' do - scope.function_pick([:undefined, 'first']).should == 'first' + expect(scope.function_pick([:undefined, 'first'])).to eq('first') end it 'should error if no values are passed' do diff --git a/spec/functions/prefix_spec.rb b/spec/functions/prefix_spec.rb index 6e8ddc5..34cac53 100755 --- a/spec/functions/prefix_spec.rb +++ b/spec/functions/prefix_spec.rb @@ -23,6 +23,6 @@ describe "the prefix function" do it "returns a prefixed array" do result = scope.function_prefix([['a','b','c'], 'p']) - result.should(eq(['pa','pb','pc'])) + expect(result).to(eq(['pa','pb','pc'])) end end diff --git a/spec/functions/range_spec.rb b/spec/functions/range_spec.rb index 0e1ad37..9b9ece0 100755 --- a/spec/functions/range_spec.rb +++ b/spec/functions/range_spec.rb @@ -5,7 +5,7 @@ describe "the range function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "exists" do - Puppet::Parser::Functions.function("range").should == "function_range" + expect(Puppet::Parser::Functions.function("range")).to eq("function_range") end it "raises a ParseError if there is less than 1 arguments" do @@ -15,56 +15,56 @@ describe "the range function" do 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'] + expect(result).to 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'] + expect(result).to 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'] + expect(result).to 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'] + expect(result).to 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] + expect(result).to 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] + expect(result).to 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] + expect(result).to 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] + expect(result).to 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 + expect(scope.function_range(["host01","host10"])).to eq expected end it "coerces zero padded digits to integers" do expected = (0..10).to_a - scope.function_range(["00", "10"]).should eq expected + expect(scope.function_range(["00", "10"])).to eq expected end end end diff --git a/spec/functions/reject_spec.rb b/spec/functions/reject_spec.rb index f2cb741..88a992e 100755 --- a/spec/functions/reject_spec.rb +++ b/spec/functions/reject_spec.rb @@ -6,15 +6,15 @@ describe "the reject function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("reject").should == "function_reject" + expect(Puppet::Parser::Functions.function("reject")).to eq("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)) + expect { scope.function_reject([]) }.to( 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"])) + expect(result).to(eq(["1111", "dddeee"])) end end diff --git a/spec/functions/reverse_spec.rb b/spec/functions/reverse_spec.rb index 1b59206..bfeabfb 100755 --- a/spec/functions/reverse_spec.rb +++ b/spec/functions/reverse_spec.rb @@ -5,15 +5,15 @@ describe "the reverse function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("reverse").should == "function_reverse" + expect(Puppet::Parser::Functions.function("reverse")).to eq("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)) + expect { scope.function_reverse([]) }.to( raise_error(Puppet::ParseError)) end it "should reverse a string" do result = scope.function_reverse(["asdfghijkl"]) - result.should(eq('lkjihgfdsa')) + expect(result).to(eq('lkjihgfdsa')) end end diff --git a/spec/functions/rstrip_spec.rb b/spec/functions/rstrip_spec.rb index d90de1d..81321d7 100755 --- a/spec/functions/rstrip_spec.rb +++ b/spec/functions/rstrip_spec.rb @@ -5,20 +5,20 @@ describe "the rstrip function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("rstrip").should == "function_rstrip" + expect(Puppet::Parser::Functions.function("rstrip")).to eq("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)) + expect { scope.function_rstrip([]) }.to( raise_error(Puppet::ParseError)) end it "should rstrip a string" do result = scope.function_rstrip(["asdf "]) - result.should(eq('asdf')) + expect(result).to(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'])) + expect(result).to(eq(['a','b','c'])) end end diff --git a/spec/functions/shuffle_spec.rb b/spec/functions/shuffle_spec.rb index 93346d5..ee0e2ff 100755 --- a/spec/functions/shuffle_spec.rb +++ b/spec/functions/shuffle_spec.rb @@ -5,20 +5,20 @@ describe "the shuffle function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("shuffle").should == "function_shuffle" + expect(Puppet::Parser::Functions.function("shuffle")).to eq("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)) + expect { scope.function_shuffle([]) }.to( 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)) + expect(result.size).to(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")) + expect(result.split("").sort.join("")).to(eq("adfs")) end end diff --git a/spec/functions/size_spec.rb b/spec/functions/size_spec.rb index b1c435a..18eb48f 100755 --- a/spec/functions/size_spec.rb +++ b/spec/functions/size_spec.rb @@ -5,20 +5,20 @@ describe "the size function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("size").should == "function_size" + expect(Puppet::Parser::Functions.function("size")).to eq("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)) + expect { scope.function_size([]) }.to( raise_error(Puppet::ParseError)) end it "should return the size of a string" do result = scope.function_size(["asdf"]) - result.should(eq(4)) + expect(result).to(eq(4)) end it "should return the size of an array" do result = scope.function_size([["a","b","c"]]) - result.should(eq(3)) + expect(result).to(eq(3)) end end diff --git a/spec/functions/sort_spec.rb b/spec/functions/sort_spec.rb index 3187a5a..4c2a66c 100755 --- a/spec/functions/sort_spec.rb +++ b/spec/functions/sort_spec.rb @@ -5,20 +5,20 @@ describe "the sort function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("sort").should == "function_sort" + expect(Puppet::Parser::Functions.function("sort")).to eq("function_sort") end it "should raise a ParseError if there is not 1 arguments" do - lambda { scope.function_sort(['','']) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_sort(['','']) }.to( raise_error(Puppet::ParseError)) end it "should sort an array" do result = scope.function_sort([["a","c","b"]]) - result.should(eq(['a','b','c'])) + expect(result).to(eq(['a','b','c'])) end it "should sort a string" do result = scope.function_sort(["acb"]) - result.should(eq('abc')) + expect(result).to(eq('abc')) end end diff --git a/spec/functions/squeeze_spec.rb b/spec/functions/squeeze_spec.rb index 60e5a30..cd0eb37 100755 --- a/spec/functions/squeeze_spec.rb +++ b/spec/functions/squeeze_spec.rb @@ -5,20 +5,20 @@ describe "the squeeze function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("squeeze").should == "function_squeeze" + expect(Puppet::Parser::Functions.function("squeeze")).to eq("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)) + expect { scope.function_squeeze([]) }.to( raise_error(Puppet::ParseError)) end it "should squeeze a string" do result = scope.function_squeeze(["aaabbbbcccc"]) - result.should(eq('abc')) + expect(result).to(eq('abc')) end it "should squeeze all elements in an array" do result = scope.function_squeeze([["aaabbbbcccc","dddfff"]]) - result.should(eq(['abc','df'])) + expect(result).to(eq(['abc','df'])) end end diff --git a/spec/functions/str2bool_spec.rb b/spec/functions/str2bool_spec.rb index 73c09c7..1d205d7 100755 --- a/spec/functions/str2bool_spec.rb +++ b/spec/functions/str2bool_spec.rb @@ -5,27 +5,27 @@ describe "the str2bool function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("str2bool").should == "function_str2bool" + expect(Puppet::Parser::Functions.function("str2bool")).to eq("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)) + expect { scope.function_str2bool([]) }.to( raise_error(Puppet::ParseError)) end it "should convert string 'true' to true" do result = scope.function_str2bool(["true"]) - result.should(eq(true)) + expect(result).to(eq(true)) end it "should convert string 'undef' to false" do result = scope.function_str2bool(["undef"]) - result.should(eq(false)) + expect(result).to(eq(false)) end it "should return the boolean it was called with" do result = scope.function_str2bool([true]) - result.should(eq(true)) + expect(result).to(eq(true)) result = scope.function_str2bool([false]) - result.should(eq(false)) + expect(result).to(eq(false)) end end diff --git a/spec/functions/str2saltedsha512_spec.rb b/spec/functions/str2saltedsha512_spec.rb index df8fb8e..ab7f57f 100755 --- a/spec/functions/str2saltedsha512_spec.rb +++ b/spec/functions/str2saltedsha512_spec.rb @@ -5,7 +5,7 @@ describe "the str2saltedsha512 function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("str2saltedsha512").should == "function_str2saltedsha512" + expect(Puppet::Parser::Functions.function("str2saltedsha512")).to eq("function_str2saltedsha512") end it "should raise a ParseError if there is less than 1 argument" do @@ -18,7 +18,7 @@ describe "the str2saltedsha512 function" do it "should return a salted-sha512 password hash 136 characters in length" do result = scope.function_str2saltedsha512(["password"]) - result.length.should(eq(136)) + expect(result.length).to(eq(136)) end it "should raise an error if you pass a non-string password" do @@ -40,6 +40,6 @@ describe "the str2saltedsha512 function" do # 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 + expect(result).to eq(password_hash) end end diff --git a/spec/functions/strftime_spec.rb b/spec/functions/strftime_spec.rb index df42b6f..ebec54b 100755 --- a/spec/functions/strftime_spec.rb +++ b/spec/functions/strftime_spec.rb @@ -5,25 +5,25 @@ describe "the strftime function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("strftime").should == "function_strftime" + expect(Puppet::Parser::Functions.function("strftime")).to eq("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)) + expect { scope.function_strftime([]) }.to( 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) + expect(result.to_i).to(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) + expect(result.to_i).to(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}$/ + expect(result).to match(/^\d{4}-\d{2}-\d{2}$/) end end diff --git a/spec/functions/strip_spec.rb b/spec/functions/strip_spec.rb index fccdd26..e228761 100755 --- a/spec/functions/strip_spec.rb +++ b/spec/functions/strip_spec.rb @@ -4,15 +4,15 @@ 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" + expect(Puppet::Parser::Functions.function("strip")).to eq("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)) + expect { scope.function_strip([]) }.to( raise_error(Puppet::ParseError)) end it "should strip a string" do result = scope.function_strip([" ab cd "]) - result.should(eq('ab cd')) + expect(result).to(eq('ab cd')) end end diff --git a/spec/functions/suffix_spec.rb b/spec/functions/suffix_spec.rb index 89ba3b8..c7783c6 100755 --- a/spec/functions/suffix_spec.rb +++ b/spec/functions/suffix_spec.rb @@ -22,6 +22,6 @@ describe "the suffix function" do it "returns a suffixed array" do result = scope.function_suffix([['a','b','c'], 'p']) - result.should(eq(['ap','bp','cp'])) + expect(result).to(eq(['ap','bp','cp'])) end end diff --git a/spec/functions/swapcase_spec.rb b/spec/functions/swapcase_spec.rb index 808b415..c6838ab 100755 --- a/spec/functions/swapcase_spec.rb +++ b/spec/functions/swapcase_spec.rb @@ -5,15 +5,15 @@ describe "the swapcase function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("swapcase").should == "function_swapcase" + expect(Puppet::Parser::Functions.function("swapcase")).to eq("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)) + expect { scope.function_swapcase([]) }.to( raise_error(Puppet::ParseError)) end it "should swapcase a string" do result = scope.function_swapcase(["aaBBccDD"]) - result.should(eq('AAbbCCdd')) + expect(result).to(eq('AAbbCCdd')) end end diff --git a/spec/functions/time_spec.rb b/spec/functions/time_spec.rb index e9fb76e..6e22515 100755 --- a/spec/functions/time_spec.rb +++ b/spec/functions/time_spec.rb @@ -5,25 +5,25 @@ describe "the time function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("time").should == "function_time" + expect(Puppet::Parser::Functions.function("time")).to eq("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)) + expect { scope.function_time(['','']) }.to( raise_error(Puppet::ParseError)) end it "should return a number" do result = scope.function_time([]) - result.should be_an(Integer) + expect(result).to be_an(Integer) end it "should be higher then when I wrote this test" do result = scope.function_time([]) - result.should(be > 1311953157) + expect(result).to(be > 1311953157) end it "should be lower then 1.5 trillion" do result = scope.function_time([]) - result.should(be < 1500000000) + expect(result).to(be < 1500000000) end end diff --git a/spec/functions/to_bytes_spec.rb b/spec/functions/to_bytes_spec.rb index d1ea4c8..68a1eb8 100755 --- a/spec/functions/to_bytes_spec.rb +++ b/spec/functions/to_bytes_spec.rb @@ -6,53 +6,53 @@ 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" + expect(Puppet::Parser::Functions.function("to_bytes")).to eq("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)) + expect { scope.function_to_bytes([]) }.to( raise_error(Puppet::ParseError)) end it "should convert kB to B" do result = scope.function_to_bytes(["4 kB"]) - result.should(eq(4096)) + expect(result).to(eq(4096)) end it "should work without B in unit" do result = scope.function_to_bytes(["4 k"]) - result.should(eq(4096)) + expect(result).to(eq(4096)) end it "should work without a space before unit" do result = scope.function_to_bytes(["4k"]) - result.should(eq(4096)) + expect(result).to(eq(4096)) end it "should work without a unit" do result = scope.function_to_bytes(["5678"]) - result.should(eq(5678)) + expect(result).to(eq(5678)) end it "should convert fractions" do result = scope.function_to_bytes(["1.5 kB"]) - result.should(eq(1536)) + expect(result).to(eq(1536)) end it "should convert scientific notation" do result = scope.function_to_bytes(["1.5e2 B"]) - result.should(eq(150)) + expect(result).to(eq(150)) end it "should do nothing with a positive number" do result = scope.function_to_bytes([5678]) - result.should(eq(5678)) + expect(result).to(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)) + expect { scope.function_to_bytes(["foo"]) }.to( 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)) + expect { scope.function_to_bytes(["5 uB"]) }.to( raise_error(Puppet::ParseError)) end end diff --git a/spec/functions/type_spec.rb b/spec/functions/type_spec.rb index 8fec88f..9dfe9d7 100755 --- a/spec/functions/type_spec.rb +++ b/spec/functions/type_spec.rb @@ -4,40 +4,40 @@ 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" + expect(Puppet::Parser::Functions.function("type")).to eq("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)) + expect { scope.function_type([]) }.to( raise_error(Puppet::ParseError)) end it "should return string when given a string" do result = scope.function_type(["aaabbbbcccc"]) - result.should(eq('string')) + expect(result).to(eq('string')) end it "should return array when given an array" do result = scope.function_type([["aaabbbbcccc","asdf"]]) - result.should(eq('array')) + expect(result).to(eq('array')) end it "should return hash when given a hash" do result = scope.function_type([{"a"=>1,"b"=>2}]) - result.should(eq('hash')) + expect(result).to(eq('hash')) end it "should return integer when given an integer" do result = scope.function_type(["1"]) - result.should(eq('integer')) + expect(result).to(eq('integer')) end it "should return float when given a float" do result = scope.function_type(["1.34"]) - result.should(eq('float')) + expect(result).to(eq('float')) end it "should return boolean when given a boolean" do result = scope.function_type([true]) - result.should(eq('boolean')) + expect(result).to(eq('boolean')) end end diff --git a/spec/functions/union_spec.rb b/spec/functions/union_spec.rb index 0d282ca..706f4cb 100755 --- a/spec/functions/union_spec.rb +++ b/spec/functions/union_spec.rb @@ -5,15 +5,15 @@ describe "the union function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("union").should == "function_union" + expect(Puppet::Parser::Functions.function("union")).to eq("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) ) + expect { scope.function_union([]) }.to( 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"])) + expect(result).to(eq(["a","b","c","d"])) end end diff --git a/spec/functions/unique_spec.rb b/spec/functions/unique_spec.rb index 5d48d49..8ec1464 100755 --- a/spec/functions/unique_spec.rb +++ b/spec/functions/unique_spec.rb @@ -5,20 +5,20 @@ describe "the unique function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("unique").should == "function_unique" + expect(Puppet::Parser::Functions.function("unique")).to eq("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)) + expect { scope.function_unique([]) }.to( raise_error(Puppet::ParseError)) end it "should remove duplicate elements in a string" do result = scope.function_unique(["aabbc"]) - result.should(eq('abc')) + expect(result).to(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'])) + expect(result).to(eq(['a','b','c'])) end end diff --git a/spec/functions/upcase_spec.rb b/spec/functions/upcase_spec.rb index 5db5513..78e55dd 100755 --- a/spec/functions/upcase_spec.rb +++ b/spec/functions/upcase_spec.rb @@ -5,20 +5,20 @@ describe "the upcase function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("upcase").should == "function_upcase" + expect(Puppet::Parser::Functions.function("upcase")).to eq("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)) + expect { scope.function_upcase([]) }.to( raise_error(Puppet::ParseError)) end it "should upcase a string" do result = scope.function_upcase(["abc"]) - result.should(eq('ABC')) + expect(result).to(eq('ABC')) end it "should do nothing if a string is already upcase" do result = scope.function_upcase(["ABC"]) - result.should(eq('ABC')) + expect(result).to(eq('ABC')) end end diff --git a/spec/functions/uriescape_spec.rb b/spec/functions/uriescape_spec.rb index 7211c88..c44e9c1 100755 --- a/spec/functions/uriescape_spec.rb +++ b/spec/functions/uriescape_spec.rb @@ -5,20 +5,20 @@ describe "the uriescape function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("uriescape").should == "function_uriescape" + expect(Puppet::Parser::Functions.function("uriescape")).to eq("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)) + expect { scope.function_uriescape([]) }.to( raise_error(Puppet::ParseError)) end it "should uriescape a string" do result = scope.function_uriescape([":/?#[]@!$&'()*+,;= \"{}"]) - result.should(eq(':/?%23[]@!$&\'()*+,;=%20%22%7B%7D')) + expect(result).to(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')) + expect(result).to(eq('ABCdef')) end end diff --git a/spec/functions/validate_slength_spec.rb b/spec/functions/validate_slength_spec.rb index 851835f..e23f61a 100755 --- a/spec/functions/validate_slength_spec.rb +++ b/spec/functions/validate_slength_spec.rb @@ -6,7 +6,7 @@ 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" + expect(Puppet::Parser::Functions.function("validate_slength")).to eq("function_validate_slength") end describe "validating the input argument types" do diff --git a/spec/functions/values_at_spec.rb b/spec/functions/values_at_spec.rb index 08e95a5..86e3c31 100755 --- a/spec/functions/values_at_spec.rb +++ b/spec/functions/values_at_spec.rb @@ -5,34 +5,34 @@ 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" + expect(Puppet::Parser::Functions.function("values_at")).to eq("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)) + expect { scope.function_values_at([]) }.to( 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)) + expect { scope.function_values_at([['a','b'],["3-1"]]) }.to( 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'])) + expect(result).to(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'])) + expect(result).to(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'])) + expect(result).to(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'])) + expect(result).to(eq(['a','c','e','f'])) end end diff --git a/spec/functions/values_spec.rb b/spec/functions/values_spec.rb index 14ae417..08d21b0 100755 --- a/spec/functions/values_spec.rb +++ b/spec/functions/values_spec.rb @@ -5,27 +5,27 @@ describe "the values function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do - Puppet::Parser::Functions.function("values").should == "function_values" + expect(Puppet::Parser::Functions.function("values")).to eq("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)) + expect { scope.function_values([]) }.to( 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 } + expect(result).to match_array(%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 } + expect(result).to match_array(%w{ 1 3 3 }) + expect(result).not_to match_array(%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)) + expect { scope.function_values([['a','b','c']]) }.to( raise_error(Puppet::ParseError)) end end diff --git a/spec/functions/zip_spec.rb b/spec/functions/zip_spec.rb index f45ab17..744bdd7 100755 --- a/spec/functions/zip_spec.rb +++ b/spec/functions/zip_spec.rb @@ -5,11 +5,11 @@ 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)) + expect { scope.function_zip([]) }.to( 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"]])) + expect(result).to(eq([["1", "4"], ["2", "5"], ["3", "6"]])) end end -- cgit v1.2.3 From 2062f9734bc955be896183790afc355aab428747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Tue, 10 Jun 2014 17:23:42 +0200 Subject: Add private() function --- README.markdown | 21 +++++++++++++ lib/puppet/parser/functions/private.rb | 29 ++++++++++++++++++ spec/functions/private_spec.rb | 55 ++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 lib/puppet/parser/functions/private.rb create mode 100755 spec/functions/private_spec.rb diff --git a/README.markdown b/README.markdown index e9ad53b..51adefe 100644 --- a/README.markdown +++ b/README.markdown @@ -725,6 +725,27 @@ Will return: ['pa','pb','pc'] - *Type*: rvalue + +private +------- +This function sets the current class or definition as private. +Calling the class or definition from outside the current module will fail. + +*Examples:* + + private() + +called in class `foo::bar` will output the following message if class is called +from outside module `foo`: + + Class foo::bar is private + +You can specify the error message you want to use as a parameter: + + private("You're not supposed to do that!") + +- *Type*: statement + range ----- When given range in the form of (start, stop) it will extrapolate a range as diff --git a/lib/puppet/parser/functions/private.rb b/lib/puppet/parser/functions/private.rb new file mode 100644 index 0000000..60210d3 --- /dev/null +++ b/lib/puppet/parser/functions/private.rb @@ -0,0 +1,29 @@ +# +# private.rb +# + +module Puppet::Parser::Functions + newfunction(:private, :doc => <<-'EOS' + Sets the current class or definition as private. + Calling the class or definition from outside the current module will fail. + EOS + ) do |args| + + raise(Puppet::ParseError, "private(): Wrong number of arguments "+ + "given (#{args.size}}) for 0 or 1)") if args.size > 1 + + scope = self + if scope.lookupvar('module_name') != scope.lookupvar('caller_module_name') + message = nil + if args[0] and args[0].is_a? String + message = args[0] + else + manifest_name = scope.source.name + manifest_type = scope.source.type + message = (manifest_type.to_s == 'hostclass') ? 'Class' : 'Definition' + message += " #{manifest_name} is private" + end + raise(Puppet::ParseError, message) + end + end +end diff --git a/spec/functions/private_spec.rb b/spec/functions/private_spec.rb new file mode 100755 index 0000000..c70759f --- /dev/null +++ b/spec/functions/private_spec.rb @@ -0,0 +1,55 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:private) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + subject do + function_name = Puppet::Parser::Functions.function(:private) + scope.method(function_name) + end + + context "when called from inside module" do + it "should not fail" do + scope.expects(:lookupvar).with('module_name').returns('foo') + scope.expects(:lookupvar).with('caller_module_name').returns('foo') + expect { + subject.call [] + }.not_to raise_error + end + end + + context "with an explicit failure message" do + it "prints the failure message on error" do + scope.expects(:lookupvar).with('module_name').returns('foo') + scope.expects(:lookupvar).with('caller_module_name').returns('bar') + expect { + subject.call ['failure message!'] + }.to raise_error Puppet::ParseError, /failure message!/ + end + end + + context "when called from private class" do + it "should fail with a class error message" do + scope.expects(:lookupvar).with('module_name').returns('foo') + scope.expects(:lookupvar).with('caller_module_name').returns('bar') + scope.source.expects(:name).returns('foo::baz') + scope.source.expects(:type).returns('hostclass') + expect { + subject.call [] + }.to raise_error Puppet::ParseError, /Class foo::baz is private/ + end + end + + context "when called from private definition" do + it "should fail with a class error message" do + scope.expects(:lookupvar).with('module_name').returns('foo') + scope.expects(:lookupvar).with('caller_module_name').returns('bar') + scope.source.expects(:name).returns('foo::baz') + scope.source.expects(:type).returns('definition') + expect { + subject.call [] + }.to raise_error Puppet::ParseError, /Definition foo::baz is private/ + end + end +end -- cgit v1.2.3 From 197e2d7e70d6570e82d2056d89de9e5e035b5750 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 19 Jun 2014 15:38:23 -0700 Subject: (FM-1587) Fix test issues on solaris 10 - ensure_packages fails because Error: Sun packages must specify a package source - ensure_resource fails for the same reason - get_module_path fails because the modulepath is different - has_interface_with fails because the interface is lo0 not lo --- spec/acceptance/ensure_packages_spec.rb | 4 ++-- spec/acceptance/ensure_resource_spec.rb | 4 ++-- spec/acceptance/get_module_path_spec.rb | 18 ++---------------- spec/acceptance/has_interface_with_spec.rb | 6 +++++- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb index aa7b14c..f3d2256 100755 --- a/spec/acceptance/ensure_packages_spec.rb +++ b/spec/acceptance/ensure_packages_spec.rb @@ -6,8 +6,8 @@ describe 'ensure_packages function', :unless => UNSUPPORTED_PLATFORMS.include?(f it 'ensure_packages a package' do apply_manifest('package { "zsh": ensure => absent, }') pp = <<-EOS - $a = "zsh" - ensure_packages($a) + $a = "rake" + ensure_packages($a,{'provider' => 'gem'}) EOS apply_manifest(pp, :expect_changes => true) do |r| diff --git a/spec/acceptance/ensure_resource_spec.rb b/spec/acceptance/ensure_resource_spec.rb index c4d8887..725f5df 100755 --- a/spec/acceptance/ensure_resource_spec.rb +++ b/spec/acceptance/ensure_resource_spec.rb @@ -6,8 +6,8 @@ describe 'ensure_resource function', :unless => UNSUPPORTED_PLATFORMS.include?(f it 'ensure_resource a package' do apply_manifest('package { "zsh": ensure => absent, }') pp = <<-EOS - $a = "zsh" - ensure_resource('package', $a) + $a = "rake" + ensure_resource('package', $a, {'provider' => 'gem'}) EOS apply_manifest(pp, :expect_changes => true) do |r| diff --git a/spec/acceptance/get_module_path_spec.rb b/spec/acceptance/get_module_path_spec.rb index 34d91fa..6ac690c 100755 --- a/spec/acceptance/get_module_path_spec.rb +++ b/spec/acceptance/get_module_path_spec.rb @@ -3,22 +3,6 @@ require 'spec_helper_acceptance' describe 'get_module_path function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do - it 'get_module_paths stdlib' do - pp = <<-EOS - $a = $::is_pe ? { - 'true' => '/opt/puppet/share/puppet/modules/stdlib', - 'false' => '/etc/puppet/modules/stdlib', - } - $o = get_module_path('stdlib') - if $o == $a { - notify { 'output correct': } - } - EOS - - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: output correct/) - end - end it 'get_module_paths dne' do pp = <<-EOS $a = $::is_pe ? { @@ -28,6 +12,8 @@ describe 'get_module_path function', :unless => UNSUPPORTED_PLATFORMS.include?(f $o = get_module_path('dne') if $o == $a { notify { 'output correct': } + } else { + notify { "failed; module path is '$o'": } } EOS diff --git a/spec/acceptance/has_interface_with_spec.rb b/spec/acceptance/has_interface_with_spec.rb index 41ae19f..7b38c95 100755 --- a/spec/acceptance/has_interface_with_spec.rb +++ b/spec/acceptance/has_interface_with_spec.rb @@ -27,7 +27,11 @@ describe 'has_interface_with function', :unless => UNSUPPORTED_PLATFORMS.include end it 'has_interface_with existing interface' do pp = <<-EOS - $a = 'lo' + if $osfamily == 'Solaris' { + $a = 'lo0' + } else { + $a = 'lo' + } $o = has_interface_with($a) notice(inline_template('has_interface_with is <%= @o.inspect %>')) EOS -- cgit v1.2.3 From 7eda161be88e4eeca44a288cb0394f51ea9e0621 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 20 Jun 2014 10:41:43 -0700 Subject: Patch ensure_* tests --- spec/acceptance/ensure_packages_spec.rb | 6 ++---- spec/acceptance/ensure_resource_spec.rb | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb index f3d2256..12da0cd 100755 --- a/spec/acceptance/ensure_packages_spec.rb +++ b/spec/acceptance/ensure_packages_spec.rb @@ -4,15 +4,13 @@ require 'spec_helper_acceptance' describe 'ensure_packages function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do it 'ensure_packages a package' do - apply_manifest('package { "zsh": ensure => absent, }') + apply_manifest('package { "rake": ensure => absent, provider => "gem", }') pp = <<-EOS $a = "rake" ensure_packages($a,{'provider' => 'gem'}) EOS - apply_manifest(pp, :expect_changes => true) do |r| - expect(r.stdout).to match(/Package\[zsh\]\/ensure: (created|ensure changed 'purged' to 'present')/) - end + apply_manifest(pp, :expect_changes => true) end it 'ensures a package already declared' it 'takes defaults arguments' diff --git a/spec/acceptance/ensure_resource_spec.rb b/spec/acceptance/ensure_resource_spec.rb index 725f5df..2aad243 100755 --- a/spec/acceptance/ensure_resource_spec.rb +++ b/spec/acceptance/ensure_resource_spec.rb @@ -4,15 +4,13 @@ require 'spec_helper_acceptance' describe 'ensure_resource function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do it 'ensure_resource a package' do - apply_manifest('package { "zsh": ensure => absent, }') + apply_manifest('package { "rake": ensure => absent, provider => "gem", }') pp = <<-EOS $a = "rake" ensure_resource('package', $a, {'provider' => 'gem'}) EOS - apply_manifest(pp, :expect_changes => true) do |r| - expect(r.stdout).to match(/Package\[zsh\]\/ensure: created/) - end + apply_manifest(pp, :expect_changes => true) end it 'ensures a resource already declared' it 'takes defaults arguments' -- cgit v1.2.3 From 24a6fecc78824ae411065aaca68e5250790bd778 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Fri, 20 Jun 2014 16:39:15 -0700 Subject: Add windows Nodesets and remove Beaker from Gemfile --- Gemfile | 1 - spec/acceptance/nodesets/windows-2003-i386.yml | 26 ++++++++++++++++++++++ spec/acceptance/nodesets/windows-2003-x86_64.yml | 26 ++++++++++++++++++++++ spec/acceptance/nodesets/windows-2008-x86_64.yml | 26 ++++++++++++++++++++++ spec/acceptance/nodesets/windows-2008r2-x86_64.yml | 26 ++++++++++++++++++++++ spec/acceptance/nodesets/windows-2012-x86_64.yml | 26 ++++++++++++++++++++++ spec/acceptance/nodesets/windows-2012r2-x86_64.yml | 26 ++++++++++++++++++++++ 7 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 spec/acceptance/nodesets/windows-2003-i386.yml create mode 100644 spec/acceptance/nodesets/windows-2003-x86_64.yml create mode 100644 spec/acceptance/nodesets/windows-2008-x86_64.yml create mode 100644 spec/acceptance/nodesets/windows-2008r2-x86_64.yml create mode 100644 spec/acceptance/nodesets/windows-2012-x86_64.yml create mode 100644 spec/acceptance/nodesets/windows-2012r2-x86_64.yml diff --git a/Gemfile b/Gemfile index bbef720..c2e58ed 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,6 @@ group :development, :test do gem 'puppet-lint', :require => false gem 'pry', :require => false gem 'simplecov', :require => false - gem 'beaker', :require => false gem 'beaker-rspec', :require => false end diff --git a/spec/acceptance/nodesets/windows-2003-i386.yml b/spec/acceptance/nodesets/windows-2003-i386.yml new file mode 100644 index 0000000..47dadbd --- /dev/null +++ b/spec/acceptance/nodesets/windows-2003-i386.yml @@ -0,0 +1,26 @@ +HOSTS: + ubuntu1204: + roles: + - master + - database + - dashboard + platform: ubuntu-12.04-amd64 + template: ubuntu-1204-x86_64 + hypervisor: vcloud + win2003_i386: + roles: + - agent + - default + platform: windows-2003-i386 + template: win-2003-i386 + hypervisor: vcloud +CONFIG: + nfs_server: none + ssh: + keys: "~/.ssh/id_rsa-acceptance" + consoleport: 443 + datastore: instance0 + folder: Delivery/Quality Assurance/Enterprise/Dynamic + resourcepool: delivery/Quality Assurance/Enterprise/Dynamic + pooling_api: http://vcloud.delivery.puppetlabs.net/ + pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ diff --git a/spec/acceptance/nodesets/windows-2003-x86_64.yml b/spec/acceptance/nodesets/windows-2003-x86_64.yml new file mode 100644 index 0000000..6a884bc --- /dev/null +++ b/spec/acceptance/nodesets/windows-2003-x86_64.yml @@ -0,0 +1,26 @@ +HOSTS: + ubuntu1204: + roles: + - master + - database + - dashboard + platform: ubuntu-12.04-amd64 + template: ubuntu-1204-x86_64 + hypervisor: vcloud + win2003_x86_64: + roles: + - agent + - default + platform: windows-2003-x86_64 + template: win-2003-x86_64 + hypervisor: vcloud +CONFIG: + nfs_server: none + ssh: + keys: "~/.ssh/id_rsa-acceptance" + consoleport: 443 + datastore: instance0 + folder: Delivery/Quality Assurance/Enterprise/Dynamic + resourcepool: delivery/Quality Assurance/Enterprise/Dynamic + pooling_api: http://vcloud.delivery.puppetlabs.net/ + pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ diff --git a/spec/acceptance/nodesets/windows-2008-x86_64.yml b/spec/acceptance/nodesets/windows-2008-x86_64.yml new file mode 100644 index 0000000..ae3c11d --- /dev/null +++ b/spec/acceptance/nodesets/windows-2008-x86_64.yml @@ -0,0 +1,26 @@ +HOSTS: + ubuntu1204: + roles: + - master + - database + - dashboard + platform: ubuntu-12.04-amd64 + template: ubuntu-1204-x86_64 + hypervisor: vcloud + win2008_x86_64: + roles: + - agent + - default + platform: windows-2008-x86_64 + template: win-2008-x86_64 + hypervisor: vcloud +CONFIG: + nfs_server: none + ssh: + keys: "~/.ssh/id_rsa-acceptance" + consoleport: 443 + datastore: instance0 + folder: Delivery/Quality Assurance/Enterprise/Dynamic + resourcepool: delivery/Quality Assurance/Enterprise/Dynamic + pooling_api: http://vcloud.delivery.puppetlabs.net/ + pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ diff --git a/spec/acceptance/nodesets/windows-2008r2-x86_64.yml b/spec/acceptance/nodesets/windows-2008r2-x86_64.yml new file mode 100644 index 0000000..63923ac --- /dev/null +++ b/spec/acceptance/nodesets/windows-2008r2-x86_64.yml @@ -0,0 +1,26 @@ +HOSTS: + ubuntu1204: + roles: + - master + - database + - dashboard + platform: ubuntu-12.04-amd64 + template: ubuntu-1204-x86_64 + hypervisor: vcloud + win2008r2: + roles: + - agent + - default + platform: windows-2008r2-x86_64 + template: win-2008r2-x86_64 + hypervisor: vcloud +CONFIG: + nfs_server: none + ssh: + keys: "~/.ssh/id_rsa-acceptance" + consoleport: 443 + datastore: instance0 + folder: Delivery/Quality Assurance/Enterprise/Dynamic + resourcepool: delivery/Quality Assurance/Enterprise/Dynamic + pooling_api: http://vcloud.delivery.puppetlabs.net/ + pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ diff --git a/spec/acceptance/nodesets/windows-2012-x86_64.yml b/spec/acceptance/nodesets/windows-2012-x86_64.yml new file mode 100644 index 0000000..eaa4eca --- /dev/null +++ b/spec/acceptance/nodesets/windows-2012-x86_64.yml @@ -0,0 +1,26 @@ +HOSTS: + ubuntu1204: + roles: + - master + - database + - dashboard + platform: ubuntu-12.04-amd64 + template: ubuntu-1204-x86_64 + hypervisor: vcloud + win2012: + roles: + - agent + - default + platform: windows-2012-x86_64 + template: win-2012-x86_64 + hypervisor: vcloud +CONFIG: + nfs_server: none + ssh: + keys: "~/.ssh/id_rsa-acceptance" + consoleport: 443 + datastore: instance0 + folder: Delivery/Quality Assurance/Enterprise/Dynamic + resourcepool: delivery/Quality Assurance/Enterprise/Dynamic + pooling_api: http://vcloud.delivery.puppetlabs.net/ + pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ diff --git a/spec/acceptance/nodesets/windows-2012r2-x86_64.yml b/spec/acceptance/nodesets/windows-2012r2-x86_64.yml new file mode 100644 index 0000000..1f0ea97 --- /dev/null +++ b/spec/acceptance/nodesets/windows-2012r2-x86_64.yml @@ -0,0 +1,26 @@ +HOSTS: + ubuntu1204: + roles: + - master + - database + - dashboard + platform: ubuntu-12.04-amd64 + template: ubuntu-1204-x86_64 + hypervisor: vcloud + win2012r2: + roles: + - agent + - default + platform: windows-2012r2-x86_64 + template: win-2012r2-x86_64 + hypervisor: vcloud +CONFIG: + nfs_server: none + ssh: + keys: "~/.ssh/id_rsa-acceptance" + consoleport: 443 + datastore: instance0 + folder: Delivery/Quality Assurance/Enterprise/Dynamic + resourcepool: delivery/Quality Assurance/Enterprise/Dynamic + pooling_api: http://vcloud.delivery.puppetlabs.net/ + pe_dir: http://neptune.puppetlabs.lan/3.2/ci-ready/ -- cgit v1.2.3 From 4b7162896a0a4ec5dc5166c8846eb5968a3c5329 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 23 Jun 2014 13:45:06 -0700 Subject: OS X also has lo0 and can't manage user homedirs --- spec/acceptance/getparam_spec.rb | 12 ++++++------ spec/acceptance/has_interface_with_spec.rb | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/acceptance/getparam_spec.rb b/spec/acceptance/getparam_spec.rb index 91fc9a0..e3e442f 100755 --- a/spec/acceptance/getparam_spec.rb +++ b/spec/acceptance/getparam_spec.rb @@ -3,18 +3,18 @@ require 'spec_helper_acceptance' describe 'getparam function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do - it 'getparam a package' do + it 'getparam a notify' do pp = <<-EOS - user { "rspec": - ensure => present, - managehome => true, + notify { 'rspec': + ensure => present, + message => 'custom rspec message', } - $o = getparam(User['rspec'], 'managehome') + $o = getparam(Notify['rspec'], 'message') notice(inline_template('getparam is <%= @o.inspect %>')) EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/getparam is true/) + expect(r.stdout).to match(/getparam is "custom rspec message"/) end end end diff --git a/spec/acceptance/has_interface_with_spec.rb b/spec/acceptance/has_interface_with_spec.rb index 7b38c95..99b7681 100755 --- a/spec/acceptance/has_interface_with_spec.rb +++ b/spec/acceptance/has_interface_with_spec.rb @@ -27,7 +27,7 @@ describe 'has_interface_with function', :unless => UNSUPPORTED_PLATFORMS.include end it 'has_interface_with existing interface' do pp = <<-EOS - if $osfamily == 'Solaris' { + if $osfamily == 'Solaris' or $osfamily == 'Darwin' { $a = 'lo0' } else { $a = 'lo' -- cgit v1.2.3 From 280d808eb4284daa32b81d4ac90da96a5609a625 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 23 Jun 2014 13:47:34 -0700 Subject: Augeas isn't present on windows --- spec/acceptance/validate_augeas_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/validate_augeas_spec.rb b/spec/acceptance/validate_augeas_spec.rb index aeec67a..71a4c84 100755 --- a/spec/acceptance/validate_augeas_spec.rb +++ b/spec/acceptance/validate_augeas_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'validate_augeas function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +describe 'validate_augeas function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows')) do describe 'prep' do it 'installs augeas for tests' end -- cgit v1.2.3 From f7b7c4a6ece9d9e5d551ea77867289eee4cfe8e8 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 23 Jun 2014 15:13:29 -0700 Subject: Windows needs a tmpdir path --- spec/acceptance/loadyaml_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/acceptance/loadyaml_spec.rb b/spec/acceptance/loadyaml_spec.rb index 944a727..1e910a9 100644 --- a/spec/acceptance/loadyaml_spec.rb +++ b/spec/acceptance/loadyaml_spec.rb @@ -1,16 +1,18 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' +tmpdir = default.tmpdir('stdlib') + describe 'loadyaml function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do it 'loadyamls array of values' do - shell('echo "--- + shell("echo '--- aaa: 1 bbb: 2 ccc: 3 - ddd: 4" > /testyaml.yaml') + ddd: 4' > #{tmpdir}/testyaml.yaml") pp = <<-EOS - $o = loadyaml('/testyaml.yaml') + $o = loadyaml('#{tmpdir}/testyaml.yaml') notice(inline_template('loadyaml[aaa] is <%= @o["aaa"].inspect %>')) notice(inline_template('loadyaml[bbb] is <%= @o["bbb"].inspect %>')) notice(inline_template('loadyaml[ccc] is <%= @o["ccc"].inspect %>')) -- cgit v1.2.3 From cfce787890cffed6889b32267204c97f24905416 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 23 Jun 2014 16:17:23 -0700 Subject: Remove Modulefile; use metadata.json --- Modulefile | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 Modulefile diff --git a/Modulefile b/Modulefile deleted file mode 100644 index bf80e3b..0000000 --- a/Modulefile +++ /dev/null @@ -1,11 +0,0 @@ -name 'puppetlabs-stdlib' -version '4.2.2' -source 'git://github.com/puppetlabs/puppetlabs-stdlib.git' -author 'puppetlabs' -license 'Apache 2.0' -summary 'Puppet Module Standard Library' -description 'Standard Library for Puppet Modules' -project_page 'https://github.com/puppetlabs/puppetlabs-stdlib' - -## Add dependencies, if any: -# dependency 'username/name', '>= 1.2.0' -- cgit v1.2.3 From 0199e2396aa841fb8d34e8c33da2373e2b2c9416 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Mon, 23 Jun 2014 16:59:46 -0700 Subject: Add windows support and work around issue with SCP_TO on windows systems --- spec/spec_helper_acceptance.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 8e56daa..dc2cfdc 100755 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -6,7 +6,12 @@ UNSUPPORTED_PLATFORMS = [] unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' if hosts.first.is_pe? install_pe - on hosts, 'mkdir -p /etc/puppetlabs/facter/facts.d' + hosts.each do |host| + if !(host['platform'] =~ /windows/) + on host, 'mkdir -p /etc/puppetlabs/facter/facts.d' + end + end + else install_puppet on hosts, 'mkdir -p /etc/facter/facts.d' @@ -26,6 +31,15 @@ RSpec.configure do |c| # Configure all nodes in nodeset c.before :suite do - puppet_module_install(:source => proj_root, :module_name => 'stdlib') + hosts.each do |host| + if host['platform'] !~ /windows/i + copy_root_module_to(host, :source => proj_root, :module_name => 'stdlib') + end + end + hosts.each do |host| + if host['platform'] =~ /windows/i + on host, puppet('plugin download') + end + end end end -- cgit v1.2.3 From 78f5141290926aaabec3980aae9d923c7bf1d359 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Mon, 23 Jun 2014 17:24:08 -0700 Subject: Removed platform check for facts.d mkdir --- spec/spec_helper_acceptance.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index dc2cfdc..e9ccc68 100755 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -6,12 +6,7 @@ UNSUPPORTED_PLATFORMS = [] unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' if hosts.first.is_pe? install_pe - hosts.each do |host| - if !(host['platform'] =~ /windows/) - on host, 'mkdir -p /etc/puppetlabs/facter/facts.d' - end - end - + on hosts, 'mkdir -p /etc/puppetlabs/facter/facts.d' else install_puppet on hosts, 'mkdir -p /etc/facter/facts.d' -- cgit v1.2.3 From 64f0ae2269be8b98d2d028dcb6a732be67b0f3a6 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Mon, 23 Jun 2014 22:47:03 -0700 Subject: Increase resilience if lookup var comes back with nil object --- lib/puppet/parser/functions/has_interface_with.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb index 7f150a7..927b0df 100644 --- a/lib/puppet/parser/functions/has_interface_with.rb +++ b/lib/puppet/parser/functions/has_interface_with.rb @@ -25,7 +25,7 @@ has_interface_with("lo") => true interfaces = lookupvar('interfaces') # If we do not have any interfaces, then there are no requested attributes - return false if (interfaces == :undefined) + return false if (interfaces == :undefined || interfaces.nil?) interfaces = interfaces.split(',') -- cgit v1.2.3 From eb507c9a5486d269ec6a36f169eb68695910bfbf Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Mon, 23 Jun 2014 23:27:59 -0700 Subject: Fixed fqdn,getparam and has_interface_with spec tests --- spec/acceptance/fqdn_rotate_spec.rb | 19 ++++++++++++++++--- spec/acceptance/getparam_spec.rb | 1 - spec/acceptance/has_interface_with_spec.rb | 10 ++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb index fc8bea2..2527c28 100755 --- a/spec/acceptance/fqdn_rotate_spec.rb +++ b/spec/acceptance/fqdn_rotate_spec.rb @@ -5,7 +5,15 @@ describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact( describe 'success' do let(:facts_d) do if fact('is_pe') == "true" - '/etc/puppetlabs/facter/facts.d' + if fact('osfamily') =~ /windows/i + if fact('kernelmajversion').to_f < 6.0 + 'C:\Documents and Settings\All Users\Application Data\PuppetLabs\facter\facts.d' + else + 'C:\ProgramData\PuppetLabs\facter\facts.d' + end + else + '/etc/puppetlabs/facter/facts.d' + end else '/etc/facter/facts.d' end @@ -13,9 +21,14 @@ describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact( after :each do shell("if [ -f #{facts_d}/fqdn.txt ] ; then rm #{facts_d}/fqdn.txt ; fi") end + before :all do + #No need to create on windows, PE creates by default + if fact('osfamily') !~ /windows/i + shell("mkdir -p #{facts_d}") + end + end it 'fqdn_rotates floats' do - shell("mkdir -p #{facts_d}") - shell("echo 'fqdn=fakehost.localdomain' > #{facts_d}/fqdn.txt") + shell("echo fqdn=fakehost.localdomain > #{facts_d}/fqdn.txt") pp = <<-EOS $a = ['a','b','c','d'] $o = fqdn_rotate($a) diff --git a/spec/acceptance/getparam_spec.rb b/spec/acceptance/getparam_spec.rb index e3e442f..b1a677e 100755 --- a/spec/acceptance/getparam_spec.rb +++ b/spec/acceptance/getparam_spec.rb @@ -6,7 +6,6 @@ describe 'getparam function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op it 'getparam a notify' do pp = <<-EOS notify { 'rspec': - ensure => present, message => 'custom rspec message', } $o = getparam(Notify['rspec'], 'message') diff --git a/spec/acceptance/has_interface_with_spec.rb b/spec/acceptance/has_interface_with_spec.rb index 99b7681..c9decdf 100755 --- a/spec/acceptance/has_interface_with_spec.rb +++ b/spec/acceptance/has_interface_with_spec.rb @@ -5,7 +5,7 @@ describe 'has_interface_with function', :unless => UNSUPPORTED_PLATFORMS.include describe 'success' do it 'has_interface_with existing ipaddress' do pp = <<-EOS - $a = '127.0.0.1' + $a = $::ipaddress $o = has_interface_with('ipaddress', $a) notice(inline_template('has_interface_with is <%= @o.inspect %>')) EOS @@ -29,7 +29,13 @@ describe 'has_interface_with function', :unless => UNSUPPORTED_PLATFORMS.include pp = <<-EOS if $osfamily == 'Solaris' or $osfamily == 'Darwin' { $a = 'lo0' - } else { + }elsif $osfamily == 'windows' { + $a = $::kernelmajversion ? { + /6\.(2|3|4)/ => 'Ethernet0', + /6\.(0|1)/ => 'Local_Area_Connection', + /5\.(1|2)/ => undef, #Broken current in facter + } + }else { $a = 'lo' } $o = has_interface_with($a) -- cgit v1.2.3 From def3af9cb018a204e4f007c41955099658591e02 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 24 Jun 2014 10:27:25 -0700 Subject: stdlib 4 isn't compatible with PE 3.2 --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index acb880f..ff35d2c 100644 --- a/metadata.json +++ b/metadata.json @@ -89,7 +89,7 @@ "requirements": [ { "name": "pe", - "version_requirement": ">= 3.2.0 < 3.4.0" + "version_requirement": "3.3.x" }, { "name": "puppet", -- cgit v1.2.3 From ca35be6480a5935a4b0e0721bdb726934269e433 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 24 Jun 2014 11:37:34 -0700 Subject: Fix pe facts and slashes --- spec/acceptance/fqdn_rotate_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb index 2527c28..bc02eb6 100755 --- a/spec/acceptance/fqdn_rotate_spec.rb +++ b/spec/acceptance/fqdn_rotate_spec.rb @@ -4,12 +4,12 @@ require 'spec_helper_acceptance' describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do let(:facts_d) do - if fact('is_pe') == "true" + if fact('is_pe', '--puppet') == "true" if fact('osfamily') =~ /windows/i if fact('kernelmajversion').to_f < 6.0 - 'C:\Documents and Settings\All Users\Application Data\PuppetLabs\facter\facts.d' + 'C:\\Documents and Settings\\All Users\\Application Data\\PuppetLabs\\facter\\facts.d' else - 'C:\ProgramData\PuppetLabs\facter\facts.d' + 'C:\\ProgramData\\PuppetLabs\\facter\\facts.d' end else '/etc/puppetlabs/facter/facts.d' -- cgit v1.2.3 From 0cac9fd0489180d7b6ae59ce67334dc34ddcc961 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 24 Jun 2014 15:03:58 -0700 Subject: Not enough escape velocity --- spec/acceptance/fqdn_rotate_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb index bc02eb6..d56c2b1 100755 --- a/spec/acceptance/fqdn_rotate_spec.rb +++ b/spec/acceptance/fqdn_rotate_spec.rb @@ -7,9 +7,9 @@ describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact( if fact('is_pe', '--puppet') == "true" if fact('osfamily') =~ /windows/i if fact('kernelmajversion').to_f < 6.0 - 'C:\\Documents and Settings\\All Users\\Application Data\\PuppetLabs\\facter\\facts.d' + 'C:/Documents and Settings/All Users/Application Data/PuppetLabs/facter/facts.d' else - 'C:\\ProgramData\\PuppetLabs\\facter\\facts.d' + 'C:/ProgramData/PuppetLabs/facter/facts.d' end else '/etc/puppetlabs/facter/facts.d' -- cgit v1.2.3 From 05b79dcabbdb67aab322fa6e12e77532ab044749 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Wed, 25 Jun 2014 10:16:06 -0700 Subject: Disable windows network stuff and quote path --- spec/acceptance/fqdn_rotate_spec.rb | 2 +- spec/acceptance/has_interface_with_spec.rb | 2 +- spec/acceptance/has_ip_address_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb index d56c2b1..ee2afb5 100755 --- a/spec/acceptance/fqdn_rotate_spec.rb +++ b/spec/acceptance/fqdn_rotate_spec.rb @@ -28,7 +28,7 @@ describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact( end end it 'fqdn_rotates floats' do - shell("echo fqdn=fakehost.localdomain > #{facts_d}/fqdn.txt") + shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") pp = <<-EOS $a = ['a','b','c','d'] $o = fqdn_rotate($a) diff --git a/spec/acceptance/has_interface_with_spec.rb b/spec/acceptance/has_interface_with_spec.rb index c9decdf..b09199a 100755 --- a/spec/acceptance/has_interface_with_spec.rb +++ b/spec/acceptance/has_interface_with_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'has_interface_with function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +describe 'has_interface_with function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows')) do describe 'success' do it 'has_interface_with existing ipaddress' do pp = <<-EOS diff --git a/spec/acceptance/has_ip_address_spec.rb b/spec/acceptance/has_ip_address_spec.rb index 7d5fd87..50eb8f5 100755 --- a/spec/acceptance/has_ip_address_spec.rb +++ b/spec/acceptance/has_ip_address_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'has_ip_address function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +describe 'has_ip_address function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows')) do describe 'success' do it 'has_ip_address existing ipaddress' do pp = <<-EOS -- cgit v1.2.3 From 18c5231469a885b5166cfa954f297127224c61f6 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Wed, 25 Jun 2014 09:32:54 -0700 Subject: Add configuration file for modulesync https://github.com/puppetlabs/modulesync --- .sync.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .sync.yml diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 0000000..ac79bae --- /dev/null +++ b/.sync.yml @@ -0,0 +1,9 @@ +--- +.travis.yml: + unmanaged: true +Rakefile: + unmanaged: true +Gemfile: + unmanaged: true +spec/spec_helper.rb: + unmanaged: true -- cgit v1.2.3 From 2fefd9c1e0249daebd327ca6e1ee3d791257e663 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Wed, 25 Jun 2014 18:00:57 -0700 Subject: Sync files --- .gitignore | 8 +- CONTRIBUTING.md | 295 ++++++++++++++++----- spec/acceptance/nodesets/centos-59-x64.yml | 10 + spec/acceptance/nodesets/centos-65-x64.yml | 10 + .../acceptance/nodesets/ubuntu-server-1404-x64.yml | 11 + 5 files changed, 267 insertions(+), 67 deletions(-) create mode 100644 spec/acceptance/nodesets/centos-59-x64.yml create mode 100644 spec/acceptance/nodesets/centos-65-x64.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-1404-x64.yml diff --git a/.gitignore b/.gitignore index 7d0fd8d..b5b7a00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ pkg/ -.DS_Store -coverage/ -spec/fixtures/ Gemfile.lock +vendor/ +spec/fixtures/ +.vagrant/ .bundle/ -vendor/bundle/ +coverage/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5280da1..e128847 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,65 +1,234 @@ -# How to contribute - -Third-party patches are essential for keeping stdlib great. We simply can't -access the huge number of platforms and myriad configurations for running -stdlib. We want to keep it as easy as possible to contribute changes that -get things working in your environment. There are a few guidelines that we -need contributors to follow so that we can have a chance of keeping on -top of things. - -## Getting Started - -* Make sure you have a [Jira account](http://tickets.puppetlabs.com) -* Make sure you have a [GitHub account](https://github.com/signup/free) -* Submit a ticket for your issue, assuming one does not already exist. - * Clearly describe the issue including steps to reproduce when it is a bug. - * Make sure you fill in the earliest version that you know has the issue. -* Fork the repository on GitHub - -## Making Changes - -* Create a topic branch from where you want to base your work. - * This is usually the master branch. - * Only target release branches if you are certain your fix must be on that - branch. - * To quickly create a topic branch based on master; `git branch - fix/master/my_contribution master` then checkout the new branch with `git - checkout fix/master/my_contribution`. Please avoid working directly on the - `master` branch. -* Make commits of logical units. -* Check for unnecessary whitespace with `git diff --check` before committing. -* Make sure your commit messages are in the proper format. - -```` - (#99999) Make the example in CONTRIBUTING imperative and concrete - - Without this patch applied the example commit message in the CONTRIBUTING - document is not a concrete example. This is a problem because the - contributor is left to imagine what the commit message should look like - based on a description rather than an example. This patch fixes the - problem by making the example concrete and imperative. - - The first line is a real life imperative statement with a ticket number - from our issue tracker. The body describes the behavior without the patch, - why this is a problem, and how the patch fixes the problem when applied. -```` - -* Make sure you have added the necessary tests for your changes. -* Run _all_ the tests to assure nothing else was accidentally broken. - -## Submitting Changes - -* Sign the [Contributor License Agreement](http://links.puppetlabs.com/cla). -* Push your changes to a topic branch in your fork of the repository. -* Submit a pull request to the repository in the puppetlabs organization. -* Update your ticket to mark that you have submitted code and are ready for it to be reviewed. - * Include a link to the pull request in the ticket - -# Additional Resources - -* [More information on contributing](http://links.puppetlabs.com/contribute-to-puppet) -* [Bug tracker (Jira)](http://tickets.puppetlabs.com) -* [Contributor License Agreement](http://links.puppetlabs.com/cla) +Checklist (and a short version for the impatient) +================================================= + + * Commits: + + - Make commits of logical units. + + - Check for unnecessary whitespace with "git diff --check" before + committing. + + - Commit using Unix line endings (check the settings around "crlf" in + git-config(1)). + + - Do not check in commented out code or unneeded files. + + - The first line of the commit message should be a short + description (50 characters is the soft limit, excluding ticket + number(s)), and should skip the full stop. + + - Associate the issue in the message. The first line should include + the issue number in the form "(#XXXX) Rest of message". + + - The body should provide a meaningful commit message, which: + + - uses the imperative, present tense: "change", not "changed" or + "changes". + + - includes motivation for the change, and contrasts its + implementation with the previous behavior. + + - Make sure that you have tests for the bug you are fixing, or + feature you are adding. + + - Make sure the test suites passes after your commit: + `bundle exec rspec spec/acceptance` More information on [testing](#Testing) below + + - When introducing a new feature, make sure it is properly + documented in the README.md + + * Submission: + + * Pre-requisites: + + - Sign the [Contributor License Agreement](https://cla.puppetlabs.com/) + + - Make sure you have a [GitHub account](https://github.com/join) + + - [Create a ticket](http://projects.puppetlabs.com/projects/modules/issues/new), or [watch the ticket](http://projects.puppetlabs.com/projects/modules/issues) you are patching for. + + * Preferred method: + + - Fork the repository on GitHub. + + - Push your changes to a topic branch in your fork of the + repository. (the format ticket/1234-short_description_of_change is + usually preferred for this project). + + - Submit a pull request to the repository in the puppetlabs + organization. + +The long version +================ + + 1. Make separate commits for logically separate changes. + + Please break your commits down into logically consistent units + which include new or changed tests relevant to the rest of the + change. The goal of doing this is to make the diff easier to + read for whoever is reviewing your code. In general, the easier + your diff is to read, the more likely someone will be happy to + review it and get it into the code base. + + If you are going to refactor a piece of code, please do so as a + separate commit from your feature or bug fix changes. + + We also really appreciate changes that include tests to make + sure the bug is not re-introduced, and that the feature is not + accidentally broken. + + Describe the technical detail of the change(s). If your + description starts to get too long, that is a good sign that you + probably need to split up your commit into more finely grained + pieces. + + Commits which plainly describe the things which help + reviewers check the patch and future developers understand the + code are much more likely to be merged in with a minimum of + bike-shedding or requested changes. Ideally, the commit message + would include information, and be in a form suitable for + inclusion in the release notes for the version of Puppet that + includes them. + + Please also check that you are not introducing any trailing + whitespace or other "whitespace errors". You can do this by + running "git diff --check" on your changes before you commit. + + 2. Sign the Contributor License Agreement + + Before we can accept your changes, we do need a signed Puppet + Labs Contributor License Agreement (CLA). + + You can access the CLA via the [Contributor License Agreement link](https://cla.puppetlabs.com/) + + If you have any questions about the CLA, please feel free to + contact Puppet Labs via email at cla-submissions@puppetlabs.com. + + 3. Sending your patches + + To submit your changes via a GitHub pull request, we _highly_ + recommend that you have them on a topic branch, instead of + directly on "master". + It makes things much easier to keep track of, especially if + you decide to work on another thing before your first change + is merged in. + + GitHub has some pretty good + [general documentation](http://help.github.com/) on using + their site. They also have documentation on + [creating pull requests](http://help.github.com/send-pull-requests/). + + In general, after pushing your topic branch up to your + repository on GitHub, you can switch to the branch in the + GitHub UI and click "Pull Request" towards the top of the page + in order to open a pull request. + + + 4. Update the related GitHub issue. + + If there is a GitHub issue associated with the change you + submitted, then you should update the ticket to include the + location of your branch, along with any other commentary you + may wish to make. + +Testing +======= + +Getting Started +--------------- + +Our puppet modules provide [`Gemfile`](./Gemfile)s which can tell a ruby +package manager such as [bundler](http://bundler.io/) what Ruby packages, +or Gems, are required to build, develop, and test this software. + +Please make sure you have [bundler installed](http://bundler.io/#getting-started) +on your system, then use it to install all dependencies needed for this project, +by running + +```shell +% bundle install +Fetching gem metadata from https://rubygems.org/........ +Fetching gem metadata from https://rubygems.org/.. +Using rake (10.1.0) +Using builder (3.2.2) +-- 8><-- many more --><8 -- +Using rspec-system-puppet (2.2.0) +Using serverspec (0.6.3) +Using rspec-system-serverspec (1.0.0) +Using bundler (1.3.5) +Your bundle is complete! +Use `bundle show [gemname]` to see where a bundled gem is installed. +``` + +NOTE some systems may require you to run this command with sudo. + +If you already have those gems installed, make sure they are up-to-date: + +```shell +% bundle update +``` + +With all dependencies in place and up-to-date we can now run the tests: + +```shell +% rake spec +``` + +This will execute all the [rspec tests](http://rspec-puppet.com/) tests +under [spec/defines](./spec/defines), [spec/classes](./spec/classes), +and so on. rspec tests may have the same kind of dependencies as the +module they are testing. While the module defines in its [Modulefile](./Modulefile), +rspec tests define them in [.fixtures.yml](./fixtures.yml). + +Some puppet modules also come with [beaker](https://github.com/puppetlabs/beaker) +tests. These tests spin up a virtual machine under +[VirtualBox](https://www.virtualbox.org/)) with, controlling it with +[Vagrant](http://www.vagrantup.com/) to actually simulate scripted test +scenarios. In order to run these, you will need both of those tools +installed on your system. + +You can run them by issuing the following command + +```shell +% rake spec_clean +% rspec spec/acceptance +``` + +This will now download a pre-fabricated image configured in the [default node-set](./spec/acceptance/nodesets/default.yml), +install puppet, copy this module and install its dependencies per [spec/spec_helper_acceptance.rb](./spec/spec_helper_acceptance.rb) +and then run all the tests under [spec/acceptance](./spec/acceptance). + +Writing Tests +------------- + +XXX getting started writing tests. + +If you have commit access to the repository +=========================================== + +Even if you have commit access to the repository, you will still need to +go through the process above, and have someone else review and merge +in your changes. The rule is that all changes must be reviewed by a +developer on the project (that did not write the code) to ensure that +all changes go through a code review process. + +Having someone other than the author of the topic branch recorded as +performing the merge is the record that they performed the code +review. + + +Additional Resources +==================== + +* [Getting additional help](http://projects.puppetlabs.com/projects/puppet/wiki/Getting_Help) + +* [Writing tests](http://projects.puppetlabs.com/projects/puppet/wiki/Development_Writing_Tests) + +* [Patchwork](https://patchwork.puppetlabs.com) + +* [Contributor License Agreement](https://projects.puppetlabs.com/contributor_licenses/sign) + * [General GitHub documentation](http://help.github.com/) + * [GitHub pull request documentation](http://help.github.com/send-pull-requests/) -* #puppet-dev IRC channel on freenode.org + diff --git a/spec/acceptance/nodesets/centos-59-x64.yml b/spec/acceptance/nodesets/centos-59-x64.yml new file mode 100644 index 0000000..2ad90b8 --- /dev/null +++ b/spec/acceptance/nodesets/centos-59-x64.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-59-x64: + roles: + - master + platform: el-5-x86_64 + box : centos-59-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box + hypervisor : vagrant +CONFIG: + type: git diff --git a/spec/acceptance/nodesets/centos-65-x64.yml b/spec/acceptance/nodesets/centos-65-x64.yml new file mode 100644 index 0000000..4e2cb80 --- /dev/null +++ b/spec/acceptance/nodesets/centos-65-x64.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-65-x64: + roles: + - master + platform: el-6-x86_64 + box : centos-65-x64-vbox436-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box + hypervisor : vagrant +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml new file mode 100644 index 0000000..cba1cd0 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + ubuntu-server-1404-x64: + roles: + - master + platform: ubuntu-14.04-amd64 + box : puppetlabs/ubuntu-14.04-64-nocm + box_url : https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm + hypervisor : vagrant +CONFIG: + log_level : debug + type: git -- cgit v1.2.3 From b93f71f0ced2cb87e4817e2eb4858fb1e47f3901 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 26 Jun 2014 13:12:39 -0700 Subject: has_ip_network doesn't work on windows either --- spec/acceptance/has_ip_network_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/has_ip_network_spec.rb b/spec/acceptance/has_ip_network_spec.rb index 692eaf9..1628746 100755 --- a/spec/acceptance/has_ip_network_spec.rb +++ b/spec/acceptance/has_ip_network_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'has_ip_network function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +describe 'has_ip_network function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows')) do describe 'success' do it 'has_ip_network existing ipaddress' do pp = <<-EOS -- cgit v1.2.3 From 1b893ff653d64ca8a923ab37a0c222fc35c0eb5f Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 26 Jun 2014 13:17:07 -0700 Subject: Need quotes for spaces in path --- spec/acceptance/fqdn_rotate_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb index ee2afb5..c37b35a 100755 --- a/spec/acceptance/fqdn_rotate_spec.rb +++ b/spec/acceptance/fqdn_rotate_spec.rb @@ -19,12 +19,12 @@ describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact( end end after :each do - shell("if [ -f #{facts_d}/fqdn.txt ] ; then rm #{facts_d}/fqdn.txt ; fi") + shell("if [ -f '#{facts_d}/fqdn.txt' ] ; then rm '#{facts_d}/fqdn.txt' ; fi") end before :all do #No need to create on windows, PE creates by default if fact('osfamily') !~ /windows/i - shell("mkdir -p #{facts_d}") + shell("mkdir -p '#{facts_d}'") end end it 'fqdn_rotates floats' do -- cgit v1.2.3 From ec607827ad659431341383b92cee20cfd0603203 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 26 Jun 2014 13:55:57 -0700 Subject: Gotta single quote yer typewriter buttons --- spec/acceptance/chop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/chop_spec.rb b/spec/acceptance/chop_spec.rb index dbc28da..a16a710 100755 --- a/spec/acceptance/chop_spec.rb +++ b/spec/acceptance/chop_spec.rb @@ -19,7 +19,7 @@ describe 'chop function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operat end it 'should eat the last two characters of \r\n' do - pp = <<-EOS + pp = <<-'EOS' $input = "test\r\n" if size($input) != 6 { fail("Size of ${input} is not 6.") -- cgit v1.2.3 From b5ea0a37f078fe2787346d1ea9c1703ecfd5a779 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Fri, 27 Jun 2014 10:03:48 -0700 Subject: Update .sync.yml to support new .travis.yml configs --- .sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.sync.yml b/.sync.yml index ac79bae..21e872e 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,6 +1,6 @@ --- .travis.yml: - unmanaged: true + script: "\"bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'\"" Rakefile: unmanaged: true Gemfile: -- cgit v1.2.3 From 4f8f7083d2b32f117ece11c14e79f328f55acd5b Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Fri, 27 Jun 2014 10:55:25 -0700 Subject: Synchronize .travis.yml --- .travis.yml | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 34d8cc9..3ed1153 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,26 +2,16 @@ language: ruby bundler_args: --without development script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'" -rvm: - - 1.8.7 - - 1.9.3 - - 2.0.0 - - ruby-head -env: - - PUPPET_GEM_VERSION=">= 3.0.0" matrix: fast_finish: true - allow_failures: - - rvm: 2.0.0 - - rvm: ruby-head include: - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.0" notifications: email: false - webhooks: - urls: - - https://puppet-dev-community.herokuapp.com/event/travis-ci/ - on_success: always - on_failure: always - on_start: yes -- cgit v1.2.3 From ae82e2cb17c2829d4568ed7223ac8888a47c1d77 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 27 Jun 2014 12:30:27 -0700 Subject: Release 4.3.0 Summary: This release is the first supported release of the stdlib 4 series. It emains backwards-compatible with the stdlib 3 series. It adds two new unctions, one bugfix, and many testin Features: - New `bool2str()` function - New `camalcase()` function Bugfixes: - Fix `has_interface_with()` when interfaces fact is nil --- CHANGELOG.md | 12 ++++++++++++ metadata.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97979bf..acf6032 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +##2014-06-27 - Supported Release 4.3.0 +### Summary +This release is the first supported release of the stdlib 4 series. It remains +backwards-compatible with the stdlib 3 series. It adds two new functions, one bugfix, and many testing updates. + +#### Features +- New `bool2str()` function +- New `camalcase()` function + +#### Bugfixes +- Fix `has_interface_with()` when interfaces fact is nil + ##2014-06-04 - Release 4.2.2 ### Summary diff --git a/metadata.json b/metadata.json index ff35d2c..121f673 100644 --- a/metadata.json +++ b/metadata.json @@ -97,7 +97,7 @@ } ], "name": "puppetlabs-stdlib", - "version": "4.2.2", + "version": "4.3.0", "source": "git://github.com/puppetlabs/puppetlabs-stdlib", "author": "puppetlabs", "license": "Apache 2.0", -- cgit v1.2.3 From 07462f2c3619e4d6589b364f11b01ea9ca37ac61 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 8 Jul 2014 13:45:36 -0700 Subject: AIX has no facter network support These functions take advantage of IP fact information and AIX does not appear to support dynamic interface detection in facter. --- spec/acceptance/has_interface_with_spec.rb | 2 +- spec/acceptance/has_ip_address_spec.rb | 2 +- spec/acceptance/has_ip_network_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/acceptance/has_interface_with_spec.rb b/spec/acceptance/has_interface_with_spec.rb index b09199a..9590193 100755 --- a/spec/acceptance/has_interface_with_spec.rb +++ b/spec/acceptance/has_interface_with_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'has_interface_with function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows')) do +describe 'has_interface_with function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows') or (fact('osfamily') == 'AIX')) do describe 'success' do it 'has_interface_with existing ipaddress' do pp = <<-EOS diff --git a/spec/acceptance/has_ip_address_spec.rb b/spec/acceptance/has_ip_address_spec.rb index 50eb8f5..149a10d 100755 --- a/spec/acceptance/has_ip_address_spec.rb +++ b/spec/acceptance/has_ip_address_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'has_ip_address function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows')) do +describe 'has_ip_address function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows') or (fact('osfamily') == 'AIX')) do describe 'success' do it 'has_ip_address existing ipaddress' do pp = <<-EOS diff --git a/spec/acceptance/has_ip_network_spec.rb b/spec/acceptance/has_ip_network_spec.rb index 1628746..7d2f34e 100755 --- a/spec/acceptance/has_ip_network_spec.rb +++ b/spec/acceptance/has_ip_network_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'has_ip_network function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows')) do +describe 'has_ip_network function', :unless => ((UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem'))) or (fact('osfamily') == 'windows') or (fact('osfamily') == 'AIX')) do describe 'success' do it 'has_ip_network existing ipaddress' do pp = <<-EOS -- cgit v1.2.3 From c0d35cfe9e5a9001901af4bd440b613dcc9cfb62 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 14 Jul 2014 15:51:21 -0700 Subject: Correct metadata.json to match checksum --- metadata.json | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/metadata.json b/metadata.json index 121f673..ddec540 100644 --- a/metadata.json +++ b/metadata.json @@ -1,4 +1,12 @@ { + "name": "puppetlabs-stdlib", + "version": "4.3.0", + "author": "puppetlabs", + "summary": "Puppet Module Standard Library", + "license": "Apache 2.0", + "source": "git://github.com/puppetlabs/puppetlabs-stdlib", + "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib", + "issues_url": "https://github.com/puppetlabs/puppetlabs-stdlib/issues", "operatingsystem_support": [ { "operatingsystem": "RedHat", @@ -96,15 +104,8 @@ "version_requirement": ">=2.7.20 <4.0.0" } ], - "name": "puppetlabs-stdlib", - "version": "4.3.0", - "source": "git://github.com/puppetlabs/puppetlabs-stdlib", - "author": "puppetlabs", - "license": "Apache 2.0", - "summary": "Puppet Module Standard Library", "description": "Standard Library for Puppet Modules", - "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib", "dependencies": [ - + ] } -- cgit v1.2.3 From 90ac0a7742e1d20905287851454a0c3a1fbb5f0a Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 14 Jul 2014 15:55:06 -0700 Subject: Release 4.3.1 Summary This supported release updates the metadata.json to work around upgrade behavior of the PMT. Bugfixes - Synchronize metadata.json with PMT-generated metadata to pass checksums --- CHANGELOG.md | 7 +++++++ metadata.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acf6032..0a63ec6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +##2014-07-14 - Supported Release 4.3.1 +### Summary +This supported release updates the metadata.json to work around upgrade behavior of the PMT. + +#### Bugfixes +- Synchronize metadata.json with PMT-generated metadata to pass checksums + ##2014-06-27 - Supported Release 4.3.0 ### Summary This release is the first supported release of the stdlib 4 series. It remains diff --git a/metadata.json b/metadata.json index ddec540..bce75e0 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-stdlib", - "version": "4.3.0", + "version": "4.3.1", "author": "puppetlabs", "summary": "Puppet Module Standard Library", "license": "Apache 2.0", -- cgit v1.2.3 From 545dcc91f5b4487e91c94b0af96003ad54e10017 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 15 Jul 2014 11:27:47 -0400 Subject: Prepare a 4.3.2 release. --- CHANGELOG.md | 6 ++++++ metadata.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a63ec6..fb5fd7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +##2014-07-15 - Supported Release 4.3.2 +###Summary + +This release merely updates metadata.json so the module can be uninstalled and +upgraded via the puppet module command. + ##2014-07-14 - Supported Release 4.3.1 ### Summary This supported release updates the metadata.json to work around upgrade behavior of the PMT. diff --git a/metadata.json b/metadata.json index bce75e0..26167b6 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-stdlib", - "version": "4.3.1", + "version": "4.3.2", "author": "puppetlabs", "summary": "Puppet Module Standard Library", "license": "Apache 2.0", -- cgit v1.2.3 From 9fd13be825aa0133156016c078b99e0e471fc737 Mon Sep 17 00:00:00 2001 From: Thomas Linkin Date: Wed, 16 Jul 2014 11:39:23 -0400 Subject: (MODULES-1221) Add file_line autorequire documentation This commit adds additional documentation to the file_line resource explaining how it will autorequire file resources when present. --- lib/puppet/type/file_line.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb index 323fc4c..9dbe43c 100644 --- a/lib/puppet/type/file_line.rb +++ b/lib/puppet/type/file_line.rb @@ -21,6 +21,9 @@ Puppet::Type.newtype(:file_line) do In this example, Puppet will ensure both of the specified lines are contained in the file /etc/sudoers. + **Autorequires:** If Puppet is managing the file that will contain the line + being managed, the file_line resource will autorequire that file. + EOT ensurable do -- cgit v1.2.3 From 31b02f84922d29ee063fbfc3d6f4d9621c7cc424 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Thu, 17 Jul 2014 10:48:25 -0400 Subject: (MODULES-927) Add missing functions to README * anchor * bool2str * camelcase * deep_merge * pick_default * validate_ipv4_address * validate_ipv6_address --- README.markdown | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/README.markdown b/README.markdown index e9ad53b..e3bc490 100644 --- a/README.markdown +++ b/README.markdown @@ -77,6 +77,43 @@ Returns the absolute value of a number, for example -34.56 becomes - *Type*: rvalue +anchor +------ +A simple resource type intended to be used as an anchor in a composite class. + +In Puppet 2.6, when a class declares another class, the resources in the +interior class are not contained by the exterior class. This interacts badly +with the pattern of composing complex modules from smaller classes, as it +makes it impossible for end users to specify order relationships between the +exterior class and other modules. + +The anchor type lets you work around this. By sandwiching any interior +classes between two no-op resources that _are_ contained by the exterior +class, you can ensure that all resources in the module are contained. + + class ntp { + # These classes will have the correct order relationship with each + # other. However, without anchors, they won't have any order + # relationship to Class['ntp']. + class { 'ntp::package': } + -> class { 'ntp::config': } + -> class { 'ntp::service': } + + # These two resources "anchor" the composed classes within the ntp + # class. + anchor { 'ntp::begin': } -> Class['ntp::package'] + Class['ntp::service'] -> anchor { 'ntp::end': } + } + +This allows the end user of the ntp module to establish require and before +relationships with Class['ntp']: + + class { 'ntp': } -> class { 'mcollective': } + class { 'mcollective': } -> class { 'ntp': } + + +- *Type*: resource + any2array --------- This converts any object to an array containing that object. Empty argument @@ -103,6 +140,19 @@ true, t, 1, y, and yes to 1 Requires a single boolean or string as an input. +- *Type*: rvalue + +bool2str +-------- +Converts a boolean to a string. +Requires a single boolean as an input. + +- *Type*: rvalue + +camelcase +--------- +Converts the case of a string or all strings in an array to camel case. + - *Type*: rvalue capitalize @@ -160,6 +210,23 @@ Count the number of elements in array that matches second argument. If called with only an array it counts the number of elements that are not nil/undef. +- *Type*: rvalue + +deep_merge +---------- +Recursively merges two or more hashes together and returns the resulting hash. + +*Example:* + + $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } } + $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } } + $merged_hash = deep_merge($hash1, $hash2) + # The resulting hash is equivalent to: + # $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } + +When there is a duplicate key that is a hash, they are recursively merged. +When there is a duplicate key that is not a hash, the key in the rightmost hash will "win." + - *Type*: rvalue defined_with_params @@ -713,6 +780,30 @@ failing that, will use a default value of 1.449. - *Type*: rvalue +pick_default +------------ +This function is similar to a coalesce function in SQL in that it will return +the first value in a list of values that is not undefined or an empty string +(two things in Puppet that will return a boolean false value). If no value is +found, it will return the last argument. + +Typically, this function is used to check for a value in the Puppet +Dashboard/Enterprise Console, and failover to a default value like the +following: + + $real_jenkins_version = pick_default($::jenkins_version, '1.449') + +The value of $real_jenkins_version will first look for a top-scope variable +called 'jenkins_version' (note that parameters set in the Puppet Dashboard/ +Enterprise Console are brought into Puppet as top-scope variables), and, +failing that, will use a default value of 1.449. + +Note that, contrary to the pick() function, the pick_default does not fail if +all arguments are empty. This allows pick_default to use an empty value as +default. + +- *Type*: rvalue + prefix ------ This function applies a prefix to all elements in an array. @@ -1166,6 +1257,43 @@ The following values will fail, causing compilation to abort: +- *Type*: statement + +validate_ipv4_address +--------------------- +Validate that all values passed are valid IPv4 addresses. +Fail compilation if any value fails this check. + +The following values will pass: + + $my_ip = "1.2.3.4" + validate_ipv4_address($my_ip) + validate_bool("8.8.8.8", "172.16.0.1", $my_ip) + +The following values will fail, causing compilation to abort: + + $some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ] + validate_ipv4_address($some_array) + +- *Type*: statement + +validate_ipv6_address +--------------------- + Validate that all values passed are valid IPv6 addresses. +Fail compilation if any value fails this check. + +The following values will pass: + + $my_ip = "3ffe:505:2" + validate_ipv6_address(1) + validate_ipv6_address($my_ip) + validate_bool("fe80::baf6:b1ff:fe19:7507", $my_ip) + +The following values will fail, causing compilation to abort: + + $some_array = [ true, false, "garbage string", "1.2.3.4" ] + validate_ipv6_address($some_array) + - *Type*: statement validate_re -- cgit v1.2.3 From b2033a0c114b4bb219502c7704aa747a636968cb Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Thu, 17 Jul 2014 11:06:00 -0400 Subject: (MODULES-927) Update docs for functions in README * range (take an optional third argument for range step) * validate_slength (take an optional third argument for minimum length) * file_line (take after and multiple attributes) --- README.markdown | 64 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/README.markdown b/README.markdown index e3bc490..e033b15 100644 --- a/README.markdown +++ b/README.markdown @@ -381,8 +381,11 @@ the type and parameters specified if it doesn't already exist. file_line --------- -This resource ensures that a given line is contained within a file. You can also use -"match" to replace existing lines. +Ensures that a given line is contained within a file. The implementation +matches the full line, including whitespace at the beginning and end. If +the line is not contained in the given file, Puppet will add the line to +ensure the desired state. Multiple resources may be declared to manage +multiple lines in the same file. *Examples:* @@ -390,13 +393,42 @@ This resource ensures that a given line is contained within a file. You can also path => '/etc/sudoers', line => '%sudo ALL=(ALL) ALL', } - - file_line { 'change_mount': - path => '/etc/fstab', - line => '10.0.0.1:/vol/data /opt/data nfs defaults 0 0', - match => '^172.16.17.2:/vol/old', + file_line { 'sudo_rule_nopw': + path => '/etc/sudoers', + line => '%sudonopw ALL=(ALL) NOPASSWD: ALL', } +In this example, Puppet will ensure both of the specified lines are +contained in the file /etc/sudoers. + +*Parameters within `file_line`:* + +**`after`** + +An optional value used to specify the line after which we will add any new +lines. (Existing lines are added in place) + +**`line`** + +The line to be appended to the file located by the path parameter. + +**`match`** + +An optional regular expression to run against existing lines in the file; +if a match is found, we replace that line rather than adding a new line. + +**`multiple`** + +An optional value to determine if match can change multiple lines. + +**`name`** + +An arbitrary name used as the identity of the resource. + +**`path`** + +The file Puppet will ensure contains the line specified by the line parameter. + - *Type*: resource flatten @@ -840,6 +872,13 @@ Will return: ["a","b","c"] Will return: ["host01", "host02", ..., "host09", "host10"] +Passing a third argument will cause the generated range to step by that +interval, e.g. + + range("0", "9", "2") + +Will return: [0,2,4,6,8] + - *Type*: rvalue reject @@ -1328,21 +1367,22 @@ A helpful error message can be returned like this: validate_slength ---------------- Validate that the first argument is a string (or an array of strings), and -less/equal to than the length of the second argument. It fails if the first -argument is not a string or array of strings, and if arg 2 is not convertable -to a number. +less/equal to than the length of the second argument. An optional third +parameter can be given a the minimum length. It fails if the first +argument is not a string or array of strings, and if arg 2 and arg 3 are +not convertable to a number. The following values will pass: validate_slength("discombobulate",17) validate_slength(["discombobulate","moo"],17) + validate_slength(["discombobulate","moo"],17,3) The following values will not: validate_slength("discombobulate",1) validate_slength(["discombobulate","thermometer"],5) - - + validate_slength(["discombobulate","moo"],17,10) - *Type*: statement -- cgit v1.2.3 From 85d5eadbab273e838eb2de33e78054b8d3867f41 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Tue, 19 Nov 2013 20:24:46 -0800 Subject: Concatenate arrays without modifying the first array --- lib/puppet/parser/functions/concat.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb index 6c86382..0d35b07 100644 --- a/lib/puppet/parser/functions/concat.rb +++ b/lib/puppet/parser/functions/concat.rb @@ -28,11 +28,7 @@ Would result in: raise(Puppet::ParseError, 'concat(): Requires array to work with') end - if b.is_a?(Array) - result = a.concat(b) - else - result = a << b - end + result = a + Array(b) return result end -- cgit v1.2.3 From a6ad0af08e408adbb4b25684b18feb8aee12cf3e Mon Sep 17 00:00:00 2001 From: Spencer Krum Date: Tue, 19 Nov 2013 20:11:08 -0800 Subject: Introduce test for array destruction It was discovered that the concat array modifies the arrays passed to it as an argument as a side effect. This test will ensure that doesn't happen again. --- spec/functions/concat_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index b853b4c..49cb2ad 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -27,4 +27,9 @@ describe "the concat function" do expect(result).to(eq(['1','2','3',['4','5'],'6'])) end + it "should leave the original array intact" do + array_original = ['1','2','3'] + result = scope.function_concat([array_original,['4','5','6']]) + array_original.should(eq(['1','2','3'])) + end end -- cgit v1.2.3 From a7c129b22d91fc723a8176c066a3eb96b03a2f56 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 5 Aug 2014 11:28:18 -0700 Subject: Remove simplecov simplecov 0.9 dropped ruby 1.8 support, and stdlib is one of the oddball modules that uses it. So we could probably just remove it and be okay. --- spec/spec_helper.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 78925fd..b490ca3 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,7 +9,6 @@ end require 'puppet' require 'rspec-puppet' -require 'simplecov' require 'puppetlabs_spec_helper/module_spec_helper' require 'puppet_spec/verbose' require 'puppet_spec/files' @@ -21,10 +20,6 @@ require 'monkey_patches/alias_should_to_must' require 'mocha/setup' -SimpleCov.start do - add_filter "/spec/" -end - RSpec.configure do |config| config.before :each do -- cgit v1.2.3 From 2023692fc98ae4a68fb702f232ba0d3c5f474313 Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Thu, 28 Aug 2014 18:30:39 -0400 Subject: Update spec_helper for more consistency --- spec/spec_helper_acceptance.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index e9ccc68..53c1661 100755 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -4,16 +4,15 @@ require 'beaker-rspec' UNSUPPORTED_PLATFORMS = [] unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' - if hosts.first.is_pe? - install_pe - on hosts, 'mkdir -p /etc/puppetlabs/facter/facts.d' - else - install_puppet - on hosts, 'mkdir -p /etc/facter/facts.d' - on hosts, '/bin/touch /etc/puppet/hiera.yaml' - end + # This will install the latest available package on el and deb based + # systems fail on windows and osx, and install via gem on other *nixes + foss_opts = { :default_action => 'gem_install' } + + if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end + hosts.each do |host| on host, "mkdir -p #{host['distmoduledir']}" + on host, "/bin/touch #{default['puppetpath']}/hiera.yaml" end end -- cgit v1.2.3 From 448e66b8bb3bd5a2b413436b21c2c480511223c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20P=C3=A1nek?= Date: Tue, 16 Sep 2014 17:55:26 +0200 Subject: Updated docs of validate_string to reflect bug See: https://tickets.puppetlabs.com/browse/MODULES-457 --- lib/puppet/parser/functions/validate_string.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/puppet/parser/functions/validate_string.rb b/lib/puppet/parser/functions/validate_string.rb index e667794..0bab21e 100644 --- a/lib/puppet/parser/functions/validate_string.rb +++ b/lib/puppet/parser/functions/validate_string.rb @@ -13,6 +13,9 @@ module Puppet::Parser::Functions validate_string(true) validate_string([ 'some', 'array' ]) + + NOTE: undef will only fail when using the future parser (See: https://tickets.puppetlabs.com/browse/MODULES-457) + $undefined = undef validate_string($undefined) -- cgit v1.2.3 From 6631934df8775305bc6c92514b5dec3624f5ba4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20P=C3=A1nek?= Date: Tue, 16 Sep 2014 19:03:02 +0200 Subject: Note that also future parser does not work --- lib/puppet/parser/functions/validate_string.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/puppet/parser/functions/validate_string.rb b/lib/puppet/parser/functions/validate_string.rb index 0bab21e..c841f6a 100644 --- a/lib/puppet/parser/functions/validate_string.rb +++ b/lib/puppet/parser/functions/validate_string.rb @@ -14,11 +14,13 @@ module Puppet::Parser::Functions validate_string(true) validate_string([ 'some', 'array' ]) - NOTE: undef will only fail when using the future parser (See: https://tickets.puppetlabs.com/browse/MODULES-457) + Note: validate_string(undef) will not fail in this version of the + functions API (incl. current and future parser). Instead, use: + + if $var == undef { + fail('...') + } - $undefined = undef - validate_string($undefined) - ENDHEREDOC unless args.length > 0 then -- cgit v1.2.3 From cf8d144caf69d884e77a4c8407083a8b5d78c9d0 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 5 Aug 2014 11:28:18 -0700 Subject: Remove simplecov simplecov 0.9 dropped ruby 1.8 support, and stdlib is one of the oddball modules that uses it. So we could probably just remove it and be okay. (cherry picked from commit a7c129b22d91fc723a8176c066a3eb96b03a2f56) --- spec/spec_helper.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 78925fd..b490ca3 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,7 +9,6 @@ end require 'puppet' require 'rspec-puppet' -require 'simplecov' require 'puppetlabs_spec_helper/module_spec_helper' require 'puppet_spec/verbose' require 'puppet_spec/files' @@ -21,10 +20,6 @@ require 'monkey_patches/alias_should_to_must' require 'mocha/setup' -SimpleCov.start do - add_filter "/spec/" -end - RSpec.configure do |config| config.before :each do -- cgit v1.2.3 From acf435d1ce5916f99a13ef12f5f6560c9e63b935 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 16 Sep 2014 10:46:19 -0700 Subject: MODULES-1248 Fix issue with not properly counting regex matches with legacy versions of ruby --- lib/puppet/provider/file_line/ruby.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb index 94e7fac..ae1a8b3 100644 --- a/lib/puppet/provider/file_line/ruby.rb +++ b/lib/puppet/provider/file_line/ruby.rb @@ -34,7 +34,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do def handle_create_with_match() regex = resource[:match] ? Regexp.new(resource[:match]) : nil - match_count = lines.select { |l| regex.match(l) }.size + match_count = count_matches(regex) if match_count > 1 && resource[:multiple].to_s != 'true' raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'" end @@ -51,9 +51,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do def handle_create_with_after regex = Regexp.new(resource[:after]) - - count = lines.count {|l| l.match(regex)} - + count = count_matches(regex) case count when 1 # find the line to put our line after File.open(resource[:path], 'w') do |fh| @@ -71,6 +69,10 @@ Puppet::Type.type(:file_line).provide(:ruby) do end end + def count_matches(regex) + lines.select{|l| l.match(regex)}.size + end + ## # append the line to the file. # -- cgit v1.2.3 From e2d7f3bb89a91d3aff6f9810d69bd84bc82ffb29 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Tue, 22 Apr 2014 09:36:28 +0200 Subject: (MODULES-707) chomp() fails because generate() no longer returns a string We need to use unless value.is_a?(String) || value.is_a?(Array) rather than klass = value.class unless [String, Array].include?(klass) because the klass version enforces type checking which is too strict, and does not allow us to accept objects wich have extended String (or Array). For example, generate() function now returns Puppet::Util::Execution::ProcessOutput which is just a very simple extension of String. While this in it's self was not intentional (PUP-2306) it is not unreasonable to cope with objects which extend Strings --- lib/puppet/parser/functions/bool2num.rb | 3 +-- lib/puppet/parser/functions/capitalize.rb | 3 +-- lib/puppet/parser/functions/chomp.rb | 3 +-- lib/puppet/parser/functions/chop.rb | 3 +-- lib/puppet/parser/functions/downcase.rb | 3 +-- lib/puppet/parser/functions/empty.rb | 3 +-- lib/puppet/parser/functions/fqdn_rotate.rb | 3 +-- lib/puppet/parser/functions/lstrip.rb | 3 +-- lib/puppet/parser/functions/reverse.rb | 3 +-- lib/puppet/parser/functions/rstrip.rb | 3 +-- lib/puppet/parser/functions/shuffle.rb | 3 +-- lib/puppet/parser/functions/strip.rb | 3 +-- lib/puppet/parser/functions/swapcase.rb | 3 +-- lib/puppet/parser/functions/unique.rb | 3 +-- lib/puppet/parser/functions/upcase.rb | 3 +-- lib/puppet/parser/functions/uriescape.rb | 3 +-- lib/puppet/parser/functions/zip.rb | 4 +--- spec/functions/bool2num_spec.rb | 18 ++++++++++++++++-- spec/functions/capitalize_spec.rb | 9 +++++++++ spec/functions/chomp_spec.rb | 9 +++++++++ spec/functions/chop_spec.rb | 9 +++++++++ spec/functions/downcase_spec.rb | 9 +++++++++ spec/functions/empty_spec.rb | 9 +++++++++ spec/functions/fqdn_rotate_spec.rb | 10 ++++++++++ spec/functions/lstrip_spec.rb | 9 +++++++++ spec/functions/reverse_spec.rb | 9 +++++++++ spec/functions/rstrip_spec.rb | 9 +++++++++ spec/functions/shuffle_spec.rb | 9 +++++++++ spec/functions/strip_spec.rb | 9 +++++++++ spec/functions/swapcase_spec.rb | 9 +++++++++ spec/functions/unique_spec.rb | 9 +++++++++ spec/functions/upcase_spec.rb | 9 +++++++++ spec/functions/uriescape_spec.rb | 9 +++++++++ spec/functions/zip_spec.rb | 16 ++++++++++++++++ 34 files changed, 185 insertions(+), 37 deletions(-) diff --git a/lib/puppet/parser/functions/bool2num.rb b/lib/puppet/parser/functions/bool2num.rb index 9a07a8a..b32a4e8 100644 --- a/lib/puppet/parser/functions/bool2num.rb +++ b/lib/puppet/parser/functions/bool2num.rb @@ -15,10 +15,9 @@ module Puppet::Parser::Functions "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class # We can have either true or false, or string which resembles boolean ... - unless [FalseClass, TrueClass, String].include?(klass) + unless value.is_a?(String) || value.is_a?(FalseClass) || value.is_a?(TrueClass) raise(Puppet::ParseError, 'bool2num(): Requires either ' + 'boolean or string to work with') end diff --git a/lib/puppet/parser/functions/capitalize.rb b/lib/puppet/parser/functions/capitalize.rb index 640d00b..98b2d16 100644 --- a/lib/puppet/parser/functions/capitalize.rb +++ b/lib/puppet/parser/functions/capitalize.rb @@ -13,9 +13,8 @@ module Puppet::Parser::Functions "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'capitalize(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/chomp.rb b/lib/puppet/parser/functions/chomp.rb index 4564a00..c55841e 100644 --- a/lib/puppet/parser/functions/chomp.rb +++ b/lib/puppet/parser/functions/chomp.rb @@ -14,9 +14,8 @@ module Puppet::Parser::Functions "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'chomp(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/chop.rb b/lib/puppet/parser/functions/chop.rb index f242af3..b24ab78 100644 --- a/lib/puppet/parser/functions/chop.rb +++ b/lib/puppet/parser/functions/chop.rb @@ -16,9 +16,8 @@ module Puppet::Parser::Functions "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'chop(): Requires either an ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/downcase.rb b/lib/puppet/parser/functions/downcase.rb index 4066d21..040b84f 100644 --- a/lib/puppet/parser/functions/downcase.rb +++ b/lib/puppet/parser/functions/downcase.rb @@ -12,9 +12,8 @@ Converts the case of a string or all strings in an array to lower case. "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'downcase(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb index 80ebb86..cca620f 100644 --- a/lib/puppet/parser/functions/empty.rb +++ b/lib/puppet/parser/functions/empty.rb @@ -12,9 +12,8 @@ Returns true if the variable is empty. "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, Hash, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String) raise(Puppet::ParseError, 'empty(): Requires either ' + 'array, hash or string to work with') end diff --git a/lib/puppet/parser/functions/fqdn_rotate.rb b/lib/puppet/parser/functions/fqdn_rotate.rb index 6558206..7f4d37d 100644 --- a/lib/puppet/parser/functions/fqdn_rotate.rb +++ b/lib/puppet/parser/functions/fqdn_rotate.rb @@ -12,10 +12,9 @@ Rotates an array a random number of times based on a nodes fqdn. "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class require 'digest/md5' - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/lstrip.rb b/lib/puppet/parser/functions/lstrip.rb index 3a64de3..624e4c8 100644 --- a/lib/puppet/parser/functions/lstrip.rb +++ b/lib/puppet/parser/functions/lstrip.rb @@ -12,9 +12,8 @@ Strips leading spaces to the left of a string. "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'lstrip(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/reverse.rb b/lib/puppet/parser/functions/reverse.rb index fe04869..7f1018f 100644 --- a/lib/puppet/parser/functions/reverse.rb +++ b/lib/puppet/parser/functions/reverse.rb @@ -12,9 +12,8 @@ Reverses the order of a string or array. "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'reverse(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/rstrip.rb b/lib/puppet/parser/functions/rstrip.rb index 29b0998..0cf8d22 100644 --- a/lib/puppet/parser/functions/rstrip.rb +++ b/lib/puppet/parser/functions/rstrip.rb @@ -12,9 +12,8 @@ Strips leading spaces to the right of the string. "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'rstrip(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/shuffle.rb b/lib/puppet/parser/functions/shuffle.rb index 18134ab..30c663d 100644 --- a/lib/puppet/parser/functions/shuffle.rb +++ b/lib/puppet/parser/functions/shuffle.rb @@ -12,9 +12,8 @@ Randomizes the order of a string or array elements. "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'shuffle(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/strip.rb b/lib/puppet/parser/functions/strip.rb index 5f4630d..3fac47d 100644 --- a/lib/puppet/parser/functions/strip.rb +++ b/lib/puppet/parser/functions/strip.rb @@ -19,9 +19,8 @@ Would result in: "aaa" "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'strip(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/swapcase.rb b/lib/puppet/parser/functions/swapcase.rb index b9e6632..eb7fe13 100644 --- a/lib/puppet/parser/functions/swapcase.rb +++ b/lib/puppet/parser/functions/swapcase.rb @@ -18,9 +18,8 @@ Would result in: "AbCd" "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'swapcase(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/unique.rb b/lib/puppet/parser/functions/unique.rb index 8844a74..cf770f3 100644 --- a/lib/puppet/parser/functions/unique.rb +++ b/lib/puppet/parser/functions/unique.rb @@ -28,9 +28,8 @@ This returns: "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'unique(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb index fe6cadc..4302b29 100644 --- a/lib/puppet/parser/functions/upcase.rb +++ b/lib/puppet/parser/functions/upcase.rb @@ -20,9 +20,8 @@ Will return: "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'upcase(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/uriescape.rb b/lib/puppet/parser/functions/uriescape.rb index 0d81de5..a486eee 100644 --- a/lib/puppet/parser/functions/uriescape.rb +++ b/lib/puppet/parser/functions/uriescape.rb @@ -14,9 +14,8 @@ module Puppet::Parser::Functions "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - klass = value.class - unless [Array, String].include?(klass) + unless value.is_a?(Array) || value.is_a?(String) raise(Puppet::ParseError, 'uriescape(): Requires either ' + 'array or string to work with') end diff --git a/lib/puppet/parser/functions/zip.rb b/lib/puppet/parser/functions/zip.rb index 2b56e9c..00266a4 100644 --- a/lib/puppet/parser/functions/zip.rb +++ b/lib/puppet/parser/functions/zip.rb @@ -30,10 +30,8 @@ Would result in: flatten = arguments[2] if arguments[2] if flatten - klass = flatten.class - # We can have either true or false, or string which resembles boolean ... - unless [FalseClass, TrueClass, String].include?(klass) + unless flatten.is_a?(String) || flatten.is_a?(FalseClass) || flatten.is_a?(TrueClass) raise(Puppet::ParseError, 'zip(): Requires either ' + 'boolean or string to work with') end diff --git a/spec/functions/bool2num_spec.rb b/spec/functions/bool2num_spec.rb index fbf461b..3904d7e 100755 --- a/spec/functions/bool2num_spec.rb +++ b/spec/functions/bool2num_spec.rb @@ -17,8 +17,22 @@ describe "the bool2num function" do expect(result).to(eq(1)) end - it "should convert false to 0" do - result = scope.function_bool2num([false]) + 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']) expect(result).to(eq(0)) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new('true') + result = scope.function_bool2num([value]) + result.should(eq(1)) + end end diff --git a/spec/functions/capitalize_spec.rb b/spec/functions/capitalize_spec.rb index 0cc2d76..fd0e92b 100755 --- a/spec/functions/capitalize_spec.rb +++ b/spec/functions/capitalize_spec.rb @@ -16,4 +16,13 @@ describe "the capitalize function" do result = scope.function_capitalize(["abc"]) expect(result).to(eq("Abc")) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new('abc') + result = scope.function_capitalize([value]) + result.should(eq('Abc')) + end end diff --git a/spec/functions/chomp_spec.rb b/spec/functions/chomp_spec.rb index d2ae287..b1e1e60 100755 --- a/spec/functions/chomp_spec.rb +++ b/spec/functions/chomp_spec.rb @@ -16,4 +16,13 @@ describe "the chomp function" do result = scope.function_chomp(["abc\n"]) expect(result).to(eq("abc")) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new("abc\n") + result = scope.function_chomp([value]) + result.should(eq("abc")) + end end diff --git a/spec/functions/chop_spec.rb b/spec/functions/chop_spec.rb index d9dbb88..c8a1951 100755 --- a/spec/functions/chop_spec.rb +++ b/spec/functions/chop_spec.rb @@ -16,4 +16,13 @@ describe "the chop function" do result = scope.function_chop(["asdf\n"]) expect(result).to(eq("asdf")) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new("abc\n") + result = scope.function_chop([value]) + result.should(eq('abc')) + end end diff --git a/spec/functions/downcase_spec.rb b/spec/functions/downcase_spec.rb index a844780..edebc44 100755 --- a/spec/functions/downcase_spec.rb +++ b/spec/functions/downcase_spec.rb @@ -21,4 +21,13 @@ describe "the downcase function" do result = scope.function_downcase(["asdf asdf"]) expect(result).to(eq("asdf asdf")) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new("ASFD") + result = scope.function_downcase([value]) + result.should(eq('asfd')) + end end diff --git a/spec/functions/empty_spec.rb b/spec/functions/empty_spec.rb index 1f2ace4..6a97c4c 100755 --- a/spec/functions/empty_spec.rb +++ b/spec/functions/empty_spec.rb @@ -20,4 +20,13 @@ describe "the empty function" do result = scope.function_empty(['asdf']) expect(result).to(eq(false)) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new() + result = scope.function_empty([value]) + result.should(eq(true)) + end end diff --git a/spec/functions/fqdn_rotate_spec.rb b/spec/functions/fqdn_rotate_spec.rb index b2dc1f5..40057d4 100755 --- a/spec/functions/fqdn_rotate_spec.rb +++ b/spec/functions/fqdn_rotate_spec.rb @@ -30,4 +30,14 @@ describe "the fqdn_rotate function" do val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"]) expect(val1).not_to eql(val2) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") + value = AlsoString.new("asdf") + result = scope.function_fqdn_rotate([value]) + result.size.should(eq(4)) + end end diff --git a/spec/functions/lstrip_spec.rb b/spec/functions/lstrip_spec.rb index 7025f97..68cca1c 100755 --- a/spec/functions/lstrip_spec.rb +++ b/spec/functions/lstrip_spec.rb @@ -16,4 +16,13 @@ describe "the lstrip function" do result = scope.function_lstrip([" asdf"]) expect(result).to(eq('asdf')) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new(" asdf") + result = scope.function_lstrip([value]) + result.should(eq("asdf")) + end end diff --git a/spec/functions/reverse_spec.rb b/spec/functions/reverse_spec.rb index bfeabfb..1f04794 100755 --- a/spec/functions/reverse_spec.rb +++ b/spec/functions/reverse_spec.rb @@ -16,4 +16,13 @@ describe "the reverse function" do result = scope.function_reverse(["asdfghijkl"]) expect(result).to(eq('lkjihgfdsa')) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new('asdfghjkl') + result = scope.function_reverse([value]) + result.should(eq('lkjhgfdsa')) + end end diff --git a/spec/functions/rstrip_spec.rb b/spec/functions/rstrip_spec.rb index 81321d7..f6b4838 100755 --- a/spec/functions/rstrip_spec.rb +++ b/spec/functions/rstrip_spec.rb @@ -21,4 +21,13 @@ describe "the rstrip function" do result = scope.function_rstrip([["a ","b ", "c "]]) expect(result).to(eq(['a','b','c'])) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new('asdf ') + result = scope.function_rstrip([value]) + result.should(eq('asdf')) + end end diff --git a/spec/functions/shuffle_spec.rb b/spec/functions/shuffle_spec.rb index ee0e2ff..a62c1fb 100755 --- a/spec/functions/shuffle_spec.rb +++ b/spec/functions/shuffle_spec.rb @@ -21,4 +21,13 @@ describe "the shuffle function" do result = scope.function_shuffle(["adfs"]) expect(result.split("").sort.join("")).to(eq("adfs")) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new('asdf') + result = scope.function_shuffle([value]) + result.size.should(eq(4)) + end end diff --git a/spec/functions/strip_spec.rb b/spec/functions/strip_spec.rb index e228761..4ac8daf 100755 --- a/spec/functions/strip_spec.rb +++ b/spec/functions/strip_spec.rb @@ -15,4 +15,13 @@ describe "the strip function" do result = scope.function_strip([" ab cd "]) expect(result).to(eq('ab cd')) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new(' as df ') + result = scope.function_strip([value]) + result.should(eq('as df')) + end end diff --git a/spec/functions/swapcase_spec.rb b/spec/functions/swapcase_spec.rb index c6838ab..791d1df 100755 --- a/spec/functions/swapcase_spec.rb +++ b/spec/functions/swapcase_spec.rb @@ -16,4 +16,13 @@ describe "the swapcase function" do result = scope.function_swapcase(["aaBBccDD"]) expect(result).to(eq('AAbbCCdd')) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new("aaBBccDD") + result = scope.function_swapcase([value]) + result.should(eq("AAbbCCdd")) + end end diff --git a/spec/functions/unique_spec.rb b/spec/functions/unique_spec.rb index 8ec1464..7cd3a56 100755 --- a/spec/functions/unique_spec.rb +++ b/spec/functions/unique_spec.rb @@ -21,4 +21,13 @@ describe "the unique function" do result = scope.function_unique([["a","a","b","b","c"]]) expect(result).to(eq(['a','b','c'])) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new('aabbc') + result = scope.function_unique([value]) + result.should(eq('abc')) + end end diff --git a/spec/functions/upcase_spec.rb b/spec/functions/upcase_spec.rb index 78e55dd..3cf8b05 100755 --- a/spec/functions/upcase_spec.rb +++ b/spec/functions/upcase_spec.rb @@ -21,4 +21,13 @@ describe "the upcase function" do result = scope.function_upcase(["ABC"]) expect(result).to(eq('ABC')) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new('abc') + result = scope.function_upcase([value]) + result.should(eq('ABC')) + end end diff --git a/spec/functions/uriescape_spec.rb b/spec/functions/uriescape_spec.rb index c44e9c1..2321e5a 100755 --- a/spec/functions/uriescape_spec.rb +++ b/spec/functions/uriescape_spec.rb @@ -21,4 +21,13 @@ describe "the uriescape function" do result = scope.function_uriescape(["ABCdef"]) expect(result).to(eq('ABCdef')) end + + it "should accept objects which extend String" do + class AlsoString < String + end + + value = AlsoString.new('abc') + result = scope.function_uriescape([value]) + result.should(eq('abc')) + end end diff --git a/spec/functions/zip_spec.rb b/spec/functions/zip_spec.rb index 744bdd7..f265fce 100755 --- a/spec/functions/zip_spec.rb +++ b/spec/functions/zip_spec.rb @@ -11,5 +11,21 @@ describe "the zip function" do it "should be able to zip an array" do result = scope.function_zip([['1','2','3'],['4','5','6']]) expect(result).to(eq([["1", "4"], ["2", "5"], ["3", "6"]])) + result = scope.function_zip([['1','2','3'],['4','5','6'], false]) + result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]])) + end + + it "should be able to zip an array and flatten" do + result = scope.function_zip([['1','2','3'],['4','5','6'], true]) + result.should(eq(["1", "4", "2", "5", "3", "6"])) + end + + it "should accept objects which extend String for the second argument" do + class AlsoString < String + end + + value = AlsoString.new('false') + result = scope.function_zip([['1','2','3'],['4','5','6'],value]) + result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]])) end end -- cgit v1.2.3 From 23bc7d51bd3aca0c3a3391bb628a797dc768422a Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 23 May 2014 08:44:50 +0200 Subject: Re-use existing str2bool code rather than doing a copy and paste --- lib/puppet/parser/functions/bool2num.rb | 24 +----------------------- lib/puppet/parser/functions/zip.rb | 26 +------------------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/lib/puppet/parser/functions/bool2num.rb b/lib/puppet/parser/functions/bool2num.rb index b32a4e8..6ad6cf4 100644 --- a/lib/puppet/parser/functions/bool2num.rb +++ b/lib/puppet/parser/functions/bool2num.rb @@ -14,29 +14,7 @@ module Puppet::Parser::Functions raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " + "given (#{arguments.size} for 1)") if arguments.size < 1 - value = arguments[0] - - # We can have either true or false, or string which resembles boolean ... - unless value.is_a?(String) || value.is_a?(FalseClass) || value.is_a?(TrueClass) - raise(Puppet::ParseError, 'bool2num(): Requires either ' + - 'boolean or string to work with') - end - - if value.is_a?(String) - # We consider all the yes, no, y, n and so on too ... - value = case value - # - # This is how undef looks like in Puppet ... - # We yield 0 (or false if you wish) in this case. - # - when /^$/, '' then false # Empty string will be false ... - when /^(1|t|y|true|yes)$/ then true - when /^(0|f|n|false|no)$/ then false - when /^(undef|undefined)$/ then false # This is not likely to happen ... - else - raise(Puppet::ParseError, 'bool2num(): Unknown type of boolean given') - end - end + value = function_str2bool([arguments[0]]) # We have real boolean values as well ... result = value ? 1 : 0 diff --git a/lib/puppet/parser/functions/zip.rb b/lib/puppet/parser/functions/zip.rb index 00266a4..3074f28 100644 --- a/lib/puppet/parser/functions/zip.rb +++ b/lib/puppet/parser/functions/zip.rb @@ -27,31 +27,7 @@ Would result in: raise(Puppet::ParseError, 'zip(): Requires array to work with') end - flatten = arguments[2] if arguments[2] - - if flatten - # We can have either true or false, or string which resembles boolean ... - unless flatten.is_a?(String) || flatten.is_a?(FalseClass) || flatten.is_a?(TrueClass) - raise(Puppet::ParseError, 'zip(): Requires either ' + - 'boolean or string to work with') - end - - if flatten.is_a?(String) - # We consider all the yes, no, y, n and so on too ... - flatten = case flatten - # - # This is how undef looks like in Puppet ... - # We yield false in this case. - # - when /^$/, '' then false # Empty string will be false ... - when /^(1|t|y|true|yes)$/ then true - when /^(0|f|n|false|no)$/ then false - when /^(undef|undefined)$/ then false # This is not likely to happen ... - else - raise(Puppet::ParseError, 'zip(): Unknown type of boolean given') - end - end - end + flatten = function_str2bool([arguments[2]]) if arguments[2] result = a.zip(b) result = flatten ? result.flatten : result -- cgit v1.2.3 From 032f93af1d9704dc218ef411e9e81befbe1c70a3 Mon Sep 17 00:00:00 2001 From: Tomas Doran Date: Fri, 18 Jul 2014 14:36:09 -0700 Subject: Fix strict_variables = true --- lib/puppet/parser/functions/getvar.rb | 5 ++++- lib/puppet/parser/functions/has_interface_with.rb | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/functions/getvar.rb b/lib/puppet/parser/functions/getvar.rb index 1621149..fb336b6 100644 --- a/lib/puppet/parser/functions/getvar.rb +++ b/lib/puppet/parser/functions/getvar.rb @@ -19,7 +19,10 @@ module Puppet::Parser::Functions raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)") end - self.lookupvar("#{args[0]}") + begin + self.lookupvar("#{args[0]}") + rescue Puppet::ParseError # Eat the exception if strict_variables = true is set + end end diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb index 927b0df..10ad542 100644 --- a/lib/puppet/parser/functions/has_interface_with.rb +++ b/lib/puppet/parser/functions/has_interface_with.rb @@ -41,7 +41,12 @@ has_interface_with("lo") => true result = false interfaces.each do |iface| - if value == lookupvar("#{kind}_#{iface}") + factval = nil + begin + factval = lookupvar("#{kind}_#{iface}") + rescue Puppet::ParseError # Eat the exception if strict_variables = true is set + end + if value == factval result = true break end -- cgit v1.2.3 From 8ad7f68ecaf444b39c4ca89e2e62790bc00ad89a Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Wed, 8 Oct 2014 10:14:10 -0700 Subject: ENTERPRISE-281 fixes issue with has_interfaces and case mismatch causing us not to return some interfaces --- lib/puppet/parser/functions/has_interface_with.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb index 927b0df..d5dbe47 100644 --- a/lib/puppet/parser/functions/has_interface_with.rb +++ b/lib/puppet/parser/functions/has_interface_with.rb @@ -34,13 +34,15 @@ has_interface_with("lo") => true end kind, value = args - + kind.downcase! + if lookupvar(kind) == value return true end result = false interfaces.each do |iface| + iface.downcase! if value == lookupvar("#{kind}_#{iface}") result = true break -- cgit v1.2.3 From 2fcc1ef189f877a05c19c95cdeb88a3e392532f3 Mon Sep 17 00:00:00 2001 From: jbondpdx Date: Wed, 8 Oct 2014 11:42:31 -0700 Subject: DOC-248 Revised and updated readme for stdlib module Reorganized and edited stdlib module readme. --- README.markdown | 1614 +++++++++++++++++-------------------------------------- 1 file changed, 498 insertions(+), 1116 deletions(-) diff --git a/README.markdown b/README.markdown index 51adefe..78839c6 100644 --- a/README.markdown +++ b/README.markdown @@ -1,9 +1,25 @@ -# Puppet Labs Standard Library # +#stdlib [![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-stdlib.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-stdlib) -This module provides a "standard library" of resources for developing Puppet -Modules. This modules will include the following additions to Puppet +####Table of Contents + +1. [Overview](#overview) +2. [Module Description - What the module does and why it is useful](#module-description) +3. [Setup - The basics of getting started with stdlib](#setup) +4. [Usage - Configuration options and additional functionality](#usage) +5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +5. [Limitations - OS compatibility, etc.](#limitations) +6. [Development - Guide for contributing to the module](#development) + +##Overview + +Adds a standard library of resources for Puppet modules. + +##Module Description + +This module provides a standard library of resources for the development of Puppet +modules. Puppet modules make heavy use of this standard library. The stdlib module adds the following resources to Puppet: * Stages * Facts @@ -12,1314 +28,680 @@ Modules. This modules will include the following additions to Puppet * Types * Providers -This module is officially curated and provided by Puppet Labs. The modules -Puppet Labs writes and distributes will make heavy use of this standard -library. - -To report or research a bug with any part of this module, please go to -[http://tickets.puppetlabs.com/browse/PUP](http://tickets.puppetlabs.com/browse/PUP) - -# Versions # - -This module follows semver.org (v1.0.0) versioning guidelines. The standard -library module is released as part of [Puppet -Enterprise](http://puppetlabs.com/puppet/puppet-enterprise/) and as a result -older versions of Puppet Enterprise that Puppet Labs still supports will have -bugfix maintenance branches periodically "merged up" into master. The current -list of integration branches are: - - * v2.1.x (v2.1.1 released in PE 1) - * v2.2.x (Never released as part of PE, only to the Forge) - * v2.3.x (Released in PE 2) - * v3.0.x (Released in PE 3) - * v4.0.x (Maintains compatibility with v3.x despite the major semantic version bump. Compatible with Puppet 2.7.x) - * v5.x (To be released when stdlib can drop support for Puppet 2.7.x. Please see [this discussion](https://github.com/puppetlabs/puppetlabs-stdlib/pull/176#issuecomment-30251414)) - * master (mainline development branch) - -The first Puppet Enterprise version including the stdlib module is Puppet -Enterprise 1.2. - -# Compatibility # - -Puppet Versions | < 2.6 | 2.6 | 2.7 | 3.x | -:---------------|:-----:|:---:|:---:|:----: -**stdlib 2.x** | no | **yes** | **yes** | no -**stdlib 3.x** | no | no | **yes** | **yes** -**stdlib 4.x** | no | no | **yes** | **yes** - -The stdlib module does not work with Puppet versions released prior to Puppet -2.6.0. - -## stdlib 2.x ## - -All stdlib releases in the 2.0 major version support Puppet 2.6 and Puppet 2.7. - -## stdlib 3.x ## - -The 3.0 major release of stdlib drops support for Puppet 2.6. Stdlib 3.x -supports Puppet 2 and Puppet 3. - -## stdlib 4.x ## - -The 4.0 major release of stdlib was intended to drop support for Puppet 2.7, -but the impact on end users was too high. The decision was made to treat -stdlib 4.x as a continuation of stdlib 3.x support. Stdlib 4.x supports Puppet -2.7 and 3. Notably, ruby 1.8.5 is no longer supported though ruby -1.8.7, 1.9.3, and 2.0.0 are fully supported. - -# Functions # - -abs ---- -Returns the absolute value of a number, for example -34.56 becomes -34.56. Takes a single integer and float value as an argument. - - -- *Type*: rvalue - -any2array ---------- -This converts any object to an array containing that object. Empty argument -lists are converted to an empty array. Arrays are left untouched. Hashes are -converted to arrays of alternating keys and values. - - -- *Type*: rvalue - -base64 --------- -Converts a string to and from base64 encoding. -Requires an action ['encode','decode'] and either a plain or base64 encoded -string - - -- *Type*: rvalue - -bool2num --------- -Converts a boolean to a number. Converts the values: -false, f, 0, n, and no to 0 -true, t, 1, y, and yes to 1 - Requires a single boolean or string as an input. - - -- *Type*: rvalue - -capitalize ----------- -Capitalizes the first letter of a string or array of strings. -Requires either a single string or an array as an input. - +##Setup -- *Type*: rvalue +Installing the stdlib module adds the functions, facts, and resources of this standard library to Puppet. -chomp ------ -Removes the record separator from the end of a string or an array of -strings, for example `hello\n` becomes `hello`. -Requires a single string or array as an input. +##Usage +After you've installed stdlib, all of its functions, facts, and resources are available for module use or development. -- *Type*: rvalue +If you want to use a standardized set of run stages for Puppet, `include stdlib` in your manifest. -chop ----- -Returns a new string with the last character removed. If the string ends -with `\r\n`, both characters are removed. Applying chop to an empty -string returns an empty string. If you wish to merely remove record -separators then you should use the `chomp` function. -Requires a string or array of strings as input. +##Reference +### Classes -- *Type*: rvalue +#### Public Classes -concat ------- -Appends the contents of array 2 onto array 1. +* `stdlib`: Most of stdlib's features are automatically loaded by Puppet. To use standardized run stages in Puppet, declare this class in your manifest with `include stdlib`. -*Example:* + When declared, stdlib declares all other classes in the module. The only other class currently included in the module is `stdlib::stages`. - concat(['1','2','3'],['4','5','6']) + The stdlib class has no parameters. -Would result in: +#### Private Classes - ['1','2','3','4','5','6'] +* `stdlib::stages`: This class manages a standard set of run stages for Puppet. It is managed by the stdlib class and should not be declared independently. - concat(['1','2','3'],'4') + The `stdlib::stages` class declares various run stages for deploying infrastructure, language runtimes, and application layers. The high level stages are (in order): -Would result in: + * setup + * main + * runtime + * setup_infra + * deploy_infra + * setup_app + * deploy_app + * deploy - ['1','2','3','4'] + Sample usage: -- *Type*: rvalue + ``` + node default { + include stdlib + class { java: stage => 'runtime' } + } + ``` -count ------ -Takes an array as first argument and an optional second argument. -Count the number of elements in array that matches second argument. -If called with only an array it counts the number of elements that are not nil/undef. +### Functions +* `abs`: Returns the absolute value of a number; for example, '-34.56' becomes '34.56'. Takes a single integer and float value as an argument. *Type*: rvalue -- *Type*: rvalue +* `any2array`: This converts any object to an array containing that object. Empty argument lists are converted to an empty array. Arrays are left untouched. Hashes are converted to arrays of alternating keys and values. *Type*: rvalue -defined_with_params -------------------- -Takes a resource reference and an optional hash of attributes. +* `base64`: Converts a string to and from base64 encoding. +Requires an action ('encode', 'decode') and either a plain or base64-encoded +string. *Type*: rvalue -Returns true if a resource with the specified attributes has already been added -to the catalog, and false otherwise. +* `bool2num`: Converts a boolean to a number. Converts values: + * 'false', 'f', '0', 'n', and 'no' to 0. + * 'true', 't', '1', 'y', and 'yes' to 1. + Requires a single boolean or string as an input. *Type*: rvalue - user { 'dan': - ensure => present, - } +* `capitalize`: Capitalizes the first letter of a string or array of strings. +Requires either a single string or an array as an input. *Type*: rvalue - if ! defined_with_params(User[dan], {'ensure' => 'present' }) { - user { 'dan': ensure => present, } - } +* `chomp`: Removes the record separator from the end of a string or an array of +strings; for example, 'hello\n' becomes 'hello'. Requires a single string or array as an input. *Type*: rvalue +* `chop`: Returns a new string with the last character removed. If the string ends with '\r\n', both characters are removed. Applying `chop` to an empty string returns an empty string. If you want to merely remove record separators, then you should use the `chomp` function. Requires a string or an array of strings as input. *Type*: rvalue -- *Type*: rvalue +* `concat`: Appends the contents of array 2 onto array 1. For example, `concat(['1','2','3'],'4')` results in: ['1','2','3','4']. *Type*: rvalue -delete ------- -Deletes all instances of a given element from an array, substring from a -string, or key from a hash. +* `count`: Takes an array as first argument and an optional second argument. Count the number of elements in array that matches second argument. If called with only an array, it counts the number of elements that are **not** nil/undef. *Type*: rvalue -*Examples:* +* `defined_with_params`: Takes a resource reference and an optional hash of attributes. Returns 'true' if a resource with the specified attributes has already been added to the catalog. Returns 'false' otherwise. - delete(['a','b','c','b'], 'b') - Would return: ['a','c'] + ``` + user { 'dan': + ensure => present, + } - delete({'a'=>1,'b'=>2,'c'=>3}, 'b') - Would return: {'a'=>1,'c'=>3} + if ! defined_with_params(User[dan], {'ensure' => 'present' }) { + user { 'dan': ensure => present, } + } + ``` + + *Type*: rvalue - delete('abracadabra', 'bra') - Would return: 'acada' +* `delete`: Deletes all instances of a given element from an array, substring from a +string, or key from a hash. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. *Type*: rvalue +* `delete_at`: Deletes a determined indexed value from an array. For example, `delete_at(['a','b','c'], 1)` returns ['a','c']. *Type*: rvalue -- *Type*: rvalue +* `delete_values`: Deletes all instances of a given value from a hash. For example, `delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B')` returns {'a'=>'A','c'=>'C','B'=>'D'} *Type*: rvalue -delete_at ---------- -Deletes a determined indexed value from an array. +* `delete_undef_values`: Deletes all instances of the undef value from an array or hash. For example, `$hash = delete_undef_values({a=>'A', b=>'', c=>undef, d => false})` returns {a => 'A', b => '', d => false}. *Type*: rvalue -*Examples:* - - delete_at(['a','b','c'], 1) - -Would return: ['a','c'] - - -- *Type*: rvalue - -delete_values -------------- -Deletes all instances of a given value from a hash. - -*Examples:* - - delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B') - -Would return: {'a'=>'A','c'=>'C','B'=>'D'} - - -- *Type*: rvalue - -delete_undef_values -------------------- -Deletes all instances of the undef value from an array or hash. - -*Examples:* - - $hash = delete_undef_values({a=>'A', b=>'', c=>undef, d => false}) - -Would return: {a => 'A', b => '', d => false} - - $array = delete_undef_values(['A','',undef,false]) - -Would return: ['A','',false] - -- *Type*: rvalue - -difference ----------- -This function returns the difference between two arrays. +* `difference`: Returns the difference between two arrays. The returned array is a copy of the original array, removing any items that -also appear in the second array. - -*Examples:* - - difference(["a","b","c"],["b","c","d"]) - -Would return: ["a"] - -dirname -------- -Returns the `dirname` of a path. - -*Examples:* - - dirname('/path/to/a/file.ext') - -Would return: '/path/to/a' - -downcase --------- -Converts the case of a string or all strings in an array to lower case. - - -- *Type*: rvalue - -empty ------ -Returns true if the variable is empty. - - -- *Type*: rvalue - -ensure_packages ---------------- -Takes a list of packages and only installs them if they don't already exist. -It optionally takes a hash as a second parameter that will be passed as the -third argument to the ensure_resource() function. - - -- *Type*: statement - -ensure_resource ---------------- -Takes a resource type, title, and a list of attributes that describe a -resource. - - user { 'dan': - ensure => present, - } - -This example only creates the resource if it does not already exist: - - ensure_resource('user', 'dan', {'ensure' => 'present' }) - -If the resource already exists but does not match the specified parameters, -this function will attempt to recreate the resource leading to a duplicate -resource definition error. - -An array of resources can also be passed in and each will be created with -the type and parameters specified if it doesn't already exist. - - ensure_resource('user', ['dan','alex'], {'ensure' => 'present'}) - - - -- *Type*: statement - -file_line ---------- -This resource ensures that a given line is contained within a file. You can also use -"match" to replace existing lines. - -*Examples:* - - file_line { 'sudo_rule': - path => '/etc/sudoers', - line => '%sudo ALL=(ALL) ALL', - } - - file_line { 'change_mount': - path => '/etc/fstab', - line => '10.0.0.1:/vol/data /opt/data nfs defaults 0 0', - match => '^172.16.17.2:/vol/old', - } - -- *Type*: resource - -flatten -------- -This function flattens any deeply nested arrays and returns a single flat array -as a result. - -*Examples:* - - flatten(['a', ['b', ['c']]]) - -Would return: ['a','b','c'] - - -- *Type*: rvalue - -floor ------ -Returns the largest integer less or equal to the argument. -Takes a single numeric value as an argument. - - -- *Type*: rvalue - -fqdn_rotate ------------ -Rotates an array a random number of times based on a nodes fqdn. - - -- *Type*: rvalue - -get_module_path ---------------- -Returns the absolute path of the specified module for the current -environment. - -Example: - $module_path = get_module_path('stdlib') - - -- *Type*: rvalue - -getparam --------- -Takes a resource reference and name of the parameter and -returns value of resource's parameter. - -*Examples:* - - define example_resource($param) { - } - - example_resource { "example_resource_instance": - param => "param_value" - } - - getparam(Example_resource["example_resource_instance"], "param") - -Would return: param_value - - -- *Type*: rvalue - -getvar ------- -Lookup a variable in a remote namespace. - -For example: - - $foo = getvar('site::data::foo') - # Equivalent to $foo = $site::data::foo - -This is useful if the namespace itself is stored in a string: - - $datalocation = 'site::data' - $bar = getvar("${datalocation}::bar") - # Equivalent to $bar = $site::data::bar - - -- *Type*: rvalue - -grep ----- -This function searches through an array and returns any elements that match -the provided regular expression. - -*Examples:* - - grep(['aaa','bbb','ccc','aaaddd'], 'aaa') - -Would return: - - ['aaa','aaaddd'] - - -- *Type*: rvalue - -has_interface_with ------------------- -Returns boolean based on kind and value: -* macaddress -* netmask -* ipaddress -* network - -*Examples:* - - has_interface_with("macaddress", "x:x:x:x:x:x") - has_interface_with("ipaddress", "127.0.0.1") => true - -etc. - -If no "kind" is given, then the presence of the interface is checked: - - has_interface_with("lo") => true - - -- *Type*: rvalue - -has_ip_address --------------- -Returns true if the client has the requested IP address on some interface. - -This function iterates through the 'interfaces' fact and checks the -'ipaddress_IFACE' facts, performing a simple string comparison. - - -- *Type*: rvalue - -has_ip_network --------------- -Returns true if the client has an IP address within the requested network. - -This function iterates through the 'interfaces' fact and checks the -'network_IFACE' facts, performing a simple string comparision. - - -- *Type*: rvalue - -has_key -------- -Determine if a hash has a certain key value. - -Example: - - $my_hash = {'key_one' => 'value_one'} - if has_key($my_hash, 'key_two') { - notice('we will not reach here') - } - if has_key($my_hash, 'key_one') { - notice('this will be printed') - } - +also appear in the second array. For example, `difference(["a","b","c"],["b","c","d"])` returns ["a"]. +* `dirname`: Returns the `dirname` of a path. For example, `dirname('/path/to/a/file.ext')` returns '/path/to/a'. -- *Type*: rvalue +* `downcase`: Converts the case of a string or of all strings in an array to lowercase. *Type*: rvalue -hash ----- -This function converts an array into a hash. +* `empty`: Returns 'true' if the variable is empty. *Type*: rvalue -*Examples:* +* `ensure_packages`: Takes a list of packages and only installs them if they don't already exist. It optionally takes a hash as a second parameter to be passed as the third argument to the `ensure_resource()` function. *Type*: statement - hash(['a',1,'b',2,'c',3]) +* `ensure_resource`: Takes a resource type, title, and a list of attributes that describe a resource. -Would return: {'a'=>1,'b'=>2,'c'=>3} + ``` + user { 'dan': + ensure => present, + } + ``` + This example only creates the resource if it does not already exist: -- *Type*: rvalue + `ensure_resource('user', 'dan', {'ensure' => 'present' })` -intersection ------------ -This function returns an array an intersection of two. + If the resource already exists, but does not match the specified parameters, this function attempts to recreate the resource, leading to a duplicate resource definition error. -*Examples:* + An array of resources can also be passed in, and each will be created with the type and parameters specified if it doesn't already exist. - intersection(["a","b","c"],["b","c","d"]) + `ensure_resource('user', ['dan','alex'], {'ensure' => 'present'})` -Would return: ["b","c"] + *Type*: statement -is_array --------- -Returns true if the variable passed to this function is an array. +* `file_line`: This resource ensures that a given line is contained within a file. You can also use match to replace existing lines. -- *Type*: rvalue + *Example:* + + ``` + file_line { 'sudo_rule': + path => '/etc/sudoers', + line => '%sudo ALL=(ALL) ALL', + } -is_bool --------- -Returns true if the variable passed to this function is a boolean. + file_line { 'change_mount': + path => '/etc/fstab', + line => '10.0.0.1:/vol/data /opt/data nfs defaults 0 0', + match => '^172.16.17.2:/vol/old', + } + ``` + + *Type*: resource -- *Type*: rvalue +* `flatten`: This function flattens any deeply nested arrays and returns a single flat array as a result. For example, `flatten(['a', ['b', ['c']]])` returns ['a','b','c']. *Type*: rvalue -is_domain_name --------------- -Returns true if the string passed to this function is a syntactically correct domain name. +* `floor`: Returns the largest integer less than or equal to the argument. +Takes a single numeric value as an argument. *Type*: rvalue -- *Type*: rvalue +* `fqdn_rotate`: Rotates an array a random number of times based on a node's fqdn. *Type*: rvalue -is_float --------- -Returns true if the variable passed to this function is a float. +* `get_module_path`: Returns the absolute path of the specified module for the current environment. -- *Type*: rvalue + `$module_path = get_module_path('stdlib')` -is_function_available ---------------------- -This function accepts a string as an argument, determines whether the -Puppet runtime has access to a function by that name. It returns a -true if the function exists, false if not. + *Type*: rvalue -- *Type*: rvalue +* `getparam`: Takes a resource reference and the name of the parameter and +returns the value of the resource's parameter. For example, the following code returns 'param_value'. -is_hash -------- -Returns true if the variable passed to this function is a hash. + *Example:* -- *Type*: rvalue + ``` + define example_resource($param) { + } -is_integer ----------- -Returns true if the variable returned to this string is an integer. + example_resource { "example_resource_instance": + param => "param_value" + } -- *Type*: rvalue + getparam(Example_resource["example_resource_instance"], "param") + ``` -is_ip_address -------------- -Returns true if the string passed to this function is a valid IP address. + *Type*: rvalue -- *Type*: rvalue +* `getvar`: Lookup a variable in a remote namespace. -is_mac_address --------------- -Returns true if the string passed to this function is a valid mac address. + For example: -- *Type*: rvalue + ``` + $foo = getvar('site::data::foo') + # Equivalent to $foo = $site::data::foo + ``` -is_numeric ----------- -Returns true if the variable passed to this function is a number. + This is useful if the namespace itself is stored in a string: -- *Type*: rvalue + ``` + $datalocation = 'site::data' + $bar = getvar("${datalocation}::bar") + # Equivalent to $bar = $site::data::bar + ``` -is_string ---------- -Returns true if the variable passed to this function is a string. + *Type*: rvalue -- *Type*: rvalue +* `grep`: This function searches through an array and returns any elements that match the provided regular expression. For example, `grep(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['aaa','aaaddd']. *Type*: rvalue -join ----- -This function joins an array into a string using a separator. +* `has_interface_with`: Returns boolean based on kind and value: + * macaddress + * netmask + * ipaddress + * network -*Examples:* + *Examples:* - join(['a','b','c'], ",") + ``` + has_interface_with("macaddress", "x:x:x:x:x:x") + has_interface_with("ipaddress", "127.0.0.1") => true + ``` + + If no kind is given, then the presence of the interface is checked: -Would result in: "a,b,c" + ``` + has_interface_with("lo") => true + ``` -- *Type*: rvalue + *Type*: rvalue -join_keys_to_values -------------------- -This function joins each key of a hash to that key's corresponding value with a -separator. Keys and values are cast to strings. The return value is an array in -which each element is one joined key/value pair. +* `has_ip_address`: Returns true if the client has the requested IP address on some interface. This function iterates through the `interfaces` fact and checks the `ipaddress_IFACE` facts, performing a simple string comparison. *Type*: rvalue -*Examples:* +* `has_ip_network`: Returns true if the client has an IP address within the requested network. This function iterates through the 'interfaces' fact and checks the 'network_IFACE' facts, performing a simple string comparision. *Type*: rvalue - join_keys_to_values({'a'=>1,'b'=>2}, " is ") +* `has_key`: Determine if a hash has a certain key value. -Would result in: ["a is 1","b is 2"] + *Example*: -- *Type*: rvalue + ``` + $my_hash = {'key_one' => 'value_one'} + if has_key($my_hash, 'key_two') { + notice('we will not reach here') + } + if has_key($my_hash, 'key_one') { + notice('this will be printed') + } + ``` + + *Type*: rvalue -keys ----- -Returns the keys of a hash as an array. +* `hash`: This function converts an array into a hash. For example, `hash(['a',1,'b',2,'c',3])` returns {'a'=>1,'b'=>2,'c'=>3}. *Type*: rvalue -- *Type*: rvalue +* `intersection`: This function returns an array an intersection of two. For example, `intersection(["a","b","c"],["b","c","d"])` returns ["b","c"]. -loadyaml --------- -Load a YAML file containing an array, string, or hash, and return the data -in the corresponding native data type. +* `is_array`: Returns 'true' if the variable passed to this function is an array. *Type*: rvalue -For example: +* `is_bool`: Returns 'true' if the variable passed to this function is a boolean. *Type*: rvalue - $myhash = loadyaml('/etc/puppet/data/myhash.yaml') +* `is_domain_name`: Returns 'true' if the string passed to this function is a syntactically correct domain name. *Type*: rvalue +* `is_float`: Returns 'true' if the variable passed to this function is a float. *Type*: rvalue -- *Type*: rvalue +* `is_function_available`: This function accepts a string as an argument and determines whether the Puppet runtime has access to a function by that name. It returns 'true' if the function exists, 'false' if not. *Type*: rvalue -lstrip ------- -Strips leading spaces to the left of a string. +* `is_hash`: Returns 'true' if the variable passed to this function is a hash. *Type*: rvalue -- *Type*: rvalue +* `is_integer`: Returns 'true' if the variable returned to this string is an integer. *Type*: rvalue -max ---- -Returns the highest value of all arguments. -Requires at least one argument. +* `is_ip_address`: Returns 'true' if the string passed to this function is a valid IP address. *Type*: rvalue -- *Type*: rvalue +* `is_mac_address`: Returns 'true' if the string passed to this function is a valid MAC address. *Type*: rvalue -member ------- -This function determines if a variable is a member of an array. +* `is_numeric`: Returns 'true' if the variable passed to this function is a number. *Type*: rvalue -*Examples:* +* `is_string`: Returns 'true' if the variable passed to this function is a string. *Type*: rvalue - member(['a','b'], 'b') +* `join`: This function joins an array into a string using a separator. For example, `join(['a','b','c'], ",")` results in: "a,b,c". *Type*: rvalue -Would return: true +* `join_keys_to_values`: This function joins each key of a hash to that key's corresponding value with a separator. Keys and values are cast to strings. The return value is an array in which each element is one joined key/value pair. For example, `join_keys_to_values({'a'=>1,'b'=>2}, " is ")` results in ["a is 1","b is 2"]. *Type*: rvalue - member(['a','b'], 'c') +* `keys`: Returns the keys of a hash as an array. *Type*: rvalue -Would return: false +* `loadyaml`: Load a YAML file containing an array, string, or hash, and return the data in the corresponding native data type. For example: -- *Type*: rvalue + ``` + $myhash = loadyaml('/etc/puppet/data/myhash.yaml') + ``` -merge ------ -Merges two or more hashes together and returns the resulting hash. + *Type*: rvalue -For example: +* `lstrip`: Strips leading spaces to the left of a string. *Type*: rvalue - $hash1 = {'one' => 1, 'two' => 2} - $hash2 = {'two' => 'dos', 'three' => 'tres'} - $merged_hash = merge($hash1, $hash2) - # The resulting hash is equivalent to: - # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'} +* `max`: Returns the highest value of all arguments. Requires at least one argument. *Type*: rvalue -When there is a duplicate key, the key in the rightmost hash will "win." +* `member`: This function determines if a variable is a member of an array. For example, `member(['a','b'], 'b')` returns 'true', while `member(['a','b'], 'c')` returns 'false'. *Type*: rvalue -- *Type*: rvalue +* `merge`: Merges two or more hashes together and returns the resulting hash. -min ---- -Returns the lowest value of all arguments. -Requires at least one argument. + *Example*: + + ``` + $hash1 = {'one' => 1, 'two' => 2} + $hash2 = {'two' => 'dos', 'three' => 'tres'} + $merged_hash = merge($hash1, $hash2) + # The resulting hash is equivalent to: + # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'} + ``` + + When there is a duplicate key, the key in the rightmost hash "wins." *Type*: rvalue -- *Type*: rvalue +* `min`: Returns the lowest value of all arguments. Requires at least one argument. *Type*: rvalue -num2bool --------- -This function converts a number or a string representation of a number into a -true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0 -become true. +* `num2bool`: This function converts a number or a string representation of a number into a true boolean. Zero or anything non-numeric becomes 'false'. Numbers greater than 0 become 'true'. *Type*: rvalue -- *Type*: rvalue +* `parsejson`: This function accepts JSON as a string and converts into the correct Puppet structure. *Type*: rvalue -parsejson ---------- -This function accepts JSON as a string and converts into the correct Puppet -structure. +* `parseyaml`: This function accepts YAML as a string and converts it into the correct Puppet structure. *Type*: rvalue -- *Type*: rvalue +* `pick`: From a list of values, returns the first value that is not undefined or an empty string. Takes any number of arguments, and raises an error if all values are undefined or empty. -parseyaml ---------- -This function accepts YAML as a string and converts it into the correct -Puppet structure. + ``` + $real_jenkins_version = pick($::jenkins_version, '1.449') + ``` + + *Type*: rvalue -- *Type*: rvalue +* `prefix`: This function applies a prefix to all elements in an array. For example, `prefix(['a','b','c'], 'p')` returns ['pa','pb','pc']. *Type*: rvalue -pick ----- -This function is similar to a coalesce function in SQL in that it will return -the first value in a list of values that is not undefined or an empty string -(two things in Puppet that will return a boolean false value). Typically, -this function is used to check for a value in the Puppet Dashboard/Enterprise -Console, and failover to a default value like the following: - $real_jenkins_version = pick($::jenkins_version, '1.449') +* `private`: This function sets the current class or definition as private. +Calling the class or definition from outside the current module will fail. For example, `private()` called in class `foo::bar` outputs the following message if class is called from outside module `foo`: -The value of $real_jenkins_version will first look for a top-scope variable -called 'jenkins_version' (note that parameters set in the Puppet Dashboard/ -Enterprise Console are brought into Puppet as top-scope variables), and, -failing that, will use a default value of 1.449. + ``` + Class foo::bar is private + ``` + + You can specify the error message you want to use: + + ``` + private("You're not supposed to do that!") + ``` -- *Type*: rvalue + *Type*: statement -prefix ------- -This function applies a prefix to all elements in an array. +* `range`: When given range in the form of '(start, stop)', `range` extrapolates a range as an array. For example, `range("0", "9")` returns [0,1,2,3,4,5,6,7,8,9]. Zero-padded strings are converted to integers automatically, so `range("00", "09")` returns [0,1,2,3,4,5,6,7,8,9]. -*Examples:* + Non-integer strings are accepted; `range("a", "c")` returns ["a","b","c"], and `range("host01", "host10")` returns ["host01", "host02", ..., "host09", "host10"]. + + *Type*: rvalue - prefix(['a','b','c'], 'p') +* `reject`: This function searches through an array and rejects all elements that match the provided regular expression. For example, `reject(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['bbb','ccc']. *Type*: rvalue -Will return: ['pa','pb','pc'] +* `reverse`: Reverses the order of a string or array. *Type*: rvalue -- *Type*: rvalue +* `rstrip`: Strips leading spaces to the right of the string.*Type*: rvalue +* `shuffle`: Randomizes the order of a string or array elements. *Type*: rvalue -private -------- -This function sets the current class or definition as private. -Calling the class or definition from outside the current module will fail. +* `size`: Returns the number of elements in a string or array. *Type*: rvalue -*Examples:* +* `sort`: Sorts strings and arrays lexically. *Type*: rvalue - private() +* `squeeze`: Returns a new string where runs of the same character that occur in this set are replaced by a single character. *Type*: rvalue -called in class `foo::bar` will output the following message if class is called -from outside module `foo`: +* `str2bool`: This converts a string to a boolean. This attempts to convert strings that contain values such as '1', 't', 'y', and 'yes' to 'true' and strings that contain values such as '0', 'f', 'n', and 'no' to 'false'. *Type*: rvalue - Class foo::bar is private +* `str2saltedsha512`: This converts a string to a salted-SHA512 password hash, used for OS X versions >= 10.7. Given any string, this function returns a hex version of a salted-SHA512 password hash, which can be inserted into your Puppet +manifests as a valid password attribute. *Type*: rvalue -You can specify the error message you want to use as a parameter: +* `strftime`: This function returns formatted time. For example, `strftime("%s")` returns the time since epoch, and `strftime("%Y=%m-%d")` returns the date. *Type*: rvalue - private("You're not supposed to do that!") + *Format:* + + * `%a`: The abbreviated weekday name ('Sun') + * `%A`: The full weekday name ('Sunday') + * `%b`: The abbreviated month name ('Jan') + * `%B`: The full month name ('January') + * `%c`: The preferred local date and time representation + * `%C`: Century (20 in 2009) + * `%d`: Day of the month (01..31) + * `%D`: Date (%m/%d/%y) + * `%e`: Day of the month, blank-padded ( 1..31) + * `%F`: Equivalent to %Y-%m-%d (the ISO 8601 date format) + * `%h`: Equivalent to %b + * `%H`: Hour of the day, 24-hour clock (00..23) + * `%I`: Hour of the day, 12-hour clock (01..12) + * `%j`: Day of the year (001..366) + * `%k`: Hour, 24-hour clock, blank-padded ( 0..23) + * `%l`: Hour, 12-hour clock, blank-padded ( 0..12) + * `%L`: Millisecond of the second (000..999) + * `%m`: Month of the year (01..12) + * `%M`: Minute of the hour (00..59) + * `%n`: Newline (\n) + * `%N`: Fractional seconds digits, default is 9 digits (nanosecond) + * `%3N`: Millisecond (3 digits) + * `%6N`: Microsecond (6 digits) + * `%9N`: Nanosecond (9 digits) + * `%p`: Meridian indicator ('AM' or 'PM') + * `%P`: Meridian indicator ('am' or 'pm') + * `%r`: Time, 12-hour (same as %I:%M:%S %p) + * `%R`: Time, 24-hour (%H:%M) + * `%s`: Number of seconds since 1970-01-01 00:00:00 UTC. + * `%S`: Second of the minute (00..60) + * `%t`: Tab character ( ) + * `%T`: Time, 24-hour (%H:%M:%S) + * `%u`: Day of the week as a decimal, Monday being 1. (1..7) + * `%U`: Week number of the current year, starting with the first Sunday as the first day of the first week (00..53) + * `%v`: VMS date (%e-%b-%Y) + * `%V`: Week number of year according to ISO 8601 (01..53) + * `%W`: Week number of the current year, starting with the first Monday as the first day of the first week (00..53) + * `%w`: Day of the week (Sunday is 0, 0..6) + * `%x`: Preferred representation for the date alone, no time + * `%X`: Preferred representation for the time alone, no date + * `%y`: Year without a century (00..99) + * `%Y`: Year with century + * `%z`: Time zone as hour offset from UTC (e.g. +0900) + * `%Z`: Time zone name + * `%%`: Literal '%' character -- *Type*: statement -range ------ -When given range in the form of (start, stop) it will extrapolate a range as -an array. +* `strip`: This function removes leading and trailing whitespace from a string or from every string inside an array. For example, `strip(" aaa ")` results in "aaa". *Type*: rvalue -*Examples:* +* `suffix`: This function applies a suffix to all elements in an array. For example, `suffix(['a','b','c'], 'p')` returns ['ap','bp','cp']. *Type*: rvalue - range("0", "9") +* `swapcase`: This function swaps the existing case of a string. For example, `swapcase("aBcD")` results in "AbCd". *Type*: rvalue -Will return: [0,1,2,3,4,5,6,7,8,9] +* `time`: This function returns the current time since epoch as an integer. For example, `time()` returns something like '1311972653'. *Type*: rvalue + +* `to_bytes`: Converts the argument into bytes, for example 4 kB becomes 4096. +Takes a single string value as an argument. *Type*: rvalue + +* `type`: Returns the type when passed a variable. Type can be a string, array, hash, float, integer, or boolean. *Type*: rvalue + +* `union`: This function returns a union of two arrays. For example, `union(["a","b","c"],["b","c","d"])` returns ["a","b","c","d"]. - range("00", "09") +* `unique`: This function removes duplicates from strings and arrays. For example, `unique("aabbcc")` returns 'abc'. -Will return: [0,1,2,3,4,5,6,7,8,9] - Zero padded strings are converted to -integers automatically +You can also use this with arrays. For example, `unique(["a","a","b","b","c","c"])` returns ["a","b","c"]. *Type*: rvalue - range("a", "c") +* `upcase`: Converts a string or an array of strings to uppercase. For example, `upcase("abcd")` returns 'ABCD'. *Type*: rvalue -Will return: ["a","b","c"] +* `uriescape`: Urlencodes a string or array of strings. Requires either a single string or an array as an input. *Type*: rvalue - range("host01", "host10") +* `validate_absolute_path`: Validate that the string represents an absolute path in the filesystem. This function works for Windows and Unix-style paths. + The following values will pass: -Will return: ["host01", "host02", ..., "host09", "host10"] + ``` + $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet" + validate_absolute_path($my_path) + $my_path2 = "/var/lib/puppet" + validate_absolute_path($my_path2) + ``` -- *Type*: rvalue + The following values will fail, causing compilation to abort: + + ``` + validate_absolute_path(true) + validate_absolute_path([ 'var/lib/puppet', '/var/foo' ]) + validate_absolute_path([ '/var/lib/puppet', 'var/foo' ]) + $undefined = undef + validate_absolute_path($undefined) + ``` + + *Type*: statement + +* `validate_array`: Validate that all passed values are array data structures. Abort catalog compilation if any value fails this check. + + The following values will pass: + + ``` + $my_array = [ 'one', 'two' ] + validate_array($my_array) + ``` + + The following values will fail, causing compilation to abort: + + ``` + validate_array(true) + validate_array('some_string') + $undefined = undef + validate_array($undefined) + ``` + + *Type*: statement + +* `validate_augeas`: Performs validation of a string using an Augeas lens. +The first argument of this function should be the string to test, and the second argument should be the name of the Augeas lens to use. If Augeas fails to parse the string with the lens, the compilation aborts with a parse error. + + A third optional argument lists paths which should **not** be found in the file. The `$file` variable points to the location of the temporary file being tested in the Augeas tree. + + For example, to make sure your passwd content never contains user `foo`: -reject ------- -This function searches through an array and rejects all elements that match -the provided regular expression. + ``` + validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo']) + ``` + + To ensure that no users use the '/bin/barsh' shell: -*Examples:* + ``` + validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]'] + ``` + + You can pass a fourth argument as the error message raised and shown to the user: - reject(['aaa','bbb','ccc','aaaddd'], 'aaa') + ``` + validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas') + ``` -Would return: + *Type*: statement - ['bbb','ccc'] +* `validate_bool`: Validate that all passed values are either true or false. Abort catalog compilation if any value fails this check. + The following values will pass: + + ``` + $iamtrue = true + validate_bool(true) + validate_bool(true, true, false, $iamtrue) + ``` + + The following values will fail, causing compilation to abort: -- *Type*: rvalue + ``` + $some_array = [ true ] + validate_bool("false") + validate_bool("true") + validate_bool($some_array) + ``` -reverse -------- -Reverses the order of a string or array. + *Type*: statement -- *Type*: rvalue +* `validate_cmd`: Performs validation of a string with an external command. The first argument of this function should be the string to test, and the second argument should be the path to a test command taking a file as last argument. If the command, launched against a tempfile containing the passed string, returns a non-null value, compilation aborts with a parse error. -rstrip ------- -Strips leading spaces to the right of the string. + You can pass a third argument as the error message raised and shown to the user: -- *Type*: rvalue + ``` + validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content') + ``` + + *Type*: statement -shuffle -------- -Randomizes the order of a string or array elements. +* `validate_hash`: Validates that all passed values are hash data structures. Abort catalog compilation if any value fails this check. -- *Type*: rvalue + The following values will pass: -size ----- -Returns the number of elements in a string or array. + ``` + $my_hash = { 'one' => 'two' } + validate_hash($my_hash) + ``` -- *Type*: rvalue + The following values will fail, causing compilation to abort: -sort ----- -Sorts strings and arrays lexically. + ``` + validate_hash(true) + validate_hash('some_string') + $undefined = undef + validate_hash($undefined) + ``` + + *Type*: statement -- *Type*: rvalue - -squeeze -------- -Returns a new string where runs of the same character that occur in this set -are replaced by a single character. - -- *Type*: rvalue - -str2bool --------- -This converts a string to a boolean. This attempts to convert strings that -contain things like: y, 1, t, true to 'true' and strings that contain things -like: 0, f, n, false, no to 'false'. - - -- *Type*: rvalue - -str2saltedsha512 ----------------- -This converts a string to a salted-SHA512 password hash (which is used for -OS X versions >= 10.7). Given any simple string, you will get a hex version -of a salted-SHA512 password hash that can be inserted into your Puppet -manifests as a valid password attribute. - - -- *Type*: rvalue - -strftime --------- -This function returns formatted time. - -*Examples:* - -To return the time since epoch: - - strftime("%s") - -To return the date: - - strftime("%Y-%m-%d") - -*Format meaning:* - - %a - The abbreviated weekday name (``Sun'') - %A - The full weekday name (``Sunday'') - %b - The abbreviated month name (``Jan'') - %B - The full month name (``January'') - %c - The preferred local date and time representation - %C - Century (20 in 2009) - %d - Day of the month (01..31) - %D - Date (%m/%d/%y) - %e - Day of the month, blank-padded ( 1..31) - %F - Equivalent to %Y-%m-%d (the ISO 8601 date format) - %h - Equivalent to %b - %H - Hour of the day, 24-hour clock (00..23) - %I - Hour of the day, 12-hour clock (01..12) - %j - Day of the year (001..366) - %k - hour, 24-hour clock, blank-padded ( 0..23) - %l - hour, 12-hour clock, blank-padded ( 0..12) - %L - Millisecond of the second (000..999) - %m - Month of the year (01..12) - %M - Minute of the hour (00..59) - %n - Newline (\n) - %N - Fractional seconds digits, default is 9 digits (nanosecond) - %3N millisecond (3 digits) - %6N microsecond (6 digits) - %9N nanosecond (9 digits) - %p - Meridian indicator (``AM'' or ``PM'') - %P - Meridian indicator (``am'' or ``pm'') - %r - time, 12-hour (same as %I:%M:%S %p) - %R - time, 24-hour (%H:%M) - %s - Number of seconds since 1970-01-01 00:00:00 UTC. - %S - Second of the minute (00..60) - %t - Tab character ( ) - %T - time, 24-hour (%H:%M:%S) - %u - Day of the week as a decimal, Monday being 1. (1..7) - %U - Week number of the current year, - starting with the first Sunday as the first - day of the first week (00..53) - %v - VMS date (%e-%b-%Y) - %V - Week number of year according to ISO 8601 (01..53) - %W - Week number of the current year, - starting with the first Monday as the first - day of the first week (00..53) - %w - Day of the week (Sunday is 0, 0..6) - %x - Preferred representation for the date alone, no time - %X - Preferred representation for the time alone, no date - %y - Year without a century (00..99) - %Y - Year with century - %z - Time zone as hour offset from UTC (e.g. +0900) - %Z - Time zone name - %% - Literal ``%'' character - - -- *Type*: rvalue - -strip ------ -This function removes leading and trailing whitespace from a string or from -every string inside an array. - -*Examples:* - - strip(" aaa ") - -Would result in: "aaa" - - -- *Type*: rvalue - -suffix ------- -This function applies a suffix to all elements in an array. - -*Examples:* - - suffix(['a','b','c'], 'p') - -Will return: ['ap','bp','cp'] - - -- *Type*: rvalue - -swapcase --------- -This function will swap the existing case of a string. - -*Examples:* - - swapcase("aBcD") - -Would result in: "AbCd" - - -- *Type*: rvalue - -time ----- -This function will return the current time since epoch as an integer. - -*Examples:* - - time() - -Will return something like: 1311972653 - - -- *Type*: rvalue - -to_bytes --------- -Converts the argument into bytes, for example 4 kB becomes 4096. -Takes a single string value as an argument. - - -- *Type*: rvalue - -type ----- -Returns the type when passed a variable. Type can be one of: - -* string -* array -* hash -* float -* integer -* boolean - - -- *Type*: rvalue - -union ------ -This function returns a union of two arrays. - -*Examples:* - - union(["a","b","c"],["b","c","d"]) - -Would return: ["a","b","c","d"] - - -unique ------- -This function will remove duplicates from strings and arrays. - -*Examples:* - - unique("aabbcc") - -Will return: - - abc - -You can also use this with arrays: - - unique(["a","a","b","b","c","c"]) - -This returns: - - ["a","b","c"] - - -- *Type*: rvalue - -upcase ------- -Converts a string or an array of strings to uppercase. - -*Examples:* - - upcase("abcd") - -Will return: - - ABCD - - -- *Type*: rvalue - -uriescape ---------- -Urlencodes a string or array of strings. -Requires either a single string or an array as an input. - - -- *Type*: rvalue - -validate_absolute_path ----------------------- -Validate the string represents an absolute path in the filesystem. This function works -for windows and unix style paths. - -The following values will pass: - - $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet" - validate_absolute_path($my_path) - $my_path2 = "/var/lib/puppet" - validate_absolute_path($my_path2) - - -The following values will fail, causing compilation to abort: - - validate_absolute_path(true) - validate_absolute_path([ 'var/lib/puppet', '/var/foo' ]) - validate_absolute_path([ '/var/lib/puppet', 'var/foo' ]) - $undefined = undef - validate_absolute_path($undefined) - - - -- *Type*: statement - -validate_array --------------- -Validate that all passed values are array data structures. Abort catalog -compilation if any value fails this check. - -The following values will pass: - - $my_array = [ 'one', 'two' ] - validate_array($my_array) - -The following values will fail, causing compilation to abort: - - validate_array(true) - validate_array('some_string') - $undefined = undef - validate_array($undefined) - - - -- *Type*: statement - -validate_augeas ---------------- -Perform validation of a string using an Augeas lens -The first argument of this function should be a string to -test, and the second argument should be the name of the Augeas lens to use. -If Augeas fails to parse the string with the lens, the compilation will -abort with a parse error. - -A third argument can be specified, listing paths which should -not be found in the file. The `$file` variable points to the location -of the temporary file being tested in the Augeas tree. - -For example, if you want to make sure your passwd content never contains -a user `foo`, you could write: - - validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo']) - -Or if you wanted to ensure that no users used the '/bin/barsh' shell, -you could use: - - validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]'] - -If a fourth argument is specified, this will be the error message raised and -seen by the user. - -A helpful error message can be returned like this: - - validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas') - - - -- *Type*: statement - -validate_bool -------------- -Validate that all passed values are either true or false. Abort catalog -compilation if any value fails this check. - -The following values will pass: - - $iamtrue = true - validate_bool(true) - validate_bool(true, true, false, $iamtrue) - -The following values will fail, causing compilation to abort: - - $some_array = [ true ] - validate_bool("false") - validate_bool("true") - validate_bool($some_array) - - - -- *Type*: statement - -validate_cmd ------------- -Perform validation of a string with an external command. -The first argument of this function should be a string to -test, and the second argument should be a path to a test command -taking a file as last argument. If the command, launched against -a tempfile containing the passed string, returns a non-null value, -compilation will abort with a parse error. - -If a third argument is specified, this will be the error message raised and -seen by the user. - -A helpful error message can be returned like this: - -Example: - - validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content') - - - -- *Type*: statement - -validate_hash -------------- -Validate that all passed values are hash data structures. Abort catalog -compilation if any value fails this check. - -The following values will pass: - - $my_hash = { 'one' => 'two' } - validate_hash($my_hash) - -The following values will fail, causing compilation to abort: - - validate_hash(true) - validate_hash('some_string') - $undefined = undef - validate_hash($undefined) - - - -- *Type*: statement - -validate_re ------------ -Perform simple validation of a string against one or more regular -expressions. The first argument of this function should be a string to +* `validate_re`: Performs simple validation of a string against one or more regular expressions. The first argument of this function should be the string to test, and the second argument should be a stringified regular expression -(without the // delimiters) or an array of regular expressions. If none -of the regular expressions match the string passed in, compilation will -abort with a parse error. - -If a third argument is specified, this will be the error message raised and -seen by the user. - -The following strings will validate against the regular expressions: - - validate_re('one', '^one$') - validate_re('one', [ '^one', '^two' ]) - -The following strings will fail to validate, causing compilation to abort: - - validate_re('one', [ '^two', '^three' ]) +(without the // delimiters) or an array of regular expressions. If none +of the regular expressions match the string passed in, compilation aborts with a parse error. -A helpful error message can be returned like this: + You can pass a third argument as the error message raised and shown to the user. - validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7') + The following strings validate against the regular expressions: + ``` + validate_re('one', '^one$') + validate_re('one', [ '^one', '^two' ]) + ``` + The following string fails to validate, causing compilation to abort: -- *Type*: statement + ``` + validate_re('one', [ '^two', '^three' ]) + ``` -validate_slength ----------------- -Validate that the first argument is a string (or an array of strings), and -less/equal to than the length of the second argument. It fails if the first -argument is not a string or array of strings, and if arg 2 is not convertable -to a number. + To set the error message: + + ``` + validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7') + ``` -The following values will pass: + *Type*: statement - validate_slength("discombobulate",17) - validate_slength(["discombobulate","moo"],17) +* `validate_slength`: Validates that the first argument is a string (or an array of strings), and is less than or equal to the length of the second argument. It fails if the first argument is not a string or array of strings, or if arg 2 is not convertable to a number. -The following values will not: + The following values pass: + + ``` + validate_slength("discombobulate",17) + validate_slength(["discombobulate","moo"],17) + ``` + + The following values fail: - validate_slength("discombobulate",1) - validate_slength(["discombobulate","thermometer"],5) + ``` + validate_slength("discombobulate",1) + validate_slength(["discombobulate","thermometer"],5) + ``` + + *Type*: statement +* `validate_string`: Validates that all passed values are string data structures. Aborts catalog compilation if any value fails this check. + The following values pass: -- *Type*: statement + ``` + $my_string = "one two" + validate_string($my_string, 'three') + ``` -validate_string ---------------- -Validate that all passed values are string data structures. Abort catalog -compilation if any value fails this check. + The following values fail, causing compilation to abort: -The following values will pass: + ``` + validate_string(true) + validate_string([ 'some', 'array' ]) + $undefined = undef + validate_string($undefined) + ``` - $my_string = "one two" - validate_string($my_string, 'three') + *Type*: statement -The following values will fail, causing compilation to abort: +* `values`: When given a hash, this function returns the values of that hash. - validate_string(true) - validate_string([ 'some', 'array' ]) - $undefined = undef - validate_string($undefined) + *Examples:* + ``` + $hash = { + 'a' => 1, + 'b' => 2, + 'c' => 3, + } + values($hash) + ``` -- *Type*: statement + The example above returns [1,2,3]. -values ------- -When given a hash this function will return the values of that hash. + *Type*: rvalue -*Examples:* +* `values_at`: Finds value inside an array based on location. The first argument is the array you want to analyze, and the second element can be a combination of: - $hash = { - 'a' => 1, - 'b' => 2, - 'c' => 3, - } - values($hash) + * A single numeric index + * A range in the form of 'start-stop' (eg. 4-9) + * An array combining the above -This example would return: + For example, `values_at(['a','b','c'], 2)` returns ['c']; `values_at(['a','b','c'], ["0-1"])` returns ['a','b']; and `values_at(['a','b','c','d','e'], [0, "2-3"])` returns ['a','c','d']. - [1,2,3] + *Type*: rvalue +* `zip`: Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments. For example, `zip(['1','2','3'],['4','5','6'])` results in ["1", "4"], ["2", "5"], ["3", "6"]. *Type*: rvalue -- *Type*: rvalue +##Limitations -values_at ---------- -Finds value inside an array based on location. +###Version Compatibility -The first argument is the array you want to analyze, and the second element can -be a combination of: - -* A single numeric index -* A range in the form of 'start-stop' (eg. 4-9) -* An array combining the above - -*Examples*: - - values_at(['a','b','c'], 2) - -Would return ['c']. - - values_at(['a','b','c'], ["0-1"]) - -Would return ['a','b']. +Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x | +:---------------|:-----:|:---:|:---:|:----: +**stdlib 2.x** | **yes** | **yes** | no | no +**stdlib 3.x** | no | **yes** | **yes** | no +**stdlib 4.x** | no | **yes** | **yes** | no +**stdlib 5.x** | no | no | **yes** | **yes** - values_at(['a','b','c','d','e'], [0, "2-3"]) +**stdlib 5.x**: When released, stdlib 5.x will drop support for Puppet 2.7.x. Please see [this discussion](https://github.com/puppetlabs/puppetlabs-stdlib/pull/176#issuecomment-30251414). -Would return ['a','c','d']. +##Development +Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. -- *Type*: rvalue +We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. -zip ---- -Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments. +You can read the complete module contribution guide on the [Puppet Labs wiki](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing). -*Example:* +To report or research a bug with any part of this module, please go to +[http://tickets.puppetlabs.com/browse/PUP](http://tickets.puppetlabs.com/browse/PUP). - zip(['1','2','3'],['4','5','6']) +##Contributors -Would result in: +The list of contributors can be found at: https://github.com/puppetlabs/puppetlabs-stdlib/graphs/contributors - ["1", "4"], ["2", "5"], ["3", "6"] -- *Type*: rvalue -*This page autogenerated on 2013-04-11 13:54:25 -0700* -- cgit v1.2.3 From 0d11bde5073d2976e9f5d9625757a7a71ddab6c4 Mon Sep 17 00:00:00 2001 From: Mathias Klette Date: Fri, 10 Oct 2014 22:54:22 +0200 Subject: ensure_resource: be more verbose in debug mode helps discovering duplication issues, especially when figthing boolean vs. string arguments --- lib/puppet/parser/functions/ensure_resource.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/ensure_resource.rb b/lib/puppet/parser/functions/ensure_resource.rb index 05e5593..1ba6a44 100644 --- a/lib/puppet/parser/functions/ensure_resource.rb +++ b/lib/puppet/parser/functions/ensure_resource.rb @@ -36,8 +36,9 @@ ENDOFDOC items.each do |item| Puppet::Parser::Functions.function(:defined_with_params) if function_defined_with_params(["#{type}[#{item}]", params]) - Puppet.debug("Resource #{type}[#{item}] not created because it already exists") + Puppet.debug("Resource #{type}[#{item}] with params #{params} not created because it already exists") else + Puppet.debug("Create new resource #{type}[#{item}] with params #{params}") Puppet::Parser::Functions.function(:create_resources) function_create_resources([type.capitalize, { item => params }]) end -- cgit v1.2.3 From 624ccbd22c845a042e8128d44c5299c0732e81de Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Fri, 24 Oct 2014 16:35:34 -0700 Subject: add require 'tempfile' to resolve a previously autorequired resource --- lib/puppet/parser/functions/validate_augeas.rb | 2 ++ lib/puppet/parser/functions/validate_cmd.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/puppet/parser/functions/validate_augeas.rb b/lib/puppet/parser/functions/validate_augeas.rb index 154d660..4ea4fe0 100644 --- a/lib/puppet/parser/functions/validate_augeas.rb +++ b/lib/puppet/parser/functions/validate_augeas.rb @@ -1,3 +1,5 @@ +require 'tempfile' + module Puppet::Parser::Functions newfunction(:validate_augeas, :doc => <<-'ENDHEREDOC') do |args| Perform validation of a string using an Augeas lens diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb index 2ebe91c..652aa55 100644 --- a/lib/puppet/parser/functions/validate_cmd.rb +++ b/lib/puppet/parser/functions/validate_cmd.rb @@ -1,4 +1,5 @@ require 'puppet/util/execution' +require 'tempfile' module Puppet::Parser::Functions newfunction(:validate_cmd, :doc => <<-'ENDHEREDOC') do |args| -- cgit v1.2.3 From 9295d0d5cae91f8c9b3b4b4fd891661666ab9e13 Mon Sep 17 00:00:00 2001 From: Zachary Alex Stern Date: Tue, 28 Oct 2014 13:14:06 -0700 Subject: Added correct converstions for PB and EB. * We were converting Exabytes to bytes as Petabytes. * Updated tests to cover ever unit. * Added note that we're going by the old, inaccurate definitions of Kilobytes, Megabytes, etc, in that we treat them as powers of 2. --- lib/puppet/parser/functions/to_bytes.rb | 5 ++++- spec/functions/to_bytes_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/to_bytes.rb b/lib/puppet/parser/functions/to_bytes.rb index 8ff73d1..df490ea 100644 --- a/lib/puppet/parser/functions/to_bytes.rb +++ b/lib/puppet/parser/functions/to_bytes.rb @@ -2,6 +2,8 @@ module Puppet::Parser::Functions newfunction(:to_bytes, :type => :rvalue, :doc => <<-EOS Converts the argument into bytes, for example 4 kB becomes 4096. Takes a single string value as an argument. + These conversions reflect a layperson's understanding of + 1 MB = 1024 KB, when in fact 1 MB = 1000 KB, and 1 MiB = 1024 KiB. EOS ) do |arguments| @@ -21,7 +23,8 @@ module Puppet::Parser::Functions when 'M' then return (value*(1<<20)).to_i when 'G' then return (value*(1<<30)).to_i when 'T' then return (value*(1<<40)).to_i - when 'E' then return (value*(1<<50)).to_i + when 'P' then return (value*(1<<50)).to_i + when 'E' then return (value*(1<<60)).to_i else raise Puppet::ParseError, "to_bytes(): Unknown prefix #{prefix}" end end diff --git a/spec/functions/to_bytes_spec.rb b/spec/functions/to_bytes_spec.rb index 68a1eb8..0f6ade9 100755 --- a/spec/functions/to_bytes_spec.rb +++ b/spec/functions/to_bytes_spec.rb @@ -18,6 +18,31 @@ describe "the to_bytes function" do expect(result).to(eq(4096)) end + it "should convert MB to B" do + result = scope.function_to_bytes(["4 MB"]) + expect(result).to(eq(4194304)) + end + + it "should convert GB to B" do + result = scope.function_to_bytes(["4 GB"]) + expect(result).to(eq(4294967296)) + end + + it "should convert TB to B" do + result = scope.function_to_bytes(["4 TB"]) + expect(result).to(eq(4398046511104)) + end + + it "should convert PB to B" do + result = scope.function_to_bytes(["4 PB"]) + expect(result).to(eq(4503599627370496)) + end + + it "should convert PB to B" do + result = scope.function_to_bytes(["4 EB"]) + expect(result).to(eq(4611686018427387904)) + end + it "should work without B in unit" do result = scope.function_to_bytes(["4 k"]) expect(result).to(eq(4096)) -- cgit v1.2.3 From 51f1d574d92cf686ac79e57e69d8aff31caf2925 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 28 Oct 2014 15:27:24 -0700 Subject: Fix testcases for Future Parser and resolve issue with values_at in assuming that it was dealing with a string --- lib/puppet/parser/functions/values_at.rb | 1 + spec/acceptance/abs_spec.rb | 4 ++-- spec/acceptance/any2array_spec.rb | 4 ++-- spec/acceptance/bool2num_spec.rb | 12 ++++++------ spec/acceptance/count_spec.rb | 4 ++-- spec/acceptance/ensure_packages_spec.rb | 2 +- spec/acceptance/merge_spec.rb | 4 ++-- spec/acceptance/type_spec.rb | 2 +- spec/acceptance/validate_cmd_spec.rb | 2 +- spec/acceptance/values_spec.rb | 6 +++++- spec/acceptance/zip_spec.rb | 28 ++++++++++++++++++++-------- spec/spec_helper_acceptance.rb | 12 ++++++++++++ 12 files changed, 55 insertions(+), 26 deletions(-) diff --git a/lib/puppet/parser/functions/values_at.rb b/lib/puppet/parser/functions/values_at.rb index d3e69d9..f350f53 100644 --- a/lib/puppet/parser/functions/values_at.rb +++ b/lib/puppet/parser/functions/values_at.rb @@ -49,6 +49,7 @@ Would return ['a','c','d']. indices_list = [] indices.each do |i| + i = i.to_s if m = i.match(/^(\d+)(\.\.\.?|\-)(\d+)$/) start = m[1].to_i stop = m[3].to_i diff --git a/spec/acceptance/abs_spec.rb b/spec/acceptance/abs_spec.rb index 8e05642..6e41e2f 100755 --- a/spec/acceptance/abs_spec.rb +++ b/spec/acceptance/abs_spec.rb @@ -7,7 +7,7 @@ describe 'abs function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati pp = <<-EOS $input = '-34.56' $output = abs($input) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| @@ -19,7 +19,7 @@ describe 'abs function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati pp = <<-EOS $input = -34.56 $output = abs($input) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| diff --git a/spec/acceptance/any2array_spec.rb b/spec/acceptance/any2array_spec.rb index 467d6af..18ea4cd 100755 --- a/spec/acceptance/any2array_spec.rb +++ b/spec/acceptance/any2array_spec.rb @@ -25,7 +25,7 @@ describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: Output: testarray/) + expect(r.stdout).to match(/Notice: Output: (\[|)test(,\s|)array(\]|)/) end end @@ -42,7 +42,7 @@ describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: Output: testarray/) + expect(r.stdout).to match(/Notice: Output: (\[|)test(,\s|)array(\]|)/) end end end diff --git a/spec/acceptance/bool2num_spec.rb b/spec/acceptance/bool2num_spec.rb index 7a70311..52ff75b 100755 --- a/spec/acceptance/bool2num_spec.rb +++ b/spec/acceptance/bool2num_spec.rb @@ -4,11 +4,11 @@ require 'spec_helper_acceptance' describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do ['false', 'f', '0', 'n', 'no'].each do |bool| - it 'should convert a given boolean, #{bool}, to 0' do + it "should convert a given boolean, #{bool}, to 0" do pp = <<-EOS - $input = #{bool} + $input = "#{bool}" $output = bool2num($input) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| @@ -18,11 +18,11 @@ describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op end ['true', 't', '1', 'y', 'yes'].each do |bool| - it 'should convert a given boolean, #{bool}, to 1' do + it "should convert a given boolean, #{bool}, to 1" do pp = <<-EOS - $input = #{bool} + $input = "#{bool}" $output = bool2num($input) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| diff --git a/spec/acceptance/count_spec.rb b/spec/acceptance/count_spec.rb index 51a40ba..fe7ca9d 100755 --- a/spec/acceptance/count_spec.rb +++ b/spec/acceptance/count_spec.rb @@ -7,7 +7,7 @@ describe 'count function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('opera pp = <<-EOS $input = [1,2,3,4] $output = count($input) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| @@ -19,7 +19,7 @@ describe 'count function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('opera pp = <<-EOS $input = [1,1,1,2] $output = count($input, 1) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb index 12da0cd..53c1035 100755 --- a/spec/acceptance/ensure_packages_spec.rb +++ b/spec/acceptance/ensure_packages_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'ensure_packages function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +describe 'ensure_packages function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || fact('operatingsystem') != 'windows') do describe 'success' do it 'ensure_packages a package' do apply_manifest('package { "rake": ensure => absent, provider => "gem", }') diff --git a/spec/acceptance/merge_spec.rb b/spec/acceptance/merge_spec.rb index a60e784..227b994 100755 --- a/spec/acceptance/merge_spec.rb +++ b/spec/acceptance/merge_spec.rb @@ -14,9 +14,9 @@ describe 'merge function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('opera EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/merge\[one\] is "1"/) + expect(r.stdout).to match(/merge\[one\] is ("1"|1)/) expect(r.stdout).to match(/merge\[two\] is "dos"/) - expect(r.stdout).to match(/merge\[three\] is {"five"=>"5"}/) + expect(r.stdout).to match(/merge\[three\] is {"five"=>("5"|5)}/) end end end diff --git a/spec/acceptance/type_spec.rb b/spec/acceptance/type_spec.rb index 0043aad..15fa217 100755 --- a/spec/acceptance/type_spec.rb +++ b/spec/acceptance/type_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'type function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +describe 'type function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || !(is_future_parser_enabled?)) do describe 'success' do it 'types arrays' do pp = <<-EOS diff --git a/spec/acceptance/validate_cmd_spec.rb b/spec/acceptance/validate_cmd_spec.rb index 385676d..a899a1d 100755 --- a/spec/acceptance/validate_cmd_spec.rb +++ b/spec/acceptance/validate_cmd_spec.rb @@ -37,7 +37,7 @@ describe 'validate_cmd function', :unless => UNSUPPORTED_PLATFORMS.include?(fact } else { $two = '/bin/aoeu' } - validate_cmd($one,$two,"aoeu is dvorak) + validate_cmd($one,$two,"aoeu is dvorak") EOS expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/aoeu is dvorak/) diff --git a/spec/acceptance/values_spec.rb b/spec/acceptance/values_spec.rb index 7ef956e..a2eff32 100755 --- a/spec/acceptance/values_spec.rb +++ b/spec/acceptance/values_spec.rb @@ -13,8 +13,12 @@ describe 'values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('oper $output = values($arg) notice(inline_template('<%= @output.sort.inspect %>')) EOS + if is_future_parser_enabled? + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[1, 2, 3\]/) + else + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "2", "3"\]/) + end - expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "2", "3"\]/) end end describe 'failure' do diff --git a/spec/acceptance/zip_spec.rb b/spec/acceptance/zip_spec.rb index 0e924e8..139079e 100755 --- a/spec/acceptance/zip_spec.rb +++ b/spec/acceptance/zip_spec.rb @@ -11,8 +11,11 @@ describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati $output = zip($one,$two) notice(inline_template('<%= @output.inspect %>')) EOS - - expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/) + if is_future_parser_enabled? + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\], \[3, 7\], \[4, 8\]\]/) + else + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/) + end end it 'zips two arrays of numbers & bools together' do pp = <<-EOS @@ -21,8 +24,11 @@ describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati $output = zip($one,$two) notice(inline_template('<%= @output.inspect %>')) EOS - - expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/) + if is_future_parser_enabled? + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, true\], \[2, true\], \["three", false\], \[4, false\]\]/) + else + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/) + end end it 'zips two arrays of numbers together and flattens them' do # XXX This only tests the argument `true`, even though the following are valid: @@ -35,8 +41,11 @@ describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati $output = zip($one,$two,true) notice(inline_template('<%= @output.inspect %>')) EOS - - expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/) + if is_future_parser_enabled? + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[1, 5, 2, 6, 3, 7, 4, 8\]/) + else + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/) + end end it 'handles unmatched length' do # XXX Is this expected behavior? @@ -46,8 +55,11 @@ describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati $output = zip($one,$two) notice(inline_template('<%= @output.inspect %>')) EOS - - expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/) + if is_future_parser_enabled? + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\]\]/) + else + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/) + end end end describe 'failure' do diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index e9ccc68..e2f6b76 100755 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -26,10 +26,15 @@ RSpec.configure do |c| # Configure all nodes in nodeset c.before :suite do + if ENV['FUTURE_PARSER'] == 'true' + default[:default_apply_opts] ||= {} + default[:default_apply_opts].merge!({:parser => 'future'}) + end hosts.each do |host| if host['platform'] !~ /windows/i copy_root_module_to(host, :source => proj_root, :module_name => 'stdlib') end + end hosts.each do |host| if host['platform'] =~ /windows/i @@ -38,3 +43,10 @@ RSpec.configure do |c| end end end + +def is_future_parser_enabled? + if default[:default_apply_opts] + return default[:default_apply_opts][:parser] == 'future' + end + return false +end -- cgit v1.2.3 From 5497f83507fcaf24accff26d08ae61d9e7e36673 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 28 Oct 2014 15:35:56 -0700 Subject: Fix logic issue with not including windows for testing ensure_packages as ruby and gem are not on the install path --- spec/acceptance/ensure_packages_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb index 53c1035..9d39220 100755 --- a/spec/acceptance/ensure_packages_spec.rb +++ b/spec/acceptance/ensure_packages_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'ensure_packages function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || fact('operatingsystem') != 'windows') do +describe 'ensure_packages function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) && fact('operatingsystem') != 'windows') do describe 'success' do it 'ensure_packages a package' do apply_manifest('package { "rake": ensure => absent, provider => "gem", }') -- cgit v1.2.3 From 9f68fd300f8228f929b384a2df518aec63516ae6 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 28 Oct 2014 16:10:50 -0700 Subject: Fixed a mistake where we were trying to touch a host file using the default which was not relavent to the host we were modifying --- spec/spec_helper_acceptance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 5f1950a..ef99723 100755 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -12,7 +12,7 @@ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' hosts.each do |host| on host, "mkdir -p #{host['distmoduledir']}" - on host, "/bin/touch #{default['puppetpath']}/hiera.yaml" + on host, "/bin/touch #{host['puppetpath']}/hiera.yaml" end end -- cgit v1.2.3 From 2b1cc82d2423c815f5aee8807e266c5e16495c36 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 28 Oct 2014 16:43:15 -0700 Subject: Add windows test exclusion to ensure_resource --- spec/acceptance/ensure_resource_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/ensure_resource_spec.rb b/spec/acceptance/ensure_resource_spec.rb index 2aad243..c3d72fc 100755 --- a/spec/acceptance/ensure_resource_spec.rb +++ b/spec/acceptance/ensure_resource_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'ensure_resource function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +describe 'ensure_resource function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) && fact('osfamily') != 'windows') do describe 'success' do it 'ensure_resource a package' do apply_manifest('package { "rake": ensure => absent, provider => "gem", }') -- cgit v1.2.3 From 328aae223f28881746f45d76c778ddbfa3adce39 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 28 Oct 2014 16:46:16 -0700 Subject: Add proper exception catching of Windows errors when CreateProcess does not succeed --- lib/puppet/parser/functions/validate_cmd.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb index 652aa55..c855c7e 100644 --- a/lib/puppet/parser/functions/validate_cmd.rb +++ b/lib/puppet/parser/functions/validate_cmd.rb @@ -42,6 +42,9 @@ module Puppet::Parser::Functions rescue Puppet::ExecutionFailure => detail msg += "\n#{detail}" raise Puppet::ParseError, msg + rescue SystemCallError => detail + msg += "\nWin32::Process::SystemCallError #{detail}" + raise Puppet::ParseError, msg ensure tmpfile.unlink end -- cgit v1.2.3 From 6c7da72c0fa6b5e0ed3e5e2d5c80ff27f1e99dee Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Wed, 29 Oct 2014 20:03:07 -0700 Subject: Fix validate_cmd, previous addition of SystemCallError only works for Puppet 3.7, previous version throw different exception. Wrapping in generic Exception catch all --- lib/puppet/parser/functions/validate_cmd.rb | 4 ++-- spec/acceptance/validate_cmd_spec.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb index c855c7e..c6136a5 100644 --- a/lib/puppet/parser/functions/validate_cmd.rb +++ b/lib/puppet/parser/functions/validate_cmd.rb @@ -42,8 +42,8 @@ module Puppet::Parser::Functions rescue Puppet::ExecutionFailure => detail msg += "\n#{detail}" raise Puppet::ParseError, msg - rescue SystemCallError => detail - msg += "\nWin32::Process::SystemCallError #{detail}" + rescue Exception => detail + msg += "\n#{detail.class.name} #{detail}" raise Puppet::ParseError, msg ensure tmpfile.unlink diff --git a/spec/acceptance/validate_cmd_spec.rb b/spec/acceptance/validate_cmd_spec.rb index a899a1d..5ac66fd 100755 --- a/spec/acceptance/validate_cmd_spec.rb +++ b/spec/acceptance/validate_cmd_spec.rb @@ -40,7 +40,9 @@ describe 'validate_cmd function', :unless => UNSUPPORTED_PLATFORMS.include?(fact validate_cmd($one,$two,"aoeu is dvorak") EOS - expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/aoeu is dvorak/) + apply_manifest(pp, :expect_failures => true) do |output| + expect(output.stderr).to match(/aoeu is dvorak/) + end end end describe 'failure' do -- cgit v1.2.3 From 26e864f22457de1291f06b0086db7afc8d6dcfeb Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 4 Nov 2014 10:42:34 -0800 Subject: Fix the unless for test cases on ensure_package and ensure_resource Conflicts: spec/acceptance/ensure_packages_spec.rb spec/acceptance/ensure_resource_spec.rb --- spec/acceptance/ensure_packages_spec.rb | 2 +- spec/acceptance/ensure_resource_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb index 53c1035..3651f29 100755 --- a/spec/acceptance/ensure_packages_spec.rb +++ b/spec/acceptance/ensure_packages_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'ensure_packages function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || fact('operatingsystem') != 'windows') do +describe 'ensure_packages function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || fact('osfamily') == 'windows') do describe 'success' do it 'ensure_packages a package' do apply_manifest('package { "rake": ensure => absent, provider => "gem", }') diff --git a/spec/acceptance/ensure_resource_spec.rb b/spec/acceptance/ensure_resource_spec.rb index 2aad243..26409fe 100755 --- a/spec/acceptance/ensure_resource_spec.rb +++ b/spec/acceptance/ensure_resource_spec.rb @@ -1,7 +1,8 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'ensure_resource function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + +describe 'ensure_resource function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || fact('osfamily') == 'windows') do describe 'success' do it 'ensure_resource a package' do apply_manifest('package { "rake": ensure => absent, provider => "gem", }') -- cgit v1.2.3 From f19aea5a75998da95617fadce7a50aee65022d3b Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Wed, 29 Oct 2014 22:02:13 -0700 Subject: MODULES-1413 Ability to for future parser to use member with FixNum types --- lib/puppet/parser/functions/member.rb | 3 ++- spec/acceptance/member_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/member.rb b/lib/puppet/parser/functions/member.rb index 43d76af..11a1d24 100644 --- a/lib/puppet/parser/functions/member.rb +++ b/lib/puppet/parser/functions/member.rb @@ -32,8 +32,9 @@ Would return: false item = arguments[1] + raise(Puppet::ParseError, 'member(): You must provide item ' + - 'to search for within array given') if item.empty? + 'to search for within array given') if item.respond_to?('empty?') && item.empty? result = array.include?(item) diff --git a/spec/acceptance/member_spec.rb b/spec/acceptance/member_spec.rb index b467dbb..fe75a07 100755 --- a/spec/acceptance/member_spec.rb +++ b/spec/acceptance/member_spec.rb @@ -2,6 +2,13 @@ require 'spec_helper_acceptance' describe 'member function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do + shared_examples 'item found' do + it 'should output correctly' do + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/Notice: output correct/) + end + end + end describe 'success' do it 'members arrays' do pp = <<-EOS @@ -18,8 +25,29 @@ describe 'member function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('oper expect(r.stdout).to match(/Notice: output correct/) end end + describe 'members array of integers' do + it_should_behave_like 'item found' do + let(:pp) { <<-EOS + if member( [1,2,3,4], 4 ){ + notify { 'output correct': } + } + EOS + } + end + end + describe 'members of mixed array' do + it_should_behave_like 'item found' do + let(:pp) { <<-EOS + if member( ['a','4',3], 'a' ){ + notify { 'output correct': } +} + EOS + } + end + end it 'members arrays without members' end + describe 'failure' do it 'handles improper argument counts' end -- cgit v1.2.3 From cbc55084c8b5df507fe9ac5effe08d744355bb15 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 10 Nov 2014 11:31:26 -0800 Subject: Release 4.4.0 Summary This release has an overhauled readme, new private manifest function, and fixes many future parser bugs. Features - All new shiny README - New `private()` function for making private manifests (yay!) Bugfixes - Code reuse in `bool2num()` and `zip()` - Fix many functions to handle `generate()` no longer returning a string on new puppets - `concat()` no longer modifies the first argument (whoops) - strict variable support for `getvar()`, `member()`, `values_at`, and `has_interface_with()` - `to_bytes()` handles PB and EB now - Fix `tempfile` ruby requirement for `validate_augeas()` and `validate_cmd()` - Fix `validate_cmd()` for windows - Correct `validate_string()` docs to reflect non-handling of `undef` - Fix `file_line` matching on older rubies --- CHANGELOG.md | 20 ++++++++++++++++++++ metadata.json | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb5fd7f..2fb73db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,23 @@ +##2014-11-10 - Supported Release 4.4.0 +###Summary +This release has an overhauled readme, new private manifest function, and fixes many future parser bugs. + +####Features +- All new shiny README +- New `private()` function for making private manifests (yay!) + +####Bugfixes +- Code reuse in `bool2num()` and `zip()` +- Fix many functions to handle `generate()` no longer returning a string on new puppets +- `concat()` no longer modifies the first argument (whoops) +- strict variable support for `getvar()`, `member()`, `values_at`, and `has_interface_with()` +- `to_bytes()` handles PB and EB now +- Fix `tempfile` ruby requirement for `validate_augeas()` and `validate_cmd()` +- Fix `validate_cmd()` for windows +- Correct `validate_string()` docs to reflect non-handling of `undef` +- Fix `file_line` matching on older rubies + + ##2014-07-15 - Supported Release 4.3.2 ###Summary diff --git a/metadata.json b/metadata.json index 26167b6..186166d 100644 --- a/metadata.json +++ b/metadata.json @@ -1,12 +1,12 @@ { "name": "puppetlabs-stdlib", - "version": "4.3.2", + "version": "4.4.0", "author": "puppetlabs", "summary": "Puppet Module Standard Library", "license": "Apache 2.0", "source": "git://github.com/puppetlabs/puppetlabs-stdlib", "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib", - "issues_url": "https://github.com/puppetlabs/puppetlabs-stdlib/issues", + "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", "operatingsystem_support": [ { "operatingsystem": "RedHat", @@ -97,7 +97,7 @@ "requirements": [ { "name": "pe", - "version_requirement": "3.3.x" + "version_requirement": "3.x" }, { "name": "puppet", -- cgit v1.2.3 From 66434f9036869f0abfabbc89104885ddb105d095 Mon Sep 17 00:00:00 2001 From: Justin Stoller Date: Mon, 10 Nov 2014 11:56:40 -0800 Subject: (QENG-1404) Segregate system testing gems Prior to this there was generic :test group. Unfortunately Beaker will be EOL-ing support for Ruby 1.8 (a number of Beaker's dependencies already have and pinning to older versions is becoming costly). Once Beaker does this it will cause failures whenever running `bundle install`. To avoid this failure we can segregate the system testing gems, allowing unit, lint and development to continue with `bundle install --without system_tests`. --- Gemfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index c2e58ed..74a16f3 100644 --- a/Gemfile +++ b/Gemfile @@ -10,15 +10,18 @@ def location_for(place, fake_version = nil) end end -group :development, :test do +group :development, :unit_tests do gem 'rake', '~> 10.1.0', :require => false gem 'rspec-puppet', :require => false gem 'puppetlabs_spec_helper', :require => false - gem 'serverspec', :require => false gem 'puppet-lint', :require => false gem 'pry', :require => false gem 'simplecov', :require => false +end + +group :system_tests do gem 'beaker-rspec', :require => false + gem 'serverspec', :require => false end ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION'] -- cgit v1.2.3 From c52e262a17d9defbd59bfed4761ab887d9e7840d Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Thu, 30 Oct 2014 23:37:00 -0700 Subject: Catch :undefined_variable thrown when Future Parser is enabled with 3.7.x --- lib/puppet/parser/functions/has_interface_with.rb | 26 +++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb index 00e405d..1e91026 100644 --- a/lib/puppet/parser/functions/has_interface_with.rb +++ b/lib/puppet/parser/functions/has_interface_with.rb @@ -16,11 +16,11 @@ etc. If no "kind" is given, then the presence of the interface is checked: has_interface_with("lo") => true - EOS + EOS ) do |args| raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments " + - "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2 + "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2 interfaces = lookupvar('interfaces') @@ -35,7 +35,13 @@ has_interface_with("lo") => true kind, value = args - if lookupvar(kind) == value + # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable + # https://tickets.puppetlabs.com/browse/PUP-3597 + factval = nil + catch :undefined_variable do + factval = lookupvar(kind) + end + if factval == value return true end @@ -44,15 +50,17 @@ has_interface_with("lo") => true iface.downcase! factval = nil begin - factval = lookupvar("#{kind}_#{iface}") + # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable + # https://tickets.puppetlabs.com/browse/PUP-3597 + catch :undefined_variable do + factval = lookupvar("#{kind}_#{iface}") + end + if value == factval + result = true + end rescue Puppet::ParseError # Eat the exception if strict_variables = true is set end - if value == factval - result = true - break - end end - result end end -- cgit v1.2.3 From 992ed8ffa8a716463be6a3520eb908cd12ca2048 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Mon, 3 Nov 2014 09:30:34 -0800 Subject: Remove windows from ensure_package and ensure_resource testing --- spec/acceptance/ensure_packages_spec.rb | 2 +- spec/acceptance/ensure_resource_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb index 3651f29..ca4b249 100755 --- a/spec/acceptance/ensure_packages_spec.rb +++ b/spec/acceptance/ensure_packages_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'ensure_packages function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || fact('osfamily') == 'windows') do +describe 'ensure_packages function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) && fact('osfamily') != 'windows') do describe 'success' do it 'ensure_packages a package' do apply_manifest('package { "rake": ensure => absent, provider => "gem", }') diff --git a/spec/acceptance/ensure_resource_spec.rb b/spec/acceptance/ensure_resource_spec.rb index f1bfa54..c3d72fc 100755 --- a/spec/acceptance/ensure_resource_spec.rb +++ b/spec/acceptance/ensure_resource_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'ensure_resource function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || fact('osfamily') == 'windows') do +describe 'ensure_resource function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) && fact('osfamily') != 'windows') do describe 'success' do it 'ensure_resource a package' do apply_manifest('package { "rake": ensure => absent, provider => "gem", }') -- cgit v1.2.3 From 4949cfd21cb97b17006d82f2f192ec9d01b0d1ee Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 10 Nov 2014 16:37:53 -0800 Subject: Fix breaking out of .each loop And some other small formatting fixes that don't belong in this patch. --- lib/puppet/parser/functions/has_interface_with.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb index 1e91026..3691524 100644 --- a/lib/puppet/parser/functions/has_interface_with.rb +++ b/lib/puppet/parser/functions/has_interface_with.rb @@ -16,11 +16,11 @@ etc. If no "kind" is given, then the presence of the interface is checked: has_interface_with("lo") => true - EOS + EOS ) do |args| raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments " + - "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2 + "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2 interfaces = lookupvar('interfaces') @@ -55,12 +55,14 @@ has_interface_with("lo") => true catch :undefined_variable do factval = lookupvar("#{kind}_#{iface}") end - if value == factval - result = true - end rescue Puppet::ParseError # Eat the exception if strict_variables = true is set end + if value == factval + result = true + break + end end + result end end -- cgit v1.2.3 From 970141e36aa454bc557d44c1962129afef39d4f2 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 11 Nov 2014 10:46:01 -0800 Subject: Correct type() logic It should NOT run if the future parser is enabled --- spec/acceptance/type_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/type_spec.rb b/spec/acceptance/type_spec.rb index 15fa217..67e3248 100755 --- a/spec/acceptance/type_spec.rb +++ b/spec/acceptance/type_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'type function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || !(is_future_parser_enabled?)) do +describe 'type function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || is_future_parser_enabled?) do describe 'success' do it 'types arrays' do pp = <<-EOS -- cgit v1.2.3 From 3584485902c83bbfbc7417b122fe73f80bcd1630 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 11 Nov 2014 15:33:43 -0800 Subject: Fix exclude windows test on ensure_package Update to fix ensure_resource as well --- spec/acceptance/ensure_packages_spec.rb | 2 +- spec/acceptance/ensure_resource_spec.rb | 2 +- spec/spec_helper_acceptance.rb | 29 ++++++++++++++--------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb index ca4b249..aedcfb5 100755 --- a/spec/acceptance/ensure_packages_spec.rb +++ b/spec/acceptance/ensure_packages_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'ensure_packages function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) && fact('osfamily') != 'windows') do +describe 'ensure_packages function', :unless => fact('osfamily') =~ /windows/i do describe 'success' do it 'ensure_packages a package' do apply_manifest('package { "rake": ensure => absent, provider => "gem", }') diff --git a/spec/acceptance/ensure_resource_spec.rb b/spec/acceptance/ensure_resource_spec.rb index c3d72fc..1cee53d 100755 --- a/spec/acceptance/ensure_resource_spec.rb +++ b/spec/acceptance/ensure_resource_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'ensure_resource function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) && fact('osfamily') != 'windows') do +describe 'ensure_resource function', :unless => fact('osfamily') =~ /windows/i do describe 'success' do it 'ensure_resource a package' do apply_manifest('package { "rake": ensure => absent, provider => "gem", }') diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index ef99723..3203ce9 100755 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -4,15 +4,23 @@ require 'beaker-rspec' UNSUPPORTED_PLATFORMS = [] unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' - # This will install the latest available package on el and deb based - # systems fail on windows and osx, and install via gem on other *nixes - foss_opts = { :default_action => 'gem_install' } + foss_opts = { + :default_action => 'gem_install', + :version => (ENV['PUPPET_VERSION'] ? ENV['PUPPET_VERSION'] : '3.7.2'), + } if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end hosts.each do |host| - on host, "mkdir -p #{host['distmoduledir']}" - on host, "/bin/touch #{host['puppetpath']}/hiera.yaml" + if host['platform'] !~ /windows/i + if host.is_pe? + on host, 'mkdir -p /etc/puppetlabs/facter/facts.d' + else + on host, "/bin/touch #{host['puppetpath']}/hiera.yaml" + on host, "mkdir -p #{host['distmoduledir']}" + on host, 'mkdir -p /etc/facter/facts.d' + end + end end end @@ -29,17 +37,8 @@ RSpec.configure do |c| default[:default_apply_opts] ||= {} default[:default_apply_opts].merge!({:parser => 'future'}) end - hosts.each do |host| - if host['platform'] !~ /windows/i - copy_root_module_to(host, :source => proj_root, :module_name => 'stdlib') - end - end - hosts.each do |host| - if host['platform'] =~ /windows/i - on host, puppet('plugin download') - end - end + copy_root_module_to(default, :source => proj_root, :module_name => 'stdlib') end end -- cgit v1.2.3 From e61f402283774883d7b7c7d0f04dec7c457c968c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Dal=C3=A9n?= Date: Wed, 12 Nov 2014 15:52:33 +0100 Subject: (maint) Fix indentation of range function --- lib/puppet/parser/functions/range.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/puppet/parser/functions/range.rb b/lib/puppet/parser/functions/range.rb index ffbdf84..06d75d4 100644 --- a/lib/puppet/parser/functions/range.rb +++ b/lib/puppet/parser/functions/range.rb @@ -65,21 +65,21 @@ Will return: [0,2,4,6,8] end end - # Check whether we have integer value if so then make it so ... - if start.match(/^\d+$/) - start = start.to_i - stop = stop.to_i - else - start = start.to_s - stop = stop.to_s - end + # Check whether we have integer value if so then make it so ... + if start.match(/^\d+$/) + start = start.to_i + stop = stop.to_i + else + start = start.to_s + stop = stop.to_s + end - range = case type - when /^(\.\.|\-)$/ then (start .. stop) - when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ... - end + range = case type + when /^(\.\.|\-)$/ then (start .. stop) + when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ... + end - result = range.step(step).collect { |i| i } # Get them all ... Pokemon ... + result = range.step(step).collect { |i| i } # Get them all ... Pokemon ... return result end -- cgit v1.2.3 From ce995e15d5c266fd6d7fa781284771a5a5d5b00e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Dal=C3=A9n?= Date: Wed, 12 Nov 2014 16:02:05 +0100 Subject: Make the range function work with integers This is needed for the future parser which actually treats numbers as numbers and strings as strings. With this patch you can use range(1,5) instead of having to quote them like range('1','5'). --- lib/puppet/parser/functions/range.rb | 2 +- spec/functions/range_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/range.rb b/lib/puppet/parser/functions/range.rb index 06d75d4..49fba21 100644 --- a/lib/puppet/parser/functions/range.rb +++ b/lib/puppet/parser/functions/range.rb @@ -66,7 +66,7 @@ Will return: [0,2,4,6,8] end # Check whether we have integer value if so then make it so ... - if start.match(/^\d+$/) + if start.to_s.match(/^\d+$/) start = start.to_i stop = stop.to_i else diff --git a/spec/functions/range_spec.rb b/spec/functions/range_spec.rb index 9b9ece0..1446b24 100755 --- a/spec/functions/range_spec.rb +++ b/spec/functions/range_spec.rb @@ -67,4 +67,11 @@ describe "the range function" do expect(scope.function_range(["00", "10"])).to eq expected end end + + describe 'with a numeric range' do + it "returns a range of numbers" do + expected = (1..10).to_a + expect(scope.function_range([1,10])).to eq expected + end + end end -- cgit v1.2.3 From af0a2779cb63b09a07f675ede3ae0b959c7442f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Dal=C3=A9n?= Date: Wed, 12 Nov 2014 16:52:36 +0100 Subject: Add range tests for numeric with step and mixed arguments --- spec/functions/range_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/functions/range_spec.rb b/spec/functions/range_spec.rb index 1446b24..ef86f97 100755 --- a/spec/functions/range_spec.rb +++ b/spec/functions/range_spec.rb @@ -73,5 +73,14 @@ describe "the range function" do expected = (1..10).to_a expect(scope.function_range([1,10])).to eq expected end + it "returns a range of numbers with step parameter" do + expected = (1..10).step(2).to_a + expect(scope.function_range([1,10,2])).to eq expected + end + it "works with mixed numeric like strings and numeric arguments" do + expected = (1..10).to_a + expect(scope.function_range(['1',10])).to eq expected + expect(scope.function_range([1,'10'])).to eq expected + end end end -- cgit v1.2.3 From c9f906f80325a12a6509633d87472bd3cbaf0364 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Mon, 15 Sep 2014 14:16:52 -0400 Subject: (MODULES-1329) Allow member function to look for array Currently, the member function allows one to only find if a variable is part of an array. Sometimes it is useful to find if an array is part of a bigger array for validation purpose. --- lib/puppet/parser/functions/member.rb | 17 +++++++++++++++-- spec/functions/member_spec.rb | 10 ++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/functions/member.rb b/lib/puppet/parser/functions/member.rb index 11a1d24..bb19a86 100644 --- a/lib/puppet/parser/functions/member.rb +++ b/lib/puppet/parser/functions/member.rb @@ -8,6 +8,7 @@ module Puppet::Parser::Functions newfunction(:member, :type => :rvalue, :doc => <<-EOS This function determines if a variable is a member of an array. +The variable can either be a string or an array. *Examples:* @@ -15,9 +16,17 @@ This function determines if a variable is a member of an array. Would return: true + member(['a', 'b', 'c'], ['a', 'b']) + +would return: true + member(['a','b'], 'c') Would return: false + + member(['a', 'b', 'c'], ['d', 'b']) + +would return: false EOS ) do |arguments| @@ -30,13 +39,17 @@ Would return: false raise(Puppet::ParseError, 'member(): Requires array to work with') end - item = arguments[1] + if arguments[1].is_a? String + item = Array(arguments[1]) + else + item = arguments[1] + end raise(Puppet::ParseError, 'member(): You must provide item ' + 'to search for within array given') if item.respond_to?('empty?') && item.empty? - result = array.include?(item) + result = (item - array).empty? return result end diff --git a/spec/functions/member_spec.rb b/spec/functions/member_spec.rb index cee6110..1a1d7c6 100755 --- a/spec/functions/member_spec.rb +++ b/spec/functions/member_spec.rb @@ -21,4 +21,14 @@ describe "the member function" do result = scope.function_member([["a","b","c"], "d"]) expect(result).to(eq(false)) end + + it "should return true if a member array is in an array" do + result = scope.function_member([["a","b","c"], ["a", "b"]]) + expect(result).to(eq(true)) + end + + it "should return false if a member array is not in an array" do + result = scope.function_member([["a","b","c"], ["d", "e"]]) + expect(result).to(eq(false)) + end end -- cgit v1.2.3 From c5467cc507c004d75037d07c70633d1e743825af Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Fri, 14 Nov 2014 14:33:59 -0800 Subject: Need to convert strings and fixnums to arrays --- lib/puppet/parser/functions/member.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/functions/member.rb b/lib/puppet/parser/functions/member.rb index bb19a86..88609ce 100644 --- a/lib/puppet/parser/functions/member.rb +++ b/lib/puppet/parser/functions/member.rb @@ -8,7 +8,7 @@ module Puppet::Parser::Functions newfunction(:member, :type => :rvalue, :doc => <<-EOS This function determines if a variable is a member of an array. -The variable can either be a string or an array. +The variable can be a string, fixnum, or array. *Examples:* @@ -39,7 +39,11 @@ would return: false raise(Puppet::ParseError, 'member(): Requires array to work with') end - if arguments[1].is_a? String + unless arguments[1].is_a? String or arguments[1].is_a? Fixnum or arguments[1].is_a? Array + raise(Puppet::ParseError, 'member(): Item to search for must be a string, fixnum, or array') + end + + if arguments[1].is_a? String or arguments[1].is_a? Fixnum item = Array(arguments[1]) else item = arguments[1] -- cgit v1.2.3 From b492115252ad381c4316b9ea85d8894ce348c4a7 Mon Sep 17 00:00:00 2001 From: jbondpdx Date: Thu, 20 Nov 2014 15:20:37 -0800 Subject: FM-1523: Added module summary to metadata.json --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 186166d..1a82f36 100644 --- a/metadata.json +++ b/metadata.json @@ -2,7 +2,7 @@ "name": "puppetlabs-stdlib", "version": "4.4.0", "author": "puppetlabs", - "summary": "Puppet Module Standard Library", + "summary": "Standard library of resources for Puppet modules.", "license": "Apache 2.0", "source": "git://github.com/puppetlabs/puppetlabs-stdlib", "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib", -- cgit v1.2.3 From 7148acdc9e8255ea4c11689747e7d1c1e20792e5 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Fri, 21 Nov 2014 16:09:17 -0500 Subject: FM-2020 SLES Support verified --- metadata.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 186166d..f049cfb 100644 --- a/metadata.json +++ b/metadata.json @@ -47,7 +47,9 @@ { "operatingsystem": "SLES", "operatingsystemrelease": [ - "11 SP1" + "10 SP4", + "11 SP1", + "12" ] }, { -- cgit v1.2.3 From 89995e4db0eacf55260cf5ca85e715e2e45dfce5 Mon Sep 17 00:00:00 2001 From: Oliver Bertuch Date: Tue, 25 Nov 2014 12:45:23 +0100 Subject: Allow array of pathes in validate_absolute_path --- README.markdown | 49 +++++++++-------- .../parser/functions/validate_absolute_path.rb | 61 +++++++++++++--------- spec/functions/validate_absolute_path_spec.rb | 38 ++++++++++---- 3 files changed, 94 insertions(+), 54 deletions(-) diff --git a/README.markdown b/README.markdown index 78839c6..957be9b 100644 --- a/README.markdown +++ b/README.markdown @@ -461,27 +461,34 @@ You can also use this with arrays. For example, `unique(["a","a","b","b","c","c" * `uriescape`: Urlencodes a string or array of strings. Requires either a single string or an array as an input. *Type*: rvalue -* `validate_absolute_path`: Validate that the string represents an absolute path in the filesystem. This function works for Windows and Unix-style paths. - The following values will pass: - - ``` - $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet" - validate_absolute_path($my_path) - $my_path2 = "/var/lib/puppet" - validate_absolute_path($my_path2) - ``` - - The following values will fail, causing compilation to abort: - - ``` - validate_absolute_path(true) - validate_absolute_path([ 'var/lib/puppet', '/var/foo' ]) - validate_absolute_path([ '/var/lib/puppet', 'var/foo' ]) - $undefined = undef - validate_absolute_path($undefined) - ``` - - *Type*: statement +* `validate_absolute_path`: Validate the string represents an absolute path in the filesystem. This function works for Windows and Unix style paths. + + The following values will pass: + + ``` + $my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet' + validate_absolute_path($my_path) + $my_path2 = '/var/lib/puppet' + validate_absolute_path($my_path2) + $my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet','C:/Program Files/Puppet Labs/Puppet'] + validate_absolute_path($my_path3) + $my_path4 = ['/var/lib/puppet','/usr/share/puppet'] + validate_absolute_path($my_path4) + ``` + + The following values will fail, causing compilation to abort: + + ``` + validate_absolute_path(true) + validate_absolute_path('../var/lib/puppet') + validate_absolute_path('var/lib/puppet') + validate_absolute_path([ 'var/lib/puppet', '/var/foo' ]) + validate_absolute_path([ '/var/lib/puppet', 'var/foo' ]) + $undefined = undef + validate_absolute_path($undefined) + ``` + + *Type*: statement * `validate_array`: Validate that all passed values are array data structures. Abort catalog compilation if any value fails this check. diff --git a/lib/puppet/parser/functions/validate_absolute_path.rb b/lib/puppet/parser/functions/validate_absolute_path.rb index fe27974..b696680 100644 --- a/lib/puppet/parser/functions/validate_absolute_path.rb +++ b/lib/puppet/parser/functions/validate_absolute_path.rb @@ -5,15 +5,20 @@ module Puppet::Parser::Functions The following values will pass: - $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet" + $my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet' validate_absolute_path($my_path) - $my_path2 = "/var/lib/puppet" + $my_path2 = '/var/lib/puppet' validate_absolute_path($my_path2) - + $my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet','C:/Program Files/Puppet Labs/Puppet'] + validate_absolute_path($my_path3) + $my_path4 = ['/var/lib/puppet','/usr/share/puppet'] + validate_absolute_path($my_path4) The following values will fail, causing compilation to abort: validate_absolute_path(true) + validate_absolute_path('../var/lib/puppet') + validate_absolute_path('var/lib/puppet') validate_absolute_path([ 'var/lib/puppet', '/var/foo' ]) validate_absolute_path([ '/var/lib/puppet', 'var/foo' ]) $undefined = undef @@ -28,28 +33,36 @@ module Puppet::Parser::Functions end args.each do |arg| - # This logic was borrowed from - # [lib/puppet/file_serving/base.rb](https://github.com/puppetlabs/puppet/blob/master/lib/puppet/file_serving/base.rb) - - # Puppet 2.7 and beyond will have Puppet::Util.absolute_path? Fall back to a back-ported implementation otherwise. - if Puppet::Util.respond_to?(:absolute_path?) then - unless Puppet::Util.absolute_path?(arg, :posix) or Puppet::Util.absolute_path?(arg, :windows) - raise Puppet::ParseError, ("#{arg.inspect} is not an absolute path.") + # put arg to candidate var to be able to replace it + candidates = arg + # if arg is just a string with a path to test, convert it to an array + # to avoid test code duplication + unless arg.is_a?(Array) then + candidates = Array.new(1,arg) + end + # iterate over all pathes within the candidates array + candidates.each do |path| + # This logic was borrowed from + # [lib/puppet/file_serving/base.rb](https://github.com/puppetlabs/puppet/blob/master/lib/puppet/file_serving/base.rb) + # Puppet 2.7 and beyond will have Puppet::Util.absolute_path? Fall back to a back-ported implementation otherwise. + if Puppet::Util.respond_to?(:absolute_path?) then + unless Puppet::Util.absolute_path?(path, :posix) or Puppet::Util.absolute_path?(path, :windows) + raise Puppet::ParseError, ("#{path.inspect} is not an absolute path.") + end + else + # This code back-ported from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path? + # Determine in a platform-specific way whether a path is absolute. This + # defaults to the local platform if none is specified. + # Escape once for the string literal, and once for the regex. + slash = '[\\\\/]' + name = '[^\\\\/]+' + regexes = { + :windows => %r!^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))!i, + :posix => %r!^/!, + } + rval = (!!(path =~ regexes[:posix])) || (!!(path =~ regexes[:windows])) + rval or raise Puppet::ParseError, ("#{path.inspect} is not an absolute path.") end - else - # This code back-ported from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path? - # Determine in a platform-specific way whether a path is absolute. This - # defaults to the local platform if none is specified. - # Escape once for the string literal, and once for the regex. - slash = '[\\\\/]' - name = '[^\\\\/]+' - regexes = { - :windows => %r!^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))!i, - :posix => %r!^/!, - } - - rval = (!!(arg =~ regexes[:posix])) || (!!(arg =~ regexes[:windows])) - rval or raise Puppet::ParseError, ("#{arg.inspect} is not an absolute path.") end end end diff --git a/spec/functions/validate_absolute_path_spec.rb b/spec/functions/validate_absolute_path_spec.rb index 342ae84..36c836b 100755 --- a/spec/functions/validate_absolute_path_spec.rb +++ b/spec/functions/validate_absolute_path_spec.rb @@ -39,6 +39,11 @@ describe Puppet::Parser::Functions.function(:validate_absolute_path) do expect { subject.call [path] }.not_to raise_error end end + valid_paths do + it "validate_absolute_path(#{valid_paths.inspect}) should not fail" do + expect { subject.call [valid_paths] }.not_to raise_error + end + end end context "Puppet without mocking" do @@ -47,6 +52,11 @@ describe Puppet::Parser::Functions.function(:validate_absolute_path) do expect { subject.call [path] }.not_to raise_error end end + valid_paths do + it "validate_absolute_path(#{valid_paths.inspect}) should not fail" do + expect { subject.call [valid_paths] }.not_to raise_error + end + end end end @@ -55,6 +65,7 @@ describe Puppet::Parser::Functions.function(:validate_absolute_path) do [ nil, [ nil ], + [ nil, nil ], { 'foo' => 'bar' }, { }, '', @@ -66,19 +77,28 @@ describe Puppet::Parser::Functions.function(:validate_absolute_path) do end context 'Relative paths' do - %w{ - relative1 - . - .. - ./foo - ../foo - etc/puppetlabs/puppet - opt/puppet/bin - }.each do |path| + def self.rel_paths + %w{ + relative1 + . + .. + ./foo + ../foo + etc/puppetlabs/puppet + opt/puppet/bin + } + end + rel_paths.each do |path| it "validate_absolute_path(#{path.inspect}) should fail" do expect { subject.call [path] }.to raise_error Puppet::ParseError end end + rel_paths do + it "validate_absolute_path(#{rel_paths.inspect}) should fail" do + expect { subject.call [rel_paths] }.to raise_error Puppet::ParseError + end + end end end end + -- cgit v1.2.3 From 22bfa50cb9db0b724ac261cd242bfe3575e2cfcf Mon Sep 17 00:00:00 2001 From: jbondpdx Date: Thu, 20 Nov 2014 15:20:37 -0800 Subject: FM-1523: Added module summary to metadata.json --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index f049cfb..6bdf82d 100644 --- a/metadata.json +++ b/metadata.json @@ -2,7 +2,7 @@ "name": "puppetlabs-stdlib", "version": "4.4.0", "author": "puppetlabs", - "summary": "Puppet Module Standard Library", + "summary": "Standard library of resources for Puppet modules.", "license": "Apache 2.0", "source": "git://github.com/puppetlabs/puppetlabs-stdlib", "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib", -- cgit v1.2.3 From 294b8b572dfeb14555c40737eed2491e7837ef29 Mon Sep 17 00:00:00 2001 From: jbondpdx Date: Tue, 25 Nov 2014 11:32:12 -0800 Subject: Added a note that stdlib no longer ships with PE 3.7+ Users didn't realize we stopped shipping stdlib module with PE. I added this information to the stdlib readme. --- README.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.markdown b/README.markdown index 78839c6..b7824ff 100644 --- a/README.markdown +++ b/README.markdown @@ -27,6 +27,8 @@ modules. Puppet modules make heavy use of this standard library. The stdlib modu * Defined resource types * Types * Providers + +> *Note:* As of version 3.7, Puppet Enterprise no longer includes the stdlib module. If you're running Puppet Enterprise, you should install the most recent release of stdlib for compatibility with Puppet modules. ##Setup @@ -676,6 +678,8 @@ of the regular expressions match the string passed in, compilation aborts with a ##Limitations +As of Puppet Enterprise version 3.7, the stdlib module is no longer included in PE. PE users should install the most recent release of stdlib for compatibility with Puppet modules. + ###Version Compatibility Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x | -- cgit v1.2.3 From ed192a04648db7786d072bef23ed72849115d9de Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:12:55 +0000 Subject: (MODULES-444) Add specs for new behaviour `concat` can now take multiple arguments --- spec/functions/concat_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index 49cb2ad..4a18cd9 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -32,4 +32,14 @@ describe "the concat function" do result = scope.function_concat([array_original,['4','5','6']]) array_original.should(eq(['1','2','3'])) end + + it "should be able to concat multiple arrays" do + result = scope.function_concat([['1','2','3'],['4','5','6'],['7','8','9']]) + expect(result).to(eq(['1','2','3','4','5','6','7','8','9'])) + end + + it "should be able to concat mix of primitives and arrays to a final array" do + result = scope.function_concat([['1','2','3'],'4',['5','6','7']]) + expect(result).to(eq(['1','2','3','4','5','6','7'])) + end end -- cgit v1.2.3 From 7c570f75a5b88b1eb057bce3f7c4cad9cac83496 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:15:03 +0000 Subject: (MODULES-444) Acceptance test for primitives `concat` should be able to concat arrays and primitives --- spec/acceptance/concat_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index 7bda365..0d5e831 100755 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -12,6 +12,17 @@ describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('oper } EOS + apply_manifest(pp, :catch_failures => true) + end + it 'should concat arrays and primitives to array' do + pp = <<-EOS + $output = concat(['1','2','3'],'4','5','6',['7','8','9']) + validate_array($output) + if size($output) != 9 { + fail("${output} should have 9 elements.") + } + EOS + apply_manifest(pp, :catch_failures => true) end end -- cgit v1.2.3 From 5e49c504580bf06353c841c51f1319a5bda893a8 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:15:33 +0000 Subject: (MODULES-444) Acceptance for multiple arrays Acceptance test to take multiple arrays for concatenation --- spec/acceptance/concat_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index 0d5e831..caf2f7d 100755 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -23,6 +23,17 @@ describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('oper } EOS + apply_manifest(pp, :catch_failures => true) + end + it 'should concat multiple arrays to one' do + pp = <<-EOS + $output = concat(['1','2','3'],['4','5','6'],['7','8','9']) + validate_array($output) + if size($output) != 6 { + fail("${output} should have 9 elements.") + } + EOS + apply_manifest(pp, :catch_failures => true) end end -- cgit v1.2.3 From 7a1c4a6d9e4123a59fa85be18bd1b86ed5539b56 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:27:38 +0000 Subject: (MODULES-444) Change test to > 2 arguments Also add extra test for just 1 argument --- spec/functions/concat_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index 4a18cd9..d443c4b 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -4,8 +4,9 @@ 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 + it "should raise a ParseError if the client does not provide at least two arguments" do expect { scope.function_concat([]) }.to(raise_error(Puppet::ParseError)) + expect { scope.function_concat([[1]]) }.to(raise_error(Puppet::ParseError)) end it "should raise a ParseError if the first parameter is not an array" do -- cgit v1.2.3 From 368c97f08046696d453afca6e1f8001b5bfc88a5 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:27:55 +0000 Subject: (MODULES-444) - Check for accepting > 2 args --- spec/functions/concat_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index d443c4b..49fa6bb 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -13,6 +13,10 @@ describe "the concat function" do expect { scope.function_concat([1, []])}.to(raise_error(Puppet::ParseError)) end + it "should not raise a ParseError if the client provides more than two arguments" do + expect { scope.function_concat([[1],[2],[3]]) }.not_to raise_error + end + it "should be able to concat an array" do result = scope.function_concat([['1','2','3'],['4','5','6']]) expect(result).to(eq(['1','2','3','4','5','6'])) -- cgit v1.2.3 From 75a6186512b0d4d02593453fcc9ffe5e1b253107 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:32:23 +0000 Subject: (MODULES-444) Update docs with new functionality --- lib/puppet/parser/functions/concat.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb index 0d35b07..4b53f59 100644 --- a/lib/puppet/parser/functions/concat.rb +++ b/lib/puppet/parser/functions/concat.rb @@ -4,15 +4,15 @@ module Puppet::Parser::Functions newfunction(:concat, :type => :rvalue, :doc => <<-EOS -Appends the contents of array 2 onto array 1. +Appends the contents of multiple arrays into array 1. *Example:* - concat(['1','2','3'],['4','5','6']) + concat(['1','2','3'],['4','5','6'],['7','8','9']) Would result in: - ['1','2','3','4','5','6'] + ['1','2','3','4','5','6','7','8','9'] EOS ) do |arguments| -- cgit v1.2.3 From 594c2dd38dc35a4f458ce511be9b7dd875915b44 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:33:23 +0000 Subject: (MODULES-444) Change argument restriction to < 2 --- lib/puppet/parser/functions/concat.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb index 4b53f59..8400f7b 100644 --- a/lib/puppet/parser/functions/concat.rb +++ b/lib/puppet/parser/functions/concat.rb @@ -16,9 +16,9 @@ Would result in: EOS ) do |arguments| - # Check that 2 arguments have been given ... + # Check that more than 2 arguments have been given ... raise(Puppet::ParseError, "concat(): Wrong number of arguments " + - "given (#{arguments.size} for 2)") if arguments.size != 2 + "given (#{arguments.size} for < 2)") if arguments.size < 2 a = arguments[0] b = arguments[1] -- cgit v1.2.3 From 84bd98645f248a1dc3e0ed791e3af6f2ba9996fa Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 4 Dec 2014 14:34:25 +0000 Subject: (MODULES-444) - Real meat of the change This is the core change, we now go through the array and add it to the first element, instead of just two arguments. --- lib/puppet/parser/functions/concat.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb index 8400f7b..618e62d 100644 --- a/lib/puppet/parser/functions/concat.rb +++ b/lib/puppet/parser/functions/concat.rb @@ -21,14 +21,18 @@ Would result in: "given (#{arguments.size} for < 2)") if arguments.size < 2 a = arguments[0] - b = arguments[1] # Check that the first parameter is an array unless a.is_a?(Array) raise(Puppet::ParseError, 'concat(): Requires array to work with') end - result = a + Array(b) + result = a + arguments.shift + + arguments.each do |x| + result = result + Array(x) + end return result end -- cgit v1.2.3 From a99971827f4769b96a4bed16bbeab3306f97a30c Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Mon, 8 Dec 2014 10:33:35 -0800 Subject: Update .travis.yml, Gemfile, Rakefile, and CONTRIBUTING.md --- .travis.yml | 2 +- CONTRIBUTING.md | 22 ++++------------------ 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3ed1153..f531306 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ --- language: ruby -bundler_args: --without development +bundler_args: --without system_tests script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'" matrix: fast_finish: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e128847..f1cbde4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,11 +41,9 @@ Checklist (and a short version for the impatient) * Pre-requisites: - - Sign the [Contributor License Agreement](https://cla.puppetlabs.com/) - - Make sure you have a [GitHub account](https://github.com/join) - - [Create a ticket](http://projects.puppetlabs.com/projects/modules/issues/new), or [watch the ticket](http://projects.puppetlabs.com/projects/modules/issues) you are patching for. + - [Create a ticket](https://tickets.puppetlabs.com/secure/CreateIssue!default.jspa), or [watch the ticket](https://tickets.puppetlabs.com/browse/) you are patching for. * Preferred method: @@ -94,17 +92,7 @@ The long version whitespace or other "whitespace errors". You can do this by running "git diff --check" on your changes before you commit. - 2. Sign the Contributor License Agreement - - Before we can accept your changes, we do need a signed Puppet - Labs Contributor License Agreement (CLA). - - You can access the CLA via the [Contributor License Agreement link](https://cla.puppetlabs.com/) - - If you have any questions about the CLA, please feel free to - contact Puppet Labs via email at cla-submissions@puppetlabs.com. - - 3. Sending your patches + 2. Sending your patches To submit your changes via a GitHub pull request, we _highly_ recommend that you have them on a topic branch, instead of @@ -124,7 +112,7 @@ The long version in order to open a pull request. - 4. Update the related GitHub issue. + 3. Update the related GitHub issue. If there is a GitHub issue associated with the change you submitted, then you should update the ticket to include the @@ -220,14 +208,12 @@ review. Additional Resources ==================== -* [Getting additional help](http://projects.puppetlabs.com/projects/puppet/wiki/Getting_Help) +* [Getting additional help](http://puppetlabs.com/community/get-help) * [Writing tests](http://projects.puppetlabs.com/projects/puppet/wiki/Development_Writing_Tests) * [Patchwork](https://patchwork.puppetlabs.com) -* [Contributor License Agreement](https://projects.puppetlabs.com/contributor_licenses/sign) - * [General GitHub documentation](http://help.github.com/) * [GitHub pull request documentation](http://help.github.com/send-pull-requests/) -- cgit v1.2.3 From 145eb08b1f5367cda9d0120796ff55ce1363e25c Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Mon, 15 Dec 2014 16:09:24 -0800 Subject: 4.5.0 prep --- CHANGELOG.md | 13 +++++++++++++ metadata.json | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fb73db..8da04af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +##2014-12-15 - Supported Release 4.5.0 +###Summary + +This release improves functionality of the member function and adds improved future parser support. + +####Features +- MODULES-1329: Update member() to allow the variable to be an array. +- Sync .travis.yml, Gemfile, Rakefile, and CONTRIBUTING.md via modulesync + +####Bugfixes +- Fix range() to work with numeric ranges with the future parser +- Accurately express SLES support in metadata.json (was missing 10SP4 and 12) + ##2014-11-10 - Supported Release 4.4.0 ###Summary This release has an overhauled readme, new private manifest function, and fixes many future parser bugs. diff --git a/metadata.json b/metadata.json index f049cfb..bf02176 100644 --- a/metadata.json +++ b/metadata.json @@ -1,10 +1,10 @@ { "name": "puppetlabs-stdlib", - "version": "4.4.0", + "version": "4.5.0", "author": "puppetlabs", "summary": "Puppet Module Standard Library", - "license": "Apache 2.0", - "source": "git://github.com/puppetlabs/puppetlabs-stdlib", + "license": "Apache-2.0", + "source": "https://github.com/puppetlabs/puppetlabs-stdlib", "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib", "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", "operatingsystem_support": [ -- cgit v1.2.3 From ec08c6074994f4e90d10e1a425b1be0fc847ef14 Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Mon, 15 Dec 2014 16:21:28 -0800 Subject: Update README for updated member() functionality --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 78839c6..bf953d4 100644 --- a/README.markdown +++ b/README.markdown @@ -312,7 +312,7 @@ returns the value of the resource's parameter. For example, the following code r * `max`: Returns the highest value of all arguments. Requires at least one argument. *Type*: rvalue -* `member`: This function determines if a variable is a member of an array. For example, `member(['a','b'], 'b')` returns 'true', while `member(['a','b'], 'c')` returns 'false'. *Type*: rvalue +* `member`: This function determines if a variable is a member of an array. The variable can be either a string, array, or fixnum. For example, `member(['a','b'], 'b')` and `member(['a','b','c'], ['b','c'])` return 'true', while `member(['a','b'], 'c')` and `member(['a','b','c'], ['c','d'])` return 'false'. *Type*: rvalue * `merge`: Merges two or more hashes together and returns the resulting hash. -- cgit v1.2.3 From c54de9498f2cd317039779b333dcd150a52cca81 Mon Sep 17 00:00:00 2001 From: jbondpdx Date: Thu, 20 Nov 2014 15:20:37 -0800 Subject: FM-1523: Added module summary to metadata.json --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index bf02176..09ad4e8 100644 --- a/metadata.json +++ b/metadata.json @@ -2,7 +2,7 @@ "name": "puppetlabs-stdlib", "version": "4.5.0", "author": "puppetlabs", - "summary": "Puppet Module Standard Library", + "summary": "Standard library of resources for Puppet modules.", "license": "Apache-2.0", "source": "https://github.com/puppetlabs/puppetlabs-stdlib", "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib", -- cgit v1.2.3 From cff764564860e20e39675bac1408b9ed87c07573 Mon Sep 17 00:00:00 2001 From: jbondpdx Date: Tue, 25 Nov 2014 11:32:12 -0800 Subject: Added a note that stdlib no longer ships with PE 3.7+ Users didn't realize we stopped shipping stdlib module with PE. I added this information to the stdlib readme. --- README.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.markdown b/README.markdown index bf953d4..5344002 100644 --- a/README.markdown +++ b/README.markdown @@ -27,6 +27,8 @@ modules. Puppet modules make heavy use of this standard library. The stdlib modu * Defined resource types * Types * Providers + +> *Note:* As of version 3.7, Puppet Enterprise no longer includes the stdlib module. If you're running Puppet Enterprise, you should install the most recent release of stdlib for compatibility with Puppet modules. ##Setup @@ -676,6 +678,8 @@ of the regular expressions match the string passed in, compilation aborts with a ##Limitations +As of Puppet Enterprise version 3.7, the stdlib module is no longer included in PE. PE users should install the most recent release of stdlib for compatibility with Puppet modules. + ###Version Compatibility Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x | -- cgit v1.2.3 From 44596dcf3cd7f27ca0dd1d839673923371e0fef2 Mon Sep 17 00:00:00 2001 From: jbondpdx Date: Tue, 16 Dec 2014 14:33:42 -0800 Subject: DOC-1095: edit file_line resource, match parameter Was unclear and not accurate; rewrote the parameter, moved file_line from function list to resource section, added missing parameters for this resource. --- README.markdown | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/README.markdown b/README.markdown index 5344002..3bdb8ed 100644 --- a/README.markdown +++ b/README.markdown @@ -40,7 +40,7 @@ After you've installed stdlib, all of its functions, facts, and resources are av If you want to use a standardized set of run stages for Puppet, `include stdlib` in your manifest. -##Reference +## Reference ### Classes @@ -75,7 +75,30 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib` class { java: stage => 'runtime' } } ``` + +### Resources +* `file_line`: This resource ensures that a given line, including whitespace at the beginning and end, is contained within a file. If the line is not contained in the given file, Puppet will add the line. Multiple resources can be declared to manage multiple lines in the same file. You can also use match to replace existing lines. + + ``` + file_line { 'sudo_rule': + path => '/etc/sudoers', + line => '%sudo ALL=(ALL) ALL', + } + file_line { 'sudo_rule_nopw': + path => '/etc/sudoers', + line => '%sudonopw ALL=(ALL) NOPASSWD: ALL', + } + ``` + + * `after`: Specify the line after which Puppet will add any new lines. (Existing lines are added in place.) Optional. + * `ensure`: Ensures whether the resource is present. Valid values are 'present', 'absent'. + * `line`: The line to be added to the file located by the `path` parameter. + * `match`: A regular expression to run against existing lines in the file; if a match is found, we replace that line rather than adding a new line. Optional. + * `multiple`: Determine if match can change multiple lines. Valid values are 'true', 'false'. Optional. + * `name`: An arbitrary name used as the identity of the resource. + * `path`: The file in which Puppet will ensure the line specified by the line parameter. + ### Functions * `abs`: Returns the absolute value of a number; for example, '-34.56' becomes '34.56'. Takes a single integer and float value as an argument. *Type*: rvalue @@ -158,25 +181,6 @@ also appear in the second array. For example, `difference(["a","b","c"],["b","c" *Type*: statement -* `file_line`: This resource ensures that a given line is contained within a file. You can also use match to replace existing lines. - - *Example:* - - ``` - file_line { 'sudo_rule': - path => '/etc/sudoers', - line => '%sudo ALL=(ALL) ALL', - } - - file_line { 'change_mount': - path => '/etc/fstab', - line => '10.0.0.1:/vol/data /opt/data nfs defaults 0 0', - match => '^172.16.17.2:/vol/old', - } - ``` - - *Type*: resource - * `flatten`: This function flattens any deeply nested arrays and returns a single flat array as a result. For example, `flatten(['a', ['b', ['c']]])` returns ['a','b','c']. *Type*: rvalue * `floor`: Returns the largest integer less than or equal to the argument. -- cgit v1.2.3 From c6c203fca8da81fea96659bfe9618bb31965b837 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 16 Dec 2014 11:48:46 -0800 Subject: Remove line match validation The `match` attribute was validated to match `line`, except that in many cases (even the example given in the docs) a user would want to match a line entirely different from the new line. See comments on the original commit https://github.com/puppetlabs/puppetlabs-stdlib/commit/a06c0d8115892a74666676b50d4282df9850a119 and ask https://ask.puppetlabs.com/question/14366/file_line-resource-match-problems/ for further examples of confusion. --- CHANGELOG.md | 1 + lib/puppet/type/file_line.rb | 7 ------- spec/unit/puppet/type/file_line_spec.rb | 4 ++-- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8da04af..c66734e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This release improves functionality of the member function and adds improved fut ####Bugfixes - Fix range() to work with numeric ranges with the future parser - Accurately express SLES support in metadata.json (was missing 10SP4 and 12) +- Don't require `line` to match the `match` parameter ##2014-11-10 - Supported Release 4.4.0 ###Summary diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb index 9dbe43c..df263e6 100644 --- a/lib/puppet/type/file_line.rb +++ b/lib/puppet/type/file_line.rb @@ -71,12 +71,5 @@ Puppet::Type.newtype(:file_line) do unless self[:line] and self[:path] raise(Puppet::Error, "Both line and path are required attributes") end - - if (self[:match]) - unless Regexp.new(self[:match]).match(self[:line]) - raise(Puppet::Error, "When providing a 'match' parameter, the value must be a regex that matches against the value of your 'line' parameter") - end - end - end end diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb index 9ef49ef..410d0bf 100755 --- a/spec/unit/puppet/type/file_line_spec.rb +++ b/spec/unit/puppet/type/file_line_spec.rb @@ -15,14 +15,14 @@ describe Puppet::Type.type(:file_line) do file_line[:match] = '^foo.*$' expect(file_line[:match]).to eq('^foo.*$') end - it 'should not accept a match regex that does not match the specified line' do + it 'should accept a match regex that does not match the specified line' do expect { Puppet::Type.type(:file_line).new( :name => 'foo', :path => '/my/path', :line => 'foo=bar', :match => '^bar=blah$' - )}.to raise_error(Puppet::Error, /the value must be a regex that matches/) + )}.not_to raise_error end it 'should accept a match regex that does match the specified line' do expect { -- 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. --- README.markdown | 7 ++++ lib/puppet/parser/functions/basename.rb | 34 ++++++++++++++++ spec/unit/puppet/parser/functions/basename_spec.rb | 46 ++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 lib/puppet/parser/functions/basename.rb create mode 100755 spec/unit/puppet/parser/functions/basename_spec.rb diff --git a/README.markdown b/README.markdown index 78839c6..67ef313 100644 --- a/README.markdown +++ b/README.markdown @@ -84,6 +84,13 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib` Requires an action ('encode', 'decode') and either a plain or base64-encoded string. *Type*: rvalue +* `basename`: Returns the `basename` of a path (optionally stripping an extension). For example: + * ('/path/to/a/file.ext') returns 'file.ext' + * ('relative/path/file.ext') returns 'file.ext' + * ('/path/to/a/file.ext', '.ext') returns 'file' + + *Type*: rvalue + * `bool2num`: Converts a boolean to a number. Converts values: * 'false', 'f', '0', 'n', and 'no' to 0. * 'true', 't', '1', 'y', and 'yes' to 1. diff --git a/lib/puppet/parser/functions/basename.rb b/lib/puppet/parser/functions/basename.rb new file mode 100644 index 0000000..f7e4438 --- /dev/null +++ b/lib/puppet/parser/functions/basename.rb @@ -0,0 +1,34 @@ +module Puppet::Parser::Functions + newfunction(:basename, :type => :rvalue, :doc => <<-EOS + Strips directory (and optional suffix) from a filename + EOS + ) do |arguments| + + if arguments.size < 1 then + raise(Puppet::ParseError, "basename(): No arguments given") + elsif arguments.size > 2 then + raise(Puppet::ParseError, "basename(): Too many arguments given (#{arguments.size})") + else + + unless arguments[0].is_a?(String) + raise(Puppet::ParseError, 'basename(): Requires string as first argument') + end + + if arguments.size == 1 then + rv = File.basename(arguments[0]) + elsif arguments.size == 2 then + + unless arguments[1].is_a?(String) + raise(Puppet::ParseError, 'basename(): Requires string as second argument') + end + + rv = File.basename(arguments[0], arguments[1]) + end + + end + + return rv + end +end + +# vim: set ts=2 sw=2 et : 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 From 165caa8be195590bfd445b87db5fe2d0227d99ad Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Tue, 9 Dec 2014 14:20:31 +0000 Subject: (MODULES-1582) Initial spike for % placeholder This simply `gsub`'s the file path into where the % placeholder is. --- lib/puppet/parser/functions/validate_cmd.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb index c6136a5..7290265 100644 --- a/lib/puppet/parser/functions/validate_cmd.rb +++ b/lib/puppet/parser/functions/validate_cmd.rb @@ -6,9 +6,9 @@ module Puppet::Parser::Functions Perform validation of a string with an external command. The first argument of this function should be a string to test, and the second argument should be a path to a test command - taking a file as last argument. If the command, launched against - a tempfile containing the passed string, returns a non-null value, - compilation will abort with a parse error. + taking a % as a placeholder for the file path (will default to the end). + If the command, launched against a tempfile containing the passed string, + returns a non-null value, compilation will abort with a parse error. If a third argument is specified, this will be the error message raised and seen by the user. @@ -17,8 +17,12 @@ module Puppet::Parser::Functions Example: + # Defaults to end of path validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content') + # % as file location + validate_cmd($haproxycontent, '/usr/sbin/haproxy -f % -c', 'Haproxy failed to validate config content') + ENDHEREDOC if (args.length < 2) or (args.length > 3) then raise Puppet::ParseError, ("validate_cmd(): wrong number of arguments (#{args.length}; must be 2 or 3)") @@ -34,10 +38,17 @@ module Puppet::Parser::Functions begin tmpfile.write(content) tmpfile.close + + if checkscript.include?('%') + check_with_correct_location = checkscript.gsub(/%/,tmpfile.path) + else + check_with_correct_location = "#{checkscript} #{tmpfile.path}" + end + if Puppet::Util::Execution.respond_to?('execute') - Puppet::Util::Execution.execute("#{checkscript} #{tmpfile.path}") + Puppet::Util::Execution.execute(check_with_correct_location) else - Puppet::Util.execute("#{checkscript} #{tmpfile.path}") + Puppet::Util.execute(check_with_correct_location) end rescue Puppet::ExecutionFailure => detail msg += "\n#{detail}" -- cgit v1.2.3 From cc8b147b5df539d1261508ed5c711a744d8584af Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Tue, 9 Dec 2014 14:42:31 +0000 Subject: (MODULES-1582) Specs for the new % placeholder These specs are pretty much the same as the originals, but now check that the output has the correct replacement for file location --- spec/functions/validate_cmd_spec.rb | 81 +++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/spec/functions/validate_cmd_spec.rb b/spec/functions/validate_cmd_spec.rb index a6e68df..7cb9782 100755 --- a/spec/functions/validate_cmd_spec.rb +++ b/spec/functions/validate_cmd_spec.rb @@ -12,37 +12,74 @@ describe Puppet::Parser::Functions.function(:validate_cmd) do 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!/ + context 'with no % placeholder' do + 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 - 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)/ + 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 - it "includes the command return value" do - expect { - subject.call ['', '/cant/run/this'] - }.to raise_error Puppet::ParseError, /returned 1\b/ + 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 - describe "when performing actual validation" do - it "can positively validate file content" do - expect { subject.call ["non-empty", "#{TESTEXE} -s"] }.to_not raise_error + context 'with % placeholder' do + describe "with an explicit failure message" do + it "prints the failure message on error" do + expect { + subject.call ['', '/bin/false % -f', '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 % -z'] + }.to raise_error Puppet::ParseError, /Execution of '\/cant\/run\/this .+ -z' returned 1/ + 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/ + 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 end -- cgit v1.2.3 From b3d007f1daa9bd7c8c02f372494df3a6e6ff6acf Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Thu, 18 Dec 2014 23:08:13 +0000 Subject: (MODULES-1582) Improve % detection Avoids any validate commands that have %'s in them other than "... % ..." --- lib/puppet/parser/functions/validate_cmd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb index 7290265..5df3c60 100644 --- a/lib/puppet/parser/functions/validate_cmd.rb +++ b/lib/puppet/parser/functions/validate_cmd.rb @@ -39,7 +39,7 @@ module Puppet::Parser::Functions tmpfile.write(content) tmpfile.close - if checkscript.include?('%') + if checkscript =~ /\s%(\s|$)/ check_with_correct_location = checkscript.gsub(/%/,tmpfile.path) else check_with_correct_location = "#{checkscript} #{tmpfile.path}" -- cgit v1.2.3 From 31a6d894107f8f2ef4e0aec081f505d153e6297c Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Thu, 18 Dec 2014 16:20:02 -0800 Subject: Fix bad check in test --- spec/acceptance/concat_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index caf2f7d..06b649f 100755 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -29,7 +29,7 @@ describe 'concat function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('oper pp = <<-EOS $output = concat(['1','2','3'],['4','5','6'],['7','8','9']) validate_array($output) - if size($output) != 6 { + if size($output) != 9 { fail("${output} should have 9 elements.") } EOS -- cgit v1.2.3 From 8ec6f8dbfdaaa4b34030cbe1f4764c42c629240e Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Fri, 19 Dec 2014 10:26:01 -0800 Subject: MODULES-1606 add ability to pass array to delete for items to delete --- lib/puppet/parser/functions/delete.rb | 24 ++++++++++++------------ spec/functions/delete_spec.rb | 31 ++++++++++++++++++------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/lib/puppet/parser/functions/delete.rb b/lib/puppet/parser/functions/delete.rb index d03a293..a1e39ed 100644 --- a/lib/puppet/parser/functions/delete.rb +++ b/lib/puppet/parser/functions/delete.rb @@ -19,25 +19,25 @@ string, or key from a hash. delete('abracadabra', 'bra') Would return: 'acada' - EOS + EOS ) do |arguments| if (arguments.size != 2) then raise(Puppet::ParseError, "delete(): Wrong number of arguments "+ - "given #{arguments.size} for 2.") + "given #{arguments.size} for 2.") end collection = arguments[0].dup - item = arguments[1] - - case collection - when Array, Hash - collection.delete item - when String - collection.gsub! item, '' - else - raise(TypeError, "delete(): First argument must be an Array, " + - "String, or Hash. Given an argument of class #{collection.class}.") + Array(arguments[1]).each do |item| + case collection + when Array, Hash + collection.delete item + when String + collection.gsub! item, '' + else + raise(TypeError, "delete(): First argument must be an Array, " + + "String, or Hash. Given an argument of class #{collection.class}.") + end end collection end diff --git a/spec/functions/delete_spec.rb b/spec/functions/delete_spec.rb index 39b3176..c8edd78 100755 --- a/spec/functions/delete_spec.rb +++ b/spec/functions/delete_spec.rb @@ -9,48 +9,53 @@ describe "the delete function" do end it "should raise a ParseError if there are fewer than 2 arguments" do - expect { scope.function_delete([]) }.to( raise_error(Puppet::ParseError)) + expect { scope.function_delete([]) }.to(raise_error(Puppet::ParseError)) end it "should raise a ParseError if there are greater than 2 arguments" do - expect { scope.function_delete([[], 'foo', 'bar']) }.to( raise_error(Puppet::ParseError)) + expect { scope.function_delete([[], 'foo', 'bar']) }.to(raise_error(Puppet::ParseError)) end it "should raise a TypeError if a number is passed as the first argument" do - expect { scope.function_delete([1, 'bar']) }.to( raise_error(TypeError)) + expect { scope.function_delete([1, 'bar']) }.to(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']) - expect(result).to(eq(['a','c'])) + result = scope.function_delete([['a', 'b', 'c', 'b'], 'b']) + expect(result).to(eq(['a', 'c'])) end it "should delete all instances of a substring from a string" do - result = scope.function_delete(['foobarbabarz','bar']) + result = scope.function_delete(['foobarbabarz', 'bar']) expect(result).to(eq('foobaz')) end it "should delete a key from a hash" do - result = scope.function_delete([{ 'a' => 1, 'b' => 2, 'c' => 3 },'b']) - expect(result).to(eq({ 'a' => 1, 'c' => 3 })) + result = scope.function_delete([{'a' => 1, 'b' => 2, 'c' => 3}, 'b']) + expect(result).to(eq({'a' => 1, 'c' => 3})) + end + + it 'should accept an array of items to delete' do + result = scope.function_delete([{'a' => 1, 'b' => 2, 'c' => 3}, ['b', 'c']]) + expect(result).to(eq({'a' => 1})) end it "should not change origin array passed as argument" do - origin_array = ['a','b','c','d'] + origin_array = ['a', 'b', 'c', 'd'] result = scope.function_delete([origin_array, 'b']) - expect(origin_array).to(eq(['a','b','c','d'])) + expect(origin_array).to(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']) + result = scope.function_delete([origin_string, 'bar']) expect(origin_string).to(eq('foobarbabarz')) end it "should not change origin hash passed as argument" do - origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } + origin_hash = {'a' => 1, 'b' => 2, 'c' => 3} result = scope.function_delete([origin_hash, 'b']) - expect(origin_hash).to(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) + expect(origin_hash).to(eq({'a' => 1, 'b' => 2, 'c' => 3})) end end -- cgit v1.2.3 From f6e20d20684f315d746e99ff554a0bdc714f96a3 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Fri, 19 Dec 2014 10:41:07 -0800 Subject: Update docs to reflect new behavior of delete function taking array in second argument --- README.markdown | 74 +++++++++++++++++------------------ lib/puppet/parser/functions/delete.rb | 3 ++ 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/README.markdown b/README.markdown index c4022c5..0c7b80a 100644 --- a/README.markdown +++ b/README.markdown @@ -14,7 +14,7 @@ ##Overview -Adds a standard library of resources for Puppet modules. +Adds a standard library of resources for Puppet modules. ##Module Description @@ -27,22 +27,22 @@ modules. Puppet modules make heavy use of this standard library. The stdlib modu * Defined resource types * Types * Providers - + > *Note:* As of version 3.7, Puppet Enterprise no longer includes the stdlib module. If you're running Puppet Enterprise, you should install the most recent release of stdlib for compatibility with Puppet modules. ##Setup -Installing the stdlib module adds the functions, facts, and resources of this standard library to Puppet. +Installing the stdlib module adds the functions, facts, and resources of this standard library to Puppet. ##Usage -After you've installed stdlib, all of its functions, facts, and resources are available for module use or development. +After you've installed stdlib, all of its functions, facts, and resources are available for module use or development. -If you want to use a standardized set of run stages for Puppet, `include stdlib` in your manifest. +If you want to use a standardized set of run stages for Puppet, `include stdlib` in your manifest. ## Reference -### Classes +### Classes #### Public Classes @@ -75,11 +75,11 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib` class { java: stage => 'runtime' } } ``` - + ### Resources -* `file_line`: This resource ensures that a given line, including whitespace at the beginning and end, is contained within a file. If the line is not contained in the given file, Puppet will add the line. Multiple resources can be declared to manage multiple lines in the same file. You can also use match to replace existing lines. - +* `file_line`: This resource ensures that a given line, including whitespace at the beginning and end, is contained within a file. If the line is not contained in the given file, Puppet will add the line. Multiple resources can be declared to manage multiple lines in the same file. You can also use match to replace existing lines. + ``` file_line { 'sudo_rule': path => '/etc/sudoers', @@ -90,7 +90,7 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib` line => '%sudonopw ALL=(ALL) NOPASSWD: ALL', } ``` - + * `after`: Specify the line after which Puppet will add any new lines. (Existing lines are added in place.) Optional. * `ensure`: Ensures whether the resource is present. Valid values are 'present', 'absent'. * `line`: The line to be added to the file located by the `path` parameter. @@ -98,7 +98,7 @@ If you want to use a standardized set of run stages for Puppet, `include stdlib` * `multiple`: Determine if match can change multiple lines. Valid values are 'true', 'false'. Optional. * `name`: An arbitrary name used as the identity of the resource. * `path`: The file in which Puppet will ensure the line specified by the line parameter. - + ### Functions * `abs`: Returns the absolute value of a number; for example, '-34.56' becomes '34.56'. Takes a single integer and float value as an argument. *Type*: rvalue @@ -144,11 +144,11 @@ strings; for example, 'hello\n' becomes 'hello'. Requires a single string or arr user { 'dan': ensure => present, } } ``` - + *Type*: rvalue * `delete`: Deletes all instances of a given element from an array, substring from a -string, or key from a hash. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. *Type*: rvalue +string, or key from a hash. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. `delete({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1} *Type*: rvalue * `delete_at`: Deletes a determined indexed value from an array. For example, `delete_at(['a','b','c'], 1)` returns ['a','c']. *Type*: rvalue @@ -252,7 +252,7 @@ returns the value of the resource's parameter. For example, the following code r has_interface_with("macaddress", "x:x:x:x:x:x") has_interface_with("ipaddress", "127.0.0.1") => true ``` - + If no kind is given, then the presence of the interface is checked: ``` @@ -278,7 +278,7 @@ returns the value of the resource's parameter. For example, the following code r notice('this will be printed') } ``` - + *Type*: rvalue * `hash`: This function converts an array into a hash. For example, `hash(['a',1,'b',2,'c',3])` returns {'a'=>1,'b'=>2,'c'=>3}. *Type*: rvalue @@ -330,7 +330,7 @@ returns the value of the resource's parameter. For example, the following code r * `merge`: Merges two or more hashes together and returns the resulting hash. *Example*: - + ``` $hash1 = {'one' => 1, 'two' => 2} $hash2 = {'two' => 'dos', 'three' => 'tres'} @@ -338,7 +338,7 @@ returns the value of the resource's parameter. For example, the following code r # The resulting hash is equivalent to: # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'} ``` - + When there is a duplicate key, the key in the rightmost hash "wins." *Type*: rvalue * `min`: Returns the lowest value of all arguments. Requires at least one argument. *Type*: rvalue @@ -354,7 +354,7 @@ returns the value of the resource's parameter. For example, the following code r ``` $real_jenkins_version = pick($::jenkins_version, '1.449') ``` - + *Type*: rvalue * `prefix`: This function applies a prefix to all elements in an array. For example, `prefix(['a','b','c'], 'p')` returns ['pa','pb','pc']. *Type*: rvalue @@ -366,9 +366,9 @@ Calling the class or definition from outside the current module will fail. For e ``` Class foo::bar is private ``` - + You can specify the error message you want to use: - + ``` private("You're not supposed to do that!") ``` @@ -377,8 +377,8 @@ Calling the class or definition from outside the current module will fail. For e * `range`: When given range in the form of '(start, stop)', `range` extrapolates a range as an array. For example, `range("0", "9")` returns [0,1,2,3,4,5,6,7,8,9]. Zero-padded strings are converted to integers automatically, so `range("00", "09")` returns [0,1,2,3,4,5,6,7,8,9]. - Non-integer strings are accepted; `range("a", "c")` returns ["a","b","c"], and `range("host01", "host10")` returns ["host01", "host02", ..., "host09", "host10"]. - + Non-integer strings are accepted; `range("a", "c")` returns ["a","b","c"], and `range("host01", "host10")` returns ["host01", "host02", ..., "host09", "host10"]. + *Type*: rvalue * `reject`: This function searches through an array and rejects all elements that match the provided regular expression. For example, `reject(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['bbb','ccc']. *Type*: rvalue @@ -403,7 +403,7 @@ manifests as a valid password attribute. *Type*: rvalue * `strftime`: This function returns formatted time. For example, `strftime("%s")` returns the time since epoch, and `strftime("%Y=%m-%d")` returns the date. *Type*: rvalue *Format:* - + * `%a`: The abbreviated weekday name ('Sun') * `%A`: The full weekday name ('Sunday') * `%b`: The abbreviated month name ('Jan') @@ -501,9 +501,9 @@ You can also use this with arrays. For example, `unique(["a","a","b","b","c","c" validate_absolute_path($undefined) ``` - *Type*: statement + *Type*: statement -* `validate_array`: Validate that all passed values are array data structures. Abort catalog compilation if any value fails this check. +* `validate_array`: Validate that all passed values are array data structures. Abort catalog compilation if any value fails this check. The following values will pass: @@ -533,13 +533,13 @@ The first argument of this function should be the string to test, and the second ``` validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo']) ``` - + To ensure that no users use the '/bin/barsh' shell: ``` validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]'] ``` - + You can pass a fourth argument as the error message raised and shown to the user: ``` @@ -551,13 +551,13 @@ The first argument of this function should be the string to test, and the second * `validate_bool`: Validate that all passed values are either true or false. Abort catalog compilation if any value fails this check. The following values will pass: - + ``` $iamtrue = true validate_bool(true) validate_bool(true, true, false, $iamtrue) ``` - + The following values will fail, causing compilation to abort: ``` @@ -576,7 +576,7 @@ The first argument of this function should be the string to test, and the second ``` validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content') ``` - + *Type*: statement * `validate_hash`: Validates that all passed values are hash data structures. Abort catalog compilation if any value fails this check. @@ -596,7 +596,7 @@ The first argument of this function should be the string to test, and the second $undefined = undef validate_hash($undefined) ``` - + *Type*: statement * `validate_re`: Performs simple validation of a string against one or more regular expressions. The first argument of this function should be the string to @@ -619,8 +619,8 @@ of the regular expressions match the string passed in, compilation aborts with a validate_re('one', [ '^two', '^three' ]) ``` - To set the error message: - + To set the error message: + ``` validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7') ``` @@ -630,19 +630,19 @@ of the regular expressions match the string passed in, compilation aborts with a * `validate_slength`: Validates that the first argument is a string (or an array of strings), and is less than or equal to the length of the second argument. It fails if the first argument is not a string or array of strings, or if arg 2 is not convertable to a number. The following values pass: - + ``` validate_slength("discombobulate",17) validate_slength(["discombobulate","moo"],17) ``` - + The following values fail: ``` validate_slength("discombobulate",1) validate_slength(["discombobulate","thermometer"],5) ``` - + *Type*: statement * `validate_string`: Validates that all passed values are string data structures. Aborts catalog compilation if any value fails this check. @@ -700,7 +700,7 @@ As of Puppet Enterprise version 3.7, the stdlib module is no longer included in ###Version Compatibility -Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x | +Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x | :---------------|:-----:|:---:|:---:|:----: **stdlib 2.x** | **yes** | **yes** | no | no **stdlib 3.x** | no | **yes** | **yes** | no diff --git a/lib/puppet/parser/functions/delete.rb b/lib/puppet/parser/functions/delete.rb index a1e39ed..f548b44 100644 --- a/lib/puppet/parser/functions/delete.rb +++ b/lib/puppet/parser/functions/delete.rb @@ -17,6 +17,9 @@ string, or key from a hash. delete({'a'=>1,'b'=>2,'c'=>3}, 'b') Would return: {'a'=>1,'c'=>3} + delete({'a'=>1,'b'=>2,'c'=>3}, ['b','c']) + Would return: {'a'=>1} + delete('abracadabra', 'bra') Would return: 'acada' EOS -- cgit v1.2.3 From c125a0899435b26f7823bdf3793b4aeb27f4a707 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Fri, 19 Dec 2014 11:52:11 +0000 Subject: README fixes for recent merges * (MODULES-444) Update README for concat changes * (MODULES-1582) Update `validate_cmd` readme * Plus some Whitespace fixes --- README.markdown | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index 0c7b80a..689660e 100644 --- a/README.markdown +++ b/README.markdown @@ -129,7 +129,9 @@ strings; for example, 'hello\n' becomes 'hello'. Requires a single string or arr * `chop`: Returns a new string with the last character removed. If the string ends with '\r\n', both characters are removed. Applying `chop` to an empty string returns an empty string. If you want to merely remove record separators, then you should use the `chomp` function. Requires a string or an array of strings as input. *Type*: rvalue -* `concat`: Appends the contents of array 2 onto array 1. For example, `concat(['1','2','3'],'4')` results in: ['1','2','3','4']. *Type*: rvalue +* `concat`: Appends the contents of multiple arrays onto array 1. For example: + * `concat(['1','2','3'],'4')` results in: ['1','2','3','4']. + * `concat(['1','2','3'],'4',['5','6','7'])` results in: ['1','2','3','4','5','6','7']. * `count`: Takes an array as first argument and an optional second argument. Count the number of elements in array that matches second argument. If called with only an array, it counts the number of elements that are **not** nil/undef. *Type*: rvalue @@ -569,13 +571,18 @@ The first argument of this function should be the string to test, and the second *Type*: statement -* `validate_cmd`: Performs validation of a string with an external command. The first argument of this function should be the string to test, and the second argument should be the path to a test command taking a file as last argument. If the command, launched against a tempfile containing the passed string, returns a non-null value, compilation aborts with a parse error. +* `validate_cmd`: Performs validation of a string with an external command. The first argument of this function should be a string to test, and the second argument should be a path to a test command taking a % as a placeholder for the file path (will default to the end of the command if no % placeholder given). If the command, launched against a tempfile containing the passed string, returns a non-null value, compilation will abort with a parse error. - You can pass a third argument as the error message raised and shown to the user: +If a third argument is specified, this will be the error message raised and seen by the user. ``` + # Defaults to end of path validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content') ``` + ``` + # % as file location + validate_cmd($haproxycontent, '/usr/sbin/haproxy -f % -c', 'Haproxy failed to validate config content') + ``` *Type*: statement -- cgit v1.2.3 From 9077bfef1e3313b7cd7f89cfec95132466730325 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Mon, 29 Dec 2014 10:41:22 -0800 Subject: Add IntelliJ files to the ignore list --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b5b7a00..b5db85e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ spec/fixtures/ .vagrant/ .bundle/ coverage/ +.idea/ +*.iml -- cgit v1.2.3 From 7c8ae311cade65e84df1054779a039ff906e630c Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 15 Dec 2014 16:11:10 -0800 Subject: (MODULES-1473) Deprecate type() function for new parser The `type()` function will cease to work on the new parser because 'type' is a reserved keyword. The `type3x()` function may be used to continue similar functionality, but will be deprecated in favor of the built-in typing system. The `type_of()` function has been included to introspect types in the new parser. --- .fixtures.yml | 3 ++ .travis.yml | 1 + README.markdown | 7 +++- lib/puppet/functions/type_of.rb | 17 ++++++++++ lib/puppet/parser/functions/type.rb | 43 ++++--------------------- lib/puppet/parser/functions/type3x.rb | 51 ++++++++++++++++++++++++++++++ spec/functions/type3x_spec.rb | 43 +++++++++++++++++++++++++ spec/functions/type_spec.rb | 5 +-- spec/unit/puppet/functions/type_of_spec.rb | 33 +++++++++++++++++++ 9 files changed, 163 insertions(+), 40 deletions(-) create mode 100644 .fixtures.yml create mode 100644 lib/puppet/functions/type_of.rb create mode 100644 lib/puppet/parser/functions/type3x.rb create mode 100644 spec/functions/type3x_spec.rb create mode 100644 spec/unit/puppet/functions/type_of_spec.rb diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..37b7377 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,3 @@ +fixtures: + symlinks: + stdlib: "#{source_dir}" diff --git a/.travis.yml b/.travis.yml index f531306..503e184 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ --- +sudo: false language: ruby bundler_args: --without system_tests script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'" diff --git a/README.markdown b/README.markdown index 689660e..e9a1f4e 100644 --- a/README.markdown +++ b/README.markdown @@ -464,7 +464,12 @@ manifests as a valid password attribute. *Type*: rvalue * `to_bytes`: Converts the argument into bytes, for example 4 kB becomes 4096. Takes a single string value as an argument. *Type*: rvalue -* `type`: Returns the type when passed a variable. Type can be a string, array, hash, float, integer, or boolean. *Type*: rvalue +* `type3x`: Returns a string description of the type when passed a value. Type can be a string, array, hash, float, integer, or boolean. This function will be removed when puppet 3 support is dropped and the new type system may be used. *Type*: rvalue + +* `type_of`: Returns the literal type when passed a value. Requires the new + parser. Useful for comparison of types with `<=` such as in `if + type_of($some_value) <= Array[String] { ... }` (which is equivalent to `if + $some_value =~ Array[String] { ... }`) *Type*: rvalue * `union`: This function returns a union of two arrays. For example, `union(["a","b","c"],["b","c","d"])` returns ["a","b","c","d"]. diff --git a/lib/puppet/functions/type_of.rb b/lib/puppet/functions/type_of.rb new file mode 100644 index 0000000..02cdd4d --- /dev/null +++ b/lib/puppet/functions/type_of.rb @@ -0,0 +1,17 @@ +# Returns the type when passed a value. +# +# @example how to compare values' types +# # compare the types of two values +# if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") } +# @example how to compare against an abstract type +# unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") } +# unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") } +# +# See the documentation for "The Puppet Type System" for more information about types. +# See the `assert_type()` function for flexible ways to assert the type of a value. +# +Puppet::Functions.create_function(:type_of) do + def type_of(value) + Puppet::Pops::Types::TypeCalculator.infer_set(value) + end +end diff --git a/lib/puppet/parser/functions/type.rb b/lib/puppet/parser/functions/type.rb index 8d85f11..016529b 100644 --- a/lib/puppet/parser/functions/type.rb +++ b/lib/puppet/parser/functions/type.rb @@ -4,46 +4,15 @@ module Puppet::Parser::Functions newfunction(:type, :type => :rvalue, :doc => <<-EOS -Returns the type when passed a variable. Type can be one of: - -* string -* array -* hash -* float -* integer -* boolean + DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system. EOS - ) do |arguments| - - raise(Puppet::ParseError, "type(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 - - value = arguments[0] - - klass = value.class - - if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass) - raise(Puppet::ParseError, 'type(): Unknown type') - end - - klass = klass.to_s # Ugly ... + ) do |args| - # We note that Integer is the parent to Bignum and Fixnum ... - result = case klass - when /^(?:Big|Fix)num$/ then 'integer' - when /^(?:True|False)Class$/ then 'boolean' - else klass + warning("type() DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") + if ! Puppet::Parser::Functions.autoloader.loaded?(:type3x) + Puppet::Parser::Functions.autoloader.load(:type3x) end - - if result == "String" then - if value == value.to_i.to_s then - result = "Integer" - elsif value == value.to_f.to_s then - result = "Float" - end - end - - return result.downcase + function_type3x(args + [false]) end end diff --git a/lib/puppet/parser/functions/type3x.rb b/lib/puppet/parser/functions/type3x.rb new file mode 100644 index 0000000..0800b4a --- /dev/null +++ b/lib/puppet/parser/functions/type3x.rb @@ -0,0 +1,51 @@ +# +# type3x.rb +# + +module Puppet::Parser::Functions + newfunction(:type3x, :type => :rvalue, :doc => <<-EOS +DEPRECATED: This function will be removed when puppet 3 support is dropped; please migrate to the new parser's typing system. + +Returns the type when passed a value. Type can be one of: + +* string +* array +* hash +* float +* integer +* boolean + EOS + ) do |args| + raise(Puppet::ParseError, "type3x(): Wrong number of arguments " + + "given (#{args.size} for 1)") if args.size < 1 + + value = args[0] + + klass = value.class + + if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass) + raise(Puppet::ParseError, 'type3x(): Unknown type') + end + + klass = klass.to_s # Ugly ... + + # We note that Integer is the parent to Bignum and Fixnum ... + result = case klass + when /^(?:Big|Fix)num$/ then 'integer' + when /^(?:True|False)Class$/ then 'boolean' + else klass + end + + if result == "String" then + if value == value.to_i.to_s then + result = "Integer" + elsif value == value.to_f.to_s then + result = "Float" + end + end + + return result.downcase + end +end + +# vim: set ts=2 sw=2 et : diff --git a/spec/functions/type3x_spec.rb b/spec/functions/type3x_spec.rb new file mode 100644 index 0000000..d21236a --- /dev/null +++ b/spec/functions/type3x_spec.rb @@ -0,0 +1,43 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the type3x function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + it "should exist" do + expect(Puppet::Parser::Functions.function("type3x")).to eq("function_type3x") + end + + it "should raise a ParseError if there is less than 1 arguments" do + expect { scope.function_type3x([]) }.to( raise_error(Puppet::ParseError)) + end + + it "should return string when given a string" do + result = scope.function_type3x(["aaabbbbcccc"]) + expect(result).to(eq('string')) + end + + it "should return array when given an array" do + result = scope.function_type3x([["aaabbbbcccc","asdf"]]) + expect(result).to(eq('array')) + end + + it "should return hash when given a hash" do + result = scope.function_type3x([{"a"=>1,"b"=>2}]) + expect(result).to(eq('hash')) + end + + it "should return integer when given an integer" do + result = scope.function_type3x(["1"]) + expect(result).to(eq('integer')) + end + + it "should return float when given a float" do + result = scope.function_type3x(["1.34"]) + expect(result).to(eq('float')) + end + + it "should return boolean when given a boolean" do + result = scope.function_type3x([true]) + expect(result).to(eq('boolean')) + end +end diff --git a/spec/functions/type_spec.rb b/spec/functions/type_spec.rb index 9dfe9d7..b683fcf 100755 --- a/spec/functions/type_spec.rb +++ b/spec/functions/type_spec.rb @@ -7,8 +7,9 @@ describe "the type function" do expect(Puppet::Parser::Functions.function("type")).to eq("function_type") end - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_type([]) }.to( raise_error(Puppet::ParseError)) + it "should give a deprecation warning when called" do + scope.expects(:warning).with("type() DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") + scope.function_type(["aoeu"]) end it "should return string when given a string" do diff --git a/spec/unit/puppet/functions/type_of_spec.rb b/spec/unit/puppet/functions/type_of_spec.rb new file mode 100644 index 0000000..8afb624 --- /dev/null +++ b/spec/unit/puppet/functions/type_of_spec.rb @@ -0,0 +1,33 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +if ENV["FUTURE_PARSER"] == 'yes' or Puppet.version >= "4" + require 'puppet/pops' + require 'puppet/loaders' + + describe 'the type_of function' do + before(:all) do + loaders = Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, [File.join(fixtures, "modules")])) + Puppet.push_context({:loaders => loaders}, "test-examples") + end + + after(:all) do + Puppet::Pops::Loaders.clear + Puppet::pop_context() + end + + let(:func) do + # Load the function from the environment modulepath's modules (ie, fixtures) + Puppet.lookup(:loaders).private_environment_loader.load(:function, 'type_of') + end + + it 'gives the type of a string' do + expect(func.call({}, 'hello world')).to be_kind_of(Puppet::Pops::Types::PStringType) + end + + it 'gives the type of an integer' do + expect(func.call({}, 5)).to be_kind_of(Puppet::Pops::Types::PIntegerType) + end + end +end -- cgit v1.2.3 From b11311ad65c925c074e6a0b34d8182b70c570225 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Fri, 9 Jan 2015 14:09:03 -0800 Subject: FM-2130 Move cache file to non temp directory --- lib/facter/facter_dot_d.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/facter/facter_dot_d.rb b/lib/facter/facter_dot_d.rb index 2c096b0..b058437 100644 --- a/lib/facter/facter_dot_d.rb +++ b/lib/facter/facter_dot_d.rb @@ -15,7 +15,7 @@ class Facter::Util::DotD require 'yaml' - def initialize(dir="/etc/facts.d", cache_file="/tmp/facts_cache.yml") + def initialize(dir="/etc/facts.d", cache_file=File.join(Puppet[:libdir], "facts_dot_d.cache")) @dir = dir @cache_file = cache_file @cache = nil @@ -23,7 +23,7 @@ class Facter::Util::DotD end def entries - Dir.entries(@dir).reject{|f| f =~ /^\.|\.ttl$/}.sort.map {|f| File.join(@dir, f) } + Dir.entries(@dir).reject { |f| f =~ /^\.|\.ttl$/ }.sort.map { |f| File.join(@dir, f) } rescue [] end @@ -113,7 +113,7 @@ class Facter::Util::DotD def cache_save! cache = load_cache - File.open(@cache_file, "w", 0600) {|f| f.write(YAML.dump(cache)) } + File.open(@cache_file, "w", 0600) { |f| f.write(YAML.dump(cache)) } rescue end -- cgit v1.2.3 From bfb526899f215f3fde98ff00cf5f63aa51e657db Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 13 Jan 2015 17:21:28 -0800 Subject: Change all to each The existence of this directory is behavior for each test, but will also stop rspec 3 from complaining. --- spec/acceptance/fqdn_rotate_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/fqdn_rotate_spec.rb b/spec/acceptance/fqdn_rotate_spec.rb index c37b35a..753068b 100755 --- a/spec/acceptance/fqdn_rotate_spec.rb +++ b/spec/acceptance/fqdn_rotate_spec.rb @@ -21,7 +21,7 @@ describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact( after :each do shell("if [ -f '#{facts_d}/fqdn.txt' ] ; then rm '#{facts_d}/fqdn.txt' ; fi") end - before :all do + before :each do #No need to create on windows, PE creates by default if fact('osfamily') !~ /windows/i shell("mkdir -p '#{facts_d}'") -- cgit v1.2.3 From cfacdd543e942f7c5d94fd07f14c2f6d8128e83d Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 13 Jan 2015 17:17:48 -0800 Subject: Prep for 4.6.0 STDLIB release --- CHANGELOG.md | 16 ++++++++++++++++ metadata.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c66734e..e49489b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +##2015-01-14 - Supported Release 4.6.0 +###Summary + +Improved functionality and preparing for Puppet Next with new parser + +####Features +- MODULES-444: concat can now take more than two arrays +- basename function added to have Ruby File.basename functionality +- delete function can now take an array of items to remove +- MODULES-1473: deprecate type function in favor of type_of + +####Bugfixes +- Several test case fixes +- Ensure_resource is more verbose on debug mode + + ##2014-12-15 - Supported Release 4.5.0 ###Summary diff --git a/metadata.json b/metadata.json index 09ad4e8..27def9c 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-stdlib", - "version": "4.5.0", + "version": "4.5.1", "author": "puppetlabs", "summary": "Standard library of resources for Puppet modules.", "license": "Apache-2.0", -- cgit v1.2.3 From e32afd7c7c3139e0435756ee56048081bb1d1340 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Fri, 9 Jan 2015 14:09:03 -0800 Subject: FM-2130 Move cache file to non temp directory --- lib/facter/facter_dot_d.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/facter/facter_dot_d.rb b/lib/facter/facter_dot_d.rb index 2c096b0..b058437 100644 --- a/lib/facter/facter_dot_d.rb +++ b/lib/facter/facter_dot_d.rb @@ -15,7 +15,7 @@ class Facter::Util::DotD require 'yaml' - def initialize(dir="/etc/facts.d", cache_file="/tmp/facts_cache.yml") + def initialize(dir="/etc/facts.d", cache_file=File.join(Puppet[:libdir], "facts_dot_d.cache")) @dir = dir @cache_file = cache_file @cache = nil @@ -23,7 +23,7 @@ class Facter::Util::DotD end def entries - Dir.entries(@dir).reject{|f| f =~ /^\.|\.ttl$/}.sort.map {|f| File.join(@dir, f) } + Dir.entries(@dir).reject { |f| f =~ /^\.|\.ttl$/ }.sort.map { |f| File.join(@dir, f) } rescue [] end @@ -113,7 +113,7 @@ class Facter::Util::DotD def cache_save! cache = load_cache - File.open(@cache_file, "w", 0600) {|f| f.write(YAML.dump(cache)) } + File.open(@cache_file, "w", 0600) { |f| f.write(YAML.dump(cache)) } rescue end -- cgit v1.2.3 From 9e380b9685edb4eb0209b815a65c696be38fb4d5 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Wed, 14 Jan 2015 12:46:10 -0800 Subject: Prepare for 4.5.1 release --- CHANGELOG.md | 8 ++++++++ metadata.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c66734e..84c8b24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +##2015-01-14 - Supported Release 4.5.1 +###Summary + +This release changes the temporary facter_dot_d cache locations outside of the /tmp directory due to a possible security vunerability. CVE-2015-1029 + +####Bugfixes +- Facter_dot_d cache will now be stored in puppet libdir instead of tmp + ##2014-12-15 - Supported Release 4.5.0 ###Summary diff --git a/metadata.json b/metadata.json index 09ad4e8..27def9c 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-stdlib", - "version": "4.5.0", + "version": "4.5.1", "author": "puppetlabs", "summary": "Standard library of resources for Puppet modules.", "license": "Apache-2.0", -- cgit v1.2.3