2020-02-27 03:01:27 -08:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2020-04-14 08:24:27 -07:00
|
|
|
"fmt"
|
2020-02-27 03:01:27 -08:00
|
|
|
"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
|
|
|
{
|
2020-04-14 08:24:27 -07: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
|
|
|
},
|
2020-04-14 08:24:27 -07:00
|
|
|
{
|
|
|
|
name: "unknown strategy",
|
|
|
|
paramInit: func() { viper.Set(flagPruning, "unknown") },
|
|
|
|
returnsErr: true,
|
|
|
|
expectedErr: fmt.Errorf("unknown pruning strategy unknown"),
|
|
|
|
},
|
2020-02-27 03:01:27 -08:00
|
|
|
{
|
|
|
|
name: "only keep-every provided",
|
|
|
|
paramInit: func() {
|
2020-04-14 08:24:27 -07:00
|
|
|
viper.Set(flagPruning, "custom")
|
2020-02-27 03:01:27 -08:00
|
|
|
viper.Set(flagPruningKeepEvery, 12345)
|
|
|
|
},
|
2020-04-14 08:24:27 -07:00
|
|
|
returnsErr: false,
|
|
|
|
expectedErr: nil,
|
2020-02-27 03:01:27 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "only snapshot-every provided",
|
|
|
|
paramInit: func() {
|
2020-04-14 08:24:27 -07:00
|
|
|
viper.Set(flagPruning, "custom")
|
2020-02-27 03:01:27 -08:00
|
|
|
viper.Set(flagPruningSnapshotEvery, 12345)
|
|
|
|
},
|
|
|
|
returnsErr: true,
|
2020-04-14 08:24:27 -07:00
|
|
|
expectedErr: fmt.Errorf("invalid granular options"),
|
2020-02-27 03:01:27 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "pruning flag with other granular options 3",
|
|
|
|
paramInit: func() {
|
2020-04-14 08:24:27 -07:00
|
|
|
viper.Set(flagPruning, "custom")
|
2020-02-27 03:01:27 -08:00
|
|
|
viper.Set(flagPruningKeepEvery, 1234)
|
|
|
|
viper.Set(flagPruningSnapshotEvery, 1234)
|
|
|
|
},
|
|
|
|
returnsErr: false,
|
|
|
|
expectedErr: nil,
|
|
|
|
},
|
|
|
|
{
|
2020-04-14 08:24:27 -07:00
|
|
|
name: "nothing strategy",
|
2020-02-27 03:01:27 -08:00
|
|
|
paramInit: func() {
|
2020-04-14 08:24:27 -07:00
|
|
|
viper.Set(flagPruning, "nothing")
|
2020-02-27 03:01:27 -08:00
|
|
|
},
|
|
|
|
returnsErr: false,
|
|
|
|
expectedErr: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
2020-02-27 08:29:13 -08:00
|
|
|
tt := tt
|
2020-02-27 03:01:27 -08:00
|
|
|
|
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()
|
2020-04-14 08:24:27 -07:00
|
|
|
viper.SetDefault(flagPruning, "syncable")
|
|
|
|
startCommand := StartCmd(nil, nil)
|
2020-02-27 07:33:30 -08:00
|
|
|
tt.paramInit()
|
2020-04-14 08:24:27 -07:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
2020-02-27 03:01:27 -08:00
|
|
|
}
|
|
|
|
}
|