github.com/cosmos/cosmos-sdk@v0.50.10/client/flags/flags_test.go (about)

     1  package flags_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  
     8  	"github.com/cosmos/cosmos-sdk/client/flags"
     9  )
    10  
    11  func TestParseGasSetting(t *testing.T) {
    12  	testCases := []struct {
    13  		name      string
    14  		input     string
    15  		expected  flags.GasSetting
    16  		expectErr bool
    17  	}{
    18  		{"empty input", "", flags.GasSetting{false, flags.DefaultGasLimit}, false},
    19  		{"auto", flags.GasFlagAuto, flags.GasSetting{true, 0}, false},
    20  		{"valid custom gas", "73800", flags.GasSetting{false, 73800}, false},
    21  		{"invalid custom gas", "-73800", flags.GasSetting{false, 0}, true},
    22  	}
    23  
    24  	for _, tc := range testCases {
    25  		tc := tc
    26  
    27  		t.Run(tc.name, func(t *testing.T) {
    28  			gs, err := flags.ParseGasSetting(tc.input)
    29  
    30  			if tc.expectErr {
    31  				require.Error(t, err)
    32  			} else {
    33  				require.NoError(t, err)
    34  				require.Equal(t, tc.expected, gs)
    35  			}
    36  		})
    37  	}
    38  }