@@ -189,3 +189,98 @@ func Test_runThrottledStatusNotifier(t *testing.T) {
189
189
case <- time .After (100 * time .Millisecond ):
190
190
}
191
191
}
192
+
193
+ func Test_equalDigest (t * testing.T ) {
194
+ for _ , testCase := range []struct {
195
+ name string
196
+ pullspecA string
197
+ pullspecB string
198
+ expected bool
199
+ }{
200
+ {
201
+ name : "both empty" ,
202
+ pullspecA : "" ,
203
+ pullspecB : "" ,
204
+ expected : true ,
205
+ },
206
+ {
207
+ name : "A empty" ,
208
+ pullspecA : "" ,
209
+ pullspecB : "example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
210
+ expected : false ,
211
+ },
212
+ {
213
+ name : "B empty" ,
214
+ pullspecA : "example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
215
+ pullspecB : "" ,
216
+ expected : false ,
217
+ },
218
+ {
219
+ name : "A implicit tag" ,
220
+ pullspecA : "example.com" ,
221
+ pullspecB : "example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
222
+ expected : false ,
223
+ },
224
+ {
225
+ name : "B implicit tag" ,
226
+ pullspecA : "example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
227
+ pullspecB : "example.com" ,
228
+ expected : false ,
229
+ },
230
+ {
231
+ name : "A by tag" ,
232
+ pullspecA : "example.com:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
233
+ pullspecB : "example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
234
+ expected : false ,
235
+ },
236
+ {
237
+ name : "B by tag" ,
238
+ pullspecA : "example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
239
+ pullspecB : "example.com:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
240
+ expected : false ,
241
+ },
242
+ {
243
+ name : "identical by tag" ,
244
+ pullspecA : "example.com:latest" ,
245
+ pullspecB : "example.com:latest" ,
246
+ expected : true ,
247
+ },
248
+ {
249
+ name : "different repositories, same tag" ,
250
+ pullspecA : "a.example.com:latest" ,
251
+ pullspecB : "b.example.com:latest" ,
252
+ expected : false ,
253
+ },
254
+ {
255
+ name : "different repositories, same digest" ,
256
+ pullspecA : "a.example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
257
+ pullspecB : "b.example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
258
+ expected : true ,
259
+ },
260
+ {
261
+ name : "same repository, different digests" ,
262
+ pullspecA : "example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
263
+ pullspecB : "example.com@sha256:01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b" ,
264
+ expected : false ,
265
+ },
266
+ {
267
+ name : "A empty repository, same digest" ,
268
+ pullspecA : "@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
269
+ pullspecB : "example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
270
+ expected : true ,
271
+ },
272
+ {
273
+ name : "B empty repository, same digest" ,
274
+ pullspecA : "example.com@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
275
+ pullspecB : "@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
276
+ expected : true ,
277
+ },
278
+ } {
279
+ t .Run (testCase .name , func (t * testing.T ) {
280
+ actual := equalDigest (testCase .pullspecA , testCase .pullspecB )
281
+ if actual != testCase .expected {
282
+ t .Fatalf ("got %t, not the expected %t" , actual , testCase .expected )
283
+ }
284
+ })
285
+ }
286
+ }
0 commit comments