@@ -40,7 +40,6 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
40
40
override_path = true
41
41
` ,
42
42
},
43
- wantErr : nil ,
44
43
},
45
44
{
46
45
name : "ECR mirror image registry with a path and no CA certificate" ,
@@ -63,7 +62,6 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
63
62
override_path = true
64
63
` ,
65
64
},
66
- wantErr : nil ,
67
65
},
68
66
{
69
67
name : "Mirror image registry with a CA and an image registry with no CA certificate" ,
@@ -91,7 +89,6 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
91
89
override_path = true
92
90
` ,
93
91
},
94
- wantErr : nil ,
95
92
},
96
93
{
97
94
name : "Mirror image registry with a CA and an image registry with a CA" ,
@@ -124,7 +121,6 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
124
121
override_path = true
125
122
` ,
126
123
},
127
- wantErr : nil ,
128
124
},
129
125
{
130
126
name : "Image registry with a CA" ,
@@ -135,8 +131,6 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
135
131
},
136
132
},
137
133
want : nil ,
138
-
139
- wantErr : nil ,
140
134
},
141
135
}
142
136
for idx := range tests {
@@ -156,6 +150,7 @@ func Test_generateRegistryCACertFiles(t *testing.T) {
156
150
name string
157
151
configs []containerdConfig
158
152
want []cabpkv1.File
153
+ wantErr error
159
154
}{
160
155
{
161
156
name : "ECR mirror image registry with no CA certificate" ,
@@ -173,8 +168,41 @@ func Test_generateRegistryCACertFiles(t *testing.T) {
173
168
{
174
169
URL : "https://registry.example.com" ,
175
170
CASecretName : "my-registry-credentials-secret" ,
171
+ CACert : "-----BEGIN CERTIFICATE-----" ,
172
+ Mirror : true ,
173
+ },
174
+ },
175
+ want : []cabpkv1.File {
176
+ {
177
+ Path : "/etc/containerd/certs.d/registry.example.com/ca.crt" ,
178
+ Owner : "" ,
179
+ Permissions : "0600" ,
180
+ Encoding : "" ,
181
+ Append : false ,
182
+ ContentFrom : & cabpkv1.FileSource {
183
+ Secret : cabpkv1.SecretFileSource {
184
+ Name : "my-registry-credentials-secret" ,
185
+ Key : "ca.crt" ,
186
+ },
187
+ },
188
+ },
189
+ },
190
+ },
191
+ {
192
+ name : "Mirror image registry and registry with the same CA certificate" ,
193
+ configs : []containerdConfig {
194
+ {
195
+ URL : "https://registry.example.com/mirror" ,
196
+ CASecretName : "my-registry-credentials-secret" ,
197
+ CACert : "-----BEGIN CERTIFICATE-----" ,
176
198
Mirror : true ,
177
199
},
200
+ {
201
+ URL : "https://registry.example.com/library" ,
202
+ CASecretName : "my-registry-credentials-secret" ,
203
+ CACert : "-----BEGIN CERTIFICATE-----" ,
204
+ Mirror : false ,
205
+ },
178
206
},
179
207
want : []cabpkv1.File {
180
208
{
@@ -192,13 +220,49 @@ func Test_generateRegistryCACertFiles(t *testing.T) {
192
220
},
193
221
},
194
222
},
223
+ {
224
+ name : "Mirror image registry and registry with different CA certificates" ,
225
+ configs : []containerdConfig {
226
+ {
227
+ URL : "https://registry.example.com/mirror" ,
228
+ CASecretName : "my-registry-credentials-secret" ,
229
+ CACert : "-----BEGIN CERTIFICATE-----" ,
230
+ Mirror : true ,
231
+ },
232
+ {
233
+ URL : "https://registry.example.com/library" ,
234
+ CASecretName : "my-registry-credentials-secret" ,
235
+ CACert : "-----BEGIN CERTIFICATE----------END CERTIFICATE-----" ,
236
+ Mirror : false ,
237
+ },
238
+ },
239
+ wantErr : ErrConflictingRegistryCACertificates ,
240
+ },
241
+ {
242
+ name : "Multiple image registries with different CA certificates" ,
243
+ configs : []containerdConfig {
244
+ {
245
+ URL : "https://registry.example.com/mirror" ,
246
+ CASecretName : "my-registry-credentials-secret" ,
247
+ CACert : "-----BEGIN CERTIFICATE-----" ,
248
+ Mirror : false ,
249
+ },
250
+ {
251
+ URL : "https://registry.example.com/library" ,
252
+ CASecretName : "my-registry-credentials-secret" ,
253
+ CACert : "-----BEGIN CERTIFICATE----------END CERTIFICATE-----" ,
254
+ Mirror : false ,
255
+ },
256
+ },
257
+ wantErr : ErrConflictingRegistryCACertificates ,
258
+ },
195
259
}
196
260
for idx := range tests {
197
261
tt := tests [idx ]
198
262
t .Run (tt .name , func (t * testing.T ) {
199
263
t .Parallel ()
200
264
file , err := generateRegistryCACertFiles (tt .configs )
201
- require .NoError (t , err )
265
+ require .ErrorIs (t , err , tt . wantErr )
202
266
assert .Equal (t , tt .want , file )
203
267
})
204
268
}
0 commit comments