diff --git a/internal/parse/parse.go b/internal/parse/parse.go index c6fbc049..7b0d4844 100644 --- a/internal/parse/parse.go +++ b/internal/parse/parse.go @@ -5,6 +5,11 @@ import ( "strconv" ) +const ( + InvalidType = "invalid type" + Negative = "negative value" +) + func Int(input interface{}) (int, error) { switch input := input.(type) { case float64: @@ -16,7 +21,7 @@ func Int(input interface{}) (int, error) { } return int(mem), nil } - return 0, nil + return 0, errors.New(InvalidType) } func Uint(input interface{}) (uint, error) { @@ -25,7 +30,7 @@ func Uint(input interface{}) (uint, error) { return 0, err } if tmpInt < 0 { - return 0, errors.New("negative value") + return 0, errors.New(Negative) } return uint(tmpInt), nil } diff --git a/internal/parse/parse_test.go b/internal/parse/parse_test.go index f4b341b8..cbf0a1d7 100644 --- a/internal/parse/parse_test.go +++ b/internal/parse/parse_test.go @@ -28,6 +28,9 @@ func Test_Int(t *testing.T) { {name: `string positive`, input: "1", output: 1}, + {name: `invalid type`, + input: interface{}(nil), + err: true}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { @@ -64,6 +67,9 @@ func Test_Uint(t *testing.T) { {name: `string positive`, input: "1", output: 1}, + {name: `invalid type`, + input: interface{}(nil), + err: true}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) {