add function to get pruning options from flags
This commit is contained in:
parent
a6cd6554ec
commit
cfb3819183
|
@ -0,0 +1,21 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func GetPruningOptionsFromFlags() store.PruningOptions {
|
||||
if viper.IsSet(flagPruning) {
|
||||
return store.NewPruningOptionsFromString(viper.GetString(flagPruning))
|
||||
}
|
||||
|
||||
if viper.IsSet(flagPruningKeepEvery) && viper.IsSet(flagPruningSnapshotEvery) {
|
||||
return store.PruningOptions{
|
||||
KeepEvery: viper.GetInt64(flagPruningKeepEvery),
|
||||
SnapshotEvery: viper.GetInt64(flagPruningSnapshotEvery),
|
||||
}
|
||||
}
|
||||
|
||||
return store.PruneSyncable
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
)
|
||||
|
||||
func TestGetPruningOptionsFromFlags(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
initParams func()
|
||||
expectedOptions store.PruningOptions
|
||||
}{
|
||||
{
|
||||
name: "pruning",
|
||||
initParams: func() {
|
||||
viper.Set(flagPruning, store.PruningStrategyNothing)
|
||||
},
|
||||
expectedOptions: store.PruneNothing,
|
||||
},
|
||||
{
|
||||
name: "granular pruning",
|
||||
initParams: func() {
|
||||
viper.Set(flagPruningSnapshotEvery, 1234)
|
||||
viper.Set(flagPruningKeepEvery, 4321)
|
||||
},
|
||||
expectedOptions: store.PruningOptions{
|
||||
SnapshotEvery: 1234,
|
||||
KeepEvery: 4321,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "default",
|
||||
initParams: func() {},
|
||||
expectedOptions: store.PruneSyncable,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(j *testing.T) {
|
||||
viper.Reset()
|
||||
tt.initParams()
|
||||
require.Equal(t, tt.expectedOptions, GetPruningOptionsFromFlags())
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue