@@ -40,7 +40,6 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
4040 override_path = true
4141` ,
4242 },
43- wantErr : nil ,
4443 },
4544 {
4645 name : "ECR mirror image registry with a path and no CA certificate" ,
@@ -63,7 +62,6 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
6362 override_path = true
6463` ,
6564 },
66- wantErr : nil ,
6765 },
6866 {
6967 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) {
9189 override_path = true
9290` ,
9391 },
94- wantErr : nil ,
9592 },
9693 {
9794 name : "Mirror image registry with a CA and an image registry with a CA" ,
@@ -124,7 +121,6 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
124121 override_path = true
125122` ,
126123 },
127- wantErr : nil ,
128124 },
129125 {
130126 name : "Image registry with a CA" ,
@@ -135,8 +131,6 @@ func Test_generateContainerdDefaultHostsFile(t *testing.T) {
135131 },
136132 },
137133 want : nil ,
138-
139- wantErr : nil ,
140134 },
141135 }
142136 for idx := range tests {
@@ -156,6 +150,7 @@ func Test_generateRegistryCACertFiles(t *testing.T) {
156150 name string
157151 configs []containerdConfig
158152 want []cabpkv1.File
153+ wantErr error
159154 }{
160155 {
161156 name : "ECR mirror image registry with no CA certificate" ,
@@ -173,8 +168,41 @@ func Test_generateRegistryCACertFiles(t *testing.T) {
173168 {
174169 URL : "https://registry.example.com" ,
175170 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-----" ,
176198 Mirror : true ,
177199 },
200+ {
201+ URL : "https://registry.example.com/library" ,
202+ CASecretName : "my-registry-credentials-secret" ,
203+ CACert : "-----BEGIN CERTIFICATE-----" ,
204+ Mirror : false ,
205+ },
178206 },
179207 want : []cabpkv1.File {
180208 {
@@ -192,13 +220,49 @@ func Test_generateRegistryCACertFiles(t *testing.T) {
192220 },
193221 },
194222 },
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+ },
195259 }
196260 for idx := range tests {
197261 tt := tests [idx ]
198262 t .Run (tt .name , func (t * testing.T ) {
199263 t .Parallel ()
200264 file , err := generateRegistryCACertFiles (tt .configs )
201- require .NoError (t , err )
265+ require .ErrorIs (t , err , tt . wantErr )
202266 assert .Equal (t , tt .want , file )
203267 })
204268 }
0 commit comments