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
|
require 'spec_helper'
describe 'apt::setting' do
let(:pre_condition) { 'class { "apt": }' }
let :facts do
{
os: { distro: { codename: 'wheezy' }, family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
lsbdistrelease: '7.0',
lsbdistcodename: 'wheezy',
operatingsystem: 'Debian',
osfamily: 'Debian',
lsbdistid: 'Debian',
puppetversion: Puppet.version,
}
end
let(:title) { 'conf-teddybear' }
let(:default_params) { { content: 'di' } }
describe 'when using the defaults' do
context 'without source or content' do
it do
is_expected.to raise_error(Puppet::Error, %r{needs either of })
end
end
context 'with title=conf-teddybear ' do
let(:params) { default_params }
it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]') }
end
context 'with title=pref-teddybear' do
let(:title) { 'pref-teddybear' }
let(:params) { default_params }
it { is_expected.to contain_file('/etc/apt/preferences.d/teddybear.pref').that_notifies('Class[Apt::Update]') }
end
context 'with title=list-teddybear' do
let(:title) { 'list-teddybear' }
let(:params) { default_params }
it { is_expected.to contain_file('/etc/apt/sources.list.d/teddybear.list').that_notifies('Class[Apt::Update]') }
end
context 'with source' do
let(:params) { { source: 'puppet:///la/die/dah' } }
it {
is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with(ensure: 'file',
owner: 'root',
group: 'root',
mode: '0644',
source: params[:source].to_s)
}
end
context 'with content' do
let(:params) { default_params }
it {
is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with(ensure: 'file',
owner: 'root',
group: 'root',
mode: '0644',
content: params[:content].to_s)
}
end
end
describe 'settings requiring settings, MODULES-769' do
let(:pre_condition) do
'class { "apt": }
apt::setting { "list-teddybear": content => "foo" }
'
end
let(:facts) do
{
os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
lsbdistid: 'Debian',
osfamily: 'Debian',
lsbdistcodename: 'wheezy',
puppetversion: Puppet.version,
}
end
let(:title) { 'conf-teddybear' }
let(:default_params) { { content: 'di' } }
let(:params) { default_params.merge(require: 'Apt::Setting[list-teddybear]') }
it { is_expected.to compile.with_all_deps }
end
describe 'when trying to pull one over' do
context 'with source and content' do
let(:params) { default_params.merge(source: 'la') }
it do
is_expected.to raise_error(Puppet::Error, %r{cannot have both })
end
end
context 'with title=ext-teddybear' do
let(:title) { 'ext-teddybear' }
let(:params) { default_params }
it do
is_expected.to raise_error(Puppet::Error, %r{must start with either})
end
end
context 'with ensure=banana' do
let(:params) { default_params.merge(ensure: 'banana') }
it do
is_expected.to raise_error(Puppet::Error, %r{Enum\['absent', 'file', 'present'\]})
end
end
context 'with priority=1.2' do
let(:params) { default_params.merge(priority: 1.2) }
if Puppet::Util::Package.versioncmp(Puppet.version, '4.0') >= 0 || ENV['FUTURE_PARSER'] == 'yes'
it { is_expected.to compile.and_raise_error(%r{expects a value of type}) }
else
it { is_expected.to compile.and_raise_error(%r{priority must be an integer or a zero-padded integer}) }
end
end
end
describe 'with priority=100' do
let(:params) { default_params.merge(priority: 100) }
it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear').that_notifies('Class[Apt::Update]') }
end
describe 'with ensure=absent' do
let(:params) { default_params.merge(ensure: 'absent') }
it {
is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with(ensure: 'absent')
}
end
end
|