summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2010-01-30 23:51:59 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit5401a7ca8550ade0443188b505a104ca5726ec80 (patch)
tree137027c51dfd95c1c5cd0c53a4d5361e8fe46576 /spec
parent9c867e6d79dcc56cd34683c9a339dc729ad2d291 (diff)
downloadpuppet-5401a7ca8550ade0443188b505a104ca5726ec80.tar.gz
puppet-5401a7ca8550ade0443188b505a104ca5726ec80.tar.xz
puppet-5401a7ca8550ade0443188b505a104ca5726ec80.zip
Adding strictness checking to resources
This is used for AST resources (and fixed the last of the tests I broke in spec/). Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/parser/ast/resource.rb82
-rwxr-xr-xspec/unit/resource.rb14
2 files changed, 47 insertions, 49 deletions
diff --git a/spec/unit/parser/ast/resource.rb b/spec/unit/parser/ast/resource.rb
index ef65f4ccd..40074c7ca 100755
--- a/spec/unit/parser/ast/resource.rb
+++ b/spec/unit/parser/ast/resource.rb
@@ -6,11 +6,11 @@ describe Puppet::Parser::AST::Resource do
ast = Puppet::Parser::AST
before :each do
- @title = stub_everything 'title'
- @compiler = stub_everything 'compiler', :environment => Puppet::Node::Environment.new
+ @title = Puppet::Parser::AST::String.new(:value => "mytitle")
+ @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
@scope = Puppet::Parser::Scope.new(:compiler => @compiler)
@scope.stubs(:resource).returns(stub_everything)
- @resource = ast::Resource.new(:title => @title, :type => "Resource", :params => ast::ASTArray.new(:children => []) )
+ @resource = ast::Resource.new(:title => @title, :type => "file", :params => ast::ASTArray.new(:children => []) )
@resource.stubs(:qualified_type).returns("Resource")
end
@@ -23,73 +23,57 @@ describe Puppet::Parser::AST::Resource do
end
it "should evaluate its title" do
-
- @title.expects(:safeevaluate).with(@scope)
-
- @resource.evaluate(@scope)
+ @resource.evaluate(@scope)[0].title.should == "mytitle"
end
it "should flatten the titles array" do
- titles = stub 'titles'
- title_array = stub 'title_array', :is_a? => true
-
- titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+ titles = []
+ %w{one two}.each do |title|
+ titles << Puppet::Parser::AST::String.new(:value => title)
+ end
- title_array.expects(:flatten).returns([])
+ array = Puppet::Parser::AST::ASTArray.new(:children => titles)
- @resource.title = titles
- @resource.evaluate(@scope)
+ @resource.title = array
+ result = @resource.evaluate(@scope).collect { |r| r.title }
+ result.should be_include("one")
+ result.should be_include("two")
end
- it "should create one resource objects per title" do
- titles = stub 'titles'
- title_array = stub 'title_array', :is_a? => true
+ it "should create and return one resource objects per title" do
+ titles = []
+ %w{one two}.each do |title|
+ titles << Puppet::Parser::AST::String.new(:value => title)
+ end
- title_array.stubs(:flatten).returns([@title])
- titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+ array = Puppet::Parser::AST::ASTArray.new(:children => titles)
- @resource.title = titles
- result = @resource.evaluate(@scope)
- result[0].should be_instance_of(Puppet::Parser::Resource)
- result[0].title.should == @title
+ @resource.title = array
+ result = @resource.evaluate(@scope).collect { |r| r.title }
+ result.should be_include("one")
+ result.should be_include("two")
end
it "should handover resources to the compiler" do
- resource = stub 'resource'
- titles = stub 'titles'
- title_array = stub 'title_array', :is_a? => true
-
- title_array.stubs(:flatten).returns([@title])
- titles.stubs(:safeevaluate).with(@scope).returns(title_array)
- Puppet::Parser::Resource.stubs(:new).returns(resource)
-
- @compiler.expects(:add_resource).with(@scope, resource)
-
- @resource.title = titles
- @resource.evaluate(@scope)
- end
-
- it "should return the newly created resources" do
- resource = stub 'resource'
- titles = stub 'titles'
- title_array = stub 'title_array', :is_a? => true
+ titles = []
+ %w{one two}.each do |title|
+ titles << Puppet::Parser::AST::String.new(:value => title)
+ end
- title_array.stubs(:flatten).returns([@title])
- titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+ array = Puppet::Parser::AST::ASTArray.new(:children => titles)
- @compiler.stubs(:add_resource)
+ @resource.title = array
+ result = @resource.evaluate(@scope)
- @resource.title = titles
- @resource.evaluate(@scope)[0].should be_instance_of(Puppet::Parser::Resource)
+ result.each do |res|
+ @compiler.catalog.resource(res.ref).should be_instance_of(Puppet::Parser::Resource)
+ end
end
-
it "should generate virtual resources if it is virtual" do
@resource.virtual = true
result = @resource.evaluate(@scope)
result[0].should be_virtual
-
- @resource.evaluate(@scope)
end
it "should generate virtual and exported resources if it is exported" do
diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb
index 834a5b078..5b82c2936 100755
--- a/spec/unit/resource.rb
+++ b/spec/unit/resource.rb
@@ -250,6 +250,20 @@ describe Puppet::Resource do
end
end
+ describe "when running in strict mode" do
+ it "should be strict" do
+ Puppet::Resource.new("file", "/path", :strict => true).should be_strict
+ end
+
+ it "should fail if invalid parameters are used" do
+ lambda { Puppet::Resource.new("file", "/path", :strict => true, :parameters => {:nosuchparam => "bar"}) }.should raise_error
+ end
+
+ it "should fail if the resource type cannot be resolved" do
+ lambda { Puppet::Resource.new("nosuchtype", "/path", :strict => true) }.should raise_error
+ end
+ end
+
describe "when managing parameters" do
before do
@resource = Puppet::Resource.new("file", "/my/file")