github.com/koko1123/flow-go-1@v0.29.6/storage/badger/epoch_statuses_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/assert" 9 "github.com/stretchr/testify/require" 10 11 "github.com/koko1123/flow-go-1/module/metrics" 12 "github.com/koko1123/flow-go-1/storage" 13 "github.com/koko1123/flow-go-1/utils/unittest" 14 15 badgerstorage "github.com/koko1123/flow-go-1/storage/badger" 16 "github.com/koko1123/flow-go-1/storage/badger/operation" 17 "github.com/koko1123/flow-go-1/storage/badger/transaction" 18 ) 19 20 func TestEpochStatusesStoreAndRetrieve(t *testing.T) { 21 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 22 metrics := metrics.NewNoopCollector() 23 store := badgerstorage.NewEpochStatuses(metrics, db) 24 25 blockID := unittest.IdentifierFixture() 26 expected := unittest.EpochStatusFixture() 27 28 _, err := store.ByBlockID(unittest.IdentifierFixture()) 29 assert.True(t, errors.Is(err, storage.ErrNotFound)) 30 31 // store epoch status 32 err = operation.RetryOnConflictTx(db, transaction.Update, store.StoreTx(blockID, expected)) 33 require.NoError(t, err) 34 35 // retreive status 36 actual, err := store.ByBlockID(blockID) 37 require.NoError(t, err) 38 require.Equal(t, expected, actual) 39 }) 40 }