-
Notifications
You must be signed in to change notification settings - Fork 0
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
Test utils/ #32
base: main
Are you sure you want to change the base?
Test utils/ #32
Conversation
{"ab_c", []string{"a", "b", "c"}, 2, [][]string{{"a", "b"}, {"c"}}}, | ||
{"abc", []string{"a", "b", "c"}, 3, [][]string{{"a", "b", "c"}}}, | ||
{"abc4", []string{"a", "b", "c"}, 4, [][]string{{"a", "b", "c"}}}, | ||
} |
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.
As the count
parameter is a signed integer, try negative numbers 😏
I would suggest making the function documentation more obvious and stating that count <= 0
will either panic or be rewritten to 1. A count
of 0 returns an infinite loop emitting empty string arrays until eternity and a negative count
results in a slice bounds out of range access.
{"abc0-to-infinity-and-beyond", []string{"a", "b", "c"}, 0, [][]string{{}, {}, {}}},
{"abc-1-crash", []string{"a", "b", "c"}, -1, nil},
=== RUN TestBatchSliceOfStrings/abc0-to-infinity-and-beyond
utils_test.go:51:
Error Trace: /home/REDACTED/git/github.com/Icinga/icinga-go-library/utils/utils_test.go:51
Error: Should be false
Test: TestBatchSliceOfStrings/abc0-to-infinity-and-beyond
Messages: receiving from channel should not return anything, received []
=== RUN TestBatchSliceOfStrings/abc-1-crash
panic: runtime error: slice bounds out of range [:-1]
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.
Where I just ref an issue/PR (like you #32 (comment)), I prefix it with * and a space, so I show its title and status. E.g.:
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.
After this got merged, please include it in the tests, e.g., by adding another shouldPanic
field to the table test struct.
{"empty_bytes", []byte(nil)}, | ||
{"space_string", " "}, | ||
{"space_bytes", []byte(" ")}, | ||
} |
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.
The Checksum
function panics for other input
types. Please test those as well.
45590ff
to
22e11dd
Compare
22e11dd
to
1a80bdc
Compare
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.
There are still two open review comments from my previous review: #32 (comment) and #32 (comment). Please address those and feel free to re-request another review again.
for _, i := range []int{0, -1, -2, -30} { | ||
t.Run(fmt.Sprint(i), func(t *testing.T) { | ||
require.Panics(t, func() { BatchSliceOfStrings(context.Background(), nil, i) }) |
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, I assert panic on negative numbers.
for _, st := range unsupported { | ||
t.Run(st.name, func(t *testing.T) { | ||
require.Panics(t, func() { Checksum(st.input) }) |
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.
And here, I assert panic on unsupported types.
No description provided.