github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/guarantees_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 TestGuaranteeStoreRetrieve(t *testing.T) { 18 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 19 metrics := metrics.NewNoopCollector() 20 store := badgerstorage.NewGuarantees(metrics, db, 1000) 21 22 // abiturary guarantees 23 expected := unittest.CollectionGuaranteeFixture() 24 25 // retrieve guarantee without stored 26 _, err := store.ByCollectionID(expected.ID()) 27 require.True(t, errors.Is(err, storage.ErrNotFound)) 28 29 // store guarantee 30 err = store.Store(expected) 31 require.NoError(t, err) 32 33 // retreive by coll idx 34 actual, err := store.ByCollectionID(expected.ID()) 35 require.NoError(t, err) 36 require.Equal(t, expected, actual) 37 }) 38 }