-
Notifications
You must be signed in to change notification settings - Fork 2
feat/add test coverage #3
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
8bd3189 to
12ccac3
Compare
12ccac3 to
5a5a5fe
Compare
|
could be nice to enable github workflows 🎉 |
|
up @hchargois :D |
hchargois
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.
Hi!
Sorry for taking so much time to answer.
First I'd like to thank you sincerely for your interest in my little project and for your contributions!
There are quite a few your tests that don't actually test esdump at all; I think these should be removed. If you really want to have tests, some functions could be extracted so they can be unit tested; as I've done for the flag validation for example.
But otherwise, I'd rather keep tests lean and focused; the less the better. Most of the tricky behavior would only be exercised by testing with a real ES cluster anyway.
Thanks again.
| var transport *http.Transport | ||
| if defaultTransport, ok := http.DefaultTransport.(*http.Transport); ok { | ||
| transport = defaultTransport.Clone() | ||
| } else { | ||
| transport = &http.Transport{} | ||
| } |
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.
This is unnecessary, DefaultTransport is never going to change, a bare type assert is fine
| transport.TLSClientConfig = &tls.Config{ | ||
| MinVersion: tls.VersionTLS12, | ||
| } |
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.
This is not a good idea, this should be left unset so that the (safe) default is used.
| const maxInt32 = int32(^uint32(0) >> 1) | ||
| scrollersLen := len(scrollers) | ||
| if scrollersLen > 0 && scrollersLen <= int(maxInt32) { | ||
| if scrollersLen <= int(^int32(0)>>1) { | ||
| d.totalHitsPending = int32(scrollersLen) | ||
| } else { | ||
| d.totalHitsPending = maxInt32 | ||
| } | ||
| } else { | ||
| d.totalHitsPending = maxInt32 | ||
| } |
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 guess this is technically necessary to prevent overflows that can't really happen anyway... That made me rethink the use of atomics in the first place (which impose those sized ints); I've changed that for a cleaner dedicated thread safe counter.
| } | ||
| } | ||
|
|
||
| func TestIPIsLoopback(t *testing.T) { |
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.
to remove
| @@ -0,0 +1,309 @@ | |||
| package main | |||
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.
to remove, none of these tests are testing esdump?
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestScrollQuery_JSONMarshaling(t *testing.T) { |
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.
to remove
| assert.InDelta(t, float64(5), slice["max"], 0.01, "slice max should be 5") | ||
| } | ||
|
|
||
| func TestSleepForThrottling(t *testing.T) { |
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.
Testing sleep durations is inherently brittle, a possible solution would be to use the new synctest package to freeze time. But a much simpler solution is not to test the actual sleep; the important thing to test is the value of the computed duration; for that reason I've extracted that logic into its own function.
| @@ -0,0 +1,156 @@ | |||
| package main | |||
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.
To remove
| @@ -0,0 +1,51 @@ | |||
| name: golang | |||
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'd rather not have github workflows, I don't know what half of this does and I find it cumbersome
Upgrade to Go 1.25 and fix Go 1.22+ linting issues
Upgrade Summary
This PR upgrades the codebase from Go 1.18 to Go 1.25 and fixes linting issues introduced by new Go 1.22+ linters.
Changes
Go Version Upgrade
go.modfromgo 1.18togo 1.25go mod tidyto update dependenciesGo 1.22+ Linting Fixes
copyloopvar (4 fixes):
main.go: Removed copies ofidxName,shards, andiininitScrollers()scroll.go: Removed copy ofscrollerinscroll()intrange (1 fix):
for i := 0; i < slices; i++→for i := range slicesFiles Modified
go.mod- Updated Go versionmain.go- Removed loop variable copies, used integer rangescroll.go- Removed loop variable copyBenefits