github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/server/pruning_test.go (about)

     1  package server
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/spf13/viper"
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/types"
    10  )
    11  
    12  func TestGetPruningOptionsFromFlags(t *testing.T) {
    13  	tests := []struct {
    14  		name            string
    15  		initParams      func()
    16  		expectedOptions types.PruningOptions
    17  		wantErr         bool
    18  	}{
    19  		{
    20  			name: FlagPruning,
    21  			initParams: func() {
    22  				viper.Set(FlagPruning, types.PruningOptionNothing)
    23  			},
    24  			expectedOptions: types.PruneNothing,
    25  		},
    26  		{
    27  			name: "custom pruning options",
    28  			initParams: func() {
    29  				viper.Set(FlagPruning, types.PruningOptionCustom)
    30  				viper.Set(FlagPruningKeepRecent, 1234)
    31  				viper.Set(FlagPruningKeepEvery, 4321)
    32  				viper.Set(FlagPruningInterval, 10)
    33  			},
    34  			expectedOptions: types.PruningOptions{
    35  				KeepRecent: 1234,
    36  				KeepEvery:  4321,
    37  				Interval:   10,
    38  			},
    39  		},
    40  		{
    41  			name:            types.PruningOptionDefault,
    42  			initParams:      func() {},
    43  			expectedOptions: types.PruneDefault,
    44  		},
    45  	}
    46  
    47  	for _, tt := range tests {
    48  		tt := tt
    49  
    50  		t.Run(tt.name, func(j *testing.T) {
    51  			viper.Reset()
    52  			viper.SetDefault(FlagPruning, types.PruningOptionDefault)
    53  			tt.initParams()
    54  
    55  			opts, err := GetPruningOptionsFromFlags()
    56  			if tt.wantErr {
    57  				require.Error(t, err)
    58  				return
    59  			}
    60  
    61  			require.Equal(t, tt.expectedOptions, opts)
    62  		})
    63  	}
    64  }