-
Notifications
You must be signed in to change notification settings - Fork 2
Support for uint #1
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
base: main
Are you sure you want to change the base?
Conversation
ccoVeille
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
It's a legitimate use case.
One minor remark anyway.
| Jane,2023-06-15T09:30:00Z,false,75.2,100,2.718,prod;live` | ||
| csvData := `name,created_at,active,score,count,rate,tags,rank | ||
| John,2023-01-02T15:04:05Z,true,98.6,42,3.14,test;debug,1 | ||
| Jane,2023-06-15T09:30:00Z,false,75.2,100,2.718,prod;live,42` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test about sending a negative number via a CSV into a uint field ?
I feel like it could be useful to validate how the library behaves in such use case.
Also, it would help to avoid regression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment. I've added a test for invalid values.
| if expectedMessage != actualMessage { | ||
| t.Errorf("Expected a panic for input '%s' with error message '%s', but got '%s'", input, expectedMessage, actualMessage) | ||
| } | ||
| } | ||
|
|
||
| test(t, "score\nnot-float", `error setting field Score: strconv.ParseFloat: parsing "not-float": invalid syntax`) | ||
| test(t, "rank\n-1", `error setting field Rank: strconv.ParseUint: parsing "-1": invalid syntax`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the test are too dependent from the implementation. You can see the error message is about strconv failing to parse.
I'm doing this comment here, but I mean it's interesting to change the implementation, and so the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind ... The whole lib is like that...
It's out of the scope of this PR
shared_test.go
Outdated
| Count int `csv:"count"` | ||
| Rate float32 `csv:"rate"` | ||
| Tags string `csv:"tags"` | ||
| Rank uint `csv:"rank"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a uint8 so you could also use 1000 as an invalid value, and simulate an issue an int64 might have with a huge number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added overflow check for both uint and int.
Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
I've noticed that support for uint was missing, so I've added it in this pull request. Let me know if any changes are needed.