github.com/koko1123/flow-go-1@v0.29.6/storage/badger/epoch_commits_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 ) 17 18 // TestEpochCommitStoreAndRetrieve tests that a commit can be stored, retrieved and attempted to be stored again without an error 19 func TestEpochCommitStoreAndRetrieve(t *testing.T) { 20 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 21 metrics := metrics.NewNoopCollector() 22 store := badgerstorage.NewEpochCommits(metrics, db) 23 24 // attempt to get a invalid commit 25 _, err := store.ByID(unittest.IdentifierFixture()) 26 assert.True(t, errors.Is(err, storage.ErrNotFound)) 27 28 // store a commit in db 29 expected := unittest.EpochCommitFixture() 30 err = store.Store(expected) 31 require.NoError(t, err) 32 33 // retrieve the commit by ID 34 actual, err := store.ByID(expected.ID()) 35 require.NoError(t, err) 36 assert.Equal(t, expected, actual) 37 38 // test storing same epoch commit 39 err = store.Store(expected) 40 require.NoError(t, err) 41 }) 42 }