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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Node::Configuration, " when compiling" do
it "should accept tags" do
config = Puppet::Node::Configuration.new("mynode")
config.tag("one")
config.tags.should == %w{one}
end
it "should accept multiple tags at once" do
config = Puppet::Node::Configuration.new("mynode")
config.tag("one", "two")
config.tags.should == %w{one two}
end
it "should convert all tags to strings" do
config = Puppet::Node::Configuration.new("mynode")
config.tag("one", :two)
config.tags.should == %w{one two}
end
it "should tag with both the qualified name and the split name" do
config = Puppet::Node::Configuration.new("mynode")
config.tag("one::two")
config.tags.include?("one").should be_true
config.tags.include?("one::two").should be_true
end
it "should accept classes" do
config = Puppet::Node::Configuration.new("mynode")
config.add_class("one")
config.classes.should == %w{one}
config.add_class("two", "three")
config.classes.should == %w{one two three}
end
it "should tag itself with passed class names" do
config = Puppet::Node::Configuration.new("mynode")
config.add_class("one")
config.tags.should == %w{one}
end
end
describe Puppet::Node::Configuration, " when extracting" do
it "should return extraction result as the method result" do
config = Puppet::Node::Configuration.new("mynode")
config.expects(:extraction_format).returns(:whatever)
config.expects(:extract_to_whatever).returns(:result)
config.extract.should == :result
end
end
describe Puppet::Node::Configuration, " when extracting transobjects" do
def mkscope
@parser = Puppet::Parser::Parser.new :Code => ""
@node = Puppet::Node.new("mynode")
@compile = Puppet::Parser::Compile.new(@node, @parser)
# XXX This is ridiculous.
@compile.send(:evaluate_main)
@scope = @compile.topscope
end
def mkresource(type, name)
Puppet::Parser::Resource.new(:type => type, :title => name, :source => @source, :scope => @scope)
end
# This isn't really a spec-style test, but I don't know how better to do it.
it "should transform the resource graph into a tree of TransBuckets and TransObjects" do
config = Puppet::Node::Configuration.new("mynode")
@scope = mkscope
@source = mock 'source'
defined = mkresource("class", :main)
builtin = mkresource("file", "/yay")
config.add_edge!(defined, builtin)
bucket = []
bucket.expects(:classes=).with(config.classes)
defined.stubs(:builtin?).returns(false)
defined.expects(:to_transbucket).returns(bucket)
builtin.expects(:to_transobject).returns(:builtin)
config.extract_to_transportable.should == [:builtin]
end
# Now try it with a more complicated graph -- a three tier graph, each tier
it "should transform arbitrarily deep graphs into isomorphic trees" do
config = Puppet::Node::Configuration.new("mynode")
@scope = mkscope
@scope.stubs(:tags).returns([])
@source = mock 'source'
# Create our scopes.
top = mkresource "class", :main
topbucket = []
topbucket.expects(:classes=).with([])
top.expects(:to_trans).returns(topbucket)
topres = mkresource "file", "/top"
topres.expects(:to_trans).returns(:topres)
config.add_edge! top, topres
middle = mkresource "class", "middle"
middle.expects(:to_trans).returns([])
config.add_edge! top, middle
midres = mkresource "file", "/mid"
midres.expects(:to_trans).returns(:midres)
config.add_edge! middle, midres
bottom = mkresource "class", "bottom"
bottom.expects(:to_trans).returns([])
config.add_edge! middle, bottom
botres = mkresource "file", "/bot"
botres.expects(:to_trans).returns(:botres)
config.add_edge! bottom, botres
toparray = config.extract_to_transportable
# This is annoying; it should look like:
# [[[:botres], :midres], :topres]
# but we can't guarantee sort order.
toparray.include?(:topres).should be_true
midarray = toparray.find { |t| t.is_a?(Array) }
midarray.include?(:midres).should be_true
botarray = midarray.find { |t| t.is_a?(Array) }
botarray.include?(:botres).should be_true
end
end
|