3
require File.dirname(__FILE__) + '/../../spec_helper'
5
require 'puppet/resource/reference'
7
describe Puppet::Resource::Reference do
8
it "should have a :title attribute" do
9
Puppet::Resource::Reference.new(:file, "foo").title.should == "foo"
12
it "should canonize types to capitalized strings" do
13
Puppet::Resource::Reference.new(:file, "foo").type.should == "File"
16
it "should canonize qualified types so all strings are capitalized" do
17
Puppet::Resource::Reference.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::Resource::Reference.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::Resource::Reference.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::Resource::Reference.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::Resource::Reference.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::Resource::Reference.new(nil, "foo::bar[baz[yay]]")
46
ref.type.should == "Foo::Bar"
47
ref.title.should =="baz[yay]"
50
it "should interpret the type as a reference and assign appropriately if the title is nil and the type contains square brackets" do
51
ref = Puppet::Resource::Reference.new("foo::bar[baz]")
52
ref.type.should == "Foo::Bar"
53
ref.title.should =="baz"
56
it "should be able to extract its information from a Puppet::Type instance" do
57
ral = Puppet::Type.type(:file).new :path => "/foo"
58
ref = Puppet::Resource::Reference.new(ral)
59
ref.type.should == "File"
60
ref.title.should == "/foo"
64
it "should fail if the title is nil and the type is not a valid resource reference string" do
65
lambda { Puppet::Resource::Reference.new("foo") }.should raise_error(ArgumentError)
68
it "should be considered builtin if an existing resource type matches the type" do
69
Puppet::Resource::Reference.new("file", "/f").should be_builtin_type
72
it "should be not considered builtin if an existing resource type does not match the type" do
73
Puppet::Resource::Reference.new("foobar", "/f").should_not be_builtin_type
76
it "should be able to produce a backward-compatible reference array" do
77
Puppet::Resource::Reference.new("foobar", "/f").to_trans_ref.should == %w{Foobar /f}
80
it "should downcase resource types when producing a backward-compatible reference array for builtin resource types" do
81
Puppet::Resource::Reference.new("file", "/f").to_trans_ref.should == %w{file /f}
84
it "should be considered equivalent to another reference if their type and title match" do
85
Puppet::Resource::Reference.new("file", "/f").should == Puppet::Resource::Reference.new("file", "/f")
88
it "should not be considered equivalent to a non-reference" do
89
Puppet::Resource::Reference.new("file", "/f").should_not == "foo"
92
it "should not be considered equivalent to another reference if their types do not match" do
93
Puppet::Resource::Reference.new("file", "/f").should_not == Puppet::Resource::Reference.new("exec", "/f")
96
it "should not be considered equivalent to another reference if their titles do not match" do
97
Puppet::Resource::Reference.new("file", "/foo").should_not == Puppet::Resource::Reference.new("file", "/f")
101
describe Puppet::Resource::Reference, "when resolving resources with a catalog" do
102
it "should resolve all resources using the catalog" do
103
config = mock 'catalog'
104
ref = Puppet::Resource::Reference.new("foo::bar", "yay")
107
config.expects(:resource).with("Foo::Bar[yay]").returns(:myresource)
109
ref.resolve.should == :myresource