blob: b257cb116d642db0ad67292469e3bcb6f5949ab6 (
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
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
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../../spec_helper'
describe Puppet::Parser::AST::Resource do
ast = Puppet::Parser::AST
before :each do
@title = stub_everything 'title'
@compiler = stub_everything 'compiler'
@scope = Puppet::Parser::Scope.new(:compiler => @compiler)
@param1 = stub_everything 'parameter', :is_a? => true
@scope.stubs(:resource).returns(stub_everything)
@params = ast::ASTArray.new( :children => [@param1])
@resource = ast::Resource.new(:title => @title, :type => "Resource", :params => @params )
@resource.stubs(:qualified_type).returns("Resource")
Puppet::Parser::Resource.stubs(:new).returns(stub_everything)
end
it "should evaluate all its parameters" do
@param1.expects(:safeevaluate).with(@scope)
@resource.evaluate(@scope)
end
it "should evaluate its title" do
@title.expects(:safeevaluate).with(@scope)
@resource.evaluate(@scope)
end
it "should flatten the titles array" do
titles = stub 'titles'
title_array = stub 'title_array', :is_a? => true
titles.stubs(:safeevaluate).with(@scope).returns(title_array)
title_array.expects(:flatten).returns([])
@resource.title = titles
@resource.evaluate(@scope)
end
it "should create one resource objects per title" do
titles = stub 'titles'
title_array = stub 'title_array', :is_a? => true
title_array.stubs(:flatten).returns([@title])
titles.stubs(:safeevaluate).with(@scope).returns(title_array)
Puppet::Parser::Resource.expects(:new).with { |hash| hash[:title] == @title }
@resource.title = titles
@resource.evaluate(@scope)
end
it "should handover resources to the compiler" do
resource = stub 'resource'
titles = stub 'titles'
title_array = stub 'title_array', :is_a? => true
title_array.stubs(:flatten).returns([@title])
titles.stubs(:safeevaluate).with(@scope).returns(title_array)
Puppet::Parser::Resource.stubs(:new).returns(resource)
@compiler.expects(:add_resource).with(@scope, resource)
@resource.title = titles
@resource.evaluate(@scope)
end
it "should return the newly created resources" do
resource = stub 'resource'
titles = stub 'titles'
title_array = stub 'title_array', :is_a? => true
title_array.stubs(:flatten).returns([@title])
titles.stubs(:safeevaluate).with(@scope).returns(title_array)
Puppet::Parser::Resource.stubs(:new).returns(resource)
@compiler.stubs(:add_resource).with(resource)
@resource.title = titles
@resource.evaluate(@scope).should == [resource]
end
it "should generate virtual resources if it is virtual" do
@resource.virtual = true
Puppet::Parser::Resource.expects(:new).with { |hash| hash[:virtual] == true }
@resource.evaluate(@scope)
end
it "should generate virtual and exported resources if it is exported" do
@resource.exported = true
Puppet::Parser::Resource.expects(:new).with { |hash| hash[:virtual] == true and hash[:exported] == true }
@resource.evaluate(@scope)
end
end
|