From b6e68fa28aa4d9643ee7683e92f25f2127b17614 Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Sun, 7 Mar 2021 00:03:20 -0800 Subject: [PATCH] Fixed few coverage flakes (#872) * blobtesting: coverage for GetMetadata() returning ErrNotFound * content: additional direct coverage for diskCommittedContentIndexCache --- internal/blobtesting/asserts.go | 10 ++++++++++ internal/blobtesting/verify.go | 1 + repo/content/committed_content_index_cache_test.go | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/internal/blobtesting/asserts.go b/internal/blobtesting/asserts.go index fee76b636..81f501efb 100644 --- a/internal/blobtesting/asserts.go +++ b/internal/blobtesting/asserts.go @@ -92,6 +92,16 @@ func AssertGetBlobNotFound(ctx context.Context, t testingT, s blob.Storage, blob } } +// AssertGetMetadataNotFound asserts that GetMetadata() for specified blobID returns ErrNotFound. +func AssertGetMetadataNotFound(ctx context.Context, t testingT, s blob.Storage, blobID blob.ID) { + t.Helper() + + _, err := s.GetMetadata(ctx, blobID) + if !errors.Is(err, blob.ErrBlobNotFound) { + t.Errorf("GetMetadata(%v) returned %v, %v but expected ErrNotFound", blobID, err) + } +} + // AssertListResults asserts that the list results with given prefix return the specified list of names in order. func AssertListResults(ctx context.Context, t testingT, s blob.Storage, prefix blob.ID, want ...blob.ID) { t.Helper() diff --git a/internal/blobtesting/verify.go b/internal/blobtesting/verify.go index a44d3a635..ecea6d171 100644 --- a/internal/blobtesting/verify.go +++ b/internal/blobtesting/verify.go @@ -30,6 +30,7 @@ func VerifyStorage(ctx context.Context, t testingT, r blob.Storage) { // First verify that blocks don't exist. for _, b := range blocks { AssertGetBlobNotFound(ctx, t, r, b.blk) + AssertGetMetadataNotFound(ctx, t, r, b.blk) } if err := r.DeleteBlob(ctx, "no-such-blob"); err != nil && !errors.Is(err, blob.ErrBlobNotFound) { diff --git a/repo/content/committed_content_index_cache_test.go b/repo/content/committed_content_index_cache_test.go index 305bd2a54..6b2b7e535 100644 --- a/repo/content/committed_content_index_cache_test.go +++ b/repo/content/committed_content_index_cache_test.go @@ -59,6 +59,11 @@ func testCache(t *testing.T, cache committedContentIndexCache, fakeTime *faketim "c4": &Info{PackBlobID: "p2345", ID: "c4"}, }))) + must(t, cache.addContentToCache(ctx, "ndx2", mustBuildPackIndex(t, packIndexBuilder{ + "c3": &Info{PackBlobID: "p2345", ID: "c3"}, + "c4": &Info{PackBlobID: "p2345", ID: "c4"}, + }))) + ndx1, err := cache.openIndex(ctx, "ndx1") must(t, err)