blob: a81a8a0d10aa1a0f21696f262e1aeb0d65f66223 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/resource_reference'
describe Puppet::ResourceReference do
it "should have a :title attribute" do
Puppet::ResourceReference.new(:file, "foo").title.should == "foo"
end
it "should canonize types to capitalized strings" do
Puppet::ResourceReference.new(:file, "foo").type.should == "File"
end
it "should canonize qualified types so all strings are capitalized" do
Puppet::ResourceReference.new("foo::bar", "foo").type.should == "Foo::Bar"
end
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
ref = Puppet::ResourceReference.new(:component, "foo")
ref.type.should == "Class"
ref.title.should == "foo"
end
it "should interpret the title as a reference and assign appropriately if the type is :component and the title contains square brackets" do
ref = Puppet::ResourceReference.new(:component, "foo::bar[yay]")
ref.type.should == "Foo::Bar"
ref.title.should == "yay"
end
it "should set the type to 'Class' if it is nil and the title contains no square brackets" do
ref = Puppet::ResourceReference.new(nil, "yay")
ref.type.should == "Class"
ref.title.should == "yay"
end
it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains square brackets" do
ref = Puppet::ResourceReference.new(nil, "foo::bar[yay]")
ref.type.should == "Foo::Bar"
ref.title.should == "yay"
end
it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains nested square brackets" do
ref = Puppet::ResourceReference.new(nil, "foo::bar[baz[yay]]")
ref.type.should == "Foo::Bar"
ref.title.should =="baz[yay]"
end
it "should be considered builtin if an existing resource type matches the type" do
Puppet::ResourceReference.new("file", "/f").should be_builtin_type
end
it "should be not considered builtin if an existing resource type does not match the type" do
Puppet::ResourceReference.new("foobar", "/f").should_not be_builtin_type
end
end
describe Puppet::ResourceReference, "when resolving resources with a catalog" do
it "should resolve all resources using the catalog" do
config = mock 'catalog'
ref = Puppet::ResourceReference.new("foo::bar", "yay")
ref.catalog = config
config.expects(:resource).with("Foo::Bar[yay]").returns(:myresource)
ref.resolve.should == :myresource
end
end
|