diff options
author | Luke Kanies <luke@madstop.com> | 2008-02-08 13:54:53 -0800 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-02-08 13:54:53 -0800 |
commit | fb4bdc0b02bba1291cb78ccd5c2a3198d3929d69 (patch) | |
tree | f23da901542f938f8b299f9608690477934b40c8 /test | |
parent | 5a0e34b4f8da22e1830ec7d0a730c3686665bceb (diff) | |
download | puppet-fb4bdc0b02bba1291cb78ccd5c2a3198d3929d69.tar.gz puppet-fb4bdc0b02bba1291cb78ccd5c2a3198d3929d69.tar.xz puppet-fb4bdc0b02bba1291cb78ccd5c2a3198d3929d69.zip |
More AST refactoring -- each of the code wrapping classes
just returns a resource from its evaluate() method, and
all of the work is done in the evaluate_code method. This
makes the code cleaner, because it means 1) evaluate() has
the same prototype as all of the other AST classes,
2) evaluate() is no longer called indirectly through
the Parser Resource class, and 3) the classes themselves
are responsible for creating the resources, rather than
it being done in the Compile class.
Diffstat (limited to 'test')
-rwxr-xr-x | test/language/ast.rb | 50 | ||||
-rwxr-xr-x | test/language/ast/definition.rb | 8 | ||||
-rwxr-xr-x | test/language/ast/hostclass.rb | 16 | ||||
-rwxr-xr-x | test/language/ast/node.rb | 68 | ||||
-rwxr-xr-x | test/language/resource.rb | 2 |
5 files changed, 81 insertions, 63 deletions
diff --git a/test/language/ast.rb b/test/language/ast.rb index 72a3ee90c..9b1c1c1dc 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -93,56 +93,6 @@ class TestAST < Test::Unit::TestCase end end - def test_node - scope = mkscope - parser = scope.compile.parser - - # Define a base node - basenode = parser.newnode "basenode", :code => AST::ASTArray.new(:children => [ - resourcedef("file", "/tmp/base", "owner" => "root") - ]) - - # Now define a subnode - nodes = parser.newnode ["mynode", "othernode"], - :code => AST::ASTArray.new(:children => [ - resourcedef("file", "/tmp/mynode", "owner" => "root"), - resourcedef("file", "/tmp/basenode", "owner" => "daemon") - ]) - - assert_instance_of(Array, nodes) - - # Make sure we can find them all. - %w{mynode othernode}.each do |node| - assert(parser.nodes[node], "Could not find %s" % node) - end - mynode = parser.nodes["mynode"] - - # Now try evaluating the node - assert_nothing_raised do - mynode.evaluate scope, scope.resource - end - - # Make sure that we can find each of the files - myfile = scope.findresource "File[/tmp/mynode]" - assert(myfile, "Could not find file from node") - assert_equal("root", myfile[:owner]) - - basefile = scope.findresource "File[/tmp/basenode]" - assert(basefile, "Could not find file from base node") - assert_equal("daemon", basefile[:owner]) - - # Now make sure we can evaluate nodes with parents - child = parser.newnode(%w{child}, :parent => "basenode").shift - - newscope = mkscope :parser => parser - assert_nothing_raised do - child.evaluate newscope, scope.resource - end - - assert(newscope.findresource("File[/tmp/base]"), - "Could not find base resource") - end - def test_collection scope = mkscope diff --git a/test/language/ast/definition.rb b/test/language/ast/definition.rb index 5f415eb41..d4e4bd185 100755 --- a/test/language/ast/definition.rb +++ b/test/language/ast/definition.rb @@ -63,7 +63,7 @@ class TestASTDefinition < Test::Unit::TestCase resource.stubs(:title) assert_nothing_raised do - klass.evaluate(scope, resource) + klass.evaluate_code(resource) end firstobj = config.findresource("File[/tmp/first]") @@ -76,7 +76,7 @@ class TestASTDefinition < Test::Unit::TestCase # Make sure we can't evaluate it with the same args assert_raise(Puppet::ParseError) do - klass.evaluate(scope, resource) + klass.evaluate_code(resource) end # Now create another with different args @@ -93,7 +93,7 @@ class TestASTDefinition < Test::Unit::TestCase resource2.send(:set_parameter, "owner", "daemon") assert_nothing_raised do - klass.evaluate(scope, resource2) + klass.evaluate_code(resource2) end secondobj = config.findresource("File[/tmp/second]") @@ -136,7 +136,7 @@ class TestASTDefinition < Test::Unit::TestCase end assert_nothing_raised("Could not evaluate definition with %s" % hash.inspect) do - klass.evaluate(scope, resource) + klass.evaluate_code(resource) end name = hash[:name] || hash[:title] diff --git a/test/language/ast/hostclass.rb b/test/language/ast/hostclass.rb index abc5e05be..7697317a6 100755 --- a/test/language/ast/hostclass.rb +++ b/test/language/ast/hostclass.rb @@ -29,12 +29,12 @@ class TestASTHostClass < Test::Unit::TestCase resource = Puppet::Parser::Resource.new(:type => "class", :title => "first", :scope => scope) assert_nothing_raised do - klass.evaluate(scope, resource) + klass.evaluate_code(resource) end # Then try it again assert_nothing_raised do - klass.evaluate(scope, resource) + klass.evaluate_code(resource) end assert(scope.compile.class_scope(klass), "Class was not considered evaluated") @@ -70,11 +70,11 @@ class TestASTHostClass < Test::Unit::TestCase ) assert_nothing_raised do - newsub.evaluate(scope, resource) + newsub.evaluate_code(resource) end assert_nothing_raised do - moresub.evaluate(scope, resource) + moresub.evaluate_code(resource) end assert(scope.compile.class_scope(newbase), "Did not eval newbase") @@ -174,11 +174,11 @@ class TestASTHostClass < Test::Unit::TestCase base = parser.newclass "base" sub = parser.newclass "sub", :parent => "base" - base.expects(:safeevaluate).with do |*args| - assert(scope.compile.catalog.tags.include?("sub"), "Did not tag with sub class name before evaluating base class") - base.evaluate(*args) + base.expects(:evaluate_code).with do |*args| + assert(scope.catalog.tags.include?("sub"), "Did not tag with sub class name before evaluating base class") + base.evaluate_code(*args) true end - sub.evaluate scope, scope.resource + sub.evaluate_code scope.resource end end diff --git a/test/language/ast/node.rb b/test/language/ast/node.rb new file mode 100755 index 000000000..df732480d --- /dev/null +++ b/test/language/ast/node.rb @@ -0,0 +1,68 @@ +#!/usr/bin/env ruby +# +# Created by Luke A. Kanies on 2008-02-09. +# Copyright (c) 2008. All rights reserved. + +require File.dirname(__FILE__) + '/../../lib/puppettest' + +require 'puppettest' +require 'mocha' +require 'puppettest/parsertesting' +require 'puppettest/resourcetesting' + +class TestASTNode < Test::Unit::TestCase + include PuppetTest + include PuppetTest::ParserTesting + include PuppetTest::ResourceTesting + AST = Puppet::Parser::AST + + def test_node + scope = mkscope + parser = scope.compile.parser + + # Define a base node + basenode = parser.newnode "basenode", :code => AST::ASTArray.new(:children => [ + resourcedef("file", "/tmp/base", "owner" => "root") + ]) + + # Now define a subnode + nodes = parser.newnode ["mynode", "othernode"], + :code => AST::ASTArray.new(:children => [ + resourcedef("file", "/tmp/mynode", "owner" => "root"), + resourcedef("file", "/tmp/basenode", "owner" => "daemon") + ]) + + assert_instance_of(Array, nodes) + + # Make sure we can find them all. + %w{mynode othernode}.each do |node| + assert(parser.nodes[node], "Could not find %s" % node) + end + mynode = parser.nodes["mynode"] + + # Now try evaluating the node + assert_nothing_raised do + mynode.evaluate_code scope.resource + end + + # Make sure that we can find each of the files + myfile = scope.findresource "File[/tmp/mynode]" + assert(myfile, "Could not find file from node") + assert_equal("root", myfile[:owner]) + + basefile = scope.findresource "File[/tmp/basenode]" + assert(basefile, "Could not find file from base node") + assert_equal("daemon", basefile[:owner]) + + # Now make sure we can evaluate nodes with parents + child = parser.newnode(%w{child}, :parent => "basenode").shift + + newscope = mkscope :parser => parser + assert_nothing_raised do + child.evaluate_code newscope.resource + end + + assert(newscope.findresource("File[/tmp/base]"), + "Could not find base resource") + end +end diff --git a/test/language/resource.rb b/test/language/resource.rb index 3c027ed07..3aa9dcf6a 100755 --- a/test/language/resource.rb +++ b/test/language/resource.rb @@ -270,7 +270,7 @@ class TestResource < PuppetTest::TestCase res.scope.expects(:compile).returns(config) config.expects(:delete_resource).with(res) - type.expects(:evaluate).with(res.scope, res) + type.expects(:evaluate_code).with(res) res.evaluate end |