3
require File.dirname(__FILE__) + '/../spec_helper'
5
require 'puppet/resource_reference'
7
describe Puppet::ResourceReference do
8
it "should have a :title attribute" do
9
Puppet::ResourceReference.new(:file, "foo").title.should == "foo"
12
it "should canonize types to capitalized strings" do
13
Puppet::ResourceReference.new(:file, "foo").type.should == "File"
16
it "should canonize qualified types so all strings are capitalized" do
17
Puppet::ResourceReference.new("foo::bar", "foo").type.should == "Foo::Bar"
20
it "should set its type to 'Class' and its title to the passed title if the passed type is :component and the title has no square brackets in it" do
21
ref = Puppet::ResourceReference.new(:component, "foo")
22
ref.type.should == "Class"
23
ref.title.should == "foo"
26
it "should interpret the title as a reference and assign appropriately if the type is :component and the title contains square brackets" do
27
ref = Puppet::ResourceReference.new(:component, "foo::bar[yay]")
28
ref.type.should == "Foo::Bar"
29
ref.title.should == "yay"
32
it "should set the type to 'Class' if it is nil and the title contains no square brackets" do
33
ref = Puppet::ResourceReference.new(nil, "yay")
34
ref.type.should == "Class"
35
ref.title.should == "yay"
38
it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains square brackets" do
39
ref = Puppet::ResourceReference.new(nil, "foo::bar[yay]")
40
ref.type.should == "Foo::Bar"
41
ref.title.should == "yay"
44
it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains nested square brackets" do
45
ref = Puppet::ResourceReference.new(nil, "foo::bar[baz[yay]]")
46
ref.type.should == "Foo::Bar"
47
ref.title.should =="baz[yay]"
51
describe Puppet::ResourceReference, "when resolving resources without a catalog" do
52
it "should be able to resolve builtin resources from their types" do
53
Puppet::Type.type(:file).expects(:[]).with("myfile").returns(:myfile)
54
Puppet::ResourceReference.new(:file, "myfile").resolve.should == :myfile
57
it "should be able to resolve defined resources from Components" do
58
Puppet::Type.type(:component).expects(:[]).with("Foo::Bar[yay]").returns(:mything)
59
Puppet::ResourceReference.new("foo::bar", "yay").resolve.should == :mything
63
describe Puppet::ResourceReference, "when resolving resources with a catalog" do
64
it "should resolve all resources using the catalog" do
65
config = mock 'catalog'
66
ref = Puppet::ResourceReference.new("foo::bar", "yay")
69
config.expects(:resource).with("Foo::Bar[yay]").returns(:myresource)
71
ref.resolve.should == :myresource