summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-03 19:38:15 -0500
committerLuke Kanies <luke@madstop.com>2007-09-03 19:38:15 -0500
commit0faf76ee187c7fa7c67a7fb7e7c345897006b7d8 (patch)
tree21b680c617e869b11579172ab9aac33518db68da /test
parent9d70b9746c09f648efd6a315b3ea088da38ecd1e (diff)
downloadpuppet-0faf76ee187c7fa7c67a7fb7e7c345897006b7d8.tar.gz
puppet-0faf76ee187c7fa7c67a7fb7e7c345897006b7d8.tar.xz
puppet-0faf76ee187c7fa7c67a7fb7e7c345897006b7d8.zip
More refactoring. I have removed a few more extraneous methods from Scope, mostly just pointing directly to the compile, and I have begun (but commented out) the move to having resources to model each of the classes and nodes, in addition to the definitions. This will, again, enable a real Configuration object, and it will enable class versioning and similar features.
Diffstat (limited to 'test')
-rwxr-xr-xtest/language/ast.rb2
-rwxr-xr-xtest/language/ast/definition.rb8
-rwxr-xr-xtest/language/ast/hostclass.rb14
-rwxr-xr-xtest/language/compile.rb4
-rwxr-xr-xtest/language/scope.rb47
5 files changed, 17 insertions, 58 deletions
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 847d24660..000a56a89 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -57,7 +57,7 @@ class TestAST < Test::Unit::TestCase
end
Puppet::Parser::Resource.expects(:new).with { |o| o.is_a?(Hash) }.returns(:override)
- scope.expects(:setoverride).with(:override)
+ scope.compile.expects(:store_override).with(:override)
ret = nil
assert_nothing_raised do
ret = ref.evaluate :scope => scope
diff --git a/test/language/ast/definition.rb b/test/language/ast/definition.rb
index 5a2e6ffea..51948b01f 100755
--- a/test/language/ast/definition.rb
+++ b/test/language/ast/definition.rb
@@ -110,10 +110,6 @@ class TestASTDefinition < Test::Unit::TestCase
# inside the loop so the subscope expectations work.
klass = parser.newdefine "yayness%s" % i
- subscope = klass.subscope(scope, "yayness%s" % i)
-
- klass.expects(:subscope).returns(subscope)
-
resource = stub 'resource',
:title => hash[:title],
:name => hash[:name] || hash[:title],
@@ -122,6 +118,10 @@ class TestASTDefinition < Test::Unit::TestCase
:exported => false,
:virtual => false
+ subscope = klass.subscope(scope, resource)
+
+ klass.expects(:subscope).returns(subscope)
+
if hash[:name]
resource.stubs(:to_hash).returns({:name => hash[:name]})
end
diff --git a/test/language/ast/hostclass.rb b/test/language/ast/hostclass.rb
index 62483730b..c88152913 100755
--- a/test/language/ast/hostclass.rb
+++ b/test/language/ast/hostclass.rb
@@ -36,7 +36,7 @@ class TestASTHostClass < Test::Unit::TestCase
klass.evaluate(:scope => scope)
end
- assert(scope.class_scope(klass), "Class was not considered evaluated")
+ assert(scope.compile.class_scope(klass), "Class was not considered evaluated")
tmp = scope.findresource("File[/tmp]")
assert(tmp, "Could not find file /tmp")
@@ -76,8 +76,8 @@ class TestASTHostClass < Test::Unit::TestCase
moresub.evaluate(:scope => scope)
end
- assert(scope.class_scope(newbase), "Did not eval newbase")
- assert(scope.class_scope(newsub), "Did not eval newsub")
+ assert(scope.compile.class_scope(newbase), "Did not eval newbase")
+ assert(scope.compile.class_scope(newsub), "Did not eval newsub")
yay = scope.findresource("File[/tmp/yay]")
assert(yay, "Did not find file /tmp/yay")
@@ -141,14 +141,14 @@ class TestASTHostClass < Test::Unit::TestCase
ret = nil
assert_nothing_raised do
- ret = scope.compile.evaluate_classes(["sub"], source)
+ ret = scope.compile.evaluate_classes(["sub"], scope)
end
- subscope = scope.class_scope(scope.findclass("sub"))
+ subscope = scope.compile.class_scope(scope.findclass("sub"))
assert(subscope, "could not find sub scope")
- mscope = scope.class_scope(scope.findclass("middle"))
+ mscope = scope.compile.class_scope(scope.findclass("middle"))
assert(mscope, "could not find middle scope")
- pscope = scope.class_scope(scope.findclass("base"))
+ pscope = scope.compile.class_scope(scope.findclass("base"))
assert(pscope, "could not find parent scope")
assert(pscope == mscope.parent, "parent scope of middle was not set correctly")
diff --git a/test/language/compile.rb b/test/language/compile.rb
index 5fde2500e..3128b8e64 100755
--- a/test/language/compile.rb
+++ b/test/language/compile.rb
@@ -270,10 +270,8 @@ class TestCompile < Test::Unit::TestCase
def test_evaluate_node_classes
config = mkconfig
- main = mock 'main'
- config.parser.expects(:findclass).with("", "").returns(main)
@node.classes = %w{one two three four}
- config.expects(:evaluate_classes).with(%w{one two three four}, main)
+ config.expects(:evaluate_classes).with(%w{one two three four}, config.topscope)
assert_nothing_raised("could not call evaluate_node_classes") do
config.send(:evaluate_node_classes)
end
diff --git a/test/language/scope.rb b/test/language/scope.rb
index fc5e085d4..43cbfd47c 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -94,7 +94,7 @@ class TestScope < Test::Unit::TestCase
classes = ["", "one", "one::two", "one::two::three"].each do |name|
klass = parser.newclass(name)
klass.evaluate(:scope => scope)
- scopes[name] = scope.class_scope(klass)
+ scopes[name] = scope.compile.class_scope(klass)
end
classes.each do |name|
@@ -188,13 +188,6 @@ class TestScope < Test::Unit::TestCase
assert_equal(top, sub.parent, "Did not find parent scope correctly")
assert_equal(top, sub.parent, "Did not find parent scope on second call")
end
-
- def test_class_scope
- config = mkconfig
- scope = config.topscope
- config.expects(:class_scope).with(:testing).returns(:myscope)
- assert_equal(:myscope, scope.class_scope(:testing), "Did not pass back the results of config.class_scope")
- end
def test_strinterp
# Make and evaluate our classes so the qualified lookups work
@@ -210,7 +203,7 @@ class TestScope < Test::Unit::TestCase
klass.evaluate(:scope => scope)
- scope = scope.class_scope("")
+ scope = scope.compile.class_scope("")
assert_nothing_raised {
scope.setvar("test","value")
}
@@ -220,7 +213,7 @@ class TestScope < Test::Unit::TestCase
%w{one one::two one::two::three}.each do |name|
klass = parser.newclass(name)
klass.evaluate(:scope => scope)
- scopes[name] = scope.class_scope(klass)
+ scopes[name] = scope.compile.class_scope(klass)
scopes[name].setvar("test", "value-%s" % name.sub(/.+::/,''))
end
@@ -274,38 +267,6 @@ class TestScope < Test::Unit::TestCase
end
end
- def test_setclass
- # Run through it when we're a normal class
- config = mkconfig
- scope = config.topscope
- klass = mock("class")
- klass.expects(:classname).returns(:myclass)
- klass.expects(:is_a?).with(AST::HostClass).returns(true)
- klass.expects(:is_a?).with(AST::Node).returns(false)
- config.expects(:class_set).with(:myclass, scope)
- scope.setclass(klass)
-
- # And when we're a node
- config = mkconfig
- scope = config.topscope
- klass = mock("class2")
- klass.expects(:classname).returns(:myclass)
- klass.expects(:is_a?).with(AST::HostClass).returns(true)
- klass.expects(:is_a?).with(AST::Node).returns(true)
- config.expects(:class_set).with(:myclass, scope)
- scope.setclass(klass)
- assert(scope.nodescope?, "Did not set the scope as a node scope when evaluating a node")
-
- # And when we're invalid
- config = mkconfig
- scope = config.topscope
- klass = mock("class3")
- klass.expects(:is_a?).with(AST::HostClass).returns(false)
- assert_raise(Puppet::DevError, "Did not fail when scope got passed a non-component") do
- scope.setclass(klass)
- end
- end
-
def test_validtags
scope = mkscope()
@@ -363,7 +324,7 @@ class TestScope < Test::Unit::TestCase
end
[myclass, otherclass].each do |klass|
- assert(scope.class_scope(klass),
+ assert(scope.compile.class_scope(klass),
"%s was not set" % klass.classname)
end
end