cosmos-sdk/server/pruning_test.go

74 lines
1.5 KiB
Go
Raw Normal View History

package server
import (
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
2020-06-22 13:31:33 -07:00
"github.com/cosmos/cosmos-sdk/store/types"
)
func TestGetPruningOptionsFromFlags(t *testing.T) {
tests := []struct {
name string
initParams func() *viper.Viper
2020-06-22 13:31:33 -07:00
expectedOptions types.PruningOptions
wantErr bool
}{
{
2020-06-22 13:31:33 -07:00
name: FlagPruning,
initParams: func() *viper.Viper {
v := viper.New()
v.Set(FlagPruning, types.PruningOptionNothing)
return v
},
2020-06-22 13:31:33 -07:00
expectedOptions: types.PruneNothing,
},
{
2020-06-22 13:31:33 -07:00
name: "custom pruning options",
initParams: func() *viper.Viper {
v := viper.New()
v.Set(FlagPruning, types.PruningOptionCustom)
v.Set(FlagPruningKeepRecent, 1234)
v.Set(FlagPruningKeepEvery, 4321)
v.Set(FlagPruningInterval, 10)
return v
},
2020-06-22 13:31:33 -07:00
expectedOptions: types.PruningOptions{
KeepRecent: 1234,
KeepEvery: 4321,
Interval: 10,
},
},
{
name: types.PruningOptionDefault,
initParams: func() *viper.Viper {
v := viper.New()
v.Set(FlagPruning, types.PruningOptionDefault)
return v
},
2020-06-22 13:31:33 -07:00
expectedOptions: types.PruneDefault,
},
}
for _, tt := range tests {
2020-02-27 08:29:13 -08:00
tt := tt
2020-06-22 13:31:33 -07:00
t.Run(tt.name, func(j *testing.T) {
viper.Reset()
2020-06-22 13:31:33 -07:00
viper.SetDefault(FlagPruning, types.PruningOptionDefault)
v := tt.initParams()
2020-06-22 13:31:33 -07:00
opts, err := GetPruningOptionsFromFlags(v)
if tt.wantErr {
require.Error(t, err)
return
}
2020-06-22 13:31:33 -07:00
require.Equal(t, tt.expectedOptions, opts)
})
}
}