github.com/koko1123/flow-go-1@v0.29.6/storage/badger/index_test.go (about)

     1  package badger_test
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/dgraph-io/badger/v3"
     8  	"github.com/stretchr/testify/require"
     9  
    10  	"github.com/koko1123/flow-go-1/module/metrics"
    11  	"github.com/koko1123/flow-go-1/storage"
    12  	"github.com/koko1123/flow-go-1/utils/unittest"
    13  
    14  	badgerstorage "github.com/koko1123/flow-go-1/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  }