зеркало из https://github.com/microsoft/docker.git
Allow to mock V2MetadataService in unit tests
Signed-off-by: Michal Minář <miminar@redhat.com>
This commit is contained in:
Родитель
c6dd51c32c
Коммит
d3bd14a4fb
|
@ -13,10 +13,21 @@ import (
|
|||
|
||||
// V2MetadataService maps layer IDs to a set of known metadata for
|
||||
// the layer.
|
||||
type V2MetadataService struct {
|
||||
type V2MetadataService interface {
|
||||
GetMetadata(diffID layer.DiffID) ([]V2Metadata, error)
|
||||
GetDiffID(dgst digest.Digest) (layer.DiffID, error)
|
||||
Add(diffID layer.DiffID, metadata V2Metadata) error
|
||||
TagAndAdd(diffID layer.DiffID, hmacKey []byte, metadata V2Metadata) error
|
||||
Remove(metadata V2Metadata) error
|
||||
}
|
||||
|
||||
// v2MetadataService implements V2MetadataService
|
||||
type v2MetadataService struct {
|
||||
store Store
|
||||
}
|
||||
|
||||
var _ V2MetadataService = &v2MetadataService{}
|
||||
|
||||
// V2Metadata contains the digest and source repository information for a layer.
|
||||
type V2Metadata struct {
|
||||
Digest digest.Digest
|
||||
|
@ -90,30 +101,30 @@ type authConfigKeyInput struct {
|
|||
const maxMetadata = 50
|
||||
|
||||
// NewV2MetadataService creates a new diff ID to v2 metadata mapping service.
|
||||
func NewV2MetadataService(store Store) *V2MetadataService {
|
||||
return &V2MetadataService{
|
||||
func NewV2MetadataService(store Store) V2MetadataService {
|
||||
return &v2MetadataService{
|
||||
store: store,
|
||||
}
|
||||
}
|
||||
|
||||
func (serv *V2MetadataService) diffIDNamespace() string {
|
||||
func (serv *v2MetadataService) diffIDNamespace() string {
|
||||
return "v2metadata-by-diffid"
|
||||
}
|
||||
|
||||
func (serv *V2MetadataService) digestNamespace() string {
|
||||
func (serv *v2MetadataService) digestNamespace() string {
|
||||
return "diffid-by-digest"
|
||||
}
|
||||
|
||||
func (serv *V2MetadataService) diffIDKey(diffID layer.DiffID) string {
|
||||
func (serv *v2MetadataService) diffIDKey(diffID layer.DiffID) string {
|
||||
return string(digest.Digest(diffID).Algorithm()) + "/" + digest.Digest(diffID).Hex()
|
||||
}
|
||||
|
||||
func (serv *V2MetadataService) digestKey(dgst digest.Digest) string {
|
||||
func (serv *v2MetadataService) digestKey(dgst digest.Digest) string {
|
||||
return string(dgst.Algorithm()) + "/" + dgst.Hex()
|
||||
}
|
||||
|
||||
// GetMetadata finds the metadata associated with a layer DiffID.
|
||||
func (serv *V2MetadataService) GetMetadata(diffID layer.DiffID) ([]V2Metadata, error) {
|
||||
func (serv *v2MetadataService) GetMetadata(diffID layer.DiffID) ([]V2Metadata, error) {
|
||||
jsonBytes, err := serv.store.Get(serv.diffIDNamespace(), serv.diffIDKey(diffID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -128,7 +139,7 @@ func (serv *V2MetadataService) GetMetadata(diffID layer.DiffID) ([]V2Metadata, e
|
|||
}
|
||||
|
||||
// GetDiffID finds a layer DiffID from a digest.
|
||||
func (serv *V2MetadataService) GetDiffID(dgst digest.Digest) (layer.DiffID, error) {
|
||||
func (serv *v2MetadataService) GetDiffID(dgst digest.Digest) (layer.DiffID, error) {
|
||||
diffIDBytes, err := serv.store.Get(serv.digestNamespace(), serv.digestKey(dgst))
|
||||
if err != nil {
|
||||
return layer.DiffID(""), err
|
||||
|
@ -139,7 +150,7 @@ func (serv *V2MetadataService) GetDiffID(dgst digest.Digest) (layer.DiffID, erro
|
|||
|
||||
// Add associates metadata with a layer DiffID. If too many metadata entries are
|
||||
// present, the oldest one is dropped.
|
||||
func (serv *V2MetadataService) Add(diffID layer.DiffID, metadata V2Metadata) error {
|
||||
func (serv *v2MetadataService) Add(diffID layer.DiffID, metadata V2Metadata) error {
|
||||
oldMetadata, err := serv.GetMetadata(diffID)
|
||||
if err != nil {
|
||||
oldMetadata = nil
|
||||
|
@ -174,13 +185,13 @@ func (serv *V2MetadataService) Add(diffID layer.DiffID, metadata V2Metadata) err
|
|||
|
||||
// TagAndAdd amends the given "meta" for hmac hashed by the given "hmacKey" and associates it with a layer
|
||||
// DiffID. If too many metadata entries are present, the oldest one is dropped.
|
||||
func (serv *V2MetadataService) TagAndAdd(diffID layer.DiffID, hmacKey []byte, meta V2Metadata) error {
|
||||
func (serv *v2MetadataService) TagAndAdd(diffID layer.DiffID, hmacKey []byte, meta V2Metadata) error {
|
||||
meta.HMAC = ComputeV2MetadataHMAC(hmacKey, &meta)
|
||||
return serv.Add(diffID, meta)
|
||||
}
|
||||
|
||||
// Remove unassociates a metadata entry from a layer DiffID.
|
||||
func (serv *V2MetadataService) Remove(metadata V2Metadata) error {
|
||||
func (serv *v2MetadataService) Remove(metadata V2Metadata) error {
|
||||
diffID, err := serv.GetDiffID(metadata.Digest)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -50,7 +50,7 @@ func (e ImageConfigPullError) Error() string {
|
|||
}
|
||||
|
||||
type v2Puller struct {
|
||||
V2MetadataService *metadata.V2MetadataService
|
||||
V2MetadataService metadata.V2MetadataService
|
||||
endpoint registry.APIEndpoint
|
||||
config *ImagePullConfig
|
||||
repoInfo *registry.RepositoryInfo
|
||||
|
@ -134,7 +134,7 @@ type v2LayerDescriptor struct {
|
|||
digest digest.Digest
|
||||
repoInfo *registry.RepositoryInfo
|
||||
repo distribution.Repository
|
||||
V2MetadataService *metadata.V2MetadataService
|
||||
V2MetadataService metadata.V2MetadataService
|
||||
tmpFile *os.File
|
||||
verifier digest.Verifier
|
||||
src distribution.Descriptor
|
||||
|
|
|
@ -41,7 +41,7 @@ type PushResult struct {
|
|||
}
|
||||
|
||||
type v2Pusher struct {
|
||||
v2MetadataService *metadata.V2MetadataService
|
||||
v2MetadataService metadata.V2MetadataService
|
||||
ref reference.Named
|
||||
endpoint registry.APIEndpoint
|
||||
repoInfo *registry.RepositoryInfo
|
||||
|
@ -243,7 +243,7 @@ func manifestFromBuilder(ctx context.Context, builder distribution.ManifestBuild
|
|||
|
||||
type v2PushDescriptor struct {
|
||||
layer layer.Layer
|
||||
v2MetadataService *metadata.V2MetadataService
|
||||
v2MetadataService metadata.V2MetadataService
|
||||
hmacKey []byte
|
||||
repoInfo reference.Named
|
||||
ref reference.Named
|
||||
|
|
Загрузка…
Ссылка в новой задаче