summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-04 15:14:39 -0500
committerLuke Kanies <luke@madstop.com>2007-09-04 15:14:39 -0500
commit11b127bd6708a18b512ca5b3018ccff1200cc47a (patch)
tree55d6f42b78404d6e6058f5bef2e50b6bf06b7105
parent3b2efd2a4b32478b6c6a71e1421061405a0bb11e (diff)
downloadpuppet-11b127bd6708a18b512ca5b3018ccff1200cc47a.tar.gz
puppet-11b127bd6708a18b512ca5b3018ccff1200cc47a.tar.xz
puppet-11b127bd6708a18b512ca5b3018ccff1200cc47a.zip
Successfully modified all tests and code so that all language tests pass again. This is the majority of the work necessary to make the separate "configuration" object work.
-rw-r--r--lib/puppet/parser/ast/definition.rb11
-rw-r--r--lib/puppet/parser/ast/node.rb2
-rw-r--r--lib/puppet/parser/compile.rb14
-rw-r--r--lib/puppet/parser/functions.rb4
-rw-r--r--lib/puppet/parser/resource.rb34
-rw-r--r--lib/puppet/parser/scope.rb38
-rwxr-xr-xtest/language/ast.rb4
-rwxr-xr-xtest/language/ast/definition.rb33
-rwxr-xr-xtest/language/ast/hostclass.rb12
-rwxr-xr-xtest/language/ast/resourceref.rb2
-rwxr-xr-xtest/language/compile.rb345
-rwxr-xr-xtest/language/functions.rb11
-rwxr-xr-xtest/language/parser.rb2
-rwxr-xr-xtest/language/resource.rb64
-rwxr-xr-xtest/language/scope.rb92
-rw-r--r--test/lib/puppettest/parsertesting.rb4
-rw-r--r--test/lib/puppettest/resourcetesting.rb2
17 files changed, 316 insertions, 358 deletions
diff --git a/lib/puppet/parser/ast/definition.rb b/lib/puppet/parser/ast/definition.rb
index 9ad1f539d..1cdaa6431 100644
--- a/lib/puppet/parser/ast/definition.rb
+++ b/lib/puppet/parser/ast/definition.rb
@@ -37,12 +37,12 @@ class Puppet::Parser::AST
# Additionally, add a tag for whatever kind of class
# we are
if @classname != "" and ! @classname.nil?
- @classname.split(/::/).each { |tag| scope.tag(tag) }
+ @classname.split(/::/).each { |tag| scope.resource.tag(tag) }
end
[resource.name, resource.title].each do |str|
unless str.nil? or str =~ /[^\w]/ or str == ""
- scope.tag(str)
+ scope.resource.tag(str)
end
end
@@ -123,10 +123,7 @@ class Puppet::Parser::AST
end
# Create a new subscope in which to evaluate our code.
- def subscope(scope, resource = nil)
- unless resource
- raise ArgumentError, "Resources are required when creating subscopes"
- end
+ def subscope(scope, resource)
args = {
:resource => resource,
:keyword => self.keyword,
@@ -192,7 +189,7 @@ class Puppet::Parser::AST
# [default.inspect, arg.inspect, @name.inspect]
else
parsefail "Must pass %s to %s of type %s" %
- [arg,title,@classname]
+ [arg, resource.title, @classname]
end
end
}
diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb
index 20c03f4ce..a296e43ba 100644
--- a/lib/puppet/parser/ast/node.rb
+++ b/lib/puppet/parser/ast/node.rb
@@ -19,7 +19,7 @@ class Puppet::Parser::AST
# We don't have to worry about the declarativeness of node parentage,
# because the entry point is always a single node definition.
if parent = self.parentobj
- scope = parent.safeevaluate :scope => scope
+ scope = parent.safeevaluate :scope => scope, :resource => options[:resource]
end
scope = scope.newscope(
diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb
index a8e80eb9d..841e58d4d 100644
--- a/lib/puppet/parser/compile.rb
+++ b/lib/puppet/parser/compile.rb
@@ -14,7 +14,7 @@ require 'puppet/util/errors'
class Puppet::Parser::Compile
include Puppet::Util
include Puppet::Util::Errors
- attr_reader :topscope, :parser, :node, :facts, :collections
+ attr_reader :topscope, :parser, :node, :facts, :collections, :configuration
attr_writer :ast_nodes
@@ -121,13 +121,14 @@ class Puppet::Parser::Compile
classes.each do |name|
# If we can find the class, then make a resource that will evaluate it.
if klass = scope.findclass(name)
- # Create a resource to model this class, and then add it to the list
- # of resources.
unless scope.source
- raise "No source for %s" % scope.to_s
+ raise Puppet::DevError, "No source for %s" % scope.to_s
end
+ # Create a resource to model this class, and then add it to the list
+ # of resources.
resource = Puppet::Parser::Resource.new(:type => "class", :title => klass.classname, :scope => scope, :source => scope.source)
store_resource(scope, resource)
+ @configuration.tag(klass.classname)
found << name
else
Puppet.info "Could not find class %s for %s" % [name, node.name]
@@ -311,11 +312,6 @@ class Puppet::Parser::Compile
@configuration.add_vertex!(@main_resource)
@resource_table["Class[main]"] = @main_resource
- #if klass = @parser.findclass("", "")
- # # Set the source, so objects can tell where they were defined.
- # topscope.source = klass
- # klass.safeevaluate :scope => topscope, :nosubscope => true
- #end
end
# Make sure the entire configuration is evaluated.
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb
index cbb7f4e2d..4c747af84 100644
--- a/lib/puppet/parser/functions.rb
+++ b/lib/puppet/parser/functions.rb
@@ -135,7 +135,7 @@ module Functions
newfunction(:tag, :doc => "Add the specified tags to the containing class
or definition. All contained objects will then acquire that tag, also.
") do |vals|
- self.tag(*vals)
+ self.resource.tag(*vals)
end
# Test whether a given tag is set. This functions as a big OR -- if any of the
@@ -148,7 +148,7 @@ module Functions
retval = true
vals.each do |val|
- unless classlist.include?(val) or self.tags.include?(val)
+ unless classlist.include?(val) or self.resource.tags.include?(val)
retval = false
break
end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 3f5ca78ae..a8da6b054 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -90,11 +90,10 @@ class Puppet::Parser::Resource
end
end
- [:scope, :source].each do |attribute|
- unless self.send(attribute)
- raise ArgumentError, "Resources require a %s" % attribute
- end
+ unless self.scope
+ raise ArgumentError, "Resources require a scope"
end
+ @source ||= scope.source
options = symbolize_options(options)
@@ -122,6 +121,13 @@ class Puppet::Parser::Resource
unless options.empty?
raise ArgumentError, "Resources do not accept %s" % options.keys.collect { |k| k.to_s }.join(", ")
end
+
+ @tags = []
+ @tags << @ref.type.to_s
+ @tags << @ref.title.to_s if @ref.title.to_s =~ /^[-\w]+$/
+ if scope.resource
+ @tags += scope.resource.tags
+ end
end
# Merge an override resource in. This will throw exceptions if
@@ -208,12 +214,22 @@ class Puppet::Parser::Resource
@ref.to_s
end
+ # Add a tag to our current list. These tags will be added to all
+ # of the objects contained in this scope.
+ def tag(*ary)
+ ary.each { |tag|
+ tag = tag.to_s
+ unless tag =~ /^\w[-\w]*$/
+ fail Puppet::ParseError, "Invalid tag %s" % tag.inspect
+ end
+ unless @tags.include?(tag)
+ @tags << tag
+ end
+ }
+ end
+
def tags
- unless defined? @tags
- @tags = scope.tags
- @tags << self.type unless @tags.include?(self.type)
- end
- @tags
+ @tags.dup
end
def to_hash
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 4516715e1..028414cc0 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -311,47 +311,11 @@ class Puppet::Parser::Scope
return out
end
- # Add a tag to our current list. These tags will be added to all
- # of the objects contained in this scope.
- def tag(*ary)
- ary.each { |tag|
- if tag.nil? or tag == ""
- puts caller
- Puppet.debug "got told to tag with %s" % tag.inspect
- next
- end
- unless tag =~ /^\w[-\w]*$/
- fail Puppet::ParseError, "Invalid tag %s" % tag.inspect
- end
- tag = tag.to_s
- unless @tags.include?(tag)
- #Puppet.info "Tagging scope %s with %s" % [self.object_id, tag]
- @tags << tag
- end
- }
- end
-
# Return the tags associated with this scope. It's basically
# just our parents' tags, plus our type. We don't cache this value
# because our parent tags might change between calls.
def tags
- tmp = [] + @tags
- unless ! defined? @type or @type.nil? or @type == ""
- tmp << @type.to_s
- end
- if parent
- #info "Looking for tags in %s" % parent.type
- parent.tags.each { |tag|
- if tag.nil? or tag == ""
- Puppet.debug "parent returned tag %s" % tag.inspect
- next
- end
- unless tmp.include?(tag)
- tmp << tag
- end
- }
- end
- return tmp.sort.uniq
+ resource.tags
end
# Used mainly for logging
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 000a56a89..f62b2340c 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -119,7 +119,7 @@ class TestAST < Test::Unit::TestCase
# Now try evaluating the node
assert_nothing_raised do
- mynode.evaluate :scope => scope
+ mynode.evaluate :scope => scope, :resource => scope.resource
end
# Make sure that we can find each of the files
@@ -136,7 +136,7 @@ class TestAST < Test::Unit::TestCase
newscope = mkscope :parser => parser
assert_nothing_raised do
- child.evaluate :scope => newscope
+ child.evaluate :scope => newscope, :resource => scope.resource
end
assert(newscope.findresource("File[/tmp/base]"),
diff --git a/test/language/ast/definition.rb b/test/language/ast/definition.rb
index 51948b01f..7db5d2849 100755
--- a/test/language/ast/definition.rb
+++ b/test/language/ast/definition.rb
@@ -41,6 +41,7 @@ class TestASTDefinition < Test::Unit::TestCase
def test_evaluate
parser = mkparser
config = mkconfig
+ config.send(:evaluate_main)
scope = config.topscope
klass = parser.newdefine "yayness",
:arguments => [["owner", stringobj("nobody")], %w{mode}],
@@ -49,13 +50,16 @@ class TestASTDefinition < Test::Unit::TestCase
"owner" => varref("owner"), "mode" => varref("mode"))]
)
- resource = stub 'resource',
+ resource = Puppet::Parser::Resource.new(
:title => "first",
- :name => "first",
:type => "yayness",
- :to_hash => {"mode" => "755"},
:exported => false,
- :virtual => false
+ :virtual => false,
+ :scope => scope,
+ :source => scope.source
+ )
+ resource.send(:set_parameter, "name", "first")
+ resource.send(:set_parameter, "mode", "755")
resource.stubs(:title)
assert_nothing_raised do
@@ -76,13 +80,17 @@ class TestASTDefinition < Test::Unit::TestCase
end
# Now create another with different args
- resource2 = stub 'resource',
+ resource2 = Puppet::Parser::Resource.new(
:title => "second",
- :name => "second",
:type => "yayness",
- :to_hash => {"mode" => "755", "owner" => "daemon"},
:exported => false,
- :virtual => false
+ :virtual => false,
+ :scope => scope,
+ :source => scope.source
+ )
+ resource2.send(:set_parameter, "name", "second")
+ resource2.send(:set_parameter, "mode", "755")
+ resource2.send(:set_parameter, "owner", "daemon")
assert_nothing_raised do
klass.evaluate(:scope => scope, :resource => resource2)
@@ -110,13 +118,14 @@ class TestASTDefinition < Test::Unit::TestCase
# inside the loop so the subscope expectations work.
klass = parser.newdefine "yayness%s" % i
- resource = stub 'resource',
+ resource = Puppet::Parser::Resource.new(
:title => hash[:title],
- :name => hash[:name] || hash[:title],
:type => "yayness%s" % i,
- :to_hash => {},
:exported => false,
- :virtual => false
+ :virtual => false,
+ :scope => scope,
+ :source => scope.source
+ )
subscope = klass.subscope(scope, resource)
diff --git a/test/language/ast/hostclass.rb b/test/language/ast/hostclass.rb
index c88152913..b53f6d5c0 100755
--- a/test/language/ast/hostclass.rb
+++ b/test/language/ast/hostclass.rb
@@ -27,13 +27,14 @@ class TestASTHostClass < Test::Unit::TestCase
"owner" => "nobody", "mode" => "755")]
)
+ resource = Puppet::Parser::Resource.new(:type => "class", :title => "first", :scope => scope)
assert_nothing_raised do
- klass.evaluate(:scope => scope)
+ klass.evaluate(:scope => scope, :resource => resource)
end
# Then try it again
assert_nothing_raised do
- klass.evaluate(:scope => scope)
+ klass.evaluate(:scope => scope, :resource => resource)
end
assert(scope.compile.class_scope(klass), "Class was not considered evaluated")
@@ -69,11 +70,11 @@ class TestASTHostClass < Test::Unit::TestCase
)
assert_nothing_raised do
- newsub.evaluate(:scope => scope)
+ newsub.evaluate(:scope => scope, :resource => resource)
end
assert_nothing_raised do
- moresub.evaluate(:scope => scope)
+ moresub.evaluate(:scope => scope, :resource => resource)
end
assert(scope.compile.class_scope(newbase), "Did not eval newbase")
@@ -115,7 +116,7 @@ class TestASTHostClass < Test::Unit::TestCase
assert_equal("funtest", define.namespace,
"component namespace was not set in the definition")
- newscope = klass.subscope(scope)
+ newscope = klass.subscope(scope, mock("resource"))
assert_equal(["funtest"], newscope.namespaces,
"Scope did not inherit namespace")
@@ -143,6 +144,7 @@ class TestASTHostClass < Test::Unit::TestCase
assert_nothing_raised do
ret = scope.compile.evaluate_classes(["sub"], scope)
end
+ scope.compile.send(:evaluate_generators)
subscope = scope.compile.class_scope(scope.findclass("sub"))
assert(subscope, "could not find sub scope")
diff --git a/test/language/ast/resourceref.rb b/test/language/ast/resourceref.rb
index dd7e7037f..33a80ad40 100755
--- a/test/language/ast/resourceref.rb
+++ b/test/language/ast/resourceref.rb
@@ -44,7 +44,7 @@ class TestASTResourceRef < Test::Unit::TestCase
@parser.newdefine "one"
@parser.newdefine "one::two"
@parser.newdefine "three"
- twoscope = @scope.newscope(:type => "one", :namespace => "one")
+ twoscope = @scope.newscope(:namespace => "one")
assert(twoscope.finddefine("two"), "Could not find 'two' definition")
title = "title"
diff --git a/test/language/compile.rb b/test/language/compile.rb
index a4adcd963..0d9c9e32a 100755
--- a/test/language/compile.rb
+++ b/test/language/compile.rb
@@ -26,44 +26,46 @@ class TestCompile < Test::Unit::TestCase
@parser = mock 'parser'
end
- def mkconfig(options = {})
+ def mkcompile(options = {})
if node = options[:node]
options.delete(:node)
else
node = mknode
end
- @config = Compile.new(node, mkparser, options)
+ @compile = Compile.new(node, mkparser, options)
end
def test_initialize
- config = nil
- assert_nothing_raised("Could not init config with all required options") do
- config = Compile.new("foo", "parser")
+ compile = nil
+ node = stub 'node', :name => "foo"
+ parser = mock 'parser'
+ assert_nothing_raised("Could not init compile with all required options") do
+ compile = Compile.new(node, parser)
end
- assert_equal("foo", config.node, "Did not set node correctly")
- assert_equal("parser", config.parser, "Did not set parser correctly")
+ assert_equal(node, compile.node, "Did not set node correctly")
+ assert_equal(parser, compile.parser, "Did not set parser correctly")
# We're not testing here whether we call initvars, because it's too difficult to
# mock.
# Now try it with some options
- assert_nothing_raised("Could not init config with extra options") do
- config = Compile.new("foo", "parser", :ast_nodes => false)
+ assert_nothing_raised("Could not init compile with extra options") do
+ compile = Compile.new(node, parser, :ast_nodes => false)
end
- assert_equal(false, config.ast_nodes?, "Did not set ast_nodes? correctly")
+ assert_equal(false, compile.ast_nodes?, "Did not set ast_nodes? correctly")
end
def test_initvars
- config = mkconfig
+ compile = mkcompile
[:class_scopes, :resource_table, :exported_resources, :resource_overrides].each do |table|
- assert_instance_of(Hash, config.send(:instance_variable_get, "@#{table}"), "Did not set %s table correctly" % table)
+ assert_instance_of(Hash, compile.send(:instance_variable_get, "@#{table}"), "Did not set %s table correctly" % table)
end
- assert_instance_of(Scope, config.topscope, "Did not create a topscope")
- graph = config.instance_variable_get("@scope_graph")
+ assert_instance_of(Scope, compile.topscope, "Did not create a topscope")
+ graph = compile.instance_variable_get("@scope_graph")
assert_instance_of(GRATR::Digraph, graph, "Did not create scope graph")
- assert(graph.vertex?(config.topscope), "Did not add top scope as a vertex in the graph")
+ assert(graph.vertex?(compile.topscope), "Did not add top scope as a vertex in the graph")
end
# Make sure we store and can retrieve references to classes and their scopes.
@@ -71,134 +73,135 @@ class TestCompile < Test::Unit::TestCase
klass = mock 'ast_class'
klass.expects(:classname).returns("myname")
- config = mkconfig
- config.expects(:tag).with("myname")
+ compile = mkcompile
+ compile.configuration.expects(:tag).with("myname")
assert_nothing_raised("Could not set class") do
- config.class_set "myname", "myscope"
+ compile.class_set "myname", "myscope"
end
# First try to retrieve it by name.
- assert_equal("myscope", config.class_scope("myname"), "Could not retrieve class scope by name")
+ assert_equal("myscope", compile.class_scope("myname"), "Could not retrieve class scope by name")
# Then by object
- assert_equal("myscope", config.class_scope(klass), "Could not retrieve class scope by object")
+ assert_equal("myscope", compile.class_scope(klass), "Could not retrieve class scope by object")
end
def test_classlist
- config = mkconfig
+ compile = mkcompile
- config.class_set "", "empty"
- config.class_set "one", "yep"
- config.class_set "two", "nope"
+ compile.class_set "", "empty"
+ compile.class_set "one", "yep"
+ compile.class_set "two", "nope"
# Make sure our class list is correct
- assert_equal(%w{one two}.sort, config.classlist.sort, "Did not get correct class list")
+ assert_equal(%w{one two}.sort, compile.classlist.sort, "Did not get correct class list")
end
# Make sure collections get added to our internal array
def test_add_collection
- config = mkconfig
+ compile = mkcompile
assert_nothing_raised("Could not add collection") do
- config.add_collection "nope"
+ compile.add_collection "nope"
end
- assert_equal(%w{nope}, config.instance_variable_get("@collections"), "Did not add collection")
+ assert_equal(%w{nope}, compile.instance_variable_get("@collections"), "Did not add collection")
end
# Make sure we create a graph of scopes.
def test_newscope
- config = mkconfig
- graph = config.instance_variable_get("@scope_graph")
- assert_instance_of(Scope, config.topscope, "Did not create top scope")
+ compile = mkcompile
+ graph = compile.instance_variable_get("@scope_graph")
+ assert_instance_of(Scope, compile.topscope, "Did not create top scope")
assert_instance_of(GRATR::Digraph, graph, "Did not create graph")
- assert(graph.vertex?(config.topscope), "The top scope is not a vertex in the graph")
+ assert(graph.vertex?(compile.topscope), "The top scope is not a vertex in the graph")
# Now that we've got the top scope, create a new, subscope
subscope = nil
assert_nothing_raised("Could not create subscope") do
- subscope = config.newscope(config.topscope)
+ subscope = compile.newscope(compile.topscope)
end
assert_instance_of(Scope, subscope, "Did not create subscope")
- assert(graph.edge?(config.topscope, subscope), "An edge between top scope and subscope was not added")
+ assert(graph.edge?(compile.topscope, subscope), "An edge between top scope and subscope was not added")
# Make sure a scope can find its parent.
- assert(config.parent(subscope), "Could not look up parent scope on compile")
- assert_equal(config.topscope.object_id, config.parent(subscope).object_id, "Did not get correct parent scope from compile")
- assert_equal(config.topscope.object_id, subscope.parent.object_id, "Scope did not correctly retrieve its parent scope")
+ assert(compile.parent(subscope), "Could not look up parent scope on compile")
+ assert_equal(compile.topscope.object_id, compile.parent(subscope).object_id, "Did not get correct parent scope from compile")
+ assert_equal(compile.topscope.object_id, subscope.parent.object_id, "Scope did not correctly retrieve its parent scope")
# Now create another, this time specifying options
another = nil
assert_nothing_raised("Could not create subscope") do
- another = config.newscope(subscope, :name => "testing")
+ another = compile.newscope(subscope, :level => 5)
end
- assert_equal("testing", another.name, "did not set scope option correctly")
+ assert_equal(5, another.level, "did not set scope option correctly")
assert_instance_of(Scope, another, "Did not create second subscope")
assert(graph.edge?(subscope, another), "An edge between parent scope and second subscope was not added")
# Make sure it can find its parent.
- assert(config.parent(another), "Could not look up parent scope of second subscope on compile")
- assert_equal(subscope.object_id, config.parent(another).object_id, "Did not get correct parent scope of second subscope from compile")
+ assert(compile.parent(another), "Could not look up parent scope of second subscope on compile")
+ assert_equal(subscope.object_id, compile.parent(another).object_id, "Did not get correct parent scope of second subscope from compile")
assert_equal(subscope.object_id, another.parent.object_id, "Second subscope did not correctly retrieve its parent scope")
# And make sure both scopes show up in the right order in the search path
- assert_equal([another.object_id, subscope.object_id, config.topscope.object_id], another.scope_path.collect { |p| p.object_id },
+ assert_equal([another.object_id, subscope.object_id, compile.topscope.object_id], another.scope_path.collect { |p| p.object_id },
"Did not get correct scope path")
end
# The heart of the action.
def test_compile
- config = mkconfig
+ compile = mkcompile
+ compile.instance_variable_get("@configuration").expects(:extract).returns(:config)
[:set_node_parameters, :evaluate_main, :evaluate_ast_node, :evaluate_node_classes, :evaluate_generators, :fail_on_unevaluated, :finish].each do |method|
- config.expects(method)
+ compile.expects(method)
end
- config.expects(:extract).returns(:config)
- assert_equal(:config, config.compile, "Did not return the results of the extraction")
+ assert_equal(:config, compile.compile, "Did not return the results of the extraction")
end
# Test setting the node's parameters into the top scope.
def test_set_node_parameters
- config = mkconfig
+ compile = mkcompile
@node.parameters = {"a" => "b", "c" => "d"}
- scope = config.topscope
+ scope = compile.topscope
@node.parameters.each do |param, value|
scope.expects(:setvar).with(param, value)
end
assert_nothing_raised("Could not call 'set_node_parameters'") do
- config.send(:set_node_parameters)
+ compile.send(:set_node_parameters)
end
end
# Test that we can evaluate the main class, which is the one named "" in namespace
# "".
def test_evaluate_main
- config = mkconfig
+ compile = mkcompile
main = mock 'main_class'
- config.topscope.expects(:source=).with(main)
- main.expects(:safeevaluate).with(:scope => config.topscope, :nosubscope => true)
+ compile.topscope.expects(:source=).with(main)
@parser.expects(:findclass).with("", "").returns(main)
assert_nothing_raised("Could not call evaluate_main") do
- config.send(:evaluate_main)
+ compile.send(:evaluate_main)
end
+
+ assert(compile.resources.find { |r| r.to_s == "Class[main]" }, "Did not create a 'main' resource")
end
# Make sure we either don't look for nodes, or that we find and evaluate the right object.
def test_evaluate_ast_node
# First try it with ast_nodes disabled
- config = mkconfig :ast_nodes => false
- config.expects(:ast_nodes?).returns(false)
- config.parser.expects(:nodes).never
+ compile = mkcompile :ast_nodes => false
+ compile.expects(:ast_nodes?).returns(false)
+ compile.parser.expects(:nodes).never
assert_nothing_raised("Could not call evaluate_ast_node when ast nodes are disabled") do
- config.send(:evaluate_ast_node)
+ compile.send(:evaluate_ast_node)
end
# Now try it with them enabled, but no node found.
nodes = mock 'node_hash'
- config = mkconfig :ast_nodes => true
- config.expects(:ast_nodes?).returns(true)
- config.parser.expects(:nodes).returns(nodes).times(4)
+ compile = mkcompile :ast_nodes => true
+ compile.expects(:ast_nodes?).returns(true)
+ compile.parser.expects(:nodes).returns(nodes).times(4)
# Set some names for our test
@node.names = %w{a b c}
@@ -211,17 +214,17 @@ class TestCompile < Test::Unit::TestCase
# And make sure the lack of a node throws an exception
assert_raise(Puppet::ParseError, "Did not fail when we couldn't find an ast node") do
- config.send(:evaluate_ast_node)
+ compile.send(:evaluate_ast_node)
end
# Finally, make sure it works dandily when we have a node
nodes = mock 'hash'
- config = mkconfig :ast_nodes => true
- config.expects(:ast_nodes?).returns(true)
- config.parser.expects(:nodes).returns(nodes).times(3)
+ compile = mkcompile :ast_nodes => true
+ compile.expects(:ast_nodes?).returns(true)
+ compile.parser.expects(:nodes).returns(nodes).times(3)
node = mock 'node'
- node.expects(:safeevaluate).with(:scope => config.topscope)
+ node.expects(:safeevaluate).with(:scope => compile.topscope)
# Set some names for our test
@node.names = %w{a b c}
nodes.expects(:[]).with("a").returns(nil)
@@ -231,17 +234,17 @@ class TestCompile < Test::Unit::TestCase
# And make sure the lack of a node throws an exception
assert_nothing_raised("Failed when a node was found") do
- config.send(:evaluate_ast_node)
+ compile.send(:evaluate_ast_node)
end
# Lastly, check when we actually find the default.
nodes = mock 'hash'
- config = mkconfig :ast_nodes => true
- config.expects(:ast_nodes?).returns(true)
- config.parser.expects(:nodes).returns(nodes).times(4)
+ compile = mkcompile :ast_nodes => true
+ compile.expects(:ast_nodes?).returns(true)
+ compile.parser.expects(:nodes).returns(nodes).times(4)
node = mock 'node'
- node.expects(:safeevaluate).with(:scope => config.topscope)
+ node.expects(:safeevaluate).with(:scope => compile.topscope)
# Set some names for our test
@node.names = %w{a b c}
nodes.expects(:[]).with("a").returns(nil)
@@ -251,59 +254,64 @@ class TestCompile < Test::Unit::TestCase
# And make sure the lack of a node throws an exception
assert_nothing_raised("Failed when a node was found") do
- config.send(:evaluate_ast_node)
+ compile.send(:evaluate_ast_node)
end
end
def test_evaluate_node_classes
- config = mkconfig
+ compile = mkcompile
@node.classes = %w{one two three four}
- config.expects(:evaluate_classes).with(%w{one two three four}, config.topscope)
+ compile.expects(:evaluate_classes).with(%w{one two three four}, compile.topscope)
assert_nothing_raised("could not call evaluate_node_classes") do
- config.send(:evaluate_node_classes)
+ compile.send(:evaluate_node_classes)
end
end
def test_evaluate_classes
- config = mkconfig
+ compile = mkcompile
+ compile.parser.expects(:findclass).with("", "").returns(stub('main', :classname => ""))
+ compile.send :evaluate_main
classes = {
- "one" => mock('class one'),
- "three" => mock('class three')
+ "one" => stub('class one', :classname => "one"),
+ "three" => stub('class three', :classname => "three")
}
classes.each do |name, obj|
- config.parser.expects(:findclass).with("", name).returns(obj)
- obj.expects(:safeevaluate).with(:scope => config.topscope)
+ compile.parser.expects(:findclass).with("", name).returns(obj)
end
%w{two four}.each do |name|
- config.parser.expects(:findclass).with("", name).returns(nil)
+ compile.parser.expects(:findclass).with("", name).returns(nil)
end
- config.expects(:tag).with("two")
- config.expects(:tag).with("four")
+ %w{one two three four}.each do |name|
+ compile.configuration.expects(:tag).with(name)
+ end
result = nil
assert_nothing_raised("could not call evaluate_node_classes") do
- result = config.send(:evaluate_classes, %w{one two three four}, config.topscope)
+ result = compile.send(:evaluate_classes, %w{one two three four}, compile.topscope)
+ end
+ %w{one three}.each do |found|
+ assert(compile.resources.find { |r| r.to_s == "Class[#{found}]" }, "Did not create a class resource for %s" % found)
end
assert_equal(%w{one three}, result, "Did not return the list of evaluated classes")
end
def test_evaluate_collections
- config = mkconfig
+ compile = mkcompile
colls = []
# Make sure we return false when there's nothing there.
- assert(! config.send(:evaluate_collections), "Returned true when there were no collections")
+ assert(! compile.send(:evaluate_collections), "Returned true when there were no collections")
# And when the collections fail to evaluate.
colls << mock("coll1-false")
colls << mock("coll2-false")
colls.each { |c| c.expects(:evaluate).returns(false) }
- config.instance_variable_set("@collections", colls)
- assert(! config.send(:evaluate_collections), "Returned true when collections both evaluated nothing")
+ compile.instance_variable_set("@collections", colls)
+ assert(! compile.send(:evaluate_collections), "Returned true when collections both evaluated nothing")
# Now have one of the colls evaluate
colls.clear
@@ -311,7 +319,7 @@ class TestCompile < Test::Unit::TestCase
colls << mock("coll2-one-true")
colls[0].expects(:evaluate).returns(true)
colls[1].expects(:evaluate).returns(false)
- assert(config.send(:evaluate_collections), "Did not return true when one collection evaluated true")
+ assert(compile.send(:evaluate_collections), "Did not return true when one collection evaluated true")
# And have them both eval true
colls.clear
@@ -319,21 +327,21 @@ class TestCompile < Test::Unit::TestCase
colls << mock("coll2-both-true")
colls[0].expects(:evaluate).returns(true)
colls[1].expects(:evaluate).returns(true)
- assert(config.send(:evaluate_collections), "Did not return true when both collections evaluated true")
+ assert(compile.send(:evaluate_collections), "Did not return true when both collections evaluated true")
end
def test_unevaluated_resources
- config = mkconfig
+ compile = mkcompile
resources = {}
- config.instance_variable_set("@resource_table", resources)
+ compile.instance_variable_set("@resource_table", resources)
# First test it when the table is empty
- assert_nil(config.send(:unevaluated_resources), "Somehow found unevaluated resources in an empty table")
+ assert_nil(compile.send(:unevaluated_resources), "Somehow found unevaluated resources in an empty table")
# Then add a builtin resources
resources["one"] = mock("builtin only")
resources["one"].expects(:builtin?).returns(true)
- assert_nil(config.send(:unevaluated_resources), "Considered a builtin resource unevaluated")
+ assert_nil(compile.send(:unevaluated_resources), "Considered a builtin resource unevaluated")
# And do both builtin and non-builtin but already evaluated
resources.clear
@@ -342,14 +350,14 @@ class TestCompile < Test::Unit::TestCase
resources["two"] = mock("evaled (with builtin)")
resources["two"].expects(:builtin?).returns(false)
resources["two"].expects(:evaluated?).returns(true)
- assert_nil(config.send(:unevaluated_resources), "Considered either a builtin or evaluated resource unevaluated")
+ assert_nil(compile.send(:unevaluated_resources), "Considered either a builtin or evaluated resource unevaluated")
# Now a single unevaluated resource.
resources.clear
resources["one"] = mock("unevaluated")
resources["one"].expects(:builtin?).returns(false)
resources["one"].expects(:evaluated?).returns(false)
- assert_equal([resources["one"]], config.send(:unevaluated_resources), "Did not find unevaluated resource")
+ assert_equal([resources["one"]], compile.send(:unevaluated_resources), "Did not find unevaluated resource")
# With two uneval'ed resources, and an eval'ed one thrown in
resources.clear
@@ -363,7 +371,7 @@ class TestCompile < Test::Unit::TestCase
resources["three"].expects(:builtin?).returns(false)
resources["three"].expects(:evaluated?).returns(true)
- result = config.send(:unevaluated_resources)
+ result = compile.send(:unevaluated_resources)
%w{one two}.each do |name|
assert(result.include?(resources[name]), "Did not find %s in the unevaluated list" % name)
end
@@ -371,11 +379,11 @@ class TestCompile < Test::Unit::TestCase
def test_evaluate_definitions
# First try the case where there's nothing to return
- config = mkconfig
- config.expects(:unevaluated_resources).returns(nil)
+ compile = mkcompile
+ compile.expects(:unevaluated_resources).returns(nil)
assert_nothing_raised("Could not test for unevaluated resources") do
- assert(! config.send(:evaluate_definitions), "evaluate_definitions returned true when no resources were evaluated")
+ assert(! compile.send(:evaluate_definitions), "evaluate_definitions returned true when no resources were evaluated")
end
# Now try it with resources left to evaluate
@@ -385,22 +393,22 @@ class TestCompile < Test::Unit::TestCase
res2 = mock("resource2")
res2.expects(:evaluate)
resources << res1 << res2
- config = mkconfig
- config.expects(:unevaluated_resources).returns(resources)
+ compile = mkcompile
+ compile.expects(:unevaluated_resources).returns(resources)
assert_nothing_raised("Could not test for unevaluated resources") do
- assert(config.send(:evaluate_definitions), "evaluate_definitions returned false when resources were evaluated")
+ assert(compile.send(:evaluate_definitions), "evaluate_definitions returned false when resources were evaluated")
end
end
def test_evaluate_generators
# First try the case where we have nothing to do
- config = mkconfig
- config.expects(:evaluate_definitions).returns(false)
- config.expects(:evaluate_collections).returns(false)
+ compile = mkcompile
+ compile.expects(:evaluate_definitions).returns(false)
+ compile.expects(:evaluate_collections).returns(false)
assert_nothing_raised("Could not call :eval_iterate") do
- config.send(:evaluate_generators)
+ compile.send(:evaluate_generators)
end
# FIXME I could not get this test to work, but the code is short
@@ -408,39 +416,39 @@ class TestCompile < Test::Unit::TestCase
# It's important that collections are evaluated before definitions,
# so make sure that's the case by verifying that collections get tested
# twice but definitions only once.
- #config = mkconfig
- #config.expects(:evaluate_collections).returns(true).returns(false)
- #config.expects(:evaluate_definitions).returns(false)
- #config.send(:eval_iterate)
+ #compile = mkcompile
+ #compile.expects(:evaluate_collections).returns(true).returns(false)
+ #compile.expects(:evaluate_definitions).returns(false)
+ #compile.send(:eval_iterate)
end
def test_store
- config = mkconfig
+ compile = mkcompile
Puppet.features.expects(:rails?).returns(true)
Puppet::Rails.expects(:connect)
node = mock 'node'
resource_table = mock 'resources'
resource_table.expects(:values).returns(:resources)
- config.instance_variable_set("@node", node)
- config.instance_variable_set("@resource_table", resource_table)
- config.expects(:store_to_active_record).with(node, :resources)
- config.send(:store)
+ compile.instance_variable_set("@node", node)
+ compile.instance_variable_set("@resource_table", resource_table)
+ compile.expects(:store_to_active_record).with(node, :resources)
+ compile.send(:store)
end
def test_store_to_active_record
- config = mkconfig
+ compile = mkcompile
node = mock 'node'
node.expects(:name).returns("myname")
Puppet::Rails::Host.stubs(:transaction).yields
Puppet::Rails::Host.expects(:store).with(node, :resources)
- config.send(:store_to_active_record, node, :resources)
+ compile.send(:store_to_active_record, node, :resources)
end
# Make sure that 'finish' gets called on all of our resources.
def test_finish
- config = mkconfig
- table = config.instance_variable_get("@resource_table")
+ compile = mkcompile
+ table = compile.instance_variable_get("@resource_table")
# Add a resource that does respond to :finish
yep = mock("finisher")
@@ -453,17 +461,17 @@ class TestCompile < Test::Unit::TestCase
dnf.expects(:respond_to?).with(:finish).returns(false)
table["dnf"] = dnf
- config.send(:finish)
+ compile.send(:finish)
end
def test_verify_uniqueness
- config = mkconfig
+ compile = mkcompile
- resources = config.instance_variable_get("@resource_table")
+ resources = compile.instance_variable_get("@resource_table")
resource = mock("noconflict")
resource.expects(:ref).returns("File[yay]")
assert_nothing_raised("Raised an exception when there should have been no conflict") do
- config.send(:verify_uniqueness, resource)
+ compile.send(:verify_uniqueness, resource)
end
# Now try the case where our type is isomorphic
@@ -477,7 +485,7 @@ class TestCompile < Test::Unit::TestCase
faketype.expects(:name).returns("whatever")
Puppet::Type.expects(:type).with("testtype").returns(faketype)
assert_nothing_raised("Raised an exception when was a conflict in non-isomorphic types") do
- config.send(:verify_uniqueness, isoconflict)
+ compile.send(:verify_uniqueness, isoconflict)
end
# Now test for when we actually have an exception
@@ -495,63 +503,62 @@ class TestCompile < Test::Unit::TestCase
faketype.expects(:isomorphic?).returns(true)
Puppet::Type.expects(:type).with("conflict").returns(faketype)
assert_raise(Puppet::ParseError, "Did not fail when two isomorphic resources conflicted") do
- config.send(:verify_uniqueness, conflict)
+ compile.send(:verify_uniqueness, conflict)
end
end
def test_store_resource
# Run once when there's no conflict
- config = mkconfig
- table = config.instance_variable_get("@resource_table")
+ compile = mkcompile
+ table = compile.instance_variable_get("@resource_table")
resource = mock("resource")
resource.expects(:ref).returns("yay")
- config.expects(:verify_uniqueness).with(resource)
- scope = mock("scope")
+ compile.expects(:verify_uniqueness).with(resource)
+ scope = stub("scope", :resource => mock('resource'))
- graph = config.instance_variable_get("@resource_graph")
- graph.expects(:add_edge!).with(scope, resource)
+ compile.configuration.expects(:add_edge!).with(scope.resource, resource)
assert_nothing_raised("Could not store resource") do
- config.store_resource(scope, resource)
+ compile.store_resource(scope, resource)
end
assert_equal(resource, table["yay"], "Did not store resource in table")
# Now for conflicts
- config = mkconfig
- table = config.instance_variable_get("@resource_table")
+ compile = mkcompile
+ table = compile.instance_variable_get("@resource_table")
resource = mock("resource")
- config.expects(:verify_uniqueness).with(resource).raises(ArgumentError)
+ compile.expects(:verify_uniqueness).with(resource).raises(ArgumentError)
assert_raise(ArgumentError, "Did not raise uniqueness exception") do
- config.store_resource(scope, resource)
+ compile.store_resource(scope, resource)
end
assert(table.empty?, "Conflicting resource was stored in table")
end
def test_fail_on_unevaluated
- config = mkconfig
- config.expects(:fail_on_unevaluated_overrides)
- config.expects(:fail_on_unevaluated_resource_collections)
- config.send :fail_on_unevaluated
+ compile = mkcompile
+ compile.expects(:fail_on_unevaluated_overrides)
+ compile.expects(:fail_on_unevaluated_resource_collections)
+ compile.send :fail_on_unevaluated
end
def test_store_override
# First test the case when the resource is not present.
- config = mkconfig
- overrides = config.instance_variable_get("@resource_overrides")
+ compile = mkcompile
+ overrides = compile.instance_variable_get("@resource_overrides")
override = Object.new
override.expects(:ref).returns(:myref).times(2)
override.expects(:override=).with(true)
assert_nothing_raised("Could not call store_override") do
- config.store_override(override)
+ compile.store_override(override)
end
assert_instance_of(Array, overrides[:myref], "Overrides table is not a hash of arrays")
assert_equal(override, overrides[:myref][0], "Did not store override in appropriately named array")
# And when the resource already exists.
resource = mock 'resource'
- resources = config.instance_variable_get("@resource_table")
+ resources = compile.instance_variable_get("@resource_table")
resources[:resref] = resource
override = mock 'override'
@@ -559,34 +566,34 @@ class TestCompile < Test::Unit::TestCase
override.expects(:override=).with(true)
override.expects(:ref).returns(:resref)
assert_nothing_raised("Could not call store_override when the resource already exists.") do
- config.store_override(override)
+ compile.store_override(override)
end
end
def test_resource_overrides
- config = mkconfig
- overrides = config.instance_variable_get("@resource_overrides")
+ compile = mkcompile
+ overrides = compile.instance_variable_get("@resource_overrides")
overrides[:test] = :yay
resource = mock 'resource'
resource.expects(:ref).returns(:test)
- assert_equal(:yay, config.resource_overrides(resource), "Did not return overrides from table")
+ assert_equal(:yay, compile.resource_overrides(resource), "Did not return overrides from table")
end
def test_fail_on_unevaluated_resource_collections
- config = mkconfig
- collections = config.instance_variable_get("@collections")
+ compile = mkcompile
+ collections = compile.instance_variable_get("@collections")
# Make sure we're fine when the list is empty
assert_nothing_raised("Failed when no collections were present") do
- config.send :fail_on_unevaluated_resource_collections
+ compile.send :fail_on_unevaluated_resource_collections
end
# And that we're fine when we've got collections but with no resources
collections << mock('coll')
collections[0].expects(:resources).returns(nil)
assert_nothing_raised("Failed when no resource collections were present") do
- config.send :fail_on_unevaluated_resource_collections
+ compile.send :fail_on_unevaluated_resource_collections
end
# But that we do fail when we've got resource collections left.
@@ -600,17 +607,17 @@ class TestCompile < Test::Unit::TestCase
collections[1].expects(:resources).returns([:one, :two])
assert_raise(Puppet::ParseError, "Did not fail on unevaluated resource collections") do
- config.send :fail_on_unevaluated_resource_collections
+ compile.send :fail_on_unevaluated_resource_collections
end
end
def test_fail_on_unevaluated_overrides
- config = mkconfig
- overrides = config.instance_variable_get("@resource_overrides")
+ compile = mkcompile
+ overrides = compile.instance_variable_get("@resource_overrides")
# Make sure we're fine when the list is empty
assert_nothing_raised("Failed when no collections were present") do
- config.send :fail_on_unevaluated_overrides
+ compile.send :fail_on_unevaluated_overrides
end
# But that we fail if there are any overrides left in the table.
@@ -619,44 +626,44 @@ class TestCompile < Test::Unit::TestCase
overrides[:bar] = [mock("override")]
overrides[:bar][0].expects(:ref).returns("yay")
assert_raise(Puppet::ParseError, "Failed to fail when overrides remain") do
- config.send :fail_on_unevaluated_overrides
+ compile.send :fail_on_unevaluated_overrides
end
end
def test_find_resource
- config = mkconfig
- resources = config.instance_variable_get("@resource_table")
+ compile = mkcompile
+ resources = compile.instance_variable_get("@resource_table")
assert_nothing_raised("Could not call findresource when the resource table was empty") do
- assert_nil(config.findresource("yay", "foo"), "Returned a non-existent resource")
- assert_nil(config.findresource("yay[foo]"), "Returned a non-existent resource")
+ assert_nil(compile.findresource("yay", "foo"), "Returned a non-existent resource")
+ assert_nil(compile.findresource("yay[foo]"), "Returned a non-existent resource")
end
resources["Foo[bar]"] = :yay
assert_nothing_raised("Could not call findresource when the resource table was not empty") do
- assert_equal(:yay, config.findresource("foo", "bar"), "Returned a non-existent resource")
- assert_equal(:yay, config.findresource("Foo[bar]"), "Returned a non-existent resource")
+ assert_equal(:yay, compile.findresource("foo", "bar"), "Returned a non-existent resource")
+ assert_equal(:yay, compile.findresource("Foo[bar]"), "Returned a non-existent resource")
end
end
# #620 - Nodes and classes should conflict, else classes don't get evaluated
def test_nodes_and_classes_name_conflict
# Test node then class
- config = mkconfig
+ compile = mkcompile
node = stub :nodescope? => true
klass = stub :nodescope? => false
- config.class_set("one", node)
+ compile.class_set("one", node)
assert_raise(Puppet::ParseError, "Did not fail when replacing node with class") do
- config.class_set("one", klass)
+ compile.class_set("one", klass)
end
# and class then node
- config = mkconfig
+ compile = mkcompile
node = stub :nodescope? => true
klass = stub :nodescope? => false
- config.class_set("two", klass)
+ compile.class_set("two", klass)
assert_raise(Puppet::ParseError, "Did not fail when replacing node with class") do
- config.class_set("two", node)
+ compile.class_set("two", node)
end
end
end
diff --git a/test/language/functions.rb b/test/language/functions.rb
index 6cea89066..efa506218 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -49,9 +49,10 @@ class TestLangFunctions < Test::Unit::TestCase
def test_taggedfunction
scope = mkscope
+ tags = []
+ scope.resource.stubs(:tags).returns(tags)
- tag = "yayness"
- scope.tag(tag)
+ tags << "yayness"
{"yayness" => true, "booness" => false}.each do |tag, retval|
func = taggedobj(tag, :rvalue)
@@ -318,7 +319,7 @@ class TestLangFunctions < Test::Unit::TestCase
[%w{file /tmp/virtual}, %w{mytype yay}].each do |type, title|
# Make a virtual resource
virtual = mkresource(:type => type, :title => title,
- :virtual => true, :params => {})
+ :virtual => true, :params => {}, :scope => scope)
scope.compile.store_resource(scope, virtual)
@@ -434,7 +435,7 @@ class TestLangFunctions < Test::Unit::TestCase
scope.function_include "myclass"
end
- assert(scope.compile.classlist.include?("myclass"),
+ assert(scope.compile.resources.find { |r| r.to_s == "Class[myclass]" },
"class was not evaluated")
# Now try multiple classes at once
@@ -445,7 +446,7 @@ class TestLangFunctions < Test::Unit::TestCase
end
classes.each do |c|
- assert(scope.compile.classlist.include?(c),
+ assert(scope.compile.resources.find { |r| r.to_s == "Class[#{c}]" },
"class %s was not evaluated" % c)
end
diff --git a/test/language/parser.rb b/test/language/parser.rb
index 0406e99ba..36e058b11 100755
--- a/test/language/parser.rb
+++ b/test/language/parser.rb
@@ -497,7 +497,7 @@ file { "/tmp/yayness":
scope.source = klass
assert_nothing_raised do
- ret.classes[""].evaluate :scope => scope
+ ret.classes[""].evaluate :scope => scope, :resource => Puppet::Parser::Resource.new(:type => "mydefine", :title => 'whatever', :scope => scope, :source => scope.source)
end
# Make sure we can find both of them
diff --git a/test/language/resource.rb b/test/language/resource.rb
index f594691c6..8978a3a37 100755
--- a/test/language/resource.rb
+++ b/test/language/resource.rb
@@ -25,7 +25,7 @@ class TestResource < PuppetTest::TestCase
def test_initialize
args = {:type => "resource", :title => "testing",
- :source => "source", :scope => "scope"}
+ :scope => mkscope}
# Check our arg requirements
args.each do |name, value|
try = args.dup
@@ -35,12 +35,14 @@ class TestResource < PuppetTest::TestCase
end
end
- Reference.expects(:new).with(:type => "resource", :title => "testing", :scope => "scope").returns(:ref)
-
res = nil
assert_nothing_raised do
res = Parser::Resource.new(args)
end
+
+ ref = res.instance_variable_get("@ref")
+ assert_equal("resource", ref.type, "did not set resource type")
+ assert_equal("testing", ref.title, "did not set resource title")
end
def test_merge
@@ -213,8 +215,8 @@ class TestResource < PuppetTest::TestCase
# First try translating a builtin resource. Make sure we use some references
# and arrays, to make sure they translate correctly.
source = mock("source")
- scope = mock("scope")
- scope.expects(:tags).returns([])
+ scope = mkscope
+ scope.stubs(:tags).returns([])
refs = []
4.times { |i| refs << Puppet::Parser::Resource::Reference.new(:title => "file%s" % i, :type => "file") }
res = Parser::Resource.new :type => "file", :title => "/tmp",
@@ -245,16 +247,15 @@ class TestResource < PuppetTest::TestCase
# FIXME This isn't a great test, but I need to move on.
def test_to_transbucket
bucket = mock("transbucket")
- Puppet::TransBucket.expects(:new).with([]).returns(bucket)
source = mock("source")
- scope = mock("scope")
+ scope = mkscope
res = Parser::Resource.new :type => "mydefine", :title => "yay",
:source => source, :scope => scope
- bucket.expects(:name=).with("yay")
- bucket.expects(:type=).with("mydefine")
- assert_equal(bucket, res.to_trans, "Resource did not return the bucket")
+ result = res.to_trans
+ assert_equal("yay", result.name, "did not set bucket name correctly")
+ assert_equal("mydefine", result.type, "did not set bucket type correctly")
end
def test_evaluate
@@ -309,7 +310,7 @@ class TestResource < PuppetTest::TestCase
def test_proxymethods
res = Parser::Resource.new :type => "evaltest", :title => "yay",
- :source => mock("source"), :scope => mock('scope')
+ :source => mock("source"), :scope => mkscope
assert_equal("evaltest", res.type)
assert_equal("yay", res.title)
@@ -337,7 +338,7 @@ class TestResource < PuppetTest::TestCase
# Now create an obj that uses it
res = mkresource :type => "file", :title => "/tmp/resource",
:params => {:require => ref}
- res.scope = stub(:tags => [])
+ res.scope = mkscope
trans = nil
assert_nothing_raised do
@@ -351,7 +352,7 @@ class TestResource < PuppetTest::TestCase
two = Parser::Resource::Reference.new(:type => "file", :title => "/tmp/ref2")
res = mkresource :type => "file", :title => "/tmp/resource2",
:params => {:require => [ref, two]}
- res.scope = stub(:tags => [])
+ res.scope = mkscope
trans = nil
assert_nothing_raised do
@@ -420,7 +421,7 @@ class TestResource < PuppetTest::TestCase
# part of #629 -- the undef keyword. Make sure 'undef' params get skipped.
def test_undef_and_to_hash
res = mkresource :type => "file", :title => "/tmp/testing",
- :source => mock("source"), :scope => mock("scope"),
+ :source => mock("source"), :scope => mkscope,
:params => {:owner => :undef, :mode => "755"}
hash = nil
@@ -470,6 +471,37 @@ class TestResource < PuppetTest::TestCase
assert(newres.exported?, "Exported defined resource generated non-exported resources")
assert(newres.virtual?, "Exported defined resource generated non-virtual resources")
end
-end
-# $Id$
+ # Make sure tags behave appropriately.
+ def test_tags
+ scope_resource = stub 'scope_resource', :tags => %w{srone srtwo}
+ scope = stub 'scope', :resource => scope_resource
+ resource = Puppet::Parser::Resource.new(:type => "file", :title => "yay", :scope => scope, :source => mock('source'))
+
+ # Make sure we get the scope resource's tags, plus the type and title
+ %w{srone srtwo yay file}.each do |tag|
+ assert(resource.tags.include?(tag), "Did not tag resource with %s" % tag)
+ end
+
+ # make sure we can only set legal tags
+ ["an invalid tag", "-anotherinvalid", "bad*tag"].each do |tag|
+ assert_raise(Puppet::ParseError, "Tag #{tag} was considered valid") do
+ resource.tag tag
+ end
+ end
+
+ # make sure good tags make it through.
+ tags = %w{good-tag yaytag GoodTag another_tag a ab A}
+ tags.each do |tag|
+ assert_nothing_raised("Tag #{tag} was considered invalid") do
+ resource.tag tag
+ end
+ end
+
+ # make sure we get each of them.
+ ptags = resource.tags
+ tags.each do |tag|
+ assert(ptags.include?(tag), "missing #{tag}")
+ end
+ end
+end
diff --git a/test/language/scope.rb b/test/language/scope.rb
index 66bc632bf..213226241 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -93,7 +93,7 @@ class TestScope < Test::Unit::TestCase
scopes = {}
classes = ["", "one", "one::two", "one::two::three"].each do |name|
klass = parser.newclass(name)
- klass.evaluate(:scope => scope)
+ Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate
scopes[name] = scope.compile.class_scope(klass)
end
@@ -194,16 +194,8 @@ class TestScope < Test::Unit::TestCase
parser = mkparser
klass = parser.newclass("")
scope = mkscope(:parser => parser)
- klass.evaluate(:scope => scope)
+ Puppet::Parser::Resource.new(:type => "class", :title => :main, :scope => scope, :source => mock('source')).evaluate
- klass = parser.newclass("one")
- klass.evaluate(:scope => scope)
-
- klass = parser.newclass("one::two")
- klass.evaluate(:scope => scope)
-
-
- scope = scope.compile.class_scope("")
assert_nothing_raised {
scope.setvar("test","value")
}
@@ -212,7 +204,7 @@ class TestScope < Test::Unit::TestCase
%w{one one::two one::two::three}.each do |name|
klass = parser.newclass(name)
- klass.evaluate(:scope => scope)
+ Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate
scopes[name] = scope.compile.class_scope(klass)
scopes[name].setvar("test", "value-%s" % name.sub(/.+::/,''))
end
@@ -267,41 +259,13 @@ class TestScope < Test::Unit::TestCase
end
end
- def test_validtags
- scope = mkscope()
-
- ["a class", "a.class"].each do |bad|
- assert_raise(Puppet::ParseError, "Incorrectly allowed %s" % bad.inspect) do
- scope.tag(bad)
- end
- end
-
- ["a-class", "a_class", "Class", "class", "yayNess"].each do |good|
- assert_nothing_raised("Incorrectly banned %s" % good.inspect) do
- scope.tag(good)
- end
- end
-
- end
-
def test_tagfunction
scope = mkscope
-
- assert_nothing_raised {
- scope.function_tag(["yayness", "booness"])
- }
-
- assert(scope.tags.include?("yayness"), "tag 'yayness' did not get set")
- assert(scope.tags.include?("booness"), "tag 'booness' did not get set")
+ resource = mock 'resource'
+ scope.resource = resource
+ resource.expects(:tag).with("yayness", "booness")
- # Now verify that the 'tagged' function works correctly
- assert(scope.function_tagged("yayness"),
- "tagged function incorrectly returned false")
- assert(scope.function_tagged("booness"),
- "tagged function incorrectly returned false")
-
- assert(! scope.function_tagged("funtest"),
- "tagged function incorrectly returned true")
+ scope.function_tag(%w{yayness booness})
end
def test_includefunction
@@ -323,6 +287,8 @@ class TestScope < Test::Unit::TestCase
function.evaluate :scope => scope
end
+ scope.compile.send(:evaluate_generators)
+
[myclass, otherclass].each do |klass|
assert(scope.compile.class_scope(klass),
"%s was not set" % klass.classname)
@@ -372,6 +338,10 @@ class TestScope < Test::Unit::TestCase
# Create a default source
config.topscope.source = parser.newclass "", ""
+ # And a scope resource
+ scope_res = stub 'scope_resource', :virtual? => true, :exported? => false, :tags => []
+ config.topscope.resource = scope_res
+
args = AST::ASTArray.new(
:file => tempfile(),
:line => rand(100),
@@ -470,42 +440,6 @@ Host <<||>>"
$stderr.puts "No ActiveRecord -- skipping collection tests"
end
- # Make sure tags behave appropriately.
- def test_tags
- parser, scope, source = mkclassframing
-
- # First make sure we can only set legal tags
- ["an invalid tag", "-anotherinvalid", "bad*tag"].each do |tag|
- assert_raise(Puppet::ParseError, "Tag #{tag} was considered valid") do
- scope.tag tag
- end
- end
-
- # Now make sure good tags make it through.
- tags = %w{good-tag yaytag GoodTag another_tag a ab A}
- tags.each do |tag|
- assert_nothing_raised("Tag #{tag} was considered invalid") do
- scope.tag tag
- end
- end
-
- # And make sure we get each of them.
- ptags = scope.tags
- tags.each do |tag|
- assert(ptags.include?(tag), "missing #{tag}")
- end
-
-
- # Now create a subscope and set some tags there
- newscope = scope.newscope(:type => 'subscope')
-
- # set some tags
- newscope.tag "onemore", "yaytag"
-
- # And make sure we get them plus our parent tags
- assert_equal((ptags + %w{onemore subscope}).sort, newscope.tags.sort)
- end
-
def test_namespaces
parser, scope, source = mkclassframing
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index 34aeca00a..9e90bbdd6 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -73,6 +73,8 @@ module PuppetTest::ParserTesting
unless config.topscope.source
raise "Could not find source for scope"
end
+ # Make the 'main' stuff
+ config.send(:evaluate_main)
config.topscope
end
@@ -404,5 +406,3 @@ module PuppetTest::ParserTesting
return trans
end
end
-
-# $Id$
diff --git a/test/lib/puppettest/resourcetesting.rb b/test/lib/puppettest/resourcetesting.rb
index e2176d5ef..54154d504 100644
--- a/test/lib/puppettest/resourcetesting.rb
+++ b/test/lib/puppettest/resourcetesting.rb
@@ -28,7 +28,7 @@ module PuppetTest::ResourceTesting
def mkresource(args = {})
args[:source] ||= "source"
- args[:scope] ||= stub :tags => []
+ args[:scope] ||= mkscope
{:type => "resource", :title => "testing",
:source => "source", :scope => "scope"}.each do |param, value|