8
8
9
9
before :each do
10
10
described_class . stubs ( :suitable? ) . returns true
11
+ described_class . stubs ( :default_target ) . returns fake_oratab
11
12
Puppet ::Type . type ( :oratab ) . stubs ( :defaultprovider ) . returns described_class
13
+ end
12
14
13
- @fake_oratab = tmpfilename ( 'oratab' )
14
- FileUtils . cp ( my_fixture ( 'input' ) , @fake_oratab )
15
- described_class . stubs ( :default_target ) . returns @fake_oratab
15
+ let :fake_oratab do
16
+ filename = tmpfilename ( 'oratab' )
17
+ unless File . exists? filename
18
+ FileUtils . cp ( my_fixture ( 'input' ) , filename )
19
+ end
20
+ filename
21
+ end
16
22
17
- @resource_absent = Puppet ::Type . type ( :oratab ) . new (
23
+ # this resource is absent in our fake oratab
24
+ let :resource_absent do
25
+ Puppet ::Type . type ( :oratab ) . new (
18
26
:name => 'NO_SUCH_DATABASE' ,
19
27
:ensure => :absent
20
28
)
21
- @resource_present = Puppet ::Type . type ( :oratab ) . new (
29
+ end
30
+
31
+ # this resource is present in our fake oratab and completly insync
32
+ let :resource_present do
33
+ Puppet ::Type . type ( :oratab ) . new (
22
34
:name => 'DB_INSYNC' ,
23
35
:ensure => :present ,
24
36
:home => '/u01/app/oracle/product/10.1.0/db_1' ,
25
37
:atboot => :yes
26
38
)
27
- @resource_create = Puppet ::Type . type ( :oratab ) . new (
39
+ end
40
+
41
+ # this resource is not present in our fake oratab
42
+ let :resource_create do
43
+ Puppet ::Type . type ( :oratab ) . new (
28
44
:name => 'DB_CREATE' ,
29
45
:ensure => :present ,
30
46
:home => '/u01/app/oracle/product/10.1.0/db_2' ,
31
47
:description => 'added by puppet' ,
32
48
:atboot => :no
33
49
)
34
- @resource_delete = Puppet ::Type . type ( :oratab ) . new (
50
+ end
51
+
52
+ # this resource is present in our fake oratab
53
+ let :resource_delete do
54
+ Puppet ::Type . type ( :oratab ) . new (
35
55
:name => 'DB_DELETE' ,
36
56
:ensure => :absent
37
57
)
38
- @resource_sync_home = Puppet ::Type . type ( :oratab ) . new (
58
+ end
59
+
60
+ # this resource is present in our fake oratab but with :home => '/u01/app/oracle/product/10.1.0/db_4'
61
+ let :resource_sync_home do
62
+ Puppet ::Type . type ( :oratab ) . new (
39
63
:name => 'DB_SYNC_HOME' ,
40
64
:ensure => :present ,
41
65
:home => '/new/home'
42
66
)
43
- @resource_sync_atboot = Puppet ::Type . type ( :oratab ) . new (
67
+ end
68
+
69
+ # this resource is present in our fake oratab but with :atboot => :no
70
+ let :resource_sync_atboot do
71
+ Puppet ::Type . type ( :oratab ) . new (
44
72
:name => 'DB_SYNC_ATBOOT' ,
45
73
:ensure => :present ,
46
74
:home => '/u01/app/oracle/product/10.1.0/db_1' ,
47
75
:atboot => :yes
48
76
)
49
- @resource_sync_description = Puppet ::Type . type ( :oratab ) . new (
77
+ end
78
+
79
+ # this resource is present in our fake oratab but with :description => 'change me'
80
+ let :resource_sync_description do
81
+ Puppet ::Type . type ( :oratab ) . new (
50
82
:name => 'DB_SYNC_DESCRIPTION' ,
51
83
:ensure => :present ,
52
84
:atboot => :no ,
53
85
:description => 'new desc'
54
86
)
55
- @resource_delete_description = Puppet ::Type . type ( :oratab ) . new (
87
+ end
88
+
89
+ # this resource is present in our fake oratab but with :description => 'delete me'
90
+ let :resource_delete_description do
91
+ Puppet ::Type . type ( :oratab ) . new (
56
92
:name => 'DB_DELETE_DESCRIPTION' ,
57
93
:ensure => :present ,
58
94
:description => ''
@@ -75,7 +111,7 @@ def run_in_catalog(*resources)
75
111
end
76
112
77
113
def check_content_against ( fixture )
78
- content = File . read ( @ fake_oratab) . lines . map { |l | l . chomp } . reject { |l | l =~ /^\s *#|^\s *$/ } . sort . join ( "\n " )
114
+ content = File . read ( fake_oratab ) . lines . map { |l | l . chomp } . reject { |l | l =~ /^\s *#|^\s *$/ } . sort . join ( "\n " )
79
115
expected_content = File . read ( my_fixture ( fixture ) ) . lines . map { |l | l . chomp } . reject { |l | l =~ /^\s *#|^\s *$/ } . sort . join ( "\n " )
80
116
content . should == expected_content
81
117
end
@@ -84,44 +120,44 @@ def check_content_against(fixture)
84
120
85
121
describe "with ensure set to absent" do
86
122
it "should do nothing if already absent" do
87
- run_in_catalog ( @ resource_absent)
123
+ run_in_catalog ( resource_absent )
88
124
check_content_against ( 'input' )
89
125
end
90
126
91
127
it "should remove oratab entry if currently present" do
92
- run_in_catalog ( @ resource_delete)
128
+ run_in_catalog ( resource_delete )
93
129
check_content_against ( 'output_single_delete' )
94
130
end
95
131
end
96
132
97
133
describe "with ensure set to present" do
98
134
it "should do nothing if already present and in sync" do
99
- run_in_catalog ( @ resource_present)
135
+ run_in_catalog ( resource_present )
100
136
check_content_against ( 'input' )
101
137
end
102
138
103
139
it "should create an oratab entry if currently absent" do
104
- run_in_catalog ( @ resource_create)
140
+ run_in_catalog ( resource_create )
105
141
check_content_against ( 'output_single_create' )
106
142
end
107
143
108
144
it "should sync home if out of sync" do
109
- run_in_catalog ( @ resource_sync_home)
145
+ run_in_catalog ( resource_sync_home )
110
146
check_content_against ( 'output_single_sync_home' )
111
147
end
112
148
113
149
it "should sync atboot if out of sync" do
114
- run_in_catalog ( @ resource_sync_atboot)
150
+ run_in_catalog ( resource_sync_atboot )
115
151
check_content_against ( 'output_single_sync_atboot' )
116
152
end
117
153
118
154
it "should sync description if out sync" do
119
- run_in_catalog ( @ resource_sync_description)
155
+ run_in_catalog ( resource_sync_description )
120
156
check_content_against ( 'output_single_sync_description' )
121
157
end
122
158
123
159
it "should remove the description (including the #-sign) if description is empty" do
124
- run_in_catalog ( @ resource_delete_description)
160
+ run_in_catalog ( resource_delete_description )
125
161
check_content_against ( 'output_single_sync_description_delete' )
126
162
end
127
163
end
@@ -130,14 +166,14 @@ def check_content_against(fixture)
130
166
describe "when managing multiple resources" do
131
167
it "should to the right thing (tm)" do
132
168
run_in_catalog (
133
- @ resource_absent,
134
- @ resource_present,
135
- @ resource_create,
136
- @ resource_delete,
137
- @ resource_sync_home,
138
- @ resource_sync_atboot,
139
- @ resource_sync_description,
140
- @ resource_delete_description
169
+ resource_absent ,
170
+ resource_present ,
171
+ resource_create ,
172
+ resource_delete ,
173
+ resource_sync_home ,
174
+ resource_sync_atboot ,
175
+ resource_sync_description ,
176
+ resource_delete_description
141
177
)
142
178
check_content_against ( 'output_multiple' )
143
179
end
0 commit comments