summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/resource/reference.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-03 18:01:00 -0500
committerLuke Kanies <luke@madstop.com>2007-09-03 18:01:00 -0500
commitb021587e309f237bd16bd4f5cc51e79266cbd222 (patch)
treeb46de15108c7f1fcf50b67a54bcb8f528854e566 /spec/unit/parser/resource/reference.rb
parent25f6d7c521cb0189cf691fb1c4bce4b675568300 (diff)
downloadpuppet-b021587e309f237bd16bd4f5cc51e79266cbd222.tar.gz
puppet-b021587e309f237bd16bd4f5cc51e79266cbd222.tar.xz
puppet-b021587e309f237bd16bd4f5cc51e79266cbd222.zip
Doing a small amount of refactoring, toward being able to use Parser resources to evaluate classes and nodes, not just definitions. This will hopefully simplify some of the parsing work, and it will enable the use of a Configuration object that more completely models a configuration.
Diffstat (limited to 'spec/unit/parser/resource/reference.rb')
-rwxr-xr-xspec/unit/parser/resource/reference.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb
new file mode 100755
index 000000000..45af3d938
--- /dev/null
+++ b/spec/unit/parser/resource/reference.rb
@@ -0,0 +1,66 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::Resource::Reference do
+ before do
+ @type = Puppet::Parser::Resource::Reference
+ end
+
+ it "should require a type" do
+ proc { @type.new(:title => "yay") }.should raise_error(Puppet::DevError)
+ end
+
+ it "should require a title" do
+ proc { @type.new(:type => "file") }.should raise_error(Puppet::DevError)
+ end
+
+ it "should know when it models a builtin type" do
+ ref = @type.new(:type => "file", :title => "/tmp/yay")
+ ref.builtin?.should be_true
+ ref.builtintype.should equal(Puppet::Type.type(:file))
+ end
+
+ it "should return a relationship-style resource reference when asked" do
+ ref = @type.new(:type => "file", :title => "/tmp/yay")
+ ref.to_ref.should == ["file", "/tmp/yay"]
+ end
+
+ it "should return a resource reference string when asked" do
+ ref = @type.new(:type => "file", :title => "/tmp/yay")
+ ref.to_s.should == "File[/tmp/yay]"
+ end
+end
+
+describe Puppet::Parser::Resource::Reference, " when modeling defined types" do
+ before do
+ @type = Puppet::Parser::Resource::Reference
+
+ @parser = Puppet::Parser::Parser.new :Code => ""
+ @definition = @parser.newdefine "mydefine"
+ @class = @parser.newclass "myclass"
+ @nodedef = @parser.newnode("mynode")[0]
+ @node = Puppet::Node.new("yaynode")
+
+ @compile = Puppet::Parser::Compile.new(@node, @parser)
+ end
+
+ it "should be able to model definitions" do
+ ref = @type.new(:type => "mydefine", :title => "/tmp/yay", :scope => @compile.topscope)
+ ref.builtin?.should be_false
+ ref.definedtype.should equal(@definition)
+ end
+
+ it "should be able to model classes" do
+ ref = @type.new(:type => "class", :title => "myclass", :scope => @compile.topscope)
+ ref.builtin?.should be_false
+ ref.definedtype.should equal(@class)
+ end
+
+ it "should be able to model nodes" do
+ ref = @type.new(:type => "node", :title => "mynode", :scope => @compile.topscope)
+ ref.builtin?.should be_false
+ ref.definedtype.object_id.should == @nodedef.object_id
+ end
+end
+