Simplify blobifocache/internal/test.GenericCache

We no longer need a cleanup callback.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač 2022-03-16 00:39:06 +01:00
parent 9a9904944d
commit a310b13598
3 changed files with 7 additions and 8 deletions

View File

@ -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) {

View File

@ -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)
})
}

View File

@ -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) {