From aa919554182fbc5ab7059ac565613090d02f9efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 16 Mar 2022 00:39:06 +0100 Subject: [PATCH] Simplify blobifocache/internal/test.GenericCache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We no longer need a cleanup callback. Signed-off-by: Miloslav Trmač --- pkg/blobinfocache/boltdb/boltdb_test.go | 4 ++-- pkg/blobinfocache/internal/test/test.go | 7 +++---- pkg/blobinfocache/memory/memory_test.go | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/blobinfocache/boltdb/boltdb_test.go b/pkg/blobinfocache/boltdb/boltdb_test.go index e53f6e9dd3..50b4784596 100644 --- a/pkg/blobinfocache/boltdb/boltdb_test.go +++ b/pkg/blobinfocache/boltdb/boltdb_test.go @@ -10,13 +10,13 @@ import ( var _ blobinfocache.BlobInfoCache2 = &cache{} -func newTestCache(t *testing.T) (blobinfocache.BlobInfoCache2, func(t *testing.T)) { +func newTestCache(t *testing.T) blobinfocache.BlobInfoCache2 { // We need a separate temporary directory here, because bolt.Open(…, &bolt.Options{Readonly:true}) can't deal with // an existing but empty file, and incorrectly fails without releasing the lock - which in turn causes // any future writes to hang. Creating a temporary directory allows us to use a path to a // non-existent file, thus replicating the expected conditions for creating a new DB. dir := t.TempDir() - return new2(filepath.Join(dir, "db")), func(t *testing.T) {} + return new2(filepath.Join(dir, "db")) } func TestNew(t *testing.T) { diff --git a/pkg/blobinfocache/internal/test/test.go b/pkg/blobinfocache/internal/test/test.go index 4e7c1d06dd..ce4ce5e302 100644 --- a/pkg/blobinfocache/internal/test/test.go +++ b/pkg/blobinfocache/internal/test/test.go @@ -24,8 +24,8 @@ const ( ) // GenericCache runs an implementation-independent set of tests, given a -// newTestCache, which can be called repeatedly and always returns a (cache, cleanup callback) pair -func GenericCache(t *testing.T, newTestCache func(t *testing.T) (blobinfocache.BlobInfoCache2, func(t *testing.T))) { +// newTestCache, which can be called repeatedly and always returns a fresh cache instance +func GenericCache(t *testing.T, newTestCache func(t *testing.T) blobinfocache.BlobInfoCache2) { for _, s := range []struct { name string fn func(t *testing.T, cache blobinfocache.BlobInfoCache2) @@ -37,8 +37,7 @@ func GenericCache(t *testing.T, newTestCache func(t *testing.T) (blobinfocache.B {"CandidateLocations2", testGenericCandidateLocations2}, } { t.Run(s.name, func(t *testing.T) { - cache, cleanup := newTestCache(t) - defer cleanup(t) + cache := newTestCache(t) s.fn(t, cache) }) } diff --git a/pkg/blobinfocache/memory/memory_test.go b/pkg/blobinfocache/memory/memory_test.go index bc8d5035fb..322f008f31 100644 --- a/pkg/blobinfocache/memory/memory_test.go +++ b/pkg/blobinfocache/memory/memory_test.go @@ -9,8 +9,8 @@ import ( var _ blobinfocache.BlobInfoCache2 = &cache{} -func newTestCache(t *testing.T) (blobinfocache.BlobInfoCache2, func(t *testing.T)) { - return new2(), func(t *testing.T) {} +func newTestCache(t *testing.T) blobinfocache.BlobInfoCache2 { + return new2() } func TestNew(t *testing.T) {