chore: increase/stabilize go test coverage (#3411)

* chore: increase/stabilize coverage for the local storage driver

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

* chore: add/stabilize coverage for soring ImageSummary objects

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

* chore: stabilize coverage in sync tests

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

---------

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
Andrei Aaron
2025-10-02 01:24:38 +03:00
committed by GitHub
parent 5e5bd1e33c
commit 5309e7f5cf
8 changed files with 1527 additions and 56 deletions
+78 -48
View File
@@ -3,54 +3,30 @@ package mocks
import (
"context"
"github.com/containers/image/v5/types"
"github.com/opencontainers/go-digest"
"github.com/regclient/regclient/types/ref"
)
type SyncRemote struct {
// Get temporary ImageReference, is used by functions in containers/image package
GetImageReferenceFn func(repo string, tag string) (types.ImageReference, error)
// Get local oci layout context, is used by functions in containers/image package
GetContextFn func() *types.SystemContext
// Get a list of repos (catalog)
GetRepositoriesFn func(ctx context.Context) ([]string, error)
// Get a list of tags given a repo
GetRepoTagsFn func(repo string) ([]string, error)
GetDockerRemoteRepoFn func(repo string) string
// Get manifest content, mediaType, digest given an ImageReference
GetManifestContentFn func(imageReference types.ImageReference) ([]byte, string, digest.Digest, error)
type SyncRemoteMock struct {
// Methods required by sync Remote interface.
GetHostNameFn func() string
GetRepositoriesFn func(ctx context.Context) ([]string, error)
GetTagsFn func(ctx context.Context, repo string) ([]string, error)
GetOCIDigestFn func(ctx context.Context, repo, tag string) (digest.Digest, digest.Digest, bool, error)
GetDigestFn func(ctx context.Context, repo, tag string) (digest.Digest, error)
GetImageReferenceFn func(repo string, tag string) (ref.Ref, error)
}
func (remote SyncRemote) GetDockerRemoteRepo(repo string) string {
if remote.GetDockerRemoteRepoFn != nil {
return remote.GetDockerRemoteRepoFn(repo)
// Methods required by sync Remote interface.
func (remote SyncRemoteMock) GetHostName() string {
if remote.GetHostNameFn != nil {
return remote.GetHostNameFn()
}
return ""
return "mock-host"
}
func (remote SyncRemote) GetImageReference(repo string, tag string) (types.ImageReference, error) {
if remote.GetImageReferenceFn != nil {
return remote.GetImageReferenceFn(repo, tag)
}
return nil, nil //nolint:nilnil
}
func (remote SyncRemote) GetContext() *types.SystemContext {
if remote.GetContextFn != nil {
return remote.GetContextFn()
}
return nil
}
func (remote SyncRemote) GetRepositories(ctx context.Context) ([]string, error) {
func (remote SyncRemoteMock) GetRepositories(ctx context.Context) ([]string, error) {
if remote.GetRepositoriesFn != nil {
return remote.GetRepositoriesFn(ctx)
}
@@ -58,23 +34,77 @@ func (remote SyncRemote) GetRepositories(ctx context.Context) ([]string, error)
return []string{}, nil
}
func (remote SyncRemote) GetRepoTags(repo string) ([]string, error) {
if remote.GetRepoTagsFn != nil {
return remote.GetRepoTagsFn(repo)
func (remote SyncRemoteMock) GetTags(ctx context.Context, repo string) ([]string, error) {
if remote.GetTagsFn != nil {
return remote.GetTagsFn(ctx, repo)
}
return []string{}, nil
}
func (remote SyncRemote) GetManifestContent(imageReference types.ImageReference) (
[]byte, string, digest.Digest, error,
func (remote SyncRemoteMock) GetOCIDigest(ctx context.Context, repo, tag string) (
digest.Digest, digest.Digest, bool, error,
) {
if remote.GetManifestContentFn != nil {
return remote.GetManifestContentFn(imageReference)
if remote.GetOCIDigestFn != nil {
return remote.GetOCIDigestFn(ctx, repo, tag)
}
return nil, "", "", nil
return digest.Digest("sha256:abc123"), digest.Digest("sha256:def456"), false, nil
}
func (remote SyncRemote) SetUpstreamAuthConfig(username, password string) {
func (remote SyncRemoteMock) GetDigest(ctx context.Context, repo, tag string) (digest.Digest, error) {
if remote.GetDigestFn != nil {
return remote.GetDigestFn(ctx, repo, tag)
}
return digest.Digest("sha256:abc123"), nil
}
func (remote SyncRemoteMock) GetImageReference(repo string, tag string) (ref.Ref, error) {
if remote.GetImageReferenceFn != nil {
return remote.GetImageReferenceFn(repo, tag)
}
return ref.New("mock-registry/" + repo + ":" + tag)
}
type SyncDestinationMock struct {
// Methods required by sync Destination interface.
GetImageReferenceFn func(repo string, tag string) (ref.Ref, error)
CanSkipImageFn func(repo string, tag string, digest digest.Digest) (bool, error)
CommitAllFn func(repo string, imageReference ref.Ref) error
CleanupImageFn func(imageReference ref.Ref, repo string) error
}
// Methods required by sync Destination interface.
func (dest SyncDestinationMock) GetImageReference(repo string, tag string) (ref.Ref, error) {
if dest.GetImageReferenceFn != nil {
return dest.GetImageReferenceFn(repo, tag)
}
return ref.New("mock-local/" + repo + ":" + tag)
}
func (dest SyncDestinationMock) CanSkipImage(repo string, tag string, digest digest.Digest) (bool, error) {
if dest.CanSkipImageFn != nil {
return dest.CanSkipImageFn(repo, tag, digest)
}
return false, nil
}
func (dest SyncDestinationMock) CommitAll(repo string, imageReference ref.Ref) error {
if dest.CommitAllFn != nil {
return dest.CommitAllFn(repo, imageReference)
}
return nil
}
func (dest SyncDestinationMock) CleanupImage(imageReference ref.Ref, repo string) error {
if dest.CleanupImageFn != nil {
return dest.CleanupImageFn(imageReference, repo)
}
return nil
}