summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2010-01-30 23:36:32 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit9c867e6d79dcc56cd34683c9a339dc729ad2d291 (patch)
tree27ee2a51648d11891a5168db1e63e064244eeef5 /spec/unit/parser
parent274d1c5e78250640b8d2c40201ca2586c0088f32 (diff)
downloadpuppet-9c867e6d79dcc56cd34683c9a339dc729ad2d291.tar.gz
puppet-9c867e6d79dcc56cd34683c9a339dc729ad2d291.tar.xz
puppet-9c867e6d79dcc56cd34683c9a339dc729ad2d291.zip
Fixing most of the broken tests in test/
This involves a bit of refactoring in the rest of the code to make it all work, but most of the changes are fixing or removing old tests. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/ast/resource.rb36
-rwxr-xr-xspec/unit/parser/collector.rb8
-rwxr-xr-xspec/unit/parser/resource.rb36
3 files changed, 49 insertions, 31 deletions
diff --git a/spec/unit/parser/ast/resource.rb b/spec/unit/parser/ast/resource.rb
index 391f4c770..ef65f4ccd 100755
--- a/spec/unit/parser/ast/resource.rb
+++ b/spec/unit/parser/ast/resource.rb
@@ -7,7 +7,7 @@ describe Puppet::Parser::AST::Resource do
before :each do
@title = stub_everything 'title'
- @compiler = stub_everything 'compiler'
+ @compiler = stub_everything 'compiler', :environment => Puppet::Node::Environment.new
@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 => []) )
@@ -99,4 +99,38 @@ describe Puppet::Parser::AST::Resource do
result[0].should be_virtual
result[0].should be_exported
end
+
+ # Related to #806, make sure resources always look up the full path to the resource.
+ describe "when generating qualified resources" do
+ before do
+ @scope = Puppet::Parser::Scope.new :compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
+ @parser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
+ @parser.newdefine "one"
+ @parser.newdefine "one::two"
+ @parser.newdefine "three"
+ @twoscope = @scope.newscope(:namespace => "one")
+ @twoscope.resource = @scope.resource
+ end
+
+ def resource(type, params = nil)
+ params ||= Puppet::Parser::AST::ASTArray.new(:children => [])
+ Puppet::Parser::AST::Resource.new(:type => type, :title => Puppet::Parser::AST::String.new(:value => "myresource"), :params => params)
+ end
+
+ it "should be able to generate resources with fully qualified type information" do
+ resource("two").evaluate(@twoscope)[0].type.should == "One::Two"
+ end
+
+ it "should be able to generate resources with unqualified type information" do
+ resource("one").evaluate(@twoscope)[0].type.should == "One"
+ end
+
+ it "should correctly generate resources that can look up builtin types" do
+ resource("file").evaluate(@twoscope)[0].type.should == "File"
+ end
+
+ it "should fail for resource types that do not exist" do
+ lambda { resource("nosuchtype").evaluate(@twoscope) }.should raise_error(Puppet::ParseError)
+ end
+ end
end
diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb
index 9c2d722e5..78d47c63f 100755
--- a/spec/unit/parser/collector.rb
+++ b/spec/unit/parser/collector.rb
@@ -174,7 +174,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
@collector.evaluate.should == [one]
end
- it "should create a resource with overriden parameters" do
+ it "should create a resource with overridden parameters" do
one = stub_everything 'one', :type => "Mytype", :virtual? => true, :title => "test"
param = stub 'param'
@compiler.stubs(:add_override)
@@ -182,7 +182,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
@compiler.expects(:resources).returns([one])
@collector.add_override(:params => param )
- Puppet::Parser::Resource.expects(:new).with { |h|
+ Puppet::Parser::Resource.expects(:new).with { |type, title, h|
h[:params] == param
}
@@ -214,7 +214,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
@compiler.expects(:resources).at_least(2).returns([one])
@collector.add_override(:params => param )
- Puppet::Parser::Resource.expects(:new).once.with { |h|
+ Puppet::Parser::Resource.expects(:new).once.with { |type, title, h|
h[:params] == param
}
@@ -375,7 +375,7 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
@compiler.stubs(:add_resource)
@collector.add_override(:params => param )
- Puppet::Parser::Resource.expects(:new).once.with { |h|
+ Puppet::Parser::Resource.expects(:new).once.with { |type, title, h|
h[:params] == param
}
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index 0c70c817e..ee0c1e089 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -16,12 +16,8 @@ describe Puppet::Parser::Resource do
end
def mkresource(args = {})
- args[:source] ||= "source"
- args[:scope] ||= stub('scope', :source => mock('source'))
-
- {:source => "source", :scope => "scope"}.each do |param, value|
- args[param] ||= value
- end
+ args[:source] ||= @source
+ args[:scope] ||= @scope
params = args[:params] || {:one => "yay", :three => "rah"}
if args[:params] == :none
@@ -101,18 +97,18 @@ describe Puppet::Parser::Resource do
end
it "should be able to use the indexing operator to access parameters" do
- resource = Puppet::Parser::Resource.new("resource", "testing", :source => "source", :scope => "scope")
+ resource = Puppet::Parser::Resource.new("resource", "testing", :source => "source", :scope => @scope)
resource["foo"] = "bar"
resource["foo"].should == "bar"
end
it "should return the title when asked for a parameter named 'title'" do
- Puppet::Parser::Resource.new("resource", "testing", :source => "source", :scope => "scope")[:title].should == "testing"
+ Puppet::Parser::Resource.new("resource", "testing", :source => @source, :scope => @scope)[:title].should == "testing"
end
describe "when initializing" do
before do
- @arguments = {:scope => stub('scope', :source => mock('source'))}
+ @arguments = {:scope => @scope}
end
it "should fail unless #{name.to_s} is specified" do
@@ -132,17 +128,6 @@ describe Puppet::Parser::Resource do
end
end
- describe "when refering to a resource with name canonicalization" do
- before do
- @arguments = {:scope => stub('scope', :source => mock('source'))}
- end
-
- it "should canonicalize its own name" do
- res = Puppet::Parser::Resource.new("file", "/path/", @arguments)
- res.ref.should == "File[/path]"
- end
- end
-
describe "when evaluating" do
it "should evaluate the associated AST definition" do
definition = newdefine "mydefine"
@@ -294,7 +279,7 @@ describe Puppet::Parser::Resource do
describe "when being tagged" do
before do
@scope_resource = stub 'scope_resource', :tags => %w{srone srtwo}
- @scope = stub 'scope', :resource => @scope_resource
+ @scope.stubs(:resource).returns @scope_resource
@resource = Puppet::Parser::Resource.new("file", "yay", :scope => @scope, :source => mock('source'))
end
@@ -448,8 +433,7 @@ describe Puppet::Parser::Resource do
describe "when being converted to a resource" do
before do
- @source = stub 'scope', :name => "myscope"
- @parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => "fum"}
+ @parser_resource = mkresource :scope => @scope, :params => {:foo => "bar", :fee => "fum"}
end
it "should create an instance of Puppet::Resource" do
@@ -537,7 +521,7 @@ describe Puppet::Parser::Resource do
describe "when validating" do
it "should check each parameter" do
- resource = Puppet::Parser::Resource.new :foo, "bar", :scope => stub("scope"), :source => stub("source")
+ resource = Puppet::Parser::Resource.new :foo, "bar", :scope => @scope, :source => stub("source")
resource[:one] = :two
resource[:three] = :four
resource.expects(:validate_parameter).with(:one)
@@ -546,7 +530,7 @@ describe Puppet::Parser::Resource do
end
it "should raise a parse error when there's a failure" do
- resource = Puppet::Parser::Resource.new :foo, "bar", :scope => stub("scope"), :source => stub("source")
+ resource = Puppet::Parser::Resource.new :foo, "bar", :scope => @scope, :source => stub("source")
resource[:one] = :two
resource.expects(:validate_parameter).with(:one).raises ArgumentError
lambda { resource.send(:validate) }.should raise_error(Puppet::ParseError)
@@ -556,7 +540,7 @@ describe Puppet::Parser::Resource do
describe "when setting parameters" do
before do
@source = newclass "foobar"
- @resource = Puppet::Parser::Resource.new :foo, "bar", :scope => stub("scope"), :source => @source
+ @resource = Puppet::Parser::Resource.new :foo, "bar", :scope => @scope, :source => @source
end
it "should accept Param instances and add them to the parameter list" do