summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/resource
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2010-01-29 20:57:21 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit7089446697ad550c22012bc2b5572030727d67e1 (patch)
tree40d160f11839fe6e20311186ded4e621d23e1242 /spec/unit/parser/resource
parent4871c909cd28c82b64d0b62d8a27e62737d8733d (diff)
downloadpuppet-7089446697ad550c22012bc2b5572030727d67e1.tar.gz
puppet-7089446697ad550c22012bc2b5572030727d67e1.tar.xz
puppet-7089446697ad550c22012bc2b5572030727d67e1.zip
Removing Resource::Reference classes
This commit is hopefully less messy than it first appears, but it's certainly cross-cutting. The reason for all of this is that we previously only looked up builtin resource types from outside the parser, but now that the defined resource types are available globally via environments, we can push that lookup code to Resource. Once we do that, however, we have to have environment and namespace information in every resource. Here I remove the Resource::Reference classes (except the AST class), and use Resource instances instead. I did this because the shared code between the two classes got incredibly complicated, such that they should have had a hierarchical relationship disallowed by their constants. This complexity convinced me just to get rid of References entirely. I also make Puppet::Parser::Resource a subclass of Puppet::Resource. There are still broken tests in test/, but this was a big enough commit I wanted to get it in. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'spec/unit/parser/resource')
-rwxr-xr-xspec/unit/parser/resource/reference.rb134
1 files changed, 0 insertions, 134 deletions
diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb
deleted file mode 100755
index a38604226..000000000
--- a/spec/unit/parser/resource/reference.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-#!/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 get its environment from its scope" do
- env = stub 'environment'
- scope = stub 'scope', :environment => env
- @type.new(:title => "foo", :type => "bar", :scope => scope).environment.should equal(env)
- end
-
- it "should use the resource type collection helper to find its known resource types" do
- Puppet::Parser::Resource::Reference.ancestors.should include(Puppet::Resource::TypeCollectionHelper)
- end
-
- it "should use the file lookup module" do
- Puppet::Parser::Resource::Reference.ancestors.should be_include(Puppet::FileCollection::Lookup)
- 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 refers to 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 downcased relationship-style resource reference for defined types" do
- ref = @type.new(:type => "file", :title => "/tmp/yay")
- ref.to_ref.should == ["file", "/tmp/yay"]
- end
-
- it "should return a capitalized relationship-style resource reference for defined types" do
- ref = @type.new(:type => "whatever", :title => "/tmp/yay")
- ref.to_ref.should == ["Whatever", "/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
-
- it "should canonize resource reference types" do
- ref = @type.new(:type => "foo::bar", :title => "/tmp/yay")
- ref.to_s.should == "Foo::Bar[/tmp/yay]"
- end
-
- it "should canonize resource reference values" do
- ref = @type.new(:type => "file", :title => "/tmp/yay/")
- ref.to_s.should == "File[/tmp/yay]"
- end
-
- it "should canonize resource reference values without order dependencies" do
- args = [[:title, "/tmp/yay/"], [:type, "file"]]
- ref = @type.new(args)
- ref.to_s.should == "File[/tmp/yay]"
- end
-
-end
-
-describe Puppet::Parser::Resource::Reference, " when modeling defined types" do
- def newclass(name)
- @known_resource_types.add Puppet::Resource::Type.new(:hostclass, name)
- end
-
- def newdefine(name)
- @known_resource_types.add Puppet::Resource::Type.new(:definition, name)
- end
-
- def newnode(name)
- @known_resource_types.add Puppet::Resource::Type.new(:node, name)
- end
-
- before do
- @type = Puppet::Parser::Resource::Reference
-
- @known_resource_types = Puppet::Resource::TypeCollection.new("myenv")
- @definition = newdefine("mydefine")
- @class = newclass("myclass")
- @nodedef = newnode("mynode")
- @node = Puppet::Node.new("yaynode")
-
- @compiler = Puppet::Parser::Compiler.new(@node)
- @compiler.environment.stubs(:known_resource_types).returns @known_resource_types
- end
-
- it "should be able to find defined types" do
- ref = @type.new(:type => "mydefine", :title => "/tmp/yay", :scope => @compiler.topscope)
- ref.builtin?.should be_false
- ref.definedtype.should equal(@definition)
- end
-
- it "should be able to find classes" do
- ref = @type.new(:type => "class", :title => "myclass", :scope => @compiler.topscope)
- ref.builtin?.should be_false
- ref.definedtype.should equal(@class)
- end
-
- it "should be able to find nodes" do
- ref = @type.new(:type => "node", :title => "mynode", :scope => @compiler.topscope)
- ref.builtin?.should be_false
- ref.definedtype.object_id.should == @nodedef.object_id
- end
-
- it "should only look for fully qualified classes" do
- top = newclass "top"
- sub = newclass "other::top"
-
- scope = @compiler.topscope.class.new(:parent => @compiler.topscope, :namespace => "other", :compiler => @compiler)
-
- ref = @type.new(:type => "class", :title => "top", :scope => scope)
- ref.definedtype.name.should equal(top.name)
- end
-
- it "should only look for fully qualified definitions" do
- top = newdefine "top"
- sub = newdefine "other::top"
-
- scope = @compiler.topscope.class.new(:parent => @compiler.topscope, :namespace => "other", :compiler => @compiler)
-
- ref = @type.new(:type => "top", :title => "foo", :scope => scope)
- ref.definedtype.name.should equal(top.name)
- end
-end