Skip to content

Commit

Permalink
test: add unit tests for deleting manifests (#48)
Browse files Browse the repository at this point in the history
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 authored Dec 12, 2022
1 parent 3474516 commit 884c54b
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions registry/storage/manifeststore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,63 @@ func testOCIManifestStorage(t *testing.T, testname string, includeMediaTypes boo
t.Fatalf("%s: unexpected MediaType for index payload, %s", testname, payloadMediaType)
}

// Test deleting the manifest
err = ms.Delete(ctx, manifestDigest)
if err != nil {
t.Fatalf("unexpected an error deleting manifest by digest: %v", err)
}

exists, err := ms.Exists(ctx, manifestDigest)
if err != nil {
t.Fatalf("Error querying manifest existence")
}
if exists {
t.Errorf("Deleted manifest should not exist")
}

deletedManifest, err := ms.Get(ctx, manifestDigest)
if err == nil {
t.Errorf("Unexpected success getting deleted manifest")
}
switch err.(type) {
case distribution.ErrManifestUnknownRevision:
break
default:
t.Errorf("Unexpected error getting deleted manifest: %s", reflect.ValueOf(err).Type())
}

if deletedManifest != nil {
t.Errorf("Deleted manifest get returned non-nil")
}

// test deleting the index
err = ms.Delete(ctx, indexDigest)
if err != nil {
t.Fatalf("unexpected an error deleting manifest by digest: %v", err)
}

exists, err = ms.Exists(ctx, indexDigest)
if err != nil {
t.Fatalf("Error querying manifest existence")
}
if exists {
t.Errorf("Deleted manifest should not exist")
}

deletedIndex, err := ms.Get(ctx, indexDigest)
if err == nil {
t.Errorf("Unexpected success getting deleted manifest")
}
switch err.(type) {
case distribution.ErrManifestUnknownRevision:
break
default:
t.Errorf("Unexpected error getting deleted manifest: %s", reflect.ValueOf(err).Type())
}

if deletedIndex != nil {
t.Errorf("Deleted manifest get returned non-nil")
}
}

func TestOCIArtifactManifestStorage(t *testing.T) {
Expand Down Expand Up @@ -622,6 +679,35 @@ func TestOCIArtifactManifestStorage(t *testing.T) {
if payloadMediaType != v1.MediaTypeArtifactManifest {
t.Fatalf("unexpected MediaType for manifest payload, %s", payloadMediaType)
}

// Test deleting the manifest
err = ms.Delete(ctx, manifestDigest)
if err != nil {
t.Fatalf("unexpected an error deleting manifest by digest: %v", err)
}

exists, err := ms.Exists(ctx, manifestDigest)
if err != nil {
t.Fatalf("Error querying manifest existence")
}
if exists {
t.Errorf("Deleted manifest should not exist")
}

deletedManifest, err := ms.Get(ctx, manifestDigest)
if err == nil {
t.Errorf("Unexpected success getting deleted manifest")
}
switch err.(type) {
case distribution.ErrManifestUnknownRevision:
break
default:
t.Errorf("Unexpected error getting deleted manifest: %s", reflect.ValueOf(err).Type())
}

if deletedManifest != nil {
t.Errorf("Deleted manifest get returned non-nil")
}
}

// TestLinkPathFuncs ensures that the link path functions behavior are locked
Expand Down

0 comments on commit 884c54b

Please sign in to comment.