|
5 | 5 | describe 'apt::backports', type: :class do |
6 | 6 | let(:pre_condition) { 'include apt' } |
7 | 7 |
|
8 | | - describe 'debian/ubuntu tests' do |
9 | | - context 'with defaults on debian' do |
10 | | - let(:facts) do |
11 | | - { |
12 | | - os: { |
13 | | - family: 'Debian', |
14 | | - name: 'Debian', |
15 | | - release: { |
16 | | - full: '12.5', |
17 | | - major: '12', |
18 | | - minor: '5' |
19 | | - }, |
20 | | - distro: { |
21 | | - codename: 'bookworm', |
22 | | - id: 'Debian' |
23 | | - } |
24 | | - } |
25 | | - } |
26 | | - end |
27 | | - |
28 | | - it { |
29 | | - expect(subject).to contain_apt__source('backports').with( |
30 | | - location: 'http://deb.debian.org/debian', |
31 | | - repos: 'main contrib non-free non-free-firmware', |
32 | | - release: 'bookworm-backports', |
33 | | - pin: { |
34 | | - 'priority' => 200, |
35 | | - 'codename' => 'bookworm-backports' |
36 | | - }, |
37 | | - keyring: '/usr/share/keyrings/debian-archive-keyring.gpg', |
38 | | - ) |
39 | | - } |
40 | | - end |
41 | | - |
42 | | - context 'with defaults on ubuntu' do |
| 8 | + # Shared examples for Ubuntu tests |
| 9 | + shared_examples 'ubuntu backports' do |release_major, release_full, codename| |
| 10 | + context "with defaults on ubuntu #{release_major}" do |
43 | 11 | let(:facts) do |
44 | 12 | { |
45 | 13 | os: { |
46 | 14 | family: 'Debian', |
47 | 15 | name: 'Ubuntu', |
48 | 16 | release: { |
49 | | - major: '22.04', |
50 | | - full: '22.04' |
| 17 | + major: release_major, |
| 18 | + full: release_full |
51 | 19 | }, |
52 | 20 | distro: { |
53 | | - codename: 'jammy', |
| 21 | + codename:, |
54 | 22 | id: 'Ubuntu' |
55 | 23 | } |
56 | 24 | } |
|
61 | 29 | expect(subject).to contain_apt__source('backports').with( |
62 | 30 | location: 'http://archive.ubuntu.com/ubuntu', |
63 | 31 | repos: 'main universe multiverse restricted', |
64 | | - release: 'jammy-backports', |
| 32 | + release: "#{codename}-backports", |
65 | 33 | pin: { |
66 | 34 | 'priority' => 200, |
67 | | - 'release' => 'jammy-backports' |
| 35 | + 'release' => "#{codename}-backports" |
68 | 36 | }, |
69 | 37 | keyring: '/usr/share/keyrings/ubuntu-archive-keyring.gpg', |
70 | 38 | ) |
71 | 39 | } |
72 | 40 | end |
73 | 41 |
|
74 | | - context 'with defaults on ubuntu 24.04' do |
| 42 | + context "with everything set on ubuntu #{release_major}" do |
75 | 43 | let(:facts) do |
76 | 44 | { |
77 | 45 | os: { |
78 | 46 | family: 'Debian', |
79 | 47 | name: 'Ubuntu', |
80 | 48 | release: { |
81 | | - major: '24.04', |
82 | | - full: '24.04' |
| 49 | + major: release_major, |
| 50 | + full: release_full |
83 | 51 | }, |
84 | 52 | distro: { |
85 | | - codename: 'noble', |
86 | | - id: 'Ubuntu' |
87 | | - } |
88 | | - } |
89 | | - } |
90 | | - end |
91 | | - |
92 | | - it { |
93 | | - expect(subject).to contain_apt__source('backports').with( |
94 | | - location: 'http://archive.ubuntu.com/ubuntu', |
95 | | - repos: 'main universe multiverse restricted', |
96 | | - release: 'noble-backports', |
97 | | - pin: { |
98 | | - 'priority' => 200, |
99 | | - 'release' => 'noble-backports' |
100 | | - }, |
101 | | - keyring: '/usr/share/keyrings/ubuntu-archive-keyring.gpg', |
102 | | - ) |
103 | | - } |
104 | | - end |
105 | | - |
106 | | - context 'with everything set' do |
107 | | - let(:facts) do |
108 | | - { |
109 | | - os: { |
110 | | - family: 'Debian', |
111 | | - name: 'Ubuntu', |
112 | | - release: { |
113 | | - major: '22.04', |
114 | | - full: '22.04' |
115 | | - }, |
116 | | - distro: { |
117 | | - codename: 'jammy', |
| 53 | + codename:, |
118 | 54 | id: 'Ubuntu' |
119 | 55 | } |
120 | 56 | } |
|
141 | 77 | } |
142 | 78 | end |
143 | 79 |
|
144 | | - context 'when set things with hashes' do |
| 80 | + context "when set things with hashes on ubuntu #{release_major}" do |
145 | 81 | let(:facts) do |
146 | 82 | { |
147 | 83 | os: { |
148 | 84 | family: 'Debian', |
149 | 85 | name: 'Ubuntu', |
150 | 86 | release: { |
151 | | - major: '22.04', |
152 | | - full: '22.04' |
| 87 | + major: release_major, |
| 88 | + full: release_full |
153 | 89 | }, |
154 | 90 | distro: { |
155 | | - codename: 'jammy', |
| 91 | + codename:, |
156 | 92 | id: 'Ubuntu' |
157 | 93 | } |
158 | 94 | } |
|
178 | 114 | end |
179 | 115 | end |
180 | 116 |
|
181 | | - describe 'validation' do |
182 | | - let(:facts) do |
183 | | - { |
184 | | - os: { |
185 | | - family: 'Debian', |
186 | | - name: 'Ubuntu', |
187 | | - release: { |
188 | | - major: '22.04', |
189 | | - full: '22.04' |
190 | | - }, |
191 | | - distro: { |
192 | | - codename: 'jammy', |
193 | | - id: 'Ubuntu' |
194 | | - } |
195 | | - } |
196 | | - } |
197 | | - end |
198 | | - |
199 | | - context 'with invalid location' do |
200 | | - let(:params) do |
| 117 | + # Shared examples for validation tests |
| 118 | + shared_examples 'validation tests' do |release_major, release_full, codename| |
| 119 | + describe "validation on ubuntu #{release_major}" do |
| 120 | + let(:facts) do |
201 | 121 | { |
202 | | - location: true |
| 122 | + os: { |
| 123 | + family: 'Debian', |
| 124 | + name: 'Ubuntu', |
| 125 | + release: { |
| 126 | + major: release_major, |
| 127 | + full: release_full |
| 128 | + }, |
| 129 | + distro: { |
| 130 | + codename:, |
| 131 | + id: 'Ubuntu' |
| 132 | + } |
| 133 | + } |
203 | 134 | } |
204 | 135 | end |
205 | 136 |
|
206 | | - it do |
207 | | - expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
208 | | - end |
209 | | - end |
| 137 | + context 'with invalid location' do |
| 138 | + let(:params) do |
| 139 | + { |
| 140 | + location: true |
| 141 | + } |
| 142 | + end |
210 | 143 |
|
211 | | - context 'with invalid release' do |
212 | | - let(:params) do |
213 | | - { |
214 | | - release: true |
215 | | - } |
| 144 | + it do |
| 145 | + expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
| 146 | + end |
216 | 147 | end |
217 | 148 |
|
218 | | - it do |
219 | | - expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
220 | | - end |
221 | | - end |
| 149 | + context 'with invalid release' do |
| 150 | + let(:params) do |
| 151 | + { |
| 152 | + release: true |
| 153 | + } |
| 154 | + end |
222 | 155 |
|
223 | | - context 'with invalid repos' do |
224 | | - let(:params) do |
225 | | - { |
226 | | - repos: true |
227 | | - } |
| 156 | + it do |
| 157 | + expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
| 158 | + end |
228 | 159 | end |
229 | 160 |
|
230 | | - it do |
231 | | - expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
| 161 | + context 'with invalid repos' do |
| 162 | + let(:params) do |
| 163 | + { |
| 164 | + repos: true |
| 165 | + } |
| 166 | + end |
| 167 | + |
| 168 | + it do |
| 169 | + expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
| 170 | + end |
232 | 171 | end |
233 | | - end |
234 | 172 |
|
235 | | - context 'with invalid key' do |
236 | | - let(:params) do |
237 | | - { |
238 | | - key: true |
239 | | - } |
| 173 | + context 'with invalid key' do |
| 174 | + let(:params) do |
| 175 | + { |
| 176 | + key: true |
| 177 | + } |
| 178 | + end |
| 179 | + |
| 180 | + it do |
| 181 | + expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
| 182 | + end |
240 | 183 | end |
241 | 184 |
|
242 | | - it do |
243 | | - expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
| 185 | + context 'with invalid pin' do |
| 186 | + let(:params) do |
| 187 | + { |
| 188 | + pin: true |
| 189 | + } |
| 190 | + end |
| 191 | + |
| 192 | + it do |
| 193 | + expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
| 194 | + end |
244 | 195 | end |
245 | 196 | end |
| 197 | + end |
246 | 198 |
|
247 | | - context 'with invalid pin' do |
248 | | - let(:params) do |
| 199 | + describe 'debian/ubuntu tests' do |
| 200 | + context 'with defaults on debian' do |
| 201 | + let(:facts) do |
249 | 202 | { |
250 | | - pin: true |
| 203 | + os: { |
| 204 | + family: 'Debian', |
| 205 | + name: 'Debian', |
| 206 | + release: { |
| 207 | + full: '12.5', |
| 208 | + major: '12', |
| 209 | + minor: '5' |
| 210 | + }, |
| 211 | + distro: { |
| 212 | + codename: 'bookworm', |
| 213 | + id: 'Debian' |
| 214 | + } |
| 215 | + } |
251 | 216 | } |
252 | 217 | end |
253 | 218 |
|
254 | | - it do |
255 | | - expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
256 | | - end |
| 219 | + it { |
| 220 | + expect(subject).to contain_apt__source('backports').with( |
| 221 | + location: 'http://deb.debian.org/debian', |
| 222 | + repos: 'main contrib non-free non-free-firmware', |
| 223 | + release: 'bookworm-backports', |
| 224 | + pin: { |
| 225 | + 'priority' => 200, |
| 226 | + 'codename' => 'bookworm-backports' |
| 227 | + }, |
| 228 | + keyring: '/usr/share/keyrings/debian-archive-keyring.gpg', |
| 229 | + ) |
| 230 | + } |
257 | 231 | end |
| 232 | + |
| 233 | + # Include shared examples for Ubuntu versions |
| 234 | + include_examples 'ubuntu backports', '22.04', '22.04', 'jammy' |
| 235 | + include_examples 'ubuntu backports', '24.04', '24.04', 'noble' |
258 | 236 | end |
| 237 | + |
| 238 | + # Include shared validation examples for Ubuntu versions |
| 239 | + include_examples 'validation tests', '22.04', '22.04', 'jammy' |
| 240 | + include_examples 'validation tests', '24.04', '24.04', 'noble' |
259 | 241 | end |
0 commit comments