prysm-pulse/validator/db/migrate_test.go

57 lines
1.7 KiB
Go
Raw Normal View History

2021-01-18 19:32:17 +00:00
package db
import (
"flag"
"testing"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
dbtest "github.com/prysmaticlabs/prysm/validator/db/testing"
"github.com/urfave/cli/v2"
)
func TestMigrateUp_NoDBFound(t *testing.T) {
2021-01-18 19:32:17 +00:00
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String(cmd.DataDirFlag.Name, "", "")
require.NoError(t, set.Set(cmd.DataDirFlag.Name, ""))
cliCtx := cli.NewContext(&app, set, nil)
err := MigrateUp(cliCtx)
2021-01-18 19:32:17 +00:00
assert.ErrorContains(t, "No validator db found at path", err)
}
func TestMigrateUp_OK(t *testing.T) {
2021-01-18 19:32:17 +00:00
validatorDB := dbtest.SetupDB(t, nil)
dbPath := validatorDB.DatabasePath()
require.NoError(t, validatorDB.Close())
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String(cmd.DataDirFlag.Name, dbPath, "")
require.NoError(t, set.Set(cmd.DataDirFlag.Name, dbPath))
cliCtx := cli.NewContext(&app, set, nil)
assert.NoError(t, MigrateUp(cliCtx))
2021-01-18 19:32:17 +00:00
}
func TestMigrateDown_NoDBFound(t *testing.T) {
2021-01-18 19:32:17 +00:00
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String(cmd.DataDirFlag.Name, "", "")
require.NoError(t, set.Set(cmd.DataDirFlag.Name, ""))
cliCtx := cli.NewContext(&app, set, nil)
err := MigrateDown(cliCtx)
2021-01-18 19:32:17 +00:00
assert.ErrorContains(t, "No validator db found at path", err)
}
func TestMigrateDown_OK(t *testing.T) {
2021-01-18 19:32:17 +00:00
validatorDB := dbtest.SetupDB(t, nil)
dbPath := validatorDB.DatabasePath()
require.NoError(t, validatorDB.Close())
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String(cmd.DataDirFlag.Name, dbPath, "")
require.NoError(t, set.Set(cmd.DataDirFlag.Name, dbPath))
cliCtx := cli.NewContext(&app, set, nil)
assert.NoError(t, MigrateDown(cliCtx))
2021-01-18 19:32:17 +00:00
}