prysm-pulse/beacon-chain/db/kv/kv_test.go
Victor Farazdagi fecbec2342
Applies assertion funcs to beacon-chain/db tests (#6938)
* 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
2020-08-08 18:39:01 +00:00

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
}