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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
#
# Author:: Adam Jacob (<adam@chef.io>)
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require "spec_helper"
require "ostruct"
describe Chef::Provider::Package::Apt do
let(:logger) { double("Mixlib::Log::Child").as_null_object }
# XXX: sorry this is ugly and was done quickly to get 12.0.2 out, this file needs a rewrite to use
# let blocks and shared examples
let(:node) { Chef::Node.new }
let(:events) { Chef::EventDispatch::Dispatcher.new }
before(:each) do
@run_context = Chef::RunContext.new(node, {}, events)
allow(@run_context).to receive(:logger).and_return(logger)
@new_resource = Chef::Resource::AptPackage.new("irssi", @run_context)
@status = double("Status", exitstatus: 0)
@provider = Chef::Provider::Package::Apt.new(@new_resource, @run_context)
@stdin = StringIO.new
@stdout = <<~PKG_STATUS
irssi:
Installed: (none)
Candidate: 0.8.14-1ubuntu4
Version table:
0.8.14-1ubuntu4 0
500 http://us.archive.ubuntu.com/ubuntu/ lucid/main Packages
PKG_STATUS
@stderr = ""
@shell_out = OpenStruct.new(stdout: @stdout, stdin: @stdin, stderr: @stderr, status: @status, exitstatus: 0)
@timeout = 900
end
describe "when loading current resource" do
it "should create a current resource with the name of the new_resource" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-cache", "policy", @new_resource.package_name,
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
).and_return(@shell_out)
@provider.load_current_resource
current_resource = @provider.current_resource
expect(current_resource).to be_a(Chef::Resource::Package)
expect(current_resource.name).to eq("irssi")
expect(current_resource.package_name).to eq("irssi")
expect(current_resource.version).to eql([nil])
end
it "should set the installed version if package has one" do
@stdout.replace(<<~INSTALLED)
sudo:
Installed: 1.7.2p1-1ubuntu5.3
Candidate: 1.7.2p1-1ubuntu5.3
Version table:
*** 1.7.2p1-1ubuntu5.3 0
500 http://us.archive.ubuntu.com/ubuntu/ lucid-updates/main Packages
500 http://security.ubuntu.com/ubuntu/ lucid-security/main Packages
100 /var/lib/dpkg/status
1.7.2p1-1ubuntu5 0
500 http://us.archive.ubuntu.com/ubuntu/ lucid/main Packages
INSTALLED
expect(@provider).to receive(:shell_out_compacted!).and_return(@shell_out)
@provider.load_current_resource
expect(@provider.current_resource.version).to eq(["1.7.2p1-1ubuntu5.3"])
expect(@provider.candidate_version).to eql(["1.7.2p1-1ubuntu5.3"])
end
# it is the superclasses responsibility to throw most exceptions
it "if the package does not exist in the cache sets installed + candidate version to nil" do
@new_resource.package_name("conic-smarms")
policy_out = <<~POLICY_STDOUT
N: Unable to locate package conic-smarms
POLICY_STDOUT
policy = double(stdout: policy_out, exitstatus: 0)
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-cache", "policy", "conic-smarms",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
).and_return(policy)
showpkg_out = <<~SHOWPKG_STDOUT
N: Unable to locate package conic-smarms
SHOWPKG_STDOUT
showpkg = double(stdout: showpkg_out, exitstatus: 0)
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-cache", "showpkg", "conic-smarms",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
).and_return(showpkg)
@provider.load_current_resource
end
# libmysqlclient-dev is a real package in newer versions of debian + ubuntu
# list of virtual packages: http://www.debian.org/doc/packaging-manuals/virtual-package-names-list.txt
it "should not install the virtual package there is a single provider package and it is installed" do
@new_resource.package_name("libmysqlclient15-dev")
virtual_package_out = <<~VPKG_STDOUT
libmysqlclient15-dev:
Installed: (none)
Candidate: (none)
Version table:
VPKG_STDOUT
virtual_package = double(stdout: virtual_package_out, exitstatus: 0)
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-cache", "policy", "libmysqlclient15-dev",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
).and_return(virtual_package)
showpkg_out = <<~SHOWPKG_STDOUT
Package: libmysqlclient15-dev
Versions:
Reverse Depends:
libmysqlclient-dev,libmysqlclient15-dev
libmysqlclient-dev,libmysqlclient15-dev
libmysqlclient-dev,libmysqlclient15-dev
libmysqlclient-dev,libmysqlclient15-dev
libmysqlclient-dev,libmysqlclient15-dev
libmysqlclient-dev,libmysqlclient15-dev
Dependencies:
Provides:
Reverse Provides:
libmysqlclient-dev 5.1.41-3ubuntu12.7
libmysqlclient-dev 5.1.41-3ubuntu12.10
libmysqlclient-dev 5.1.41-3ubuntu12
SHOWPKG_STDOUT
showpkg = double(stdout: showpkg_out, exitstatus: 0)
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-cache", "showpkg", "libmysqlclient15-dev",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
).and_return(showpkg)
real_package_out = <<~RPKG_STDOUT
libmysqlclient-dev:
Installed: 5.1.41-3ubuntu12.10
Candidate: 5.1.41-3ubuntu12.10
Version table:
*** 5.1.41-3ubuntu12.10 0
500 http://us.archive.ubuntu.com/ubuntu/ lucid-updates/main Packages
100 /var/lib/dpkg/status
5.1.41-3ubuntu12.7 0
500 http://security.ubuntu.com/ubuntu/ lucid-security/main Packages
5.1.41-3ubuntu12 0
500 http://us.archive.ubuntu.com/ubuntu/ lucid/main Packages
RPKG_STDOUT
real_package = double(stdout: real_package_out, exitstatus: 0)
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-cache", "policy", "libmysqlclient-dev",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
).and_return(real_package)
@provider.load_current_resource
end
it "should raise an exception if you specify a virtual package with multiple provider packages" do
@new_resource.package_name("mp3-decoder")
virtual_package_out = <<~VPKG_STDOUT
mp3-decoder:
Installed: (none)
Candidate: (none)
Version table:
VPKG_STDOUT
virtual_package = double(stdout: virtual_package_out, exitstatus: 0)
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-cache", "policy", "mp3-decoder",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
).and_return(virtual_package)
showpkg_out = <<~SHOWPKG_STDOUT
Package: mp3-decoder
Versions:
Reverse Depends:
nautilus,mp3-decoder
vux,mp3-decoder
plait,mp3-decoder
ecasound,mp3-decoder
nautilus,mp3-decoder
Dependencies:
Provides:
Reverse Provides:
vlc-nox 1.0.6-1ubuntu1.8
vlc 1.0.6-1ubuntu1.8
vlc-nox 1.0.6-1ubuntu1
vlc 1.0.6-1ubuntu1
opencubicplayer 1:0.1.17-2
mpg321 0.2.10.6
mpg123 1.12.1-0ubuntu1
SHOWPKG_STDOUT
showpkg = double(stdout: showpkg_out, exitstatus: 0)
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-cache", "showpkg", "mp3-decoder",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
).and_return(showpkg)
expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package)
end
it "should run apt-cache policy with the default_release option, if there is one on the resource" do
@new_resource = Chef::Resource::AptPackage.new("irssi", @run_context)
@provider = Chef::Provider::Package::Apt.new(@new_resource, @run_context)
@new_resource.default_release("lenny-backports")
@new_resource.provider(nil)
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-cache", "-o", "APT::Default-Release=lenny-backports", "policy", "irssi",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
).and_return(@shell_out)
@provider.load_current_resource
end
it "raises an exception if a source is specified (CHEF-5113)" do
@new_resource.source "pluto"
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-cache", "policy", @new_resource.package_name,
env: { "DEBIAN_FRONTEND" => "noninteractive" } ,
timeout: @timeout
).and_return(@shell_out)
expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
end
end
context "after loading the current resource" do
before do
@current_resource = Chef::Resource::AptPackage.new("irssi", @run_context)
@provider.current_resource = @current_resource
allow(@provider).to receive(:package_data).and_return({
"irssi" => {
virtual: false,
candidate_version: "0.8.12-7",
installed_version: nil,
},
"libmysqlclient15-dev" => {
virtual: true,
candidate_version: nil,
installed_version: nil,
},
})
end
def ubuntu1804downgrade_stubs
so = instance_double(Mixlib::ShellOut, stdout: "apt 1.6~beta1 (amd64)\notherstuff\n")
so2 = instance_double(Mixlib::ShellOut, error?: false)
allow(@provider).to receive(:shell_out).with("apt-get --version").and_return(so)
allow(@provider).to receive(:shell_out).with("dpkg", "--compare-versions", "1.6~beta1", "gt", "1.1.0").and_return(so2)
end
def ubuntu1404downgrade_stubs
so = instance_double(Mixlib::ShellOut, stdout: "apt 1.0.1ubuntu2 for amd64 compiled on Dec 8 2016 16:23:38\notherstuff\n")
so2 = instance_double(Mixlib::ShellOut, error?: true)
allow(@provider).to receive(:shell_out).with("apt-get --version").and_return(so)
allow(@provider).to receive(:shell_out).with("dpkg", "--compare-versions", "1.0.1ubuntu2", "gt", "1.1.0").and_return(so2)
allow(@provider).to receive(:shell_out).with("dpkg", "--compare-versions", "1.0.1ubuntu2", "eq", "1.1.0").and_return(so2)
end
describe "install_package" do
before(:each) do
ubuntu1804downgrade_stubs
end
it "should run apt-get install with the package name and version" do
expect(@provider).to receive(:shell_out_compacted!). with(
"apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.install_package(["irssi"], ["0.8.12-7"])
end
it "should run apt-get install with the package name and version and options if specified" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--force-yes", "install", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@new_resource.options("--force-yes")
@provider.install_package(["irssi"], ["0.8.12-7"])
end
it "should run apt-get install with the package name and version and default_release if there is one and provider is explicitly defined" do
@new_resource = nil
@new_resource = Chef::Resource::AptPackage.new("irssi", @run_context)
@new_resource.default_release("lenny-backports")
@new_resource.provider = nil
@provider.new_resource = @new_resource
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "-o", "APT::Default-Release=lenny-backports", "install", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.install_package(["irssi"], ["0.8.12-7"])
end
it "should run apt-get install with the package name and quotes options if specified" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "--allow-downgrades", "--force-yes", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confnew", "install", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@new_resource.options('--force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew"')
@provider.install_package(["irssi"], ["0.8.12-7"])
end
end
describe "install_package with old apt-get" do
# tests apt-get on 1404 that does not support --allow-downgrades
before(:each) do
ubuntu1404downgrade_stubs
end
it "should run apt-get install with the package name and version" do
expect(@provider).to receive(:shell_out_compacted!). with(
"apt-get", "-q", "-y", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.install_package(["irssi"], ["0.8.12-7"])
end
it "should run apt-get install with the package name and version and options if specified" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--force-yes", "install", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@new_resource.options("--force-yes")
@provider.install_package(["irssi"], ["0.8.12-7"])
end
it "should run apt-get install with the package name and version and default_release if there is one and provider is explicitly defined" do
@new_resource = nil
@new_resource = Chef::Resource::AptPackage.new("irssi", @run_context)
@new_resource.default_release("lenny-backports")
@new_resource.provider = nil
@provider.new_resource = @new_resource
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "-o", "APT::Default-Release=lenny-backports", "install", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.install_package(["irssi"], ["0.8.12-7"])
end
it "should run apt-get install with the package name and quotes options if specified" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "--force-yes", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confnew", "install", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@new_resource.options('--force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew"')
@provider.install_package(["irssi"], ["0.8.12-7"])
end
end
describe Chef::Resource::AptPackage, "upgrade_package" do
it "should run install_package with the name and version" do
expect(@provider).to receive(:install_package).with(["irssi"], ["0.8.12-7"])
@provider.upgrade_package(["irssi"], ["0.8.12-7"])
end
end
describe Chef::Resource::AptPackage, "remove_package" do
it "should run apt-get remove with the package name" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "remove", "irssi",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.remove_package(["irssi"], ["0.8.12-7"])
end
it "should run apt-get remove with the package name and options if specified" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "--force-yes", "remove", "irssi",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@new_resource.options("--force-yes")
@provider.remove_package(["irssi"], ["0.8.12-7"])
end
end
describe "when purging a package" do
it "should run apt-get purge with the package name" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "purge", "irssi",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.purge_package(["irssi"], ["0.8.12-7"])
end
it "should run apt-get purge with the package name and options if specified" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "--force-yes", "purge", "irssi",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@new_resource.options("--force-yes")
@provider.purge_package(["irssi"], ["0.8.12-7"])
end
end
describe "when given a response file" do
it_behaves_like "given a response file" do
before do
@provider = Chef::Provider::Package::Apt.new(new_resource, run_context)
end
let(:new_resource) do
new_resource = Chef::Resource::AptPackage.new("irssi", run_context)
new_resource.response_file("irssi.response")
new_resource.cookbook_name = "irssi"
new_resource
end
let(:path) { "preseed/irssi" }
let(:tmp_path) { "/tmp/preseed/irssi" }
let(:package_name) { "irssi" }
let(:package_version) { "1.0.5-1" }
let(:response) { "irssi.response" }
let(:tmp_preseed_path) { "/tmp/preseed/irssi/irssi-1.0.5-1.seed" }
let(:preseed_path) { "/preseed--irssi--irssi-1.0.5-1.seed" }
end
end
describe "when preseeding a package" do
before(:each) do
allow(@provider).to receive(:get_preseed_file).and_return("/tmp/irssi-0.8.12-7.seed")
end
it "should get the full path to the preseed response file" do
file = "/tmp/irssi-0.8.12-7.seed"
expect(@provider).to receive(:shell_out_compacted!).with(
"debconf-set-selections", "/tmp/irssi-0.8.12-7.seed",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.preseed_package(file)
end
it "should run debconf-set-selections on the preseed file if it has changed" do
expect(@provider).to receive(:shell_out_compacted!).with(
"debconf-set-selections", "/tmp/irssi-0.8.12-7.seed",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
file = @provider.get_preseed_file("irssi", "0.8.12-7")
@provider.preseed_package(file)
end
it "should not run debconf-set-selections if the preseed file has not changed" do
allow(@provider).to receive(:check_all_packages_state)
@current_resource.version "0.8.11"
@new_resource.response_file "/tmp/file"
allow(@provider).to receive(:get_preseed_file).and_return(false)
expect(@provider).not_to receive(:shell_out_compacted!)
@provider.run_action(:reconfig)
end
end
describe "when reconfiguring a package" do
it "should run dpkg-reconfigure package" do
expect(@provider).to receive(:shell_out_compacted!).with(
"dpkg-reconfigure", "irssi",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.reconfig_package("irssi")
end
end
describe "when locking a package" do
it "should run apt-mark hold package" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-mark", "hold", "irssi",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.lock_package("irssi", "0.8.12-7")
end
it "should not lock if the package is already locked" do
allow(@provider).to receive(:shell_out_compacted!).with(
"apt-mark", "showhold", timeout: 900
).and_return(instance_double(
Mixlib::ShellOut, stdout: "irssi"
))
expect(logger).to receive(:trace).with("#{@provider.new_resource} is already locked")
@provider.action_lock
end
end
describe "when unlocking a package" do
it "should run apt-mark unhold package" do
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-mark", "unhold", "irssi",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.unlock_package("irssi", "0.8.12-7")
end
it "should not unlock if the package is already unlocked" do
allow(@provider).to receive(:shell_out_compacted!).with(
"apt-mark", "showhold", timeout: 900
).and_return(instance_double(
Mixlib::ShellOut, stdout: ""
))
expect(logger).to receive(:trace).with("#{@provider.new_resource} is already unlocked")
@provider.action_unlock
end
end
describe "when installing a virtual package" do
it "should install the package without specifying a version" do
ubuntu1804downgrade_stubs
@provider.package_data["libmysqlclient15-dev"][:virtual] = true
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "libmysqlclient15-dev",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.install_package(["libmysqlclient15-dev"], ["not_a_real_version"])
end
end
describe "when removing a virtual package" do
it "should remove the resolved name instead of the virtual package name" do
expect(@provider).to receive(:resolve_virtual_package_name).with("libmysqlclient15-dev").and_return("libmysqlclient-dev")
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "remove", "libmysqlclient-dev",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.remove_package(["libmysqlclient15-dev"], ["not_a_real_version"])
end
end
describe "when purging a virtual package" do
it "should purge the resolved name instead of the virtual package name" do
expect(@provider).to receive(:resolve_virtual_package_name).with("libmysqlclient15-dev").and_return("libmysqlclient-dev")
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "purge", "libmysqlclient-dev",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.purge_package(["libmysqlclient15-dev"], ["not_a_real_version"])
end
end
describe "when installing multiple packages" do
it "can install a virtual package followed by a non-virtual package" do
ubuntu1804downgrade_stubs
# https://github.com/chef/chef/issues/2914
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "libmysqlclient15-dev", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.install_package(%w{libmysqlclient15-dev irssi}, ["not_a_real_version", "0.8.12-7"])
end
end
describe "#action_install" do
it "should run dpkg to compare versions if an existing version is installed" do
allow(@provider).to receive(:get_current_versions).and_return("1.4.0")
allow(@new_resource).to receive(:allow_downgrade).and_return(false)
expect(@provider).to receive(:shell_out_compacted).with(
"dpkg", "--compare-versions", "1.4.0", "gt", "0.8.12-7", timeout: 900
).and_return(double(error?: false))
@provider.run_action(:upgrade)
end
it "should install the package if the installed version is older" do
ubuntu1804downgrade_stubs
expect(@provider).to receive(:version_compare).with("1.6~beta1", "1.1.0").and_return(1)
allow(@provider).to receive(:get_current_versions).and_return("0.4.0")
allow(@new_resource).to receive(:allow_downgrade).and_return(false)
expect(@provider).to receive(:version_compare).with("0.4.0", any_args).and_return(-1)
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.run_action(:upgrade)
end
it "should not compare versions if an existing version is not installed" do
ubuntu1804downgrade_stubs
expect(@provider).to receive(:version_compare).with("1.6~beta1", "1.1.0").and_return(1)
allow(@provider).to receive(:get_current_versions).and_return(nil)
allow(@new_resource).to receive(:allow_downgrade).and_return(false)
expect(@provider).not_to receive(:version_compare).with("0.4.0", any_args)
expect(@provider).to receive(:shell_out_compacted!).with(
"apt-get", "-q", "-y", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "irssi=0.8.12-7",
env: { "DEBIAN_FRONTEND" => "noninteractive" },
timeout: @timeout
)
@provider.run_action(:upgrade)
end
end
end
end
|