1
0
mirror of https://github.com/distribution/distribution synced 2024-11-12 05:45:51 +01:00

better name and updated tests

- use ManifestDigests name instead of Indexes
- update tests to validate against multiple tags

Signed-off-by: Manish Tomar <manish.tomar@docker.com>
This commit is contained in:
Manish Tomar 2018-11-01 10:31:08 -07:00
parent 9ebf151ac2
commit 1251e51ad0
3 changed files with 44 additions and 20 deletions

@ -197,7 +197,7 @@ func (ts *tagStore) Lookup(ctx context.Context, desc distribution.Descriptor) ([
return tags, nil return tags, nil
} }
func (ts *tagStore) Indexes(ctx context.Context, tag string) ([]digest.Digest, error) { func (ts *tagStore) ManifestDigests(ctx context.Context, tag string) ([]digest.Digest, error) {
var tagLinkPath = func(name string, dgst digest.Digest) (string, error) { var tagLinkPath = func(name string, dgst digest.Digest) (string, error) {
return pathFor(manifestTagIndexEntryLinkPathSpec{ return pathFor(manifestTagIndexEntryLinkPathSpec{
name: name, name: name,

@ -226,9 +226,9 @@ func TestTagIndexes(t *testing.T) {
tagStore := env.ts tagStore := env.ts
ctx := env.ctx ctx := env.ctx
indexes, ok := tagStore.(distribution.TagIndexes) md, ok := tagStore.(distribution.TagManifestsProvider)
if !ok { if !ok {
t.Fatal("tagStore does not implement TagIndexes interface") t.Fatal("tagStore does not implement TagManifestDigests interface")
} }
conf, err := env.bs.Put(ctx, "application/octet-stream", []byte{0}) conf, err := env.bs.Put(ctx, "application/octet-stream", []byte{0})
@ -236,8 +236,9 @@ func TestTagIndexes(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
dgstsSet := make(map[digest.Digest]bool) t1Dgsts := make(map[digest.Digest]struct{})
for i := 0; i < 3; i++ { t2Dgsts := make(map[digest.Digest]struct{})
for i := 0; i < 5; i++ {
layer, err := env.bs.Put(ctx, "application/octet-stream", []byte{byte(i + 1)}) layer, err := env.bs.Put(ctx, "application/octet-stream", []byte{byte(i + 1)})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -272,22 +273,44 @@ func TestTagIndexes(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = tagStore.Tag(ctx, "t", desc) if i < 3 {
if err != nil { // tag first 3 manifests as "t1"
t.Fatal(err) err = tagStore.Tag(ctx, "t1", desc)
if err != nil {
t.Fatal(err)
}
t1Dgsts[dgst] = struct{}{}
} else {
// the last two under "t2"
err = tagStore.Tag(ctx, "t2", desc)
if err != nil {
t.Fatal(err)
}
t2Dgsts[dgst] = struct{}{}
} }
dgstsSet[dgst] = true
} }
gotDgsts, err := indexes.Indexes(ctx, "t") gotT1Dgsts, err := md.ManifestDigests(ctx, "t1")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
gotDgstsSet := make(map[digest.Digest]bool) if !reflect.DeepEqual(t1Dgsts, digestMap(gotT1Dgsts)) {
for _, dgst := range gotDgsts { t.Fatalf("Expected digests: %v but got digests: %v", t1Dgsts, digestMap(gotT1Dgsts))
gotDgstsSet[dgst] = true
} }
if !reflect.DeepEqual(dgstsSet, gotDgstsSet) {
t.Fatalf("Expected digests: %v but got digests: %v", dgstsSet, gotDgstsSet) gotT2Dgsts, err := md.ManifestDigests(ctx, "t2")
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(t2Dgsts, digestMap(gotT2Dgsts)) {
t.Fatalf("Expected digests: %v but got digests: %v", t2Dgsts, digestMap(gotT2Dgsts))
} }
} }
func digestMap(dgsts []digest.Digest) map[digest.Digest]struct{} {
set := make(map[digest.Digest]struct{})
for _, dgst := range dgsts {
set[dgst] = struct{}{}
}
return set
}

11
tags.go

@ -28,9 +28,10 @@ type TagService interface {
Lookup(ctx context.Context, digest Descriptor) ([]string, error) Lookup(ctx context.Context, digest Descriptor) ([]string, error)
} }
// TagIndexes proves method to retreive all the digests that a tag historically pointed to // TagManifestsProvider provides method to retreive the digests of manifests that a tag historically
type TagIndexes interface { // pointed to
// Indexes returns set of digests that this tag historically pointed to. This also includes type TagManifestsProvider interface {
// currently linked digest. There is no ordering guaranteed // ManifestDigests returns set of digests that this tag historically pointed to. This also
Indexes(ctx context.Context, tag string) ([]digest.Digest, error) // includes currently linked digest. There is no ordering guaranteed
ManifestDigests(ctx context.Context, tag string) ([]digest.Digest, error)
} }