github.com/Finschia/finschia-sdk@v0.48.1/client/flags/flags_test.go (about) 1 package flags_test 2 3 import ( 4 "testing" 5 6 "github.com/spf13/cobra" 7 "github.com/stretchr/testify/require" 8 9 "github.com/Finschia/finschia-sdk/client/flags" 10 ) 11 12 func TestParseGasSetting(t *testing.T) { 13 testCases := []struct { 14 name string 15 input string 16 expected flags.GasSetting 17 expectErr bool 18 }{ 19 {"empty input", "", flags.GasSetting{false, flags.DefaultGasLimit}, false}, 20 {"auto", flags.GasFlagAuto, flags.GasSetting{true, 0}, false}, 21 {"valid custom gas", "73800", flags.GasSetting{false, 73800}, false}, 22 {"invalid custom gas", "-73800", flags.GasSetting{false, 0}, true}, 23 } 24 25 for _, tc := range testCases { 26 tc := tc 27 28 t.Run(tc.name, func(t *testing.T) { 29 gs, err := flags.ParseGasSetting(tc.input) 30 31 if tc.expectErr { 32 require.Error(t, err) 33 } else { 34 require.NoError(t, err) 35 require.Equal(t, tc.expected, gs) 36 } 37 }) 38 } 39 } 40 41 func TestAddFlagsToCmd(t *testing.T) { 42 cmd := cobra.Command{} 43 flags.AddQueryFlagsToCmd(&cmd) 44 45 cmd = cobra.Command{} 46 flags.AddTxFlagsToCmd(&cmd) 47 48 cmd = cobra.Command{} 49 flags.AddPaginationFlagsToCmd(&cmd, "") 50 }