zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/pkg/test/mocks/sync_remote_mock.go (about)

     1  package mocks
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/containers/image/v5/types"
     7  	"github.com/opencontainers/go-digest"
     8  )
     9  
    10  type SyncRemote struct {
    11  	// Get temporary ImageReference, is used by functions in containers/image package
    12  	GetImageReferenceFn func(repo string, tag string) (types.ImageReference, error)
    13  
    14  	// Get local oci layout context, is used by functions in containers/image package
    15  	GetContextFn func() *types.SystemContext
    16  
    17  	// Get a list of repos (catalog)
    18  	GetRepositoriesFn func(ctx context.Context) ([]string, error)
    19  
    20  	// Get a list of tags given a repo
    21  	GetRepoTagsFn func(repo string) ([]string, error)
    22  
    23  	GetDockerRemoteRepoFn func(repo string) string
    24  
    25  	// Get manifest content, mediaType, digest given an ImageReference
    26  	GetManifestContentFn func(imageReference types.ImageReference) ([]byte, string, digest.Digest, error)
    27  }
    28  
    29  func (remote SyncRemote) GetDockerRemoteRepo(repo string) string {
    30  	if remote.GetDockerRemoteRepoFn != nil {
    31  		return remote.GetDockerRemoteRepoFn(repo)
    32  	}
    33  
    34  	return ""
    35  }
    36  
    37  func (remote SyncRemote) GetImageReference(repo string, tag string) (types.ImageReference, error) {
    38  	if remote.GetImageReferenceFn != nil {
    39  		return remote.GetImageReferenceFn(repo, tag)
    40  	}
    41  
    42  	return nil, nil
    43  }
    44  
    45  func (remote SyncRemote) GetContext() *types.SystemContext {
    46  	if remote.GetContextFn != nil {
    47  		return remote.GetContextFn()
    48  	}
    49  
    50  	return nil
    51  }
    52  
    53  func (remote SyncRemote) GetRepositories(ctx context.Context) ([]string, error) {
    54  	if remote.GetRepositoriesFn != nil {
    55  		return remote.GetRepositoriesFn(ctx)
    56  	}
    57  
    58  	return []string{}, nil
    59  }
    60  
    61  func (remote SyncRemote) GetRepoTags(repo string) ([]string, error) {
    62  	if remote.GetRepoTagsFn != nil {
    63  		return remote.GetRepoTagsFn(repo)
    64  	}
    65  
    66  	return []string{}, nil
    67  }
    68  
    69  func (remote SyncRemote) GetManifestContent(imageReference types.ImageReference) (
    70  	[]byte, string, digest.Digest, error,
    71  ) {
    72  	if remote.GetManifestContentFn != nil {
    73  		return remote.GetManifestContentFn(imageReference)
    74  	}
    75  
    76  	return nil, "", "", nil
    77  }