mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
fecbec2342
* part1 * go tidy * Merge branch 'go-tidy' into apply-testutils-assertions-to-beaconchain-db * updated beacon-chain/db/kv tests * Merge branch 'master' into apply-testutils-assertions-to-beaconchain-db * Merge refs/heads/master into apply-testutils-assertions-to-beaconchain-db * Merge refs/heads/master into apply-testutils-assertions-to-beaconchain-db
30 lines
884 B
Go
30 lines
884 B
Go
package kv
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"math/big"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
// setupDB instantiates and returns a Store instance.
|
|
func setupDB(t testing.TB) *Store {
|
|
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
|
require.NoError(t, err, "Could not generate random file path")
|
|
p := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
|
|
require.NoError(t, os.RemoveAll(p), "Failed to remove directory")
|
|
db, err := NewKVStore(p, cache.NewStateSummaryCache())
|
|
require.NoError(t, err, "Failed to instantiate DB")
|
|
t.Cleanup(func() {
|
|
require.NoError(t, db.Close(), "Failed to close database")
|
|
require.NoError(t, os.RemoveAll(db.DatabasePath()), "Failed to remove directory")
|
|
})
|
|
return db
|
|
}
|