diff options
| author | Luke Kanies <luke@madstop.com> | 2009-02-11 13:51:48 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2009-02-11 13:51:48 -0600 |
| commit | a2270b4a4f093c6c4f171dcf0c0e05fe101dd979 (patch) | |
| tree | f0d893dfe6fe13c8c9e0670c1e5459ec336318ba /spec/unit/parser | |
| parent | 9bac833dcfdd8d6a00188faee0487e787b7a0101 (diff) | |
| parent | 6b0c1b9170c69829bdf5956d1dec0949dcc08b35 (diff) | |
Merge branch '0.24.x'
Conflicts:
CHANGELOG
spec/unit/type/file/selinux.rb
Diffstat (limited to 'spec/unit/parser')
| -rwxr-xr-x | spec/unit/parser/ast/astarray.rb | 4 | ||||
| -rwxr-xr-x | spec/unit/parser/ast/resource.rb | 103 | ||||
| -rwxr-xr-x | spec/unit/parser/collector.rb | 8 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/realize.rb | 51 |
4 files changed, 160 insertions, 6 deletions
diff --git a/spec/unit/parser/ast/astarray.rb b/spec/unit/parser/ast/astarray.rb index f1c28ce47..b3026fe1e 100755 --- a/spec/unit/parser/ast/astarray.rb +++ b/spec/unit/parser/ast/astarray.rb @@ -49,7 +49,7 @@ describe Puppet::Parser::AST::ASTArray do operator.evaluate(@scope).should == [123] end - it "should flatten the results of children evaluation" do + it "should not flatten the results of children evaluation" do item1 = stub "item1", :is_a? => true item2 = stub "item2" item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true) @@ -59,7 +59,7 @@ describe Puppet::Parser::AST::ASTArray do item1.expects(:safeevaluate).with(@scope).returns([123]) operator = Puppet::Parser::AST::ASTArray.new :children => [item2] - operator.evaluate(@scope).should == [123] + operator.evaluate(@scope).should == [[123]] end diff --git a/spec/unit/parser/ast/resource.rb b/spec/unit/parser/ast/resource.rb new file mode 100755 index 000000000..b257cb116 --- /dev/null +++ b/spec/unit/parser/ast/resource.rb @@ -0,0 +1,103 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe Puppet::Parser::AST::Resource do + ast = Puppet::Parser::AST + + before :each do + @title = stub_everything 'title' + @compiler = stub_everything 'compiler' + @scope = Puppet::Parser::Scope.new(:compiler => @compiler) + @param1 = stub_everything 'parameter', :is_a? => true + @scope.stubs(:resource).returns(stub_everything) + @params = ast::ASTArray.new( :children => [@param1]) + @resource = ast::Resource.new(:title => @title, :type => "Resource", :params => @params ) + @resource.stubs(:qualified_type).returns("Resource") + Puppet::Parser::Resource.stubs(:new).returns(stub_everything) + end + + it "should evaluate all its parameters" do + @param1.expects(:safeevaluate).with(@scope) + + @resource.evaluate(@scope) + end + + it "should evaluate its title" do + + @title.expects(:safeevaluate).with(@scope) + + @resource.evaluate(@scope) + 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) + + title_array.expects(:flatten).returns([]) + + @resource.title = titles + @resource.evaluate(@scope) + end + + it "should create one resource objects per title" do + 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.expects(:new).with { |hash| hash[:title] == @title } + + @resource.title = titles + @resource.evaluate(@scope) + 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 + + title_array.stubs(:flatten).returns([@title]) + titles.stubs(:safeevaluate).with(@scope).returns(title_array) + Puppet::Parser::Resource.stubs(:new).returns(resource) + + @compiler.stubs(:add_resource).with(resource) + + @resource.title = titles + @resource.evaluate(@scope).should == [resource] + end + + it "should generate virtual resources if it is virtual" do + @resource.virtual = true + + Puppet::Parser::Resource.expects(:new).with { |hash| hash[:virtual] == true } + + @resource.evaluate(@scope) + end + + it "should generate virtual and exported resources if it is exported" do + @resource.exported = true + + Puppet::Parser::Resource.expects(:new).with { |hash| hash[:virtual] == true and hash[:exported] == true } + + @resource.evaluate(@scope) + end +end diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb index edd74e25f..f92b881c8 100755 --- a/spec/unit/parser/collector.rb +++ b/spec/unit/parser/collector.rb @@ -240,10 +240,10 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do one = stub 'one', :type => "Mytype", :virtual? => true, :exported? => true two = stub 'two', :type => "Mytype", :virtual? => true, :exported? => true - one.expects(:exported=).with(false) - one.expects(:virtual=).with(false) - two.expects(:exported=).with(false) - two.expects(:virtual=).with(false) + one.stubs(:exported=) + one.stubs(:virtual=) + two.stubs(:exported=) + two.stubs(:virtual=) @compiler.expects(:resources).returns([one, two]) diff --git a/spec/unit/parser/functions/realize.rb b/spec/unit/parser/functions/realize.rb new file mode 100755 index 000000000..d9c94b143 --- /dev/null +++ b/spec/unit/parser/functions/realize.rb @@ -0,0 +1,51 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe "the realize function" do + + before :each do + @collector = stub_everything 'collector' + @scope = Puppet::Parser::Scope.new() + @compiler = stub 'compiler' + @compiler.stubs(:add_collection).with(@collector) + @scope.stubs(:compiler).returns(@compiler) + end + + it "should exist" do + Puppet::Parser::Functions.function("realize").should == "function_realize" + end + + it "should create a Collector when called" do + + Puppet::Parser::Collector.expects(:new).returns(@collector) + + @scope.function_realize("test") + end + + it "should assign the passed-in resources to the collector" do + Puppet::Parser::Collector.stubs(:new).returns(@collector) + + @collector.expects(:resources=).with(["test"]) + + @scope.function_realize("test") + end + + it "should flatten the resources assigned to the collector" do + Puppet::Parser::Collector.stubs(:new).returns(@collector) + + @collector.expects(:resources=).with(["test"]) + + @scope.function_realize([["test"]]) + end + + it "should let the compiler know this collector" do + Puppet::Parser::Collector.stubs(:new).returns(@collector) + @collector.stubs(:resources=).with(["test"]) + + @compiler.expects(:add_collection).with(@collector) + + @scope.function_realize("test") + end + +end |
