github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/pebble/testutil.go (about) 1 package pebble 2 3 import ( 4 "testing" 5 6 "github.com/cockroachdb/pebble" 7 "github.com/stretchr/testify/require" 8 9 "github.com/onflow/flow-go/utils/unittest" 10 ) 11 12 func RunWithRegistersStorageAtInitialHeights(tb testing.TB, first uint64, latest uint64, f func(r *Registers)) { 13 unittest.RunWithTempDir(tb, func(dir string) { 14 db := NewBootstrappedRegistersWithPathForTest(tb, dir, first, latest) 15 r, err := NewRegisters(db) 16 require.NoError(tb, err) 17 18 f(r) 19 20 require.NoError(tb, db.Close()) 21 }) 22 } 23 24 func NewBootstrappedRegistersWithPathForTest(tb testing.TB, dir string, first, latest uint64) *pebble.DB { 25 db, err := OpenRegisterPebbleDB(dir) 26 require.NoError(tb, err) 27 28 // insert initial heights to pebble 29 require.NoError(tb, db.Set(firstHeightKey, encodedUint64(first), nil)) 30 require.NoError(tb, db.Set(latestHeightKey, encodedUint64(latest), nil)) 31 return db 32 }