cosmos-sdk/server/start_test.go

86 lines
1.8 KiB
Go
Raw Normal View History

package server
import (
"fmt"
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)
func TestPruningOptions(t *testing.T) {
tests := []struct {
name string
paramInit func()
returnsErr bool
expectedErr error
}{
2020-02-27 03:18:21 -08:00
{
name: "default",
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: "unknown strategy",
paramInit: func() { viper.Set(flagPruning, "unknown") },
returnsErr: true,
expectedErr: fmt.Errorf("unknown pruning strategy unknown"),
},
{
name: "only keep-every provided",
paramInit: func() {
viper.Set(flagPruning, "custom")
viper.Set(flagPruningKeepEvery, 12345)
},
returnsErr: false,
expectedErr: nil,
},
{
name: "only snapshot-every provided",
paramInit: func() {
viper.Set(flagPruning, "custom")
viper.Set(flagPruningSnapshotEvery, 12345)
},
returnsErr: true,
expectedErr: fmt.Errorf("invalid granular options"),
},
{
name: "pruning flag with other granular options 3",
paramInit: func() {
viper.Set(flagPruning, "custom")
viper.Set(flagPruningKeepEvery, 1234)
viper.Set(flagPruningSnapshotEvery, 1234)
},
returnsErr: false,
expectedErr: nil,
},
{
name: "nothing strategy",
paramInit: func() {
viper.Set(flagPruning, "nothing")
},
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()
viper.SetDefault(flagPruning, "syncable")
startCommand := StartCmd(nil, nil)
2020-02-27 07:33:30 -08:00
tt.paramInit()
err := startCommand.PreRunE(startCommand, nil)
2020-02-27 07:33:30 -08:00
if tt.returnsErr {
require.EqualError(t, err, tt.expectedErr.Error())
} else {
require.NoError(t, err)
}
})
}
}