2020-02-13 16:19:46 +00:00
|
|
|
package testing
|
2019-09-26 16:29:10 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2020-12-03 22:28:57 +00:00
|
|
|
"path/filepath"
|
2019-09-26 16:29:10 +00:00
|
|
|
"testing"
|
2020-05-04 01:14:34 +00:00
|
|
|
|
2020-08-18 12:41:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-05-04 01:14:34 +00:00
|
|
|
slasherDB "github.com/prysmaticlabs/prysm/slasher/db"
|
|
|
|
"github.com/prysmaticlabs/prysm/slasher/db/kv"
|
2019-09-26 16:29:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestClearDB(t *testing.T) {
|
2020-05-04 01:14:34 +00:00
|
|
|
// Setting up manually is required, since SetupDB() will also register a teardown procedure.
|
|
|
|
cfg := &kv.Config{}
|
2020-11-10 22:45:17 +00:00
|
|
|
db, err := slasherDB.NewDB(t.TempDir(), cfg)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err, "Failed to instantiate DB")
|
2020-05-29 12:09:04 +00:00
|
|
|
db.EnableSpanCache(false)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, db.ClearDB())
|
2020-12-03 22:28:57 +00:00
|
|
|
_, err = os.Stat(filepath.Join(db.DatabasePath(), "slasher.db"))
|
2020-08-18 12:41:25 +00:00
|
|
|
require.Equal(t, true, os.IsNotExist(err), "Db wasnt cleared %v", err)
|
2019-09-26 16:29:10 +00:00
|
|
|
}
|