Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve test coverage #353

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions internal/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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) {
Expand All @@ -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
}
6 changes: 6 additions & 0 deletions internal/parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading