mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 00:44:27 +00:00
0eaf0cf27b
* handles possible nil values
40 lines
986 B
Go
40 lines
986 B
Go
package testing
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"math/big"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
slasherDB "github.com/prysmaticlabs/prysm/slasher/db"
|
|
"github.com/prysmaticlabs/prysm/slasher/db/kv"
|
|
)
|
|
|
|
func TestClearDB(t *testing.T) {
|
|
// Setting up manually is required, since SetupDB() will also register a teardown procedure.
|
|
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
|
if err != nil {
|
|
t.Fatalf("Could not generate random file path: %v", err)
|
|
}
|
|
p := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
|
|
if err := os.RemoveAll(p); err != nil {
|
|
t.Fatalf("Failed to remove directory: %v", err)
|
|
}
|
|
cfg := &kv.Config{}
|
|
db, err := slasherDB.NewDB(p, cfg)
|
|
if err != nil {
|
|
t.Fatalf("Failed to instantiate DB: %v", err)
|
|
}
|
|
db.EnableSpanCache(false)
|
|
if err := db.ClearDB(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if _, err := os.Stat(db.DatabasePath()); !os.IsNotExist(err) {
|
|
t.Fatalf("db wasnt cleared %v", err)
|
|
}
|
|
}
|