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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/transaction'
describe Puppet::Transaction do
it "should match resources by name, not title, when prefetching" do
@catalog = Puppet::Resource::Catalog.new
@transaction = Puppet::Transaction.new(@catalog)
# Have both a title and name
resource = Puppet::Type.type(:sshkey).create :title => "foo", :name => "bar", :type => :dsa, :key => "eh"
@catalog.add_resource resource
resource.provider.class.expects(:prefetch).with("bar" => resource)
@transaction.prefetch
end
describe "when generating resources" do
it "should finish all resources" do
generator = stub 'generator', :depthfirst? => true
resource = stub 'resource'
@catalog = Puppet::Resource::Catalog.new
@transaction = Puppet::Transaction.new(@catalog)
generator.expects(:generate).returns [resource]
@catalog.expects(:add_resource).yields(resource)
resource.expects(:finish)
@transaction.generate_additional_resources(generator, :generate)
end
it "should skip generated resources that conflict with existing resources" do
generator = mock 'generator'
resource = stub 'resource'
@catalog = Puppet::Resource::Catalog.new
@transaction = Puppet::Transaction.new(@catalog)
generator.expects(:generate).returns [resource]
@catalog.expects(:add_resource).raises(Puppet::Resource::Catalog::DuplicateResourceError.new("foo"))
resource.expects(:finish).never
resource.expects(:info) # log that it's skipped
@transaction.generate_additional_resources(generator, :generate).should be_empty
end
end
describe "when skipping a resource" do
before :each do
@resource = stub_everything 'res', :exported? => true
@catalog = Puppet::Resource::Catalog.new
@transaction = Puppet::Transaction.new(@catalog)
end
it "should skip resource with missing tags" do
@transaction.stubs(:missing_tags?).returns(true)
@transaction.skip?(@resource).should be_true
end
it "should skip not scheduled resources" do
@transaction.stubs(:scheduled?).returns(false)
@transaction.skip?(@resource).should be_true
end
it "should skip resources with failed dependencies" do
@transaction.stubs(:failed_dependencies?).returns(false)
@transaction.skip?(@resource).should be_true
end
it "should skip exported resource" do
@transaction.skip?(@resource).should be_true
end
end
end
describe Puppet::Transaction, " when determining tags" do
before do
@config = Puppet::Resource::Catalog.new
@transaction = Puppet::Transaction.new(@config)
end
it "should default to the tags specified in the :tags setting" do
Puppet.expects(:[]).with(:tags).returns("one")
@transaction.tags.should == %w{one}
end
it "should split tags based on ','" do
Puppet.expects(:[]).with(:tags).returns("one,two")
@transaction.tags.should == %w{one two}
end
it "should use any tags set after creation" do
Puppet.expects(:[]).with(:tags).never
@transaction.tags = %w{one two}
@transaction.tags.should == %w{one two}
end
it "should always convert assigned tags to an array" do
@transaction.tags = "one::two"
@transaction.tags.should == %w{one::two}
end
end
|