mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
0006377aec
* 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
38 lines
976 B
Go
38 lines
976 B
Go
package kv
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/rand"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
// setupDB instantiates and returns a DB instance for the validator client.
|
|
func setupDB(t testing.TB, pubkeys [][48]byte) *Store {
|
|
randPath := rand.NewDeterministicGenerator().Int()
|
|
p := filepath.Join(tempdir(), fmt.Sprintf("/%d", randPath))
|
|
require.NoError(t, os.RemoveAll(p), "Failed to remove directory")
|
|
db, err := NewKVStore(p, pubkeys)
|
|
require.NoError(t, err, "Failed to instantiate DB")
|
|
|
|
t.Cleanup(func() {
|
|
require.NoError(t, db.Close(), "Failed to close database")
|
|
require.NoError(t, db.ClearDB(), "Failed to clear database")
|
|
})
|
|
return db
|
|
}
|
|
|
|
// tempdir returns a directory path for temporary test storage.
|
|
func tempdir() string {
|
|
d := os.Getenv("TEST_TMPDIR")
|
|
|
|
// If the test is not run via bazel, the environment var won't be set.
|
|
if d == "" {
|
|
return os.TempDir()
|
|
}
|
|
return d
|
|
}
|