github.com/koko1123/flow-go-1@v0.29.6/storage/badger/epoch_setups_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 // TestEpochSetupStoreAndRetrieve tests that a setup can be stored, retrieved and attempted to be stored again without an error 21 func TestEpochSetupStoreAndRetrieve(t *testing.T) { 22 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 23 metrics := metrics.NewNoopCollector() 24 store := badgerstorage.NewEpochSetups(metrics, db) 25 26 // attempt to get a setup that doesn't exist 27 _, err := store.ByID(unittest.IdentifierFixture()) 28 assert.True(t, errors.Is(err, storage.ErrNotFound)) 29 30 // store a setup in db 31 expected := unittest.EpochSetupFixture() 32 err = operation.RetryOnConflictTx(db, transaction.Update, store.StoreTx(expected)) 33 require.NoError(t, err) 34 35 // retrieve the setup by ID 36 actual, err := store.ByID(expected.ID()) 37 require.NoError(t, err) 38 assert.Equal(t, expected, actual) 39 40 // test storing same epoch setup 41 err = operation.RetryOnConflictTx(db, transaction.Update, store.StoreTx(expected)) 42 require.NoError(t, err) 43 }) 44 }