From a2c144693f813e0da1d11b5550ac711c95f574d7 Mon Sep 17 00:00:00 2001 From: Andrei Aaron Date: Wed, 22 Oct 2025 12:21:29 +0300 Subject: [PATCH] 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 --- pkg/extensions/sync/sync_internal_test.go | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pkg/extensions/sync/sync_internal_test.go b/pkg/extensions/sync/sync_internal_test.go index 8b901211..60b33e42 100644 --- a/pkg/extensions/sync/sync_internal_test.go +++ b/pkg/extensions/sync/sync_internal_test.go @@ -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