|
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 everything set' 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: '22.04', |
82 | | - full: '22.04' |
| 49 | + major: release_major, |
| 50 | + full: release_full |
83 | 51 | }, |
84 | 52 | distro: { |
85 | | - codename: 'jammy', |
| 53 | + codename:, |
86 | 54 | id: 'Ubuntu' |
87 | 55 | } |
88 | 56 | } |
|
109 | 77 | } |
110 | 78 | end |
111 | 79 |
|
112 | | - context 'when set things with hashes' do |
| 80 | + context "when set things with hashes on ubuntu #{release_major}" do |
113 | 81 | let(:facts) do |
114 | 82 | { |
115 | 83 | os: { |
116 | 84 | family: 'Debian', |
117 | 85 | name: 'Ubuntu', |
118 | 86 | release: { |
119 | | - major: '22.04', |
120 | | - full: '22.04' |
| 87 | + major: release_major, |
| 88 | + full: release_full |
121 | 89 | }, |
122 | 90 | distro: { |
123 | | - codename: 'jammy', |
| 91 | + codename:, |
124 | 92 | id: 'Ubuntu' |
125 | 93 | } |
126 | 94 | } |
|
146 | 114 | end |
147 | 115 | end |
148 | 116 |
|
149 | | - describe 'validation' do |
150 | | - let(:facts) do |
151 | | - { |
152 | | - os: { |
153 | | - family: 'Debian', |
154 | | - name: 'Ubuntu', |
155 | | - release: { |
156 | | - major: '22.04', |
157 | | - full: '22.04' |
158 | | - }, |
159 | | - distro: { |
160 | | - codename: 'jammy', |
161 | | - id: 'Ubuntu' |
162 | | - } |
163 | | - } |
164 | | - } |
165 | | - end |
166 | | - |
167 | | - context 'with invalid location' do |
168 | | - 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 |
169 | 121 | { |
170 | | - 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 | + } |
171 | 134 | } |
172 | 135 | end |
173 | 136 |
|
174 | | - it do |
175 | | - expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
176 | | - end |
177 | | - end |
| 137 | + context 'with invalid location' do |
| 138 | + let(:params) do |
| 139 | + { |
| 140 | + location: true |
| 141 | + } |
| 142 | + end |
178 | 143 |
|
179 | | - context 'with invalid release' do |
180 | | - let(:params) do |
181 | | - { |
182 | | - release: true |
183 | | - } |
| 144 | + it do |
| 145 | + expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
| 146 | + end |
184 | 147 | end |
185 | 148 |
|
186 | | - it do |
187 | | - expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
188 | | - end |
189 | | - end |
| 149 | + context 'with invalid release' do |
| 150 | + let(:params) do |
| 151 | + { |
| 152 | + release: true |
| 153 | + } |
| 154 | + end |
190 | 155 |
|
191 | | - context 'with invalid repos' do |
192 | | - let(:params) do |
193 | | - { |
194 | | - repos: true |
195 | | - } |
| 156 | + it do |
| 157 | + expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
| 158 | + end |
196 | 159 | end |
197 | 160 |
|
198 | | - it do |
199 | | - 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 |
200 | 171 | end |
201 | | - end |
202 | 172 |
|
203 | | - context 'with invalid key' do |
204 | | - let(:params) do |
205 | | - { |
206 | | - key: true |
207 | | - } |
| 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 |
208 | 183 | end |
209 | 184 |
|
210 | | - it do |
211 | | - 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 |
212 | 195 | end |
213 | 196 | end |
| 197 | + end |
214 | 198 |
|
215 | | - context 'with invalid pin' do |
216 | | - let(:params) do |
| 199 | + describe 'debian/ubuntu tests' do |
| 200 | + context 'with defaults on debian' do |
| 201 | + let(:facts) do |
217 | 202 | { |
218 | | - 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 | + } |
219 | 216 | } |
220 | 217 | end |
221 | 218 |
|
222 | | - it do |
223 | | - expect(subject).to raise_error(Puppet::Error, %r{expects a}) |
224 | | - 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 | + } |
225 | 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' |
226 | 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' |
227 | 241 | end |
0 commit comments