Skip to content

Commit

Permalink
Simplify blobifocache/internal/test.GenericCache
Browse files Browse the repository at this point in the history
We no longer need a cleanup callback.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Mar 16, 2022
1 parent ef44aae commit aa91955
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/blobinfocache/boltdb/boltdb_test.go
Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions pkg/blobinfocache/internal/test/test.go
Expand Up @@ -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)
Expand All @@ -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)
})
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/blobinfocache/memory/memory_test.go
Expand Up @@ -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) {
Expand Down

0 comments on commit aa91955

Please sign in to comment.