2020-06-27 02:37:43 +00:00
|
|
|
package testing
|
2020-01-08 18:16:17 +00:00
|
|
|
|
|
|
|
import (
|
2020-05-04 01:14:34 +00:00
|
|
|
"crypto/rand"
|
|
|
|
"fmt"
|
|
|
|
"math/big"
|
2020-01-08 18:16:17 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
2020-06-27 02:37:43 +00:00
|
|
|
|
2020-07-23 01:13:52 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-06-27 02:37:43 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/db/kv"
|
2020-01-08 18:16:17 +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.
|
|
|
|
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
2020-07-23 01:13:52 +00:00
|
|
|
require.NoError(t, err, "Could not generate random file path")
|
2020-05-04 01:14:34 +00:00
|
|
|
p := filepath.Join(TempDir(), fmt.Sprintf("/%d", randPath))
|
2020-07-23 01:13:52 +00:00
|
|
|
require.NoError(t, os.RemoveAll(p), "Failed to remove directory")
|
2020-06-27 02:37:43 +00:00
|
|
|
testDB, err := kv.NewKVStore(p, [][48]byte{})
|
2020-07-23 01:13:52 +00:00
|
|
|
require.NoError(t, err, "Failed to instantiate DB")
|
|
|
|
require.NoError(t, testDB.ClearDB())
|
2020-01-08 18:16:17 +00:00
|
|
|
|
2020-06-27 02:37:43 +00:00
|
|
|
if _, err := os.Stat(filepath.Join(testDB.DatabasePath(), "validator.db")); !os.IsNotExist(err) {
|
2020-01-08 18:16:17 +00:00
|
|
|
t.Fatalf("DB was not cleared: %v", err)
|
|
|
|
}
|
|
|
|
}
|