prysm-pulse/validator/db/testing/setup_db_test.go
Victor Farazdagi 0006377aec
Applies assertion funcs to validator tests (#6694)
* Applies assertion funcs to validator/keymanager/v1 tests
* gazelle
* Applies assertion funcs to validator/keymanager/v2 tests
* Applies assertion funcs to validator/misc tests
* Applies assertion funcs to validator/misc tests
* Merge branch 'master' into validator-apply-testutils-assertions
* gazelle
* Merge branch 'master' into validator-apply-testutils-assertions
* Merge branch 'master' into validator-apply-testutils-assertions
* Merge refs/heads/master into validator-apply-testutils-assertions
2020-07-23 01:13:52 +00:00

29 lines
871 B
Go

package testing
import (
"crypto/rand"
"fmt"
"math/big"
"os"
"path/filepath"
"testing"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/validator/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))
require.NoError(t, err, "Could not generate random file path")
p := filepath.Join(TempDir(), fmt.Sprintf("/%d", randPath))
require.NoError(t, os.RemoveAll(p), "Failed to remove directory")
testDB, err := kv.NewKVStore(p, [][48]byte{})
require.NoError(t, err, "Failed to instantiate DB")
require.NoError(t, testDB.ClearDB())
if _, err := os.Stat(filepath.Join(testDB.DatabasePath(), "validator.db")); !os.IsNotExist(err) {
t.Fatalf("DB was not cleared: %v", err)
}
}