diff --git a/registry/storage/garbagecollect_test.go b/registry/storage/garbagecollect_test.go index 35e6cd71..695dbe9d 100644 --- a/registry/storage/garbagecollect_test.go +++ b/registry/storage/garbagecollect_test.go @@ -186,21 +186,11 @@ func TestDeleteManifestIfTagNotFound(t *testing.T) { t.Fatalf("failed to make layers: %v", err) } - digests1 := []digest.Digest{} - for digest := range randomLayers1 { - digests1 = append(digests1, digest) - } - randomLayers2, err := testutil.CreateRandomLayers(3) if err != nil { t.Fatalf("failed to make layers: %v", err) } - digests2 := []digest.Digest{} - for digest := range randomLayers2 { - digests2 = append(digests2, digest) - } - // Upload all layers err = testutil.UploadBlobs(repo, randomLayers1) if err != nil { @@ -213,12 +203,12 @@ func TestDeleteManifestIfTagNotFound(t *testing.T) { } // Construct manifests - manifest1, err := testutil.MakeSchema2Manifest(repo, digests1) + manifest1, err := testutil.MakeSchema2Manifest(repo, getKeys(randomLayers1)) if err != nil { t.Fatalf("failed to make manifest: %v", err) } - manifest2, err := testutil.MakeSchema2Manifest(repo, digests2) + manifest2, err := testutil.MakeSchema2Manifest(repo, getKeys(randomLayers2)) if err != nil { t.Fatalf("failed to make manifest: %v", err) } @@ -370,6 +360,13 @@ func getAnyKey(digests map[digest.Digest]io.ReadSeeker) (d digest.Digest) { return } +func getKeys(digests map[digest.Digest]io.ReadSeeker) (ds []digest.Digest) { + for d := range digests { + ds = append(ds, d) + } + return +} + func TestDeletionWithSharedLayer(t *testing.T) { ctx := context.Background() inmemoryDriver := inmemory.New() @@ -383,21 +380,11 @@ func TestDeletionWithSharedLayer(t *testing.T) { t.Fatalf("failed to make layers: %v", err) } - digests1 := []digest.Digest{} - for digest := range randomLayers1 { - digests1 = append(digests1, digest) - } - randomLayers2, err := testutil.CreateRandomLayers(3) if err != nil { t.Fatalf("failed to make layers: %v", err) } - digests2 := []digest.Digest{} - for digest := range randomLayers2 { - digests2 = append(digests2, digest) - } - // Upload all layers err = testutil.UploadBlobs(repo, randomLayers1) if err != nil { @@ -410,13 +397,13 @@ func TestDeletionWithSharedLayer(t *testing.T) { } // Construct manifests - manifest1, err := testutil.MakeSchema2Manifest(repo, digests1) + manifest1, err := testutil.MakeSchema2Manifest(repo, getKeys(randomLayers1)) if err != nil { t.Fatalf("failed to make manifest: %v", err) } sharedKey := getAnyKey(randomLayers1) - manifest2, err := testutil.MakeSchema2Manifest(repo, append(digests2, sharedKey)) + manifest2, err := testutil.MakeSchema2Manifest(repo, append(getKeys(randomLayers2), sharedKey)) if err != nil { t.Fatalf("failed to make manifest: %v", err) } diff --git a/registry/storage/manifeststore_test.go b/registry/storage/manifeststore_test.go index 54e19913..3285d541 100644 --- a/registry/storage/manifeststore_test.go +++ b/registry/storage/manifeststore_test.go @@ -98,27 +98,12 @@ func testManifestStorage(t *testing.T, options ...RegistryOption) { MediaType: schema2.MediaTypeManifest, }, Config: distribution.Descriptor{ - Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", - Size: 3253, + Digest: digest.FromBytes(sampleConfig), + Size: int64(len(sampleConfig)), MediaType: schema2.MediaTypeImageConfig, }, - Layers: []distribution.Descriptor{ - { - Digest: "sha256:463434349086340864309863409683460843608348608934092322395278926a", - Size: 6323, - MediaType: schema2.MediaTypeLayer, - }, - { - Digest: "sha256:630923423623623423352523525237238023652897356239852383652aaaaaaa", - Size: 6863, - MediaType: schema2.MediaTypeLayer, - }, - }, + Layers: []distribution.Descriptor{}, } - sampleConfigDigest := digest.FromBytes(sampleConfig) - sampleConfigSize := int64(len(sampleConfig)) - m.Config.Digest = sampleConfigDigest - m.Config.Size = sampleConfigSize // Build up some test layers and add them to the manifest, saving the // readseekers for upload later. @@ -130,7 +115,12 @@ func testManifestStorage(t *testing.T, options ...RegistryOption) { } testLayers[dgst] = rs - m.Layers[i].Digest = dgst + layer := distribution.Descriptor{ + Digest: dgst, + Size: 6323, + MediaType: schema2.MediaTypeLayer, + } + m.Layers = append(m.Layers, layer) } // Now, upload the layers that were missing!