cosmos-sdk/server/start_test.go

105 lines
2.2 KiB
Go
Raw Normal View History

package server
import (
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)
func TestPruningOptions(t *testing.T) {
startCommand := StartCmd(nil, nil)
tests := []struct {
name string
paramInit func()
returnsErr bool
expectedErr error
}{
2020-02-27 03:18:21 -08:00
{
2020-02-27 06:56:07 -08:00
name: "none set, returns nil and will use default from flags",
2020-02-27 03:18:21 -08:00
paramInit: func() {},
2020-02-27 06:56:07 -08:00
returnsErr: false,
expectedErr: nil,
2020-02-27 03:18:21 -08:00
},
{
name: "only keep-every provided",
paramInit: func() {
viper.Set(flagPruningKeepEvery, 12345)
},
returnsErr: true,
expectedErr: errPruningGranularOptions,
},
{
name: "only snapshot-every provided",
paramInit: func() {
viper.Set(flagPruningSnapshotEvery, 12345)
},
returnsErr: true,
expectedErr: errPruningGranularOptions,
},
{
name: "pruning flag with other granular options 1",
paramInit: func() {
viper.Set(flagPruning, "set")
viper.Set(flagPruningSnapshotEvery, 1234)
},
returnsErr: true,
expectedErr: errPruningWithGranularOptions,
},
{
name: "pruning flag with other granular options 2",
paramInit: func() {
viper.Set(flagPruning, "set")
viper.Set(flagPruningKeepEvery, 1234)
},
returnsErr: true,
expectedErr: errPruningWithGranularOptions,
},
{
name: "pruning flag with other granular options 3",
paramInit: func() {
viper.Set(flagPruning, "set")
viper.Set(flagPruningKeepEvery, 1234)
viper.Set(flagPruningSnapshotEvery, 1234)
},
returnsErr: true,
expectedErr: errPruningWithGranularOptions,
},
{
name: "only prunning set",
paramInit: func() {
viper.Set(flagPruning, "set")
},
returnsErr: false,
expectedErr: nil,
},
{
name: "only granular set",
paramInit: func() {
viper.Set(flagPruningSnapshotEvery, 12345)
viper.Set(flagPruningKeepEvery, 12345)
},
returnsErr: false,
expectedErr: nil,
},
}
for _, tt := range tests {
2020-02-27 08:29:13 -08:00
tt := tt
2020-02-27 08:29:13 -08:00
t.Run(tt.name, func(t *testing.T) {
2020-02-27 07:33:30 -08:00
viper.Reset()
tt.paramInit()
2020-02-27 07:33:30 -08:00
err := startCommand.PreRunE(nil, nil)
if tt.returnsErr {
require.EqualError(t, err, tt.expectedErr.Error())
} else {
require.NoError(t, err)
}
})
}
}