mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 03:31:20 +00:00
2f11e55869
* use t.TempDir() * remove redundant delete * simplify setupDB() * simplify db/testing/setup_db * fix tests
27 lines
674 B
Go
27 lines
674 B
Go
// Package testing defines useful helper functions for unit tests with
|
|
// the slasher database.
|
|
package testing
|
|
|
|
import (
|
|
"testing"
|
|
|
|
slasherDB "github.com/prysmaticlabs/prysm/slasher/db"
|
|
"github.com/prysmaticlabs/prysm/slasher/db/kv"
|
|
)
|
|
|
|
// SetupSlasherDB instantiates and returns a SlasherDB instance.
|
|
func SetupSlasherDB(t testing.TB, spanCacheEnabled bool) *kv.Store {
|
|
cfg := &kv.Config{}
|
|
db, err := slasherDB.NewDB(t.TempDir(), cfg)
|
|
if err != nil {
|
|
t.Fatalf("Failed to instantiate DB: %v", err)
|
|
}
|
|
db.EnableSpanCache(spanCacheEnabled)
|
|
t.Cleanup(func() {
|
|
if err := db.Close(); err != nil {
|
|
t.Fatalf("Failed to close database: %v", err)
|
|
}
|
|
})
|
|
return db
|
|
}
|