[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585
James Turnbull
james at lovedthanlost.net
Fri Jan 23 14:21:16 UTC 2009
The following commit has been merged in the master branch:
commit 79bb1f201c1479a15fa2f0f8ad5467bd357ed707
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date: Sat Oct 4 00:16:17 2008 +0200
Rspec Tests for #381.
Moved part of the old resource reference tests to rspec.
diff --git a/CHANGELOG b/CHANGELOG
index 3f0c963..fec8ad6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,6 @@
0.24.x
+ Fixed #381 - Allow Allow multiple overrides in one statement
+
Fixing #947 - pluginsync no longer fails poorly when no plugins exist
Fixed #981 - Removed 'Adding aliases' info message
diff --git a/spec/unit/parser/ast/resource_override.rb b/spec/unit/parser/ast/resource_override.rb
new file mode 100755
index 0000000..3fbeb32
--- /dev/null
+++ b/spec/unit/parser/ast/resource_override.rb
@@ -0,0 +1,51 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::ResourceOverride do
+
+ AST = Puppet::Parser::AST
+
+ before :each do
+ @compiler = stub 'compiler'
+ @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
+ @params = AST::ASTArray.new({})
+ @compiler.stubs(:add_override)
+ end
+
+ it "should evaluate the overriden object" do
+ klass = stub 'klass', :title => "title", :type => "type"
+ object = mock 'object'
+ object.expects(:safeevaluate).with(@scope).returns(klass)
+ AST::ResourceOverride.new(:object => object, :params => @params ).evaluate(@scope)
+ end
+
+ it "should tell the compiler to override the resource with our own" do
+ @compiler.expects(:add_override)
+
+ klass = stub 'klass', :title => "title", :type => "one"
+ object = mock 'object', :safeevaluate => klass
+ AST::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope)
+ end
+
+ it "should return the overriden resource directly when called with one item" do
+ klass = stub 'klass', :title => "title", :type => "one"
+ object = mock 'object', :safeevaluate => klass
+ override = AST::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope)
+ override.should be_an_instance_of(Puppet::Parser::Resource)
+ override.title.should == "title"
+ override.type.should == "One"
+ end
+
+ it "should return an array of overriden resources when called with an array of titles" do
+ klass1 = stub 'klass1', :title => "title1", :type => "one"
+ klass2 = stub 'klass2', :title => "title2", :type => "one"
+
+ object = mock 'object', :safeevaluate => [klass1,klass2]
+
+ override = AST::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope)
+ override.should have(2).elements
+ override.each {|o| o.should be_an_instance_of(Puppet::Parser::Resource) }
+ end
+
+end
\ No newline at end of file
diff --git a/spec/unit/parser/ast/resource_reference.rb b/spec/unit/parser/ast/resource_reference.rb
new file mode 100755
index 0000000..e4b7c76
--- /dev/null
+++ b/spec/unit/parser/ast/resource_reference.rb
@@ -0,0 +1,63 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::ResourceReference do
+
+ AST = Puppet::Parser::AST
+
+ before :each do
+ @scope = Puppet::Parser::Scope.new()
+ end
+
+ def newref(title, type)
+ title = stub 'title', :safeevaluate => title
+ ref = AST::ResourceReference.new(:type => type, :title => title)
+ end
+
+ it "should evaluate correctly reference to builtin types" do
+ newref("/tmp/yay", "File").evaluate(@scope).to_s.should == "File[/tmp/yay]"
+ end
+
+ %{ "one::two" "one-two"}.each do |type|
+ it "should evaluate correctly reference to define" do
+ klass = stub 'klass', :title => "three", :classname => type
+ @scope.stubs(:finddefine).returns(klass)
+
+ newref("three", type).evaluate(@scope).to_ref.should == Puppet::Parser::Resource::Reference.new( :type => type, :title => "three" ).to_ref
+ end
+ end
+
+ it "should be able to call qualified_class" do
+ klass = stub 'klass', :title => "three", :classname => "one"
+ @scope.expects(:findclass).with("one").returns(klass)
+ newref("three","class").qualified_class(@scope,"one").should == "one"
+ end
+
+ it "should be able to find qualified classes when evaluating" do
+ klass = stub 'klass', :title => "one", :classname => "one"
+ @scope.stubs(:findclass).returns(klass)
+
+ evaled = newref("one", "class").evaluate(@scope)
+ evaled.type.should == "Class"
+ evaled.title.should == "one"
+ end
+
+ it "should return an array of reference if given an array of titles" do
+ titles = mock 'titles', :safeevaluate => ["title1","title2"]
+ ref = AST::ResourceReference.new( :title => titles, :type => "Resource" )
+ ref.stubs(:qualified_type).with(@scope).returns("Resource")
+
+ ref.evaluate(@scope).should have(2).elements
+ end
+
+ it "should qualify class of all titles for Class resource references" do
+ titles = mock 'titles', :safeevaluate => ["title1","title2"]
+ ref = AST::ResourceReference.new( :title => titles, :type => "Class" )
+ ref.expects(:qualified_class).with(@scope,"title1").returns("class")
+ ref.expects(:qualified_class).with(@scope,"title2").returns("class")
+
+ ref.evaluate(@scope)
+ end
+
+end
\ No newline at end of file
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index 17e80bb..0092a99 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -76,5 +76,44 @@ describe Puppet::Parser do
lambda { @parser.parse("if (1 > 2 > ) or (1 == 2) { $var = 1 }") }.should raise_error
end
- end
+ end
+
+ describe Puppet::Parser, "when parsing resource references" do
+
+ it "should not raise syntax errors" do
+ lambda { @parser.parse('exec { test: param => File["a"] }') }.should_not raise_error
+ end
+
+ it "should not raise syntax errors with multiple references" do
+ lambda { @parser.parse('exec { test: param => File["a","b"] }') }.should_not raise_error
+ end
+
+ it "should create an AST::ResourceReference" do
+ AST::Resource.stubs(:new)
+ AST::ResourceReference.expects(:new).with { |arg|
+ arg[:line]==1 and arg[:type]=="File" and arg[:title].is_a?(AST::ASTArray)
+ }
+ @parser.parse('exec { test: command => File["a","b"] }')
+ end
+ end
+
+ describe Puppet::Parser, "when parsing resource overrides" do
+
+ it "should not raise syntax errors" do
+ lambda { @parser.parse('Resource["title"] { param => value }') }.should_not raise_error
+ end
+
+ it "should not raise syntax errors with multiple overrides" do
+ lambda { @parser.parse('Resource["title1","title2"] { param => value }') }.should_not raise_error
+ end
+
+ it "should create an AST::ResourceOverride" do
+ AST::ResourceOverride.expects(:new).with { |arg|
+ arg[:line]==1 and arg[:object].is_a?(AST::ResourceReference) and arg[:params].is_a?(AST::ResourceParam)
+ }
+ @parser.parse('Resource["title1","title2"] { param => value }')
+ end
+
+ end
+
end
diff --git a/test/language/ast/resource_reference.rb b/test/language/ast/resource_reference.rb
index 1f554d9..75cb53c 100755
--- a/test/language/ast/resource_reference.rb
+++ b/test/language/ast/resource_reference.rb
@@ -23,34 +23,6 @@ class TestASTResourceReference < Test::Unit::TestCase
@parser = @scope.compiler.parser
end
- def test_evaluate
- @parser.newdefine "one::two"
- @parser.newdefine "one-two"
- [%w{File /tmp/yay}, %w{One::Two three}, %w{One-two three}].each do |type, title|
- ref = newref(type, title)
-
- evaled = nil
- assert_nothing_raised("Could not evaluate resource ref") do
- evaled = ref.evaluate(@scope)
- end
-
- assert_equal(type, evaled.type, "Type did not translate correctly")
- assert_equal(title, evaled.title, "Title did not translate correctly")
- end
- end
-
- def test_finding_classes_for_reference
- @parser.newclass "one"
- ref = newref("Class", "one")
- evaled = nil
- assert_nothing_raised("Could not evaluate resource ref") do
- evaled = ref.evaluate(@scope)
- end
-
- assert_equal("Class", evaled.type, "Did not set type to 'class'")
- assert_equal("one", evaled.title, "Did not look up class corectly")
- end
-
# Related to #706, make sure resource references correctly translate to qualified types.
def test_scoped_references
@parser.newdefine "one"
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list