github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/pebble/open_test.go (about) 1 package pebble 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 "github.com/onflow/flow-go/storage" 10 "github.com/onflow/flow-go/utils/unittest" 11 ) 12 13 func TestIsBootstrapped(t *testing.T) { 14 t.Parallel() 15 unittest.RunWithTempDir(t, func(dir string) { 16 db, err := OpenRegisterPebbleDB(dir) 17 require.NoError(t, err) 18 bootstrapped, err := IsBootstrapped(db) 19 require.NoError(t, err) 20 require.False(t, bootstrapped) 21 require.NoError(t, db.Close()) 22 }) 23 } 24 25 func TestReadHeightsFromBootstrappedDB(t *testing.T) { 26 t.Parallel() 27 unittest.RunWithTempDir(t, func(dir string) { 28 db, err := OpenRegisterPebbleDB(dir) 29 require.NoError(t, err) 30 31 // init with first height 32 firstHeight := uint64(10) 33 require.NoError(t, initHeights(db, firstHeight)) 34 35 bootstrapped, err := IsBootstrapped(db) 36 require.NoError(t, err) 37 38 require.True(t, bootstrapped) 39 require.NoError(t, db.Close()) 40 41 // reopen the db 42 registers, db, err := NewBootstrappedRegistersWithPath(dir) 43 require.NoError(t, err) 44 45 require.Equal(t, firstHeight, registers.FirstHeight()) 46 require.Equal(t, firstHeight, registers.LatestHeight()) 47 48 require.NoError(t, db.Close()) 49 }) 50 } 51 52 func TestNewBootstrappedRegistersWithPath(t *testing.T) { 53 t.Parallel() 54 unittest.RunWithTempDir(t, func(dir string) { 55 _, db, err := NewBootstrappedRegistersWithPath(dir) 56 require.Error(t, err) 57 require.True(t, errors.Is(err, storage.ErrNotBootstrapped)) 58 59 // verify the db is closed 60 require.True(t, db == nil) 61 62 // bootstrap the db 63 // init with first height 64 db2, err := OpenRegisterPebbleDB(dir) 65 require.NoError(t, err) 66 firstHeight := uint64(10) 67 require.NoError(t, initHeights(db2, firstHeight)) 68 69 registers, err := NewRegisters(db2) 70 require.NoError(t, err) 71 require.Equal(t, firstHeight, registers.FirstHeight()) 72 require.Equal(t, firstHeight, registers.LatestHeight()) 73 74 require.NoError(t, db2.Close()) 75 }) 76 }