-
Notifications
You must be signed in to change notification settings - Fork 57
/
install_deb_spec.rb
94 lines (76 loc) · 2.55 KB
/
install_deb_spec.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
# Encoding: UTF-8
require 'spec_helper'
describe 'clamav::install_deb' do
let(:packages) { %w(clamav clamav-daemon clamav-freshclam) }
let(:clamd_service) { 'service[clamav-daemon]' }
let(:freshclam_service) { 'service[clamav-freshclam]' }
let(:attributes) { {} }
let(:platform) { { platform: 'ubuntu', version: '12.04' } }
let(:runner) do
ChefSpec::SoloRunner.new(platform) do |node|
attributes.each { |k, v| node.set[k] = v }
end
end
let(:chef_run) { runner.converge(described_recipe) }
shared_examples_for 'any node' do
it 'installs the pertinent packages' do
packages.each do |p|
expect(chef_run).to install_package(p)
end
end
it 'cleans up files left behind by the packages' do
%w(
/etc/logrotate.d/clamav-daemon
/etc/logrotate.d/clamav-freshclam
).each do |f|
expect(chef_run).to delete_file(f)
end
end
end
shared_examples_for 'a node with all default attributes' do
it 'does not send any restart notifications' do
packages.each do |p|
[clamd_service, freshclam_service].each do |s|
expect(chef_run.package(p)).to_not notify(s).to(:restart)
end
end
end
end
context 'an entirey default node' do
it_behaves_like 'any node'
it_behaves_like 'a node with all default attributes'
end
context 'a node with the dev package enabled' do
let(:attributes) { { clamav: { dev_package: true } } }
it_behaves_like 'any node'
it 'installs the ClamAV dev package' do
expect(chef_run).to install_package('libclamav-dev')
end
end
context 'a node with the package versions overridden' do
let(:attributes) { { clamav: { version: '42.42.42' } } }
it_behaves_like 'any node'
it 'installs the packages at the specified version' do
packages.each do |p|
expect(chef_run).to install_package(p).with(version: '42.42.42')
end
end
end
context 'a node with the clamd daemon enabled' do
let(:attributes) { { clamav: { clamd: { enabled: true } } } }
it_behaves_like 'any node'
it 'sends a restart notification to clamd' do
packages.each do |p|
expect(chef_run.package(p)).to notify(clamd_service).to(:restart)
end
end
end
context 'a node with the freshclam daemon enabled' do
let(:attributes) { { clamav: { freshclam: { enabled: true } } } }
it_behaves_like 'any node'
it 'sends a restart notification to freshclam' do
expect(chef_run.package(packages[0])).to notify(freshclam_service)
.to(:restart)
end
end
end