prysm-pulse/beacon-chain/internal/db_test_util.go
Nishant Das f46ee335bd
Allow Sync Service to Query State Of Network (#787)
* adding proto messages

* adding fields

* adding new service

* new changes

* checking in file from syncFix

* fixing test

* add test

* adding to node

* goimports

* adding query service to sync services

* sync working

* finally works

* fix test

* lint

* fix build

* fix test
2018-11-19 09:59:11 +08:00

40 lines
934 B
Go

package internal
import (
"crypto/rand"
"fmt"
"math/big"
"os"
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
)
// SetupDB instantiates and returns a BeaconDB instance.
func SetupDB(t *testing.T) *db.BeaconDB {
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
if err != nil {
t.Fatalf("Could not generate random file path: %v", err)
}
path := path.Join(os.TempDir(), fmt.Sprintf("/%d", randPath))
if err := os.RemoveAll(path); err != nil {
t.Fatalf("Failed to remove directory: %v", err)
}
db, err := db.NewDB(path)
if err != nil {
t.Fatalf("Could not setup DB: %v", err)
}
return db
}
// TeardownDB cleans up a BeaconDB instance.
func TeardownDB(t *testing.T, db *db.BeaconDB) {
if err := db.Close(); err != nil {
t.Fatalf("Failed to close database: %v", err)
}
if err := os.RemoveAll(db.DatabasePath); err != nil {
t.Fatalf("Could not remove tmp db dir: %v", err)
}
}