Skip to content

Commit

Permalink
Remove redundant paren, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
cfilby committed Oct 16, 2019
1 parent 395fc85 commit c3930f5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion graphql/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func UnmarshalID(v interface{}) (string, error) {
case int:
return strconv.Itoa(v), nil
case int64:
return strconv.Itoa((int(v))), nil
return strconv.Itoa(int(v)), nil
case float64:
return fmt.Sprintf("%f", v), nil
case bool:
Expand Down
35 changes: 35 additions & 0 deletions graphql/id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package graphql

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestMarshalID(t *testing.T) {
tests := []struct {
Name string
Input interface{}
Expected string
ShouldError bool
}{
{
Name: "int64",
Input: int64(12),
Expected: "12",
ShouldError: false,
},
}

for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
id, err := UnmarshalID(tt.Input)

assert.Equal(t, tt.Expected, id)
if tt.ShouldError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}

0 comments on commit c3930f5

Please sign in to comment.