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

Test utils/ #32

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Test utils/ #32

wants to merge 6 commits into from

Conversation

Al2Klimov
Copy link
Member

No description provided.

@Al2Klimov Al2Klimov added the enhancement New feature or request label Jul 5, 2024
@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Jul 5, 2024
@oxzi oxzi added the tests Adding tests to existing code label Jul 19, 2024
@Al2Klimov Al2Klimov removed the enhancement New feature or request label Jul 19, 2024
utils/utils_test.go Outdated Show resolved Hide resolved
utils/utils_test.go Show resolved Hide resolved
{"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"}}},
}
Copy link
Member

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]

Copy link
Member Author

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.:

Copy link
Member

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(" ")},
}
Copy link
Member

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.

utils/utils_test.go Outdated Show resolved Hide resolved
Copy link
Member

@oxzi oxzi left a 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.

Comment on lines +58 to +60
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) })
Copy link
Member Author

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.

Comment on lines +96 to +98
for _, st := range unsupported {
t.Run(st.name, func(t *testing.T) {
require.Panics(t, func() { Checksum(st.input) })
Copy link
Member Author

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.

@Al2Klimov Al2Klimov requested a review from oxzi October 22, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR tests Adding tests to existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants