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