3
require File.dirname(__FILE__) + '/../../spec_helper'
5
describe Puppet::TransBucket do
7
@bucket = Puppet::TransBucket.new
10
it "should be able to produce a RAL component" do
15
proc { resource = @bucket.to_type }.should_not raise_error
16
resource.should be_instance_of(Puppet::Type::Component)
17
resource.title.should == "User[luke]"
20
it "should accept TransObjects into its children list" do
21
object = Puppet::TransObject.new("luke", "user")
22
proc { @bucket.push(object) }.should_not raise_error
24
o.should equal(object)
28
it "should accept TransBuckets into its children list" do
29
object = Puppet::TransBucket.new()
30
proc { @bucket.push(object) }.should_not raise_error
32
o.should equal(object)
36
it "should refuse to accept any children that are not TransObjects or TransBuckets" do
37
proc { @bucket.push "a test" }.should raise_error
40
it "should return use 'node' as the type and the provided name as the title if only a type is provided" do
41
@bucket.type = "mystuff"
42
@bucket.to_ref.should == "Node[mystuff]"
45
it "should return use 'component' as the type and the provided type as the title if only a name is provided" do
46
@bucket.name = "mystuff"
47
@bucket.to_ref.should == "Class[mystuff]"
50
it "should return nil as its reference when type and name are missing" do
51
@bucket.to_ref.should be_nil
54
it "should return the title as its reference" do
57
@bucket.to_ref.should == "User[luke]"
60
it "should canonize resource references when the type is 'component'" do
61
@bucket.name = 'something'
62
@bucket.type = 'foo::bar'
64
@bucket.to_ref.should == "Foo::Bar[something]"
68
describe Puppet::TransBucket, " when generating a catalog" do
70
@bottom = Puppet::TransBucket.new
72
@bottom.name = "bottom"
73
@bottomobj = Puppet::TransObject.new("bottom", "user")
74
@bottom.push @bottomobj
76
@middle = Puppet::TransBucket.new
78
@middle.name = "middle"
79
@middleobj = Puppet::TransObject.new("middle", "user")
80
@middle.push(@middleobj)
83
@top = Puppet::TransBucket.new
86
@topobj = Puppet::TransObject.new("top", "user")
90
@users = %w{top middle bottom}
91
@fakes = %w{Fake[bottom] Fake[middle] Fake[top]}
98
it "should convert all transportable objects to RAL resources" do
99
@catalog = @top.to_catalog
100
@users.each do |name|
101
@catalog.vertices.find { |r| r.class.name == :user and r.title == name }.should be_instance_of(Puppet::Type.type(:user))
105
it "should fail if any transportable resources fail to convert to RAL resources" do
106
@bottomobj.expects(:to_type).raises ArgumentError
107
lambda { @bottom.to_catalog }.should raise_error(ArgumentError)
110
it "should convert all transportable buckets to RAL components" do
111
@catalog = @top.to_catalog
112
@fakes.each do |name|
113
@catalog.vertices.find { |r| r.class.name == :component and r.title == name }.should be_instance_of(Puppet::Type.type(:component))
117
it "should add all resources to the graph's resource table" do
118
@catalog = @top.to_catalog
119
@catalog.resource("fake[top]").should equal(@top)
122
it "should finalize all resources" do
123
@catalog = @top.to_catalog
124
@catalog.vertices.each do |vertex| vertex.should be_finalized end
127
it "should only call to_type on each resource once" do
128
# We just raise exceptions here because we're not interested in
129
# what happens with the result, only that the method only
131
resource = @topobj.to_type
132
@topobj.expects(:to_type).once.returns resource
136
it "should set each TransObject's catalog before converting to a RAL resource" do
137
@middleobj.expects(:catalog=).with { |c| c.is_a?(Puppet::Node::Catalog) }
141
it "should set each TransBucket's catalog before converting to a RAL resource" do
142
# each bucket is seen twice in the loop, so we have to handle the case where the config
144
@bottom.expects(:catalog=).with { |c| c.is_a?(Puppet::Node::Catalog) }.at_least_once
149
describe Puppet::TransBucket, " when serializing" do
151
@bucket = Puppet::TransBucket.new(%w{one two})
156
it "should be able to be dumped to yaml" do
157
proc { YAML.dump(@bucket) }.should_not raise_error
160
it "should dump YAML that produces an equivalent object" do
161
result = YAML.dump(@bucket)
163
newobj = YAML.load(result)
164
newobj.name.should == "one"
165
newobj.type.should == "two"
170
children.should == %w{one two}