-
Notifications
You must be signed in to change notification settings - Fork 19
/
mac_os_x.rb
278 lines (221 loc) · 8 KB
/
mac_os_x.rb
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# frozen_string_literal: true
require_relative '../chef_dk_app'
shared_context 'resources::chef_dk_app::mac_os_x' do
include_context 'resources::chef_dk_app'
let(:installed_version) { nil }
before(:each) do
allow_any_instance_of(Chef::Recipe).to receive(:homebrew_owner)
.and_return('test')
allow_any_instance_of(Chef::Resource).to receive(:homebrew_owner)
.and_return('test')
allow_any_instance_of(Chef::Mixin::ShellOut).to receive(:shell_out)
.and_call_original
allow_any_instance_of(Chef::Mixin::ShellOut).to receive(:shell_out)
.with('pkgutil --pkg-info com.getchef.pkg.chefdk')
.and_return(double(exitstatus: installed_version.nil? ? 1 : 0,
stdout: "test\nversion: #{installed_version}\nthings"))
end
shared_examples_for 'any Mac OS X platform' do
it_behaves_like 'any platform'
context 'the default action (:install)' do
include_context description
context 'the default source (:direct)' do
include_context description
shared_examples_for 'installs Chef-DK' do
it 'installs the correct Chef-DK package' do
expect(chef_run).to install_dmg_package('Chef Development Kit')
.with(app: 'chefdk',
volumes_dir: 'Chef Development Kit',
source: "http://example.com/#{channel || 'stable'}/chefdk",
type: 'pkg',
package_id: 'com.getchef.pkg.chefdk',
checksum: '1234')
end
end
shared_examples_for 'does not install Chef-DK' do
it 'does not install the correct Chef-DK package' do
expect(chef_run).to_not install_dmg_package('Chef Development Kit')
end
end
[
'all default properties',
'an overridden channel property',
'an overridden version property'
].each do |c|
context c do
include_context description
it_behaves_like 'installs Chef-DK'
end
end
context 'the latest version already installed' do
include_context description
it_behaves_like 'does not install Chef-DK'
end
context 'an older version already installed' do
include_context description
it_behaves_like 'does not install Chef-DK'
end
end
context 'the :repo source' do
include_context description
before(:each) do
stub_command('which git').and_return('/usr/bin/git')
end
context 'all default properties' do
include_context description
it 'ensures Homebrew is installed' do
expect(chef_run).to include_recipe('homebrew')
end
it 'installs the chefdk Homebrew cask' do
expect(chef_run).to install_homebrew_cask('chefdk')
end
end
context 'an overridden version property' do
include_context description
it 'raises an error' do
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end
context 'an overridden channel property' do
include_context description
it 'raises an error' do
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end
end
context 'a custom source' do
include_context description
shared_examples_for 'does not install Chef-DK' do
it 'does not install the correct Chef-DK package' do
expect(chef_run).to_not install_dmg_package('Chef Development Kit')
end
end
context 'all default properties' do
include_context description
it 'installs the correct Chef-DK package' do
expect(chef_run).to install_dmg_package('Chef Development Kit')
.with(app: 'cdk',
volumes_dir: 'Chef Development Kit',
source: 'https://example.biz/cdk',
type: 'pkg',
package_id: 'com.getchef.pkg.chefdk',
checksum: '12345')
end
end
context 'the latest version already installed' do
include_context description
it_behaves_like 'does not install Chef-DK'
end
context 'an older version already installed' do
include_context description
it_behaves_like 'does not install Chef-DK'
end
end
end
context 'the :upgrade action' do
include_context description
context 'the default source (:direct)' do
include_context description
shared_examples_for 'upgrades Chef-DK' do
it 'installs the correct Chef-DK package' do
expect(chef_run).to install_dmg_package('Chef Development Kit')
.with(app: 'chefdk',
volumes_dir: 'Chef Development Kit',
source: "http://example.com/#{channel || 'stable'}/chefdk",
type: 'pkg',
package_id: 'com.getchef.pkg.chefdk',
checksum: '1234')
end
end
shared_examples_for 'does not upgrade Chef-DK' do
it 'does not install the correct Chef-DK package' do
expect(chef_run).to_not install_dmg_package('Chef Development Kit')
end
end
[
'all default properties',
'an overridden channel property'
].each do |c|
context c do
include_context description
it_behaves_like 'upgrades Chef-DK'
end
end
context 'the latest version already installed' do
include_context description
it_behaves_like 'does not upgrade Chef-DK'
end
context 'an older version already installed' do
include_context description
it_behaves_like 'upgrades Chef-DK'
end
end
context 'the :repo source' do
include_context description
before(:each) do
stub_command('which git').and_return('/usr/bin/git')
end
context 'all default properties' do
include_context description
it 'raises an error' do
expect { chef_run }
.to raise_error(Chef::Exceptions::UnsupportedAction)
end
end
context 'an overridden version property' do
include_context description
it 'raises an error' do
expect { chef_run }
.to raise_error(Chef::Exceptions::UnsupportedAction)
end
end
context 'an overridden channel property' do
include_context description
it 'raises an error' do
expect { chef_run }
.to raise_error(Chef::Exceptions::UnsupportedAction)
end
end
end
end
context 'the :remove action' do
include_context description
[
'the default source (:direct)',
'a custom source'
].each do |c|
context c do
include_context description
before(:each) do
stub_command('pkgutil --pkg-info com.getchef.pkg.chefdk')
.and_return('somestuff')
end
it 'deletes the main chefdk directory' do
expect(chef_run).to delete_directory('/opt/chefdk')
.with(recursive: true)
end
it 'deletes the chefdk user directory' do
expect(chef_run).to delete_directory(
File.expand_path('~/.chefdk')
).with(recursive: true)
end
it 'forgets the chefdk package' do
expect(chef_run).to run_execute(
'pkgutil --forget com.getchef.pkg.chefdk'
)
end
end
end
context 'the :repo source' do
include_context description
it 'removes the chefdk Homebrew package' do
expect(chef_run).to uninstall_homebrew_cask('chefdk')
end
end
end
end
end