chore: stabilize coverage in specific sync test (#3480)

Take care of https://app.codecov.io/gh/project-zot/zot/pull/3479/indirect-changes

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
Andrei Aaron
2025-10-22 12:21:29 +03:00
committed by GitHub
parent 559d9cf2fc
commit a2c144693f
+41
View File
@@ -161,6 +161,47 @@ func TestService(t *testing.T) {
So(err.Error(), ShouldContainSubstring, "ref is not set")
})
Convey("test syncReferrers ReferrerList error", t, func() {
conf := syncconf.RegistryConfig{
URLs: []string{"http://localhost"},
}
service, err := New(conf, "", nil, os.TempDir(), storage.StoreController{}, mocks.MetaDBMock{}, log.NewTestLogger())
So(err, ShouldBeNil)
// Create a mock remote that returns valid references
mockRemote := &mocks.SyncRemoteMock{
GetImageReferenceFn: func(repo string, tag string) (ref.Ref, error) {
return ref.New(repo + ":" + tag)
},
GetDigestFn: func(ctx context.Context, repo, tag string) (godigest.Digest, error) {
return godigest.Digest("sha256:abc123"), nil
},
}
service.remote = mockRemote
// Create a mock destination
mockDest := &mocks.SyncDestinationMock{
GetImageReferenceFn: func(repo string, tag string) (ref.Ref, error) {
return ref.New("local/" + repo + ":" + tag)
},
}
service.destination = mockDest
ctx := context.Background()
localImageRef, err := ref.New("local/repo:tag")
So(err, ShouldBeNil)
// Create an invalid remote reference that will cause ReferrerList to fail with "ref is not set" error
remoteImageRef := ref.Ref{}
err = service.syncReferrers(ctx, []string{"tag"}, "localrepo", "remoterepo", localImageRef, remoteImageRef)
// The error should be "ref is not set" as defined in regclient ReferrerList function
So(err, ShouldNotBeNil)
So(err.Error(), ShouldContainSubstring, "ref is not set")
})
Convey("test LoadOrStore continue path by pre-populating requestStore", t, func() {
// Strategy: Pre-populate requestStore to force LoadOrStore to return true
maxRetries := 2