diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-05-03 20:45:25 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-05-03 20:45:25 +0000 |
| commit | 0c07125397428a0c1ca9a4a4d0176f45d8be0979 (patch) | |
| tree | 1b390027a563b47a26341b439288b81473c6cdcf | |
| parent | 8d7ec14836809f1433e645c3069691d2f6c70e52 (diff) | |
| download | puppet-0c07125397428a0c1ca9a4a4d0176f45d8be0979.tar.gz puppet-0c07125397428a0c1ca9a4a4d0176f45d8be0979.tar.xz puppet-0c07125397428a0c1ca9a4a4d0176f45d8be0979.zip | |
Fixing #615 (subclasses with similar names) by getting rid of the class "type" and "fqname", and instead using "classname" everywhere. You should no longer see unqualified class/definition names anywhere. Also, rewriting how snippet tests work, to avoid creating all of the files, since the point was the parsing tests, not functional tests.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2458 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/puppet/parser/ast/component.rb | 20 | ||||
| -rw-r--r-- | lib/puppet/parser/grammar.ra | 28 | ||||
| -rw-r--r-- | lib/puppet/parser/interpreter.rb | 48 | ||||
| -rw-r--r-- | lib/puppet/parser/parser.rb | 18 | ||||
| -rw-r--r-- | lib/puppet/parser/scope.rb | 14 | ||||
| -rw-r--r-- | test/data/snippets/dirchmod | 15 | ||||
| -rw-r--r-- | test/data/snippets/failmissingexecpath.pp | 3 | ||||
| -rwxr-xr-x | test/data/snippets/subclass_name_duplication.pp | 11 | ||||
| -rwxr-xr-x | test/language/ast/component.rb | 9 | ||||
| -rwxr-xr-x | test/language/interpreter.rb | 22 | ||||
| -rwxr-xr-x | test/language/node.rb | 2 | ||||
| -rwxr-xr-x | test/language/parser.rb | 6 | ||||
| -rwxr-xr-x | test/language/scope.rb | 2 | ||||
| -rwxr-xr-x | test/language/snippets.rb | 264 |
14 files changed, 212 insertions, 250 deletions
diff --git a/lib/puppet/parser/ast/component.rb b/lib/puppet/parser/ast/component.rb index 058d8d871..6a309ac8c 100644 --- a/lib/puppet/parser/ast/component.rb +++ b/lib/puppet/parser/ast/component.rb @@ -15,8 +15,8 @@ class Puppet::Parser::AST # The class name @name = :definition - attr_accessor :type, :arguments, :code, :scope, :keyword - attr_accessor :exported, :namespace, :fqname, :interp + attr_accessor :classname, :arguments, :code, :scope, :keyword + attr_accessor :exported, :namespace, :interp # These are retrieved when looking up the superclass attr_accessor :name @@ -27,7 +27,6 @@ class Puppet::Parser::AST def evaluate(hash) origscope = hash[:scope] - objtype = hash[:type] title = hash[:title] args = symbolize_options(hash[:arguments] || {}) @@ -44,8 +43,8 @@ class Puppet::Parser::AST # Additionally, add a tag for whatever kind of class # we are - if @type != "" and ! @type.nil? - scope.tag(@type) + if @classname != "" and ! @classname.nil? + @classname.split(/::/).each { |tag| scope.tag(tag) } end [name, title].each do |str| @@ -68,7 +67,7 @@ class Puppet::Parser::AST # [default.inspect, arg.inspect, @name.inspect] else parsefail "Must pass %s to %s of type %s" % - [arg,title,@type] + [arg,title,@classname] end end } @@ -78,7 +77,7 @@ class Puppet::Parser::AST # component's scope. args.each { |arg,value| unless validattr?(arg) - parsefail "%s does not accept attribute %s" % [@type, arg] + parsefail "%s does not accept attribute %s" % [@classname, arg] end exceptwrap do @@ -142,7 +141,7 @@ class Puppet::Parser::AST # Set our parent class, with a little check to avoid some potential # weirdness. def parentclass=(name) - if name == self.type + if name == self.classname parsefail "Parent classes must have dissimilar names" end @@ -173,13 +172,12 @@ class Puppet::Parser::AST # Create a new subscope in which to evaluate our code. def subscope(scope, name = nil) args = { - :type => @type, + :type => self.classname, :keyword => self.keyword, :namespace => self.namespace } args[:name] = name if name - args[:type] = self.type if self.type scope = scope.newscope(args) scope.source = self @@ -187,7 +185,7 @@ class Puppet::Parser::AST end def to_s - fqname + classname end # Check whether a given argument is valid. Searches up through diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 2a962822b..16aa10459 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -111,7 +111,7 @@ resourcerefs: resourceref result = val[0] } -resource: fqname LBRACE resourceinstances endsemi RBRACE { +resource: classname LBRACE resourceinstances endsemi RBRACE { array = val[2] if array.instance_of?(AST::ResourceInst) array = [array] @@ -130,7 +130,7 @@ resource: fqname LBRACE resourceinstances endsemi RBRACE { :title => instance[0], :params => instance[1]) } -} | fqname LBRACE params endcomma RBRACE { +} | classname LBRACE params endcomma RBRACE { # This is a deprecated syntax. error "All resource specifications require names" } | TYPE LBRACE params endcomma RBRACE { @@ -466,28 +466,28 @@ import: IMPORT qtexts { # Disable definition inheritance for now. 8/27/06, luke #definition: DEFINE NAME argumentlist parent LBRACE statements RBRACE { -definition: DEFINE fqname argumentlist LBRACE statements RBRACE { - interp.newdefine fqname(val[1]), :arguments => val[2], :code => val[4] +definition: DEFINE classname argumentlist LBRACE statements RBRACE { + interp.newdefine classname(val[1]), :arguments => val[2], :code => val[4] @lexer.indefine = false result = nil #} | DEFINE NAME argumentlist parent LBRACE RBRACE { -} | DEFINE fqname argumentlist LBRACE RBRACE { - interp.newdefine fqname(val[1]), :arguments => val[2] +} | DEFINE classname argumentlist LBRACE RBRACE { + interp.newdefine classname(val[1]), :arguments => val[2] @lexer.indefine = false result = nil } #hostclass: CLASS NAME argumentlist parent LBRACE statements RBRACE { -hostclass: CLASS fqname classparent LBRACE statements RBRACE { +hostclass: CLASS classname classparent LBRACE statements RBRACE { # Our class gets defined in the parent namespace, not our own. @lexer.namepop - interp.newclass fqname(val[1]), :code => val[4], :parent => val[2] + interp.newclass classname(val[1]), :code => val[4], :parent => val[2] result = nil -} | CLASS fqname classparent LBRACE RBRACE { +} | CLASS classname classparent LBRACE RBRACE { # Our class gets defined in the parent namespace, not our own. @lexer.namepop - interp.newclass fqname(val[1]), :parent => val[2] + interp.newclass classname(val[1]), :parent => val[2] result = nil } @@ -499,7 +499,7 @@ nodedef: NODE hostnames nodeparent LBRACE statements RBRACE { result = nil } -fqname: NAME +classname: NAME | CLASSNAME # Multiple hostnames, as used for node names. These are all literal @@ -558,12 +558,12 @@ nodeparent: nil } classparent: nil - | INHERITS fqnameordefault { + | INHERITS classnameordefault { result = val[1] } nameordefault: NAME | DEFAULT -fqnameordefault: fqname | DEFAULT +classnameordefault: classname | DEFAULT variable: VARIABLE { result = ast AST::Variable, :value => val[0] @@ -746,7 +746,7 @@ def initvars end # The fully qualifed name, with the full namespace. -def fqname(name) +def classname(name) [@lexer.namespace, name].join("::").sub(/^::/, '') end diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 641e69cf3..9391ec866 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -321,7 +321,7 @@ class Puppet::Parser::Interpreter arghash = { :name => name, :interp => self, - :fqname => name + :classname => name } if (classes.is_a?(Array) and classes.empty?) or classes.nil? @@ -528,20 +528,20 @@ class Puppet::Parser::Interpreter end # Create a new class, or merge with an existing class. - def newclass(fqname, options = {}) - fqname = fqname.downcase - if @definetable.include?(fqname) + def newclass(name, options = {}) + name = name.downcase + if @definetable.include?(name) raise Puppet::ParseError, "Cannot redefine class %s as a definition" % - fqname + name end code = options[:code] parent = options[:parent] # If the class is already defined, then add code to it. - if other = @classtable[fqname] + if other = @classtable[name] # Make sure the parents match if parent and other.parentclass and (parent != other.parentclass) - @parser.error("Class %s is already defined at %s:%s; cannot redefine" % [fqname, other.file, other.line]) + @parser.error("Class %s is already defined at %s:%s; cannot redefine" % [name, other.file, other.line]) end # This might be dangerous... @@ -551,7 +551,7 @@ class Puppet::Parser::Interpreter # This might just be an empty, stub class. if code - tmp = fqname + tmp = name if tmp == "" tmp = "main" end @@ -566,46 +566,43 @@ class Puppet::Parser::Interpreter end else # Define it anew. - ns, name = namesplit(fqname) - # Note we're doing something somewhat weird here -- we're setting # the class's namespace to its fully qualified name. This means # anything inside that class starts looking in that namespace first. - args = {:type => name, :namespace => fqname, :fqname => fqname, :interp => self} + args = {:namespace => name, :classname => name, :interp => self} args[:code] = code if code args[:parentclass] = parent if parent - @classtable[fqname] = @parser.ast AST::HostClass, args + @classtable[name] = @parser.ast AST::HostClass, args end - return @classtable[fqname] + return @classtable[name] end # Create a new definition. - def newdefine(fqname, options = {}) - fqname = fqname.downcase - if @classtable.include?(fqname) + def newdefine(name, options = {}) + name = name.downcase + if @classtable.include?(name) raise Puppet::ParseError, "Cannot redefine class %s as a definition" % - fqname + name end # Make sure our definition doesn't already exist - if other = @definetable[fqname] - @parser.error("%s is already defined at %s:%s; cannot redefine" % [fqname, other.file, other.line]) + if other = @definetable[name] + @parser.error("%s is already defined at %s:%s; cannot redefine" % [name, other.file, other.line]) end - ns, name = namesplit(fqname) + ns, whatever = namesplit(name) args = { - :type => name, :namespace => ns, :arguments => options[:arguments], :code => options[:code], - :fqname => fqname + :classname => name } [:code, :arguments].each do |param| args[param] = options[param] if options[param] end - @definetable[fqname] = @parser.ast AST::Component, args + @definetable[name] = @parser.ast AST::Component, args end # Create a new node. Nodes are special, because they're stored in a global @@ -628,8 +625,7 @@ class Puppet::Parser::Interpreter args[:parentclass] = options[:parent] end @nodetable[name] = @parser.ast(AST::Node, args) - @nodetable[name].fqname = name - @nodetable[name] + @nodetable[name].classname = name @nodetable[name].interp = self @nodetable[name] end @@ -700,7 +696,7 @@ class Puppet::Parser::Interpreter end if output =~ /\A\s+\Z/ # all whitespace - puts "empty response for %s" % name + Puppet.debug "Empty response for %s from external node source" % name return nil end diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index eb296de31..ee8470a26 100644 --- a/lib/puppet/parser/parser.rb +++ b/lib/puppet/parser/parser.rb @@ -29,7 +29,7 @@ module Puppet class Parser < Racc::Parser -module_eval <<'..end grammar.ra modeval..id2ea020a302', 'grammar.ra', 606 +module_eval <<'..end grammar.ra modeval..id70ce3bc052', 'grammar.ra', 606 require 'puppet/parser/functions' attr_reader :file, :interp @@ -173,7 +173,7 @@ def initvars end # The fully qualifed name, with the full namespace. -def fqname(name) +def classname(name) [@lexer.namespace, name].join("::").sub(/^::/, '') end @@ -254,7 +254,7 @@ end # $Id$ -..end grammar.ra modeval..id2ea020a302 +..end grammar.ra modeval..id70ce3bc052 ##### racc 1.4.5 generates ### @@ -829,7 +829,7 @@ Racc_token_to_s_table = [ 'variable', 'quotedtext', 'resourceref', -'fqname', +'classname', 'resourceinstances', 'endsemi', 'params', @@ -873,7 +873,7 @@ Racc_token_to_s_table = [ 'arguments', 'argument', 'nameordefault', -'fqnameordefault'] +'classnameordefault'] Racc_debug_parser = false @@ -1570,7 +1570,7 @@ module_eval <<'.,.,', 'grammar.ra', 465 module_eval <<'.,.,', 'grammar.ra', 475 def _reduce_122( val, _values, result ) - interp.newdefine fqname(val[1]), :arguments => val[2], :code => val[4] + interp.newdefine classname(val[1]), :arguments => val[2], :code => val[4] @lexer.indefine = false result = nil @@ -1581,7 +1581,7 @@ module_eval <<'.,.,', 'grammar.ra', 475 module_eval <<'.,.,', 'grammar.ra', 479 def _reduce_123( val, _values, result ) - interp.newdefine fqname(val[1]), :arguments => val[2] + interp.newdefine classname(val[1]), :arguments => val[2] @lexer.indefine = false result = nil result @@ -1592,7 +1592,7 @@ module_eval <<'.,.,', 'grammar.ra', 487 def _reduce_124( val, _values, result ) # Our class gets defined in the parent namespace, not our own. @lexer.namepop - interp.newclass fqname(val[1]), :code => val[4], :parent => val[2] + interp.newclass classname(val[1]), :code => val[4], :parent => val[2] result = nil result end @@ -1602,7 +1602,7 @@ module_eval <<'.,.,', 'grammar.ra', 492 def _reduce_125( val, _values, result ) # Our class gets defined in the parent namespace, not our own. @lexer.namepop - interp.newclass fqname(val[1]), :parent => val[2] + interp.newclass classname(val[1]), :parent => val[2] result = nil result end diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 25a6551af..709884296 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -123,8 +123,8 @@ class Puppet::Parser::Scope # that subclasses can set their parent scopes to be the scope of # their parent class. def class_scope(klass) - if klass.respond_to?(:fqname) - @classtable[klass.fqname] + if klass.respond_to?(:classname) + @classtable[klass.classname] else @classtable[klass] end @@ -406,7 +406,7 @@ class Puppet::Parser::Scope raise Puppet::ParseError, "Could not find class %s" % klassname end unless kscope = class_scope(klass) - raise Puppet::ParseError, "Class %s has not been evaluated so its variables cannot be referenced" % klass.fqname + raise Puppet::ParseError, "Class %s has not been evaluated so its variables cannot be referenced" % klass.classname end return kscope.lookupvar(shortname, usestring) end @@ -459,8 +459,8 @@ class Puppet::Parser::Scope end def setclass?(obj) - if obj.respond_to?(:fqname) - @classtable.has_key?(obj.fqname) + if obj.respond_to?(:classname) + @classtable.has_key?(obj.classname) else @classtable[obj] end @@ -472,11 +472,11 @@ class Puppet::Parser::Scope # can support multiple unrelated classes with the same name. def setclass(obj) if obj.is_a?(AST::HostClass) - unless obj.fqname + unless obj.classname raise Puppet::DevError, "Got a %s with no fully qualified name" % obj.class end - @classtable[obj.fqname] = self + @classtable[obj.classname] = self else raise Puppet::DevError, "Invalid class %s" % obj.inspect end diff --git a/test/data/snippets/dirchmod b/test/data/snippets/dirchmod deleted file mode 100644 index 15421ea10..000000000 --- a/test/data/snippets/dirchmod +++ /dev/null @@ -1,15 +0,0 @@ -# $Id$ - -file { - "/tmp/dirchmodtesta": ensure => directory; - "/tmp/dirchmodtesta/testing": ensure => file -} - -File["/tmp/dirchmodtesta"] { mode => 644, recurse => true } - -file { - "/tmp/dirchmodtestb": ensure => directory; - "/tmp/dirchmodtestb/testing": ensure => file -} - -File["/tmp/dirchmodtestb"] { mode => 600, recurse => true } diff --git a/test/data/snippets/failmissingexecpath.pp b/test/data/snippets/failmissingexecpath.pp index aae1a09fa..b03875547 100644 --- a/test/data/snippets/failmissingexecpath.pp +++ b/test/data/snippets/failmissingexecpath.pp @@ -2,7 +2,8 @@ define distloc($path) { file { "/tmp/exectesting1": ensure => file } - exec { "touch $path": + exec { "exectest": + command => "touch $path", subscribe => File["/tmp/exectesting1"], refreshonly => true } diff --git a/test/data/snippets/subclass_name_duplication.pp b/test/data/snippets/subclass_name_duplication.pp new file mode 100755 index 000000000..10f1d75ed --- /dev/null +++ b/test/data/snippets/subclass_name_duplication.pp @@ -0,0 +1,11 @@ +#!/usr/bin/env puppet + +class one::fake { + file { "/tmp/subclass_name_duplication1": ensure => present } +} + +class two::fake { + file { "/tmp/subclass_name_duplication2": ensure => present } +} + +include one::fake, two::fake diff --git a/test/language/ast/component.rb b/test/language/ast/component.rb index 1500aa397..40543e9ab 100755 --- a/test/language/ast/component.rb +++ b/test/language/ast/component.rb @@ -129,5 +129,14 @@ class TestASTComponent < Test::Unit::TestCase end end end + + # Testing the root cause of #615. We should be using the fqname for the type, instead + # of just the short name. + def test_fully_qualified_types + interp = mkinterp + klass = interp.newclass("one::two") + + assert_equal("one::two", klass.classname, "Class did not get fully qualified class name") + end end # $Id$ diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb index d4ecbd563..74c6e4642 100755 --- a/test/language/interpreter.rb +++ b/test/language/interpreter.rb @@ -193,7 +193,7 @@ class TestInterpreter < Test::Unit::TestCase assert(culain, "Did not find culain in ldap") assert_nothing_raised do - assert_equal(basenode.fqname.to_s, culain.parentclass.fqname.to_s, + assert_equal(basenode.classname.to_s, culain.parentclass.classname.to_s, "Did not get parent class") end end @@ -266,7 +266,7 @@ class TestInterpreter < Test::Unit::TestCase obj = interp.nodesearch("node") end assert(obj, "Did not find node") - assert_equal("node", obj.fqname) + assert_equal("node", obj.classname) end # Make sure searchnode behaves as we expect. @@ -298,14 +298,14 @@ class TestInterpreter < Test::Unit::TestCase assert_nothing_raised do default = interp.nodesearch("nosuchnode") assert(default, "Did not find default node") - assert_equal("default", default.fqname) + assert_equal("default", default.classname) end # Now make sure the longest match always wins node = interp.nodesearch(*%w{node2 node2.domain.com}) assert(node, "Did not find node2") - assert_equal("node2.domain.com", node.fqname, + assert_equal("node2.domain.com", node.classname, "Did not get longest match") end @@ -386,7 +386,7 @@ class TestInterpreter < Test::Unit::TestCase interp.newnode(:foo) # And make sure we get things back correctly - assert_equal("foo", interp.nodesearch_code("simplenode").parentclass.fqname) + assert_equal("foo", interp.nodesearch_code("simplenode").parentclass.classname) assert_nil(interp.nodesearch_code("simplenode").code) # Now make sure that trying to redefine it throws an error. @@ -497,9 +497,9 @@ class TestInterpreter < Test::Unit::TestCase mydefine = interp.finddefine("", "mydefine") assert(mydefine, "Could not find definition") - assert_equal("mydefine", interp.finddefine("", "mydefine").type) + assert_equal("mydefine", interp.finddefine("", "mydefine").classname) assert_equal("", mydefine.namespace) - assert_equal("mydefine", mydefine.type) + assert_equal("mydefine", mydefine.classname) assert_raise(Puppet::ParseError) do interp.newdefine("mydefine", :code => :yay, @@ -517,8 +517,7 @@ class TestInterpreter < Test::Unit::TestCase "Could not find other::mydefine") assert_equal(:other, other.code) assert_equal("other", other.namespace) - assert_equal("mydefine", other.type) - assert_equal("other::mydefine", other.fqname) + assert_equal("other::mydefine", other.classname) end def test_newclass @@ -543,7 +542,7 @@ class TestInterpreter < Test::Unit::TestCase assert(klass, "Did not return class") assert(interp.findclass("", "myclass"), "Could not find definition") - assert_equal("myclass", interp.findclass("", "myclass").type) + assert_equal("myclass", interp.findclass("", "myclass").classname) assert_equal(%w{original code}, interp.findclass("", "myclass").code.evaluate(:scope => scope)) @@ -556,9 +555,8 @@ class TestInterpreter < Test::Unit::TestCase other = interp.findclass("other", "myclass") assert(other, "Could not find class") assert(interp.findclass("", "other::myclass"), "Could not find class") - assert_equal("other::myclass", other.fqname) + assert_equal("other::myclass", other.classname) assert_equal("other::myclass", other.namespace) - assert_equal("myclass", other.type) assert_equal(%w{something diff}, interp.findclass("other", "myclass").code.evaluate(:scope => scope)) diff --git a/test/language/node.rb b/test/language/node.rb index 5b5550d9a..d9661760a 100755 --- a/test/language/node.rb +++ b/test/language/node.rb @@ -110,6 +110,6 @@ node default { assert(default, "Did not find default node") - assert_equal("default", default.fqname) + assert_equal("default", default.classname) end end diff --git a/test/language/parser.rb b/test/language/parser.rb index 14e27d86b..a555c0082 100755 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -397,7 +397,7 @@ file { "/tmp/yayness": } sub = interp.findclass("", "container::deep::sub") assert(sub, "Could not find sub") - assert_equal("base", sub.parentclass.type) + assert_equal("base", sub.parentclass.classname) # Now try it with a parent class being a fq class assert_nothing_raised { @@ -405,7 +405,7 @@ file { "/tmp/yayness": } sub = interp.findclass("", "container::one") assert(sub, "Could not find one") - assert_equal("sub", sub.parentclass.type) + assert_equal("container::deep::sub", sub.parentclass.classname) # Finally, try including a qualified class assert_nothing_raised("Could not include fully qualified class") { @@ -431,7 +431,7 @@ file { "/tmp/yayness": assert_nothing_raised do out = parser.parse "Exec { path => '/usr/bin:/usr/sbin' }" assert_instance_of(AST::ASTArray, out) - assert_equal("", parser.interp.findclass("", "").type) + assert_equal("", parser.interp.findclass("", "").classname) assert_equal("", parser.interp.findclass("", "").namespace) assert_equal(out.object_id, parser.interp.findclass("", "").code.object_id) end diff --git a/test/language/scope.rb b/test/language/scope.rb index 610375f0d..428fe3e09 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -412,7 +412,7 @@ class TestScope < Test::Unit::TestCase [myclass, otherclass].each do |klass| assert(scope.setclass?(klass), - "%s was not set" % klass.fqname) + "%s was not set" % klass.classname) end end diff --git a/test/language/snippets.rb b/test/language/snippets.rb index 685110647..67c5b1f4f 100755 --- a/test/language/snippets.rb +++ b/test/language/snippets.rb @@ -13,10 +13,33 @@ class TestSnippets < Test::Unit::TestCase include PuppetTest include ObjectSpace + def setup + require 'profile' + super + @file = Puppet::Type.type(:file) + end + def self.snippetdir PuppetTest.datadir "snippets" end + def assert_file(path, msg = nil) + unless file = @file[path] + msg ||= "Could not find file %s" % path + raise msg + end + end + + def assert_mode_equal(mode, path) + unless file = @file[path] + raise "Could not find file %s" % path + end + + unless mode == file.should(:mode) + raise "Mode for %s is incorrect: %o vs %o" % [path, mode, file.should(:mode)] + end + end + def snippet(name) File.join(self.class.snippetdir, name) end @@ -151,73 +174,57 @@ class TestSnippets < Test::Unit::TestCase def snippet_filecreate %w{a b c d}.each { |letter| - file = "/tmp/create%stest" % letter - Puppet.info "testing %s" % file - assert(Puppet.type(:file)[file], "File %s does not exist" % file) - assert(FileTest.exists?(file)) - @@tmpfiles << file - } - %w{a b}.each { |letter| - file = "/tmp/create%stest" % letter - assert(File.stat(file).mode & 007777 == 0755) + path = "/tmp/create%stest" % letter + assert_file(path) + if %w{a b}.include?(letter) + assert_mode_equal(0755, path) + end } end def snippet_simpledefaults - file = "/tmp/defaulttest" - @@tmpfiles << file - assert(FileTest.exists?(file), "File %s does not exist" % file) - assert(File.stat(file).mode & 007777 == 0755) + path = "/tmp/defaulttest" + assert_file(path) + assert_mode_equal(0755, path) end def snippet_simpleselector files = %w{a b c d}.collect { |letter| - "/tmp/snippetselect%stest" % letter - } - @@tmpfiles += files - - files.each { |file| - assert(FileTest.exists?(file), "File %s does not exist" % file) - assert(File.stat(file).mode & 007777 == 0755, - "File %s is the incorrect mode" % file) - @@tmpfiles << file + path = "/tmp/snippetselect%stest" % letter + assert_file(path) + assert_mode_equal(0755, path) } end def snippet_classpathtest - file = "/tmp/classtest" - @@tmpfiles << file - - assert(FileTest.exists?(file)) + path = "/tmp/classtest" - obj = nil - assert_nothing_raised { - obj = Puppet.type(:file)[file] - } + file = @file[path] + assert(file, "did not create file %s" % path) assert_nothing_raised { assert_equal( "//testing/component[componentname]/File[/tmp/classtest]", - obj.path) - #Puppet.err obj.path + file.path) } end def snippet_argumentdefaults - file1 = "/tmp/argumenttest1" - file2 = "/tmp/argumenttest2" - @@tmpfiles << file1 - @@tmpfiles << file2 + path1 = "/tmp/argumenttest1" + path2 = "/tmp/argumenttest2" - assert(FileTest.exists?(file1)) - assert(File.stat(file1).mode & 007777 == 0755) - - assert(FileTest.exists?(file2)) - assert(File.stat(file2).mode & 007777 == 0644) + file1 = @file[path1] + file2 = @file[path2] + + assert_file(path1) + assert_mode_equal(0755, path1) + + assert_file(path2) + assert_mode_equal(0644, path2) end def snippet_casestatement - files = %w{ + paths = %w{ /tmp/existsfile /tmp/existsfile2 /tmp/existsfile3 @@ -225,32 +232,29 @@ class TestSnippets < Test::Unit::TestCase /tmp/existsfile5 } - files.each { |file| - assert(FileTest.exists?(file), "File %s is missing" % file) - assert(File.stat(file).mode & 007777 == 0755, "File %s is not 755" % file) + paths.each { |path| + file = @file[path] + assert(file, "File %s is missing" % path) + assert_mode_equal(0755, path) } end def snippet_implicititeration - files = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l } - - files.each { |file| - @@tmpfiles << file - assert(FileTest.exists?(file), "File %s does not exist" % file) - assert(File.stat(file).mode & 007777 == 0755, - "File %s is not 755" % file) + paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l } + paths.each { |path| + file = @file[path] + assert_file(path) + assert_mode_equal(0755, path) } end def snippet_multipleinstances - files = %w{a b c}.collect { |l| "/tmp/multipleinstances%s" % l } + paths = %w{a b c}.collect { |l| "/tmp/multipleinstances%s" % l } - files.each { |file| - @@tmpfiles << file - assert(FileTest.exists?(file), "File %s does not exist" % file) - assert(File.stat(file).mode & 007777 == 0755, - "File %s is not 755" % file) + paths.each { |path| + assert_file(path) + assert_mode_equal(0755, path) } end @@ -258,26 +262,23 @@ class TestSnippets < Test::Unit::TestCase def snippet_namevartest file = "/tmp/testfiletest" dir = "/tmp/testdirtest" - @@tmpfiles << file - @@tmpfiles << dir - assert(FileTest.file?(file), "File %s does not exist" % file) - assert(FileTest.directory?(dir), "Directory %s does not exist" % dir) + assert_file(file) + assert_file(dir) + assert_equal(:directory, @file[dir].should(:ensure), "Directory is not set to be a directory") end def snippet_scopetest file = "/tmp/scopetest" - @@tmpfiles << file - assert(FileTest.file?(file), "File %s does not exist" % file) - assert(File.stat(file).mode & 007777 == 0755, - "File %s is not 755" % file) + assert_file(file) + assert_mode_equal(0755, file) end def snippet_failmissingexecpath file = "/tmp/exectesting1" execfile = "/tmp/execdisttesting" - @@tmpfiles << file - @@tmpfiles << execfile - assert(!FileTest.exists?(execfile), "File %s exists" % execfile) + assert_file(file) + + assert_nil(Puppet::Type.type(:exec)["exectest"], "invalid exec was created") end def snippet_selectorvalues @@ -287,10 +288,8 @@ class TestSnippets < Test::Unit::TestCase } files.each { |f| - @@tmpfiles << f - assert(FileTest.exists?(f), "File %s does not exist" % f) - assert(File.stat(f).mode & 007777 == 0755, - "File %s is not 755" % f) + assert_file(f) + assert_mode_equal(0755, f) } end @@ -301,66 +300,56 @@ class TestSnippets < Test::Unit::TestCase } files.each { |f| - @@tmpfiles << f - assert(FileTest.exists?(f), "File %s does not exist" % f) - assert(File.stat(f).mode & 007777 == 0755, - "File %s is not 755" % f) + assert_file(f) + assert_mode_equal(0755, f) } end def snippet_falsevalues file = "/tmp/falsevaluesfalse" - @@tmpfiles << file - assert(FileTest.exists?(file), "File %s does not exist" % file) + assert_file(file) end def disabled_snippet_classargtest [1,2].each { |num| file = "/tmp/classargtest%s" % num - @@tmpfiles << file - assert(FileTest.file?(file), "File %s does not exist" % file) - assert(File.stat(file).mode & 007777 == 0755, - "File %s is not 755" % file) + assert_file(file) + assert_mode_equal(0755, file) } end def snippet_classheirarchy [1,2,3].each { |num| file = "/tmp/classheir%s" % num - @@tmpfiles << file - assert(FileTest.file?(file), "File %s does not exist" % file) - assert(File.stat(file).mode & 007777 == 0755, - "File %s is not 755" % file) + assert_file(file) + assert_mode_equal(0755, file) } end def snippet_singleary [1,2,3,4].each { |num| file = "/tmp/singleary%s" % num - @@tmpfiles << file - assert(FileTest.file?(file), "File %s does not exist" % file) + assert_file(file) } end def snippet_classincludes [1,2,3].each { |num| file = "/tmp/classincludes%s" % num - @@tmpfiles << file - assert(FileTest.file?(file), "File %s does not exist" % file) - assert(File.stat(file).mode & 007777 == 0755, - "File %s is not 755" % file) + assert_file(file) + assert_mode_equal(0755, file) } end def snippet_componentmetaparams ["/tmp/component1", "/tmp/component2"].each { |file| - assert(FileTest.file?(file), "File %s does not exist" % file) + assert_file(file) } end def snippet_aliastest %w{/tmp/aliastest /tmp/aliastest2 /tmp/aliastest3}.each { |file| - assert(FileTest.file?(file), "File %s does not exist" % file) + assert_file(file) } end @@ -369,17 +358,14 @@ class TestSnippets < Test::Unit::TestCase 2 => 'some "\yayness\"' }.each { |count, str| path = "/tmp/singlequote%s" % count - assert(FileTest.exists?(path), "File %s is missing" % path) - text = File.read(path) - - assert_equal(str, text) + assert_file(path) + assert_equal(str, @file[path].should(:content)) } end # There's no way to actually retrieve the list of classes from the # transaction. def snippet_tag - @@tmpfiles << "/tmp/settestingness" end # Make sure that set tags are correctly in place, yo. @@ -388,25 +374,21 @@ class TestSnippets < Test::Unit::TestCase "both" => false, "bothtrue" => true, "define" => true} tags.each do |tag, retval| - @@tmpfiles << "/tmp/tagged#{tag}true" - @@tmpfiles << "/tmp/tagged#{tag}false" - - assert(FileTest.exists?("/tmp/tagged#{tag}#{retval.to_s}"), - "'tagged' did not return %s with %s" % [retval, tag]) + assert_file("/tmp/tagged#{tag}#{retval.to_s}") end end def snippet_defineoverrides file = "/tmp/defineoverrides1" - assert(FileTest.exists?(file), "File does not exist") - assert_equal(0755, filemode(file)) + assert_file(file) + assert_mode_equal(0755, file) end def snippet_deepclassheirarchy 5.times { |i| i += 1 file = "/tmp/deepclassheir%s" % i - assert(FileTest.exists?(file), "File %s does not exist" % file) + assert_file(file) } end @@ -415,70 +397,56 @@ class TestSnippets < Test::Unit::TestCase end def snippet_emptyexec - assert(FileTest.exists?("/tmp/emptyexectest"), - "Empty exec was ignored") - - @@tmpfiles << "/tmp/emptyexextest" + assert(Puppet::Type.type(:exec)["touch /tmp/emptyexectest"], + "Did not create exec") end def snippet_multisubs path = "/tmp/multisubtest" - assert(FileTest.exists?(path), "Did not create file") - assert_equal("sub2", File.read(path), "sub2 did not override content") - assert_equal(0755, filemode(path), "sub1 did not override mode") + assert_file(path) + file = @file[path] + assert_equal("sub2", file.should(:content), "sub2 did not override content") + assert_mode_equal(0755, path) end def snippet_collection - assert(FileTest.exists?("/tmp/colltest1"), "Did not collect file") - assert(! FileTest.exists?("/tmp/colltest2"), "Incorrectly collected file") + assert_file("/tmp/colltest1") + assert_nil(@file["/tmp/colltest2"], "Incorrectly collected file") end def snippet_virtualresources %w{1 2 3 4}.each do |num| - assert(FileTest.exists?("/tmp/virtualtest#{num}"), - "Did not collect file #{num}") + assert_file("/tmp/virtualtest#{num}") end end def snippet_componentrequire %w{1 2}.each do |num| - assert(FileTest.exists?("/tmp/testing_component_requires#{num}"), + assert_file("/tmp/testing_component_requires#{num}", "#{num} does not exist") - end + end end def snippet_realize_defined_types - assert(FileTest.exists?("/tmp/realize_defined_test1"), - "Did not make file from realized defined type") - assert(FileTest.exists?("/tmp/realize_defined_test2"), - "Did not make file from realized file inside defined type") + assert_file("/tmp/realize_defined_test1") + assert_file("/tmp/realize_defined_test2") end def snippet_fqparents - assert(FileTest.exists?("/tmp/fqparent1"), - "Did not make file from parent class") - assert(FileTest.exists?("/tmp/fqparent2"), - "Did not make file from subclass") + assert_file("/tmp/fqparent1", "Did not make file from parent class") + assert_file("/tmp/fqparent2", "Did not make file from subclass") end def snippet_fqdefinition - assert(FileTest.exists?("/tmp/fqdefinition"), + assert_file("/tmp/fqdefinition", "Did not make file from fully-qualified definition") end - def snippet_dirchmod - dirs = %w{a b}.collect { |letter| - "/tmp/dirchmodtest%s" % letter - } - - @@tmpfiles << dirs - - dirs.each { |dir| - assert(FileTest.directory?(dir)) - } - - assert(File.stat("/tmp/dirchmodtesta").mode & 007777 == 0755) - assert(File.stat("/tmp/dirchmodtestb").mode & 007777 == 0700) + def snippet_subclass_name_duplication + assert_file("/tmp/subclass_name_duplication1", + "Did not make first file from duplicate subclass names") + assert_file("/tmp/subclass_name_duplication2", + "Did not make second file from duplicate subclass names") end # Iterate across each of the snippets and create a test. @@ -517,9 +485,9 @@ class TestSnippets < Test::Unit::TestCase assert_nothing_raised { client.getconfig() } - assert_nothing_raised { - trans = client.apply() - } + #assert_nothing_raised { + # trans = client.apply() + #} Puppet::Type.eachtype { |type| type.each { |obj| @@ -529,10 +497,6 @@ class TestSnippets < Test::Unit::TestCase # assert(obj.parent, "%s has no parent" % obj.name) #end assert(obj.name) - - if obj.is_a?(Puppet.type(:file)) - @@tmpfiles << obj[:path] - end } } assert_nothing_raised { |
