github.com/koko1123/flow-go-1@v0.29.6/storage/util/testing.go (about) 1 package util 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "github.com/dgraph-io/badger/v3" 9 "github.com/stretchr/testify/require" 10 11 "github.com/koko1123/flow-go-1/module/metrics" 12 storage "github.com/koko1123/flow-go-1/storage/badger" 13 "github.com/koko1123/flow-go-1/utils/unittest" 14 ) 15 16 func StorageLayer(t testing.TB, db *badger.DB) (*storage.Headers, *storage.Guarantees, *storage.Seals, *storage.Index, *storage.Payloads, *storage.Blocks, *storage.EpochSetups, *storage.EpochCommits, *storage.EpochStatuses, *storage.ExecutionResults) { 17 metrics := metrics.NewNoopCollector() 18 headers := storage.NewHeaders(metrics, db) 19 guarantees := storage.NewGuarantees(metrics, db, storage.DefaultCacheSize) 20 seals := storage.NewSeals(metrics, db) 21 results := storage.NewExecutionResults(metrics, db) 22 receipts := storage.NewExecutionReceipts(metrics, db, results, storage.DefaultCacheSize) 23 index := storage.NewIndex(metrics, db) 24 payloads := storage.NewPayloads(db, index, guarantees, seals, receipts, results) 25 blocks := storage.NewBlocks(db, headers, payloads) 26 setups := storage.NewEpochSetups(metrics, db) 27 commits := storage.NewEpochCommits(metrics, db) 28 statuses := storage.NewEpochStatuses(metrics, db) 29 return headers, guarantees, seals, index, payloads, blocks, setups, commits, statuses, results 30 } 31 32 func RunWithStorageLayer(t testing.TB, f func(*badger.DB, *storage.Headers, *storage.Guarantees, *storage.Seals, *storage.Index, *storage.Payloads, *storage.Blocks, *storage.EpochSetups, *storage.EpochCommits, *storage.EpochStatuses)) { 33 unittest.RunWithBadgerDB(t, func(db *badger.DB) { 34 headers, guarantees, seals, index, payloads, blocks, setups, commits, statuses, _ := StorageLayer(t, db) 35 f(db, headers, guarantees, seals, index, payloads, blocks, setups, commits, statuses) 36 }) 37 } 38 39 func CreateFiles(t *testing.T, dir string, names ...string) { 40 for _, name := range names { 41 _, err := os.Create(filepath.Join(dir, name)) 42 require.NoError(t, err) 43 //err = file. 44 //require.NoError(t, err) 45 } 46 }