Skip to content

Commit

Permalink
Add negative test case to TestBlobMount
Browse files Browse the repository at this point in the history
Signed-off-by: Sargun Dhillon <[email protected]>
  • Loading branch information
sargun committed Sep 16, 2021
1 parent 789ba58 commit bc27e4e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions registry/storage/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,12 @@ func TestBlobMount(t *testing.T) {
}

source := createSource(ctx, t, registry)
source2 := createSource(ctx, t, registry)
canonicalRef, err := reference.WithDigest(source.repository.Named(), source.desc.Digest)
if err != nil {
t.Fatal(err)
}

imageName, _ := reference.WithName("foo/bar")
repository, err := registry.Repository(ctx, imageName)
if err != nil {
Expand All @@ -465,6 +467,20 @@ func TestBlobMount(t *testing.T) {
t.Fatalf("descriptors not equal: %v != %v", ebm.Descriptor, source.desc)
}

// Test the negative case
// This uses the source repo from the first repo, but the digest from the second
wrongCanonicalRef, err := reference.WithDigest(source.repository.Named(), source2.desc.Digest)
if err != nil {
t.Fatal(err)
}
bw2, err := bs.Create(ctx, WithMountFrom(wrongCanonicalRef))
if err != nil {
t.Fatalf("Received unexpected non-error, when uploading with cross-mount from \"wrong\" repository")
}
if bw2 == nil {
t.Fatalf("Did not start upload upon failed cross mount")
}

// Test for existence.
statDesc, err := bs.Stat(ctx, source.desc.Digest)
if err != nil {
Expand Down

0 comments on commit bc27e4e

Please sign in to comment.