summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/functions
Commit message (Collapse)AuthorAgeFilesLines
* Maint: Fix miscellaneous testsJosh Cooper2011-07-191-1/+2
| | | | | | | | | | | | | | | | | | | | Several tests were broken due to pecularities of Windows and Ruby on Windows: * Ruby on windows does not differentiate between group and other file permissions. * All open file handles must be closed before the file can be deleted * Sometimes the current working directory (Dir.getwd) is reported as C:/foo and other times as C:\\foo, which confuses the spec tests. * Ruby's sprintf formats floating point values differently on Windows vs Unix. The Windows exponent has an extra leading zero. * Needed to stub execution of security command with the SMF service provider. Reviewed-by: Jacob Helwig <jacob@puppetlabs.com>
* Fix tests with "relative" paths on WindowsJosh Cooper2011-07-191-3/+6
| | | | | | | | | | | | | Absolute paths on Unix, e.g. /foo/bar, are not absolute on Windows, which breaks many test cases. This commit adds a method to PuppetSpec::Files.make_absolute that makes the path absolute in test cases. On Unix (Puppet.features.posix?) it is a no-op. On Windows, (Puppet.features.microsoft_windows?) the drive from the current working directory is prepended. Reviewed-by: Jacob Helwig <jacob@puppetlabs.com>
* Fixing a failing test because of mismatched error stringLuke Kanies2011-07-151-1/+1
| | | | | Signed-off-by: Luke Kanies <luke@puppetlabs.com> Reviewed-by: Nick Lewis <nick@puppetlabs.com>
* Adding []/[]= support to ScopeLuke Kanies2011-07-152-15/+7
| | | | | | | | | | | | | | | | | | The interface to scope is much clearer this way anyway, but this is needed to integrate Puppet with Hiera[1]. It just provides hash-like behavior to Scope, which Hiera and others can now easily rely on. I also went through all of the code that used Scope#lookupvar and Scope#setvar and changed it if possible, and at the same time cleaned up a lot of tests that were unnecessarily stubbing (and thus making it difficult to tell if I had actually broken anything). 1 - https://github.com/ripienaar/hiera Signed-off-by: Luke Kanies <luke@puppetlabs.com> Reviewed-by: Nick Lewis <nick@puppetlabs.com>
* (#7507) Add ability to filter Ruby 1.9 spec failuresMatt Robinson2011-05-174-7/+7
| | | | | | | | | | | | | | | By running: rspec spec --tag ~@fails_on_ruby_1.9.2 We can now just run the specs that pass under Ruby 1.9. Obviously in the long term we want to have all the specs passing, but until then we need notification when we regress. From now on new code will be required to pass under Ruby 1.9, and Jenkins will give us email notification if it doesn't or if we break something that was already working. Reviewed-by: Daniel Pittman <daniel@puppetlabs.com>
* maint: clean up the spec test headers in bulk.Daniel Pittman2011-04-1315-30/+15
| | | | | | | We now use a shebang of: #!/usr/bin/env rspec This enables the direct execution of spec tests again, which was lost earlier during the transition to more directly using the rspec2 runtime environment.
* Fix for #5063 -- explicitly scope internal variable lookupsMarkus Roberts2011-04-122-15/+15
| | | | | When we lookup a global variable / fact from code we should explicitly look in the global scope.
* maint: just require 'spec_helper', thanks rspec2Daniel Pittman2011-04-0816-16/+16
| | | | | | | | | | | rspec2 automatically sets a bunch of load-path stuff we were by hand, so we can just stop. As a side-effect we can now avoid a whole pile of stupid things to try and include the spec_helper.rb file... ...and then we can stop protecting spec_helper from evaluating twice, since we now require it with a consistent name. Yay. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
* (5200) -- replace containers with sentinalsMarkus Roberts2011-04-061-17/+19
| | | | | | | | | | | | | | | | | | | | | This commit removes the last remaining use of topsort (in SimpleGraph#splice!) by fixing #5200 in a way that is compatible with graph fontiers. Instead of replacing containers with many-to-many relationships, we now replace them with a pair of sentinals (whits) that bracket them. Thus a graph consisting of two containers, each containing ten resources, and a dependency between the containers, which would have gone from 21 edges to 100 edges will instead have only 43, and a graph consisting of two containers (e.g. stages) each containing a similar graph, which would have gone from 45 edges to 400 will only go to 95. This change had minor consequences on many parts of the system and required lots of small changes for consistancy, but the core of it is in Catelog#splice! (which replaces SimpleGraph#splice!) and Transaction#eval_generate. Everything else is just adjustments to the fact that some one-step edges are now two-step edges and tests, event propagation, etc. need to reflect that. Paired-with: Jesse Wolfe
* Merge branch 'feature/2.6.next/5909' of https://github.com/bodepd/puppet ↵Jesse Wolfe2011-03-291-0/+135
|\ | | | | | | into next
| * (5909) Function to dyncamically generate resources.Dan Bode2011-03-161-0/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This function allows you to dynamically generate resources, passing them as a hash to the create_resources function. This was originally written to be used together with an ENC. Resources can be programitally generated as yaml and passed to a class. classes: webserver::instances: instances: instance1: foo: bar instance2: foo: blah Then puppet code can consume the hash parameters and convert then into resources class webserver::instances ( $instances = {} ) { create_resources('webserver::instance', $instances) } Now I can dynamically determine how webserver instances are deployed to nodes by updating the YAML files.
* | (#6722) load all functions before testing...Daniel Pittman2011-03-1615-4/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We historically had a state-dependency across tests in the parser function support area; the first test caused the function to be loaded, and other tests would then fail as a consequence of that. We now autoload all functions at the top of each test suite, allowing us to correctly and sensibly test on them as we should. This theoretically prevents us from testing the autoloader implicitly in these tests, but that should be tested independently. Paired-With: Nick Lewis <nick@puppetlabs.com>
* | maint: Use expand_path when requiring spec_helper or puppettestMatt Robinson2010-12-0615-15/+15
|/ | | | | | | | | Doing a require to a relative path can cause files to be required more than once when they're required from different relative paths. If you expand the path fully, this won't happen. Ruby 1.9 also requires that you use expand_path when doing these requires. Paired-with: Jesse Wolfe
* [#4370] Fixes extlookup precedence getting overwritten between runsMatt Robinson2010-08-031-3/+13
| | | | | | | | | | | | | | | We found the gsub! in extlookup was actually modifying the value for extlookup_precedence, so the next node to call it just got the interpolated value from the first run. We did two things in the code to prevent this: 1. We returned a dup of the ast string object so that modifying it wouldn’t change puppet’s state. We didn’t do this for all possible return values because we depend on using the original ast array object to do array concatenation 2. We fixed extlookup to not do a destructive gsub Reviewed by: Jesse Wolfe
* [#4397]+[#4344] Move type-name resolution out of Puppet::Resource into the ↵Jesse Wolfe2010-08-032-1/+2
| | | | | | | | | | | | | | | | | | AST resources. Move type-name resolution out of Puppet::Resource into the AST resources. Move find_resource_type out of Puppet::Resource into Scope Thus, never pass unqualified type names to Puppet::Resource objects. Thus, Puppet::Resource objects don't need the namespace property, and Puppet::Resource objects never consult the harddrive to look for .pp files that might contain their type definitions, Thus, performance is improved. Also removes the temporary fix for #4257 that caused #4397 (The code was too eager to look for a class in the topscope) Paired-With: Paul Berry <paul@puppetlabs.com> Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
* [#4242] Fixed (removed) a broken unit testNick Lewis2010-08-031-22/+0
| | | | | This test ran into a mocha bug, and was stubbing too much anyway. It's being moved to an acceptance test.
* extlookup() is a builtinJesse Wolfe2010-07-251-0/+85
| | | | | | This patch promotes extlookup() to being a builtin function. It also adds test and makes some minor tweaks to the code. The behavior of extlookup has been left unchanged.
* Temporary tweak to tests for #4242Markus Roberts2010-07-251-0/+5
| | | | | | | The tests introduced with the fix for #4242 have isolation issues apparently due to the creation of a stage resource which is global and persistent. This patch stubs the creation, marks the one test which is thus invalidated pending, and adds comments noting the problem.
* [#4242] Fixed recursion due to parents including their childrenNick Lewis2010-07-251-0/+50
| | | | | | | | | | | | | | | Resources mark themselves as evaluated to prevent being evaluated again. Unfortunately, they were not marking themselves until after they had finished being completely evaluated. Thus, there was nothing actually stopping recursive evaluations. This patch just makes resources mark themselves as evaluated when they start evaluating, and adds tests. The original setting of evaluated was done in an ensure block, so this doesn't change the behavior of a resource which fails to evaluate. The only places evaluated? is checked aren't affected by this change, as they wouldn't want to evaluate it when it's already being evaluated anyway.
* Code smell: Two space indentationMarkus Roberts2010-07-0913-596/+596
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
* Code smell: Avoid needless decorationsMarkus Roberts2010-07-0912-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 704 occurances of (.*)\b([a-z_]+)\(\) with \1\2 3 Examples: The code: ctx = OpenSSL::SSL::SSLContext.new() becomes: ctx = OpenSSL::SSL::SSLContext.new The code: skip() becomes: skip The code: path = tempfile() becomes: path = tempfile * Replaced 31 occurances of ^( *)end *#.* with \1end 3 Examples: The code: becomes: The code: end # Dir.foreach becomes: end The code: end # def becomes: end
* Code smell: Use string interpolationMarkus Roberts2010-07-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 83 occurances of (.*)" *[+] *([$@]?[\w_0-9.:]+?)(.to_s\b)?(?! *[*(%\w_0-9.:{\[]) with \1#{\2}" 3 Examples: The code: puts "PUPPET " + status + ": " + process + ", " + state becomes: puts "PUPPET " + status + ": " + process + ", #{state}" The code: puts "PUPPET " + status + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" The code: }.compact.join( "\n" ) + "\n" + t + "]\n" becomes: }.compact.join( "\n" ) + "\n#{t}" + "]\n" * Replaced 21 occurances of (.*)" *[+] *" with \1 3 Examples: The code: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}, #{state}" The code: puts "PUPPET #{status}" + ": #{process}, #{state}" becomes: puts "PUPPET #{status}: #{process}, #{state}" The code: res = self.class.name + ": #{@name}" + "\n" becomes: res = self.class.name + ": #{@name}\n" * Don't use string concatenation to split lines unless they would be very long. Replaced 11 occurances of (.*)(['"]) *[+] *(['"])(.*) with 3 Examples: The code: o.define_head "The check_puppet Nagios plug-in checks that specified " + "Puppet process is running and the state file is no " + becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + The code: o.separator "Mandatory arguments to long options are mandatory for " + "short options too." becomes: o.separator "Mandatory arguments to long options are mandatory for short options too." The code: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + "older than specified interval." becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no older than specified interval." * Replaced no occurances of do (.*?) end with {\1} * Replaced 1488 occurances of "([^"\n]*%s[^"\n]*)" *% *(.+?)(?=$| *\b(do|if|while|until|unless|#)\b) with 20 Examples: The code: args[0].split(/\./).map do |s| "dc=%s"%[s] end.join(",") becomes: args[0].split(/\./).map do |s| "dc=#{s}" end.join(",") The code: puts "%s" % Puppet.version becomes: puts "#{Puppet.version}" The code: raise "Could not find information for %s" % node becomes: raise "Could not find information for #{node}" The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create #{dir}: basedir #{File.join(path)} is a file" The code: Puppet.err "Could not run %s: %s" % [client_class, detail] becomes: Puppet.err "Could not run #{client_class}: #{detail}" The code: raise "Could not find handler for %s" % arg becomes: raise "Could not find handler for #{arg}" The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}" The code: raise Puppet::Error, "Could not deserialize catalog from pson: %s" % detail becomes: raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}" The code: raise "Could not find facts for %s" % Puppet[:certname] becomes: raise "Could not find facts for #{Puppet[:certname]}" The code: raise ArgumentError, "%s is not readable" % path becomes: raise ArgumentError, "#{path} is not readable" The code: raise ArgumentError, "Invalid handler %s" % name becomes: raise ArgumentError, "Invalid handler #{name}" The code: debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str] becomes: debug "Executing '#{command}' in zone #{@resource[:name]} with '#{str}'" The code: raise Puppet::Error, "unknown cert type '%s'" % hash[:type] becomes: raise Puppet::Error, "unknown cert type '#{hash[:type]}'" The code: Puppet.info "Creating a new certificate request for %s" % Puppet[:certname] becomes: Puppet.info "Creating a new certificate request for #{Puppet[:certname]}" The code: "Cannot create alias %s: object already exists" % [name] becomes: "Cannot create alias #{name}: object already exists" The code: return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum] becomes: return "replacing from source #{metadata.source} with contents #{metadata.checksum}" The code: it "should have a %s parameter" % param do becomes: it "should have a #{param} parameter" do The code: describe "when registring '%s' messages" % log do becomes: describe "when registring '#{log}' messages" do The code: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l } becomes: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" } The code: assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do becomes: assert_raise(Puppet::Error, "Check '#{check}' did not fail on false") do
* Code smell: Inconsistent indentation and related formatting issuesMarkus Roberts2010-07-095-103/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Replaced 163 occurances of defined\? +([@a-zA-Z_.0-9?=]+) with defined?(\1) This makes detecting subsequent patterns easier. 3 Examples: The code: if ! defined? @parse_config becomes: if ! defined?(@parse_config) The code: return @option_parser if defined? @option_parser becomes: return @option_parser if defined?(@option_parser) The code: if defined? @local and @local becomes: if defined?(@local) and @local * Eliminate trailing spaces. Replaced 428 occurances of ^(.*?) +$ with \1 1 file was skipped. test/ral/providers/host/parsed.rb because 0 * Replace leading tabs with an appropriate number of spaces. Replaced 306 occurances of ^(\t+)(.*) with Tabs are not consistently expanded in all environments. * Don't arbitrarily wrap on sprintf (%) operator. Replaced 143 occurances of (.*['"] *%) +(.*) with Splitting the line does nothing to aid clarity and hinders further refactorings. 3 Examples: The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] The code: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus] becomes: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus] * Don't break short arrays/parameter list in two. Replaced 228 occurances of (.*) +(.*) with 3 Examples: The code: puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true) becomes: puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true) The code: assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type) becomes: assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type) The code: assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk") becomes: assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk") * If arguments must wrap, treat them all equally Replaced 510 occurances of lines ending in things like ...(foo, or ...(bar(1,3), with \1 \2 3 Examples: The code: midscope.to_hash(false), becomes: assert_equal( The code: botscope.to_hash(true), becomes: # bottomscope, then checking that we see the right stuff. The code: :path => link, becomes: * Replaced 4516 occurances of ^( *)(.*) with The present code base is supposed to use four-space indentation. In some places we failed to maintain that standard. These should be fixed regardless of the 2 vs. 4 space question. 15 Examples: The code: def run_comp(cmd) puts cmd results = [] old_sync = $stdout.sync $stdout.sync = true line = [] begin open("| #{cmd}", "r") do |f| until f.eof? do c = f.getc becomes: def run_comp(cmd) puts cmd results = [] old_sync = $stdout.sync $stdout.sync = true line = [] begin open("| #{cmd}", "r") do |f| until f.eof? do c = f.getc The code: s.gsub!(/.{4}/n, '\\\\u\&') } string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } string.gsub!(/( becomes: s.gsub!(/.{4}/n, '\\\\u\&') } string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } string.gsub!(/( The code: end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } becomes: end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } The code: #passwdproc = proc { @password } keytext = @key.export( OpenSSL::Cipher::DES.new(:EDE3, :CBC), @password ) File.open(@keyfile, "w", 0400) { |f| f << keytext } becomes: # passwdproc = proc { @password } keytext = @key.export( OpenSSL::Cipher::DES.new(:EDE3, :CBC), @password ) File.open(@keyfile, "w", 0400) { |f| f << keytext } The code: end def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") becomes: end def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") The code: via the augeas tool. Requires: - augeas to be installed (http://www.augeas.net) - ruby-augeas bindings Sample usage with a string:: augeas{\"test1\" : context => \"/files/etc/sysconfig/firstboot\", changes => \"set RUN_FIRSTBOOT YES\", becomes: via the augeas tool. Requires: - augeas to be installed (http://www.augeas.net) - ruby-augeas bindings Sample usage with a string:: augeas{\"test1\" : context => \"/files/etc/sysconfig/firstboot\", changes => \"set RUN_FIRSTBOOT YES\", The code: names.should_not be_include("root") end describe "when generating a purgeable resource" do it "should be included in the generated resources" do Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource] @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref) end end describe "when the instance's do not have an ensure property" do becomes: names.should_not be_include("root") end describe "when generating a purgeable resource" do it "should be included in the generated resources" do Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource] @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref) end end describe "when the instance's do not have an ensure property" do The code: describe "when the instance's do not have an ensure property" do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref) end end describe "when the instance's ensure property does not accept absent" do it "should not be included in the generated resources" do @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar') becomes: describe "when the instance's do not have an ensure property" do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref) end end describe "when the instance's ensure property does not accept absent" do it "should not be included in the generated resources" do @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar') The code: func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) becomes: func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) The code: assert( @store.allowed?("hostname.madstop.com", "192.168.1.50"), "hostname not allowed") assert( ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") becomes: assert( @store.allowed?("hostname.madstop.com", "192.168.1.50"), "hostname not allowed") assert( ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") The code: assert_nothing_raised { server = Puppet::Network::Handler.fileserver.new( :Local => true, :Config => false ) } becomes: assert_nothing_raised { server = Puppet::Network::Handler.fileserver.new( :Local => true, :Config => false ) } The code: 'yay', { :failonfail => false, :uid => @user.uid, :gid => @user.gid } ).returns('output') output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid becomes: 'yay', { :failonfail => false, :uid => @user.uid, :gid => @user.gid } ).returns('output') output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid The code: ).times(1) pkg.provider.expects( :aptget ).with( '-y', '-q', 'remove', 'faff' becomes: ).times(1) pkg.provider.expects( :aptget ).with( '-y', '-q', 'remove', 'faff' The code: johnny one two billy three four\n" # Just parse and generate, to make sure it's isomorphic. assert_nothing_raised do assert_equal(text, @parser.to_file(@parser.parse(text)), "parsing was not isomorphic") end end def test_valid_attrs becomes: johnny one two billy three four\n" # Just parse and generate, to make sure it's isomorphic. assert_nothing_raised do assert_equal(text, @parser.to_file(@parser.parse(text)), "parsing was not isomorphic") end end def test_valid_attrs The code: "testing", :onboolean => [true, "An on bool"], :string => ["a string", "A string arg"] ) result = [] should = [] assert_nothing_raised("Add args failed") do @config.addargs(result) end @config.each do |name, element| becomes: "testing", :onboolean => [true, "An on bool"], :string => ["a string", "A string arg"] ) result = [] should = [] assert_nothing_raised("Add args failed") do @config.addargs(result) end @config.each do |name, element|
* [#3994-part 3] rename spec tests from *_spec_spec to *_spec.rbMarkus Roberts2010-06-2813-0/+0
| | | | Part 2 re-did the change on the spec files, which it shouldn't have.
* [#3994-part 2] rename integration tests to *_spec.rbMarkus Roberts2010-06-2813-0/+0
| | | | | | | | | Some spec files like active_record.rb had names that would confuse the load path and get loaded instead of the intended implentation when the spec was run from the same directory as the file. Author: Matt Robinson <matt@puppetlabs.com> Date: Fri Jun 11 15:29:33 2010 -0700
* [#3994] rename the specs to have _spec.rb at the endMarkus Roberts2010-06-2313-0/+0
| | | | | | | | | Some spec files like active_record.rb had names that would confuse the load path and get loaded instead of the intended implentation when the spec was run from the same directory as the file. Author: Matt Robinson <matt@puppetlabs.com> Date: Fri Jun 11 15:29:33 2010 -0700
* Part 2 of fix for #1175 (functions in environments)Markus Roberts2010-02-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Jesse and I are shooting for the minimal viable fix here, with the idea that a great deal of refactoring is needed but isn't appropriate at this time. The changes in this commit are: * Index the function-holding modules by environment * We need to know the "current environment" when we're defining a function so we can attach it to the proper module, and this information isn't dynamically available when user-defined functions are being created (we're being called by user written code that doesn't "know" about environments) so we cheat and stash the value in Puppet::Node::Environment * since we must do this anyway, it turns out to be cleaner & safer to do the same when we are evaluating a functon. This is the main change from the prior version of this patch. * Add a special *root* environment for the built in functions, and extend all scopes with it. * Index the function characteristics (name, type, docstring, etc.) by environment * Make the autoloader environment aware, so that it uses the modulepath for the specified environment rather than the default * Turn off caching of the modulepath since it potentially changes for each node * Tweak tests that weren't environment aware
* Fixes #3295 - generate() now sets the working directory to the directory ↵Paul Lathrop2010-02-171-0/+41
| | | | | | containing the specified command. Also adds rspec tests for generate().
* Fixing all 'require' function testsLuke Kanies2010-04-091-7/+12
| | | | | | | This involved making some tests better, but mostly just involved fixing calls to use new APIs and such. Signed-off-by: Luke Kanies <luke@puppetlabs.com>
* Removing Resource::Reference classesLuke Kanies2010-02-173-1/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit is hopefully less messy than it first appears, but it's certainly cross-cutting. The reason for all of this is that we previously only looked up builtin resource types from outside the parser, but now that the defined resource types are available globally via environments, we can push that lookup code to Resource. Once we do that, however, we have to have environment and namespace information in every resource. Here I remove the Resource::Reference classes (except the AST class), and use Resource instances instead. I did this because the shared code between the two classes got incredibly complicated, such that they should have had a hierarchical relationship disallowed by their constants. This complexity convinced me just to get rid of References entirely. I also make Puppet::Parser::Resource a subclass of Puppet::Resource. There are still broken tests in test/, but this was a big enough commit I wanted to get it in. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
* Fixing "require" function to use new class interfaceLuke Kanies2010-02-171-2/+2
| | | | Signed-off-by: Luke Kanies <luke@reductivelabs.com>
* Fix #3186 - require function set relationship only on the last classBrice Figureau2010-02-171-2/+12
| | | | | | | | Due to the fact that resource.set_parameter is overwriting the previous set_parameters, we were losing the previous relationships we set there, either in a previous call of require or in the same call. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #3150 - require function doesn't like ::class syntaxBrice Figureau2010-02-171-0/+11
| | | | Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fixing #2752 - "require" loads "include"Luke Kanies2009-10-261-0/+6
| | | | Signed-off-by: Luke Kanies <luke@madstop.com>
* Fixing #2632 - 'require' works for 0.25 clientsLuke Kanies2009-09-221-7/+13
| | | | | | | | I couldn't find a way to make it compatible with earlier clients, so the docs specify that it doesn't work with them, and it helpfully fails. Signed-off-by: Luke Kanies <luke@madstop.com>
* Merged fix for #2601Markus Roberts2009-09-161-0/+62
| | | | | | | | | | | This patch rolls up the changeses discussed on the list & the ticket The fqdn_rand now takes any number of additional arguments of any type that has a string representation (typically integers or strings) and concatenats them on to the salt. The tests have been adjusted to reflect this. Signed-off-by: Markus Roberts <Markus@reality.com>
* Make regsubst() function operate on arrays (feature #2491).Thomas Bellman2009-09-151-0/+80
| | | | | | | | | | | Allow the first argument to the regsubst() function be an array, and perform regexp replacement on each element of the array in that case. This patch also adds more error checking to give better error messages to the user when given bad parameters. Signed-off-by: Thomas Bellman <bellman@nsc.liu.se>
* Add shellquote() function.Thomas Bellman2009-08-081-0/+92
| | | | | | | | | | This adds a new function shellquote() which can be used for quoting arguments in shell commands used in the exec type. This only supports Unixoid operating systems. Other systems would likely require some other quoting. Signed-off-by: Thomas Bellman <bellman@nsc.liu.se>
* Updated split function and add split function unit tests (courtesy of Thomas ↵James Turnbull2009-06-125-0/+51
| | | | Bellman)
* Fix #1907 (or sort) - 'require' puppet functionBrice Figureau2009-06-101-0/+36
| | | | | | | | This function acts exactly as the 'include' function, but also adds an ordering relation between the included class and the class where the require function is. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Removed extra whitespace from end of linesIan Taylor2009-06-061-2/+2
|
* Changed tabs to spaces without interfering with indentation or alignmentIan Taylor2009-06-062-53/+53
|
* Merge branch '0.24.x'Luke Kanies2009-02-132-0/+130
|\ | | | | | | | | | | | | | | | | | | Conflicts: lib/puppet/indirector/facts/facter.rb lib/puppet/provider/augeas/augeas.rb lib/puppet/util/filetype.rb spec/unit/indirector/facts/facter.rb spec/unit/provider/augeas/augeas.rb test/util/filetype.rb
| * Fixed #1831 - Added sprintf functionJames Turnbull2009-02-141-0/+42
| |
| * Fixed #1830 - Added regsubst functionJames Turnbull2009-02-141-0/+88
| |
* | Merge branch '0.24.x'Luke Kanies2009-02-111-0/+51
|\| | | | | | | | | | | Conflicts: CHANGELOG spec/unit/type/file/selinux.rb
| * Fix #1691 - Realize fails with array of Resource ReferencesBrice Figureau2009-02-111-0/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following snippet: realize( File["/tmp/a","/tmp/b"] ) is parsed into: AST::Function @name=realize @arguments= AST::ASTArray @children = [ AST::ResourceReference @title= AST::ASTArray @children = [ String(/tmp/a), String(/tmp/b) ] ] When evaluated: ResourceReference gives -> [ File[/tmp/a], File[/tmp/b] ] which means the function arguments are: [[File[/tmp/a], File[/tmp/b]] after evaluating the @arguments ASTArray of AST::Functions. Then the collector complains that it can't find the resource because it is not supposed to work on non-flattened resource array. The fix is to flatten in the realize function (although it can be done more generally in the AST::Function evaluation) before the resources are given to the Collector. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* | Fix #1829 - Add puppet function versioncmp to compare versionsBrice Figureau2008-12-271-0/+29
|/ | | | Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
* Fix #1741 - Add inline_template functionBrice Figureau2008-11-291-0/+59
|
* Fix #1741 - refactor TemplateWrapper, test for template functionBrice Figureau2008-11-291-0/+62