-
Notifications
You must be signed in to change notification settings - Fork 19
/
debian.rb
247 lines (194 loc) · 6.91 KB
/
debian.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
# frozen_string_literal: true
require_relative '../chef_dk_app'
shared_context 'resources::chef_dk_app::debian' do
include_context 'resources::chef_dk_app'
before(:each) do
allow_any_instance_of(Chef::Provider::Package::Dpkg)
.to receive(:load_current_resource)
.and_return(double(version: [installed_version]))
end
shared_examples_for 'any Debian 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 'downloads the correct Chef-DK' do
expect(chef_run).to create_remote_file('/tmp/cache/chefdk')
.with(source: "http://example.com/#{channel || 'stable'}/chefdk",
checksum: '1234')
end
it 'installs the downloaded package' do
expect(chef_run).to install_dpkg_package('/tmp/cache/chefdk')
end
end
shared_examples_for 'does not install Chef-DK' do
it 'does not download the correct Chef-DK' do
expect(chef_run).to_not create_remote_file('/tmp/cache/chefdk')
end
it 'does not install the downloaded package' do
expect(chef_run).to_not install_dpkg_package('/tmp/cache/chefdk')
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
shared_examples_for 'any property set' do
it 'ensures apt-transport-https is installed' do
expect(chef_run).to install_package('apt-transport-https')
end
it 'configures the Chef APT repo' do
expect(chef_run).to include_recipe(
"apt-chef::#{channel || 'stable'}"
)
end
it 'installs the chefdk package' do
expect(chef_run).to install_package('chefdk').with(version: version)
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 'any property set'
end
end
end
context 'a custom source' do
include_context description
shared_examples_for 'does not install Chef-DK' do
it 'does not download the correct Chef-DK' do
expect(chef_run).to_not create_remote_file('/tmp/cache/chefdk')
end
it 'does not install the downloaded package' do
expect(chef_run).to_not install_dpkg_package('/tmp/cache/chefdk')
end
end
context 'all default properties' do
include_context description
it 'downloads the correct Chef-DK' do
expect(chef_run).to create_remote_file('/tmp/cache/cdk')
.with(source: 'https://example.biz/cdk', checksum: '12345')
end
it 'installs the downloaded package' do
expect(chef_run).to install_dpkg_package('/tmp/cache/cdk')
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 'downloads the correct Chef-DK' do
expect(chef_run).to create_remote_file('/tmp/cache/chefdk')
.with(source: "http://example.com/#{channel || 'stable'}/chefdk",
checksum: '1234')
end
it 'installs the downloaded package' do
expect(chef_run).to install_dpkg_package('/tmp/cache/chefdk')
end
end
shared_examples_for 'does not upgrade Chef-DK' do
it 'does not download the correct Chef-DK' do
expect(chef_run).to_not create_remote_file('/tmp/cache/chefdk')
end
it 'does not install the downloaded package' do
expect(chef_run).to_not install_dpkg_package('/tmp/cache/chefdk')
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
shared_examples_for 'any property set' do
it 'ensures apt-transport-https is installed' do
expect(chef_run).to install_package('apt-transport-https')
end
it 'configures the Chef APT repo' do
expect(chef_run).to include_recipe(
"apt-chef::#{channel || 'stable'}"
)
end
it 'upgrades the chefdk package' do
expect(chef_run).to upgrade_package('chefdk').with(version: version)
end
end
[
'all default properties',
'an overridden channel property'
].each do |c|
context c do
include_context description
it_behaves_like 'any property set'
end
end
end
end
context 'the :remove action' do
include_context description
shared_examples_for 'any property set' do
it 'purges the package' do
expect(chef_run).to purge_package('chefdk')
end
end
[
'the default source (:direct)',
'the :repo source',
'a custom source'
].each do |c|
context c do
include_context description
it_behaves_like 'any property set'
end
end
end
end
end