mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
f46ee335bd
* 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
38 lines
878 B
Go
38 lines
878 B
Go
package db
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"math/big"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
)
|
|
|
|
// setupDB instantiates and returns a BeaconDB instance.
|
|
func setupDB(t *testing.T) *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 := NewDB(path)
|
|
if err != nil {
|
|
t.Fatalf("Failed to instantiate DB: %v", err)
|
|
}
|
|
return db
|
|
}
|
|
|
|
// teardownDB cleans up a test BeaconDB instance.
|
|
func teardownDB(t *testing.T, 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("Failed to remove directory: %v", err)
|
|
}
|
|
}
|