diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-06 18:45:41 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-06 18:45:41 -0500 |
| commit | 653c1514b613f27cb22d24b4bdd7b6c118047566 (patch) | |
| tree | 54fadb5316bed0637e646c1e6f9ad09077416435 /test/language/ast | |
| parent | 40e3b372ec2a3b45a5254a85f9b808bf3450e316 (diff) | |
| download | puppet-653c1514b613f27cb22d24b4bdd7b6c118047566.tar.gz puppet-653c1514b613f27cb22d24b4bdd7b6c118047566.tar.xz puppet-653c1514b613f27cb22d24b4bdd7b6c118047566.zip | |
Fixing #806. Resources correctly look up their fully qualified definition type, just like resource references do, which causes the resource and reference to again agree on the full name of a given defined type.
Diffstat (limited to 'test/language/ast')
| -rwxr-xr-x | test/language/ast/resourcedef.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/language/ast/resourcedef.rb b/test/language/ast/resourcedef.rb new file mode 100755 index 000000000..d79a02cfa --- /dev/null +++ b/test/language/ast/resourcedef.rb @@ -0,0 +1,59 @@ +#!/usr/bin/env ruby +# +# Created by Luke A. Kanies on 2007-07-8. +# Copyright (c) 2007. All rights reserved. + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppettest' +require 'puppettest/parsertesting' + +class TestASTResourceDef < Test::Unit::TestCase + include PuppetTest + include PuppetTest::ParserTesting + AST = Puppet::Parser::AST + + def setup + super + @scope = mkscope + @parser = @scope.compile.parser + @scope.compile.send(:evaluate_main) + end + + def newdef(type, title, params = nil) + params ||= AST::ASTArray.new(:children => []) + AST::ResourceDef.new(:type => type, :title => AST::String.new(:value => title), :params => params) + end + + # Related to #806, make sure resources always look up the full path to the resource. + def test_scoped_types + @parser.newdefine "one" + @parser.newdefine "one::two" + @parser.newdefine "three" + twoscope = @scope.newscope(:namespace => "one") + twoscope.resource = @scope.resource + assert(twoscope.finddefine("two"), "Could not find 'two' definition") + title = "title" + + # First try a qualified type + assert_equal("one::two", newdef("two", title).evaluate(:scope => twoscope)[0].type, + "Defined type was not made fully qualified") + + # Then try a type that does not need to be qualified + assert_equal("one", newdef("one", title).evaluate(:scope => twoscope)[0].type, + "Unqualified defined type was not handled correctly") + + # Then an unqualified type from within the one namespace + assert_equal("three", newdef("three", title).evaluate(:scope => twoscope)[0].type, + "Defined type was not made fully qualified") + + # Then a builtin type + assert_equal("file", newdef("file", title).evaluate(:scope => twoscope)[0].type, + "Builtin type was not handled correctly") + + # Now try a type that does not exist, which should throw an error. + assert_raise(Puppet::ParseError, "Did not fail on a missing type in a resource reference") do + newdef("nosuchtype", title).evaluate(:scope => twoscope) + end + end +end |
