github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/index_test.go (about) 1 package badger_test 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/dgraph-io/badger/v2" 8 "github.com/stretchr/testify/require" 9 10 "github.com/onflow/flow-go/module/metrics" 11 "github.com/onflow/flow-go/storage" 12 "github.com/onflow/flow-go/utils/unittest" 13 14 badgerstorage "github.com/onflow/flow-go/storage/badger" 15 ) 16 17 func TestIndexStoreRetrieve(t *testing.T) { 18 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 19 metrics := metrics.NewNoopCollector() 20 store := badgerstorage.NewIndex(metrics, db) 21 22 blockID := unittest.IdentifierFixture() 23 expected := unittest.IndexFixture() 24 25 // retreive without store 26 _, err := store.ByBlockID(blockID) 27 require.True(t, errors.Is(err, storage.ErrNotFound)) 28 29 // store index 30 err = store.Store(blockID, expected) 31 require.NoError(t, err) 32 33 // retreive index 34 actual, err := store.ByBlockID(blockID) 35 require.NoError(t, err) 36 require.Equal(t, expected, actual) 37 }) 38 }