Skip to content

feat/add test coverage#3

Open
meshenka wants to merge 1 commit intohchargois:mainfrom
meshenka:feat/add-test-coverage
Open

feat/add test coverage#3
meshenka wants to merge 1 commit intohchargois:mainfrom
meshenka:feat/add-test-coverage

Conversation

@meshenka
Copy link
Copy Markdown
Contributor

@meshenka meshenka commented Nov 4, 2025

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

  • Updated go.mod from go 1.18 to go 1.25
  • Ran go mod tidy to update dependencies

Go 1.22+ Linting Fixes

copyloopvar (4 fixes):

  • Removed unnecessary loop variable copies in closures
  • In Go 1.22+, loop variables are automatically captured correctly, making explicit copies redundant
  • Fixed in:
    • main.go: Removed copies of idxName, shards, and i in initScrollers()
    • scroll.go: Removed copy of scroller in scroll()

intrange (1 fix):

  • Changed traditional for loop to use integer range syntax
  • for i := 0; i < slices; i++for i := range slices
  • More idiomatic Go 1.22+ syntax

Files Modified

  • go.mod - Updated Go version
  • main.go - Removed loop variable copies, used integer range
  • scroll.go - Removed loop variable copy

Benefits

  • Modern Go syntax: Uses Go 1.22+ features for cleaner code
  • Improved performance: Removed unnecessary variable copies
  • Better maintainability: More idiomatic Go code
  • Linter compliance: All new Go 1.22+ linters satisfied

Comment thread main_test.go
Comment thread main_test.go
@meshenka meshenka force-pushed the feat/add-test-coverage branch 2 times, most recently from 8bd3189 to 12ccac3 Compare November 18, 2025 13:00
@meshenka meshenka force-pushed the feat/add-test-coverage branch from 12ccac3 to 5a5a5fe Compare November 18, 2025 13:37
@meshenka meshenka marked this pull request as ready for review November 18, 2025 13:38
@meshenka
Copy link
Copy Markdown
Contributor Author

could be nice to enable github workflows

🎉

@meshenka
Copy link
Copy Markdown
Contributor Author

up @hchargois :D

@meshenka
Copy link
Copy Markdown
Contributor Author

🙏 @hchargois

Copy link
Copy Markdown
Owner

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

Comment thread http.go
Comment on lines +73 to +78
var transport *http.Transport
if defaultTransport, ok := http.DefaultTransport.(*http.Transport); ok {
transport = defaultTransport.Clone()
} else {
transport = &http.Transport{}
}
Copy link
Copy Markdown
Owner

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

Comment thread http.go
Comment on lines +83 to +85
transport.TLSClientConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
Copy link
Copy Markdown
Owner

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.

Comment thread main.go
Comment on lines +288 to +298
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
}
Copy link
Copy Markdown
Owner

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.

Comment thread main_test.go
Comment thread main_test.go
}
}

func TestIPIsLoopback(t *testing.T) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove

Comment thread query_test.go
@@ -0,0 +1,309 @@
package main
Copy link
Copy Markdown
Owner

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?

Comment thread scroll_test.go
"github.com/stretchr/testify/require"
)

func TestScrollQuery_JSONMarshaling(t *testing.T) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove

Comment thread scroll_test.go
assert.InDelta(t, float64(5), slice["max"], 0.01, "slice max should be 5")
}

func TestSleepForThrottling(t *testing.T) {
Copy link
Copy Markdown
Owner

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.

Comment thread write_test.go
@@ -0,0 +1,156 @@
package main
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove

Comment thread .github/workflows/go.yaml
@@ -0,0 +1,51 @@
name: golang
Copy link
Copy Markdown
Owner

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

@meshenka
Copy link
Copy Markdown
Contributor Author

@hchargois thanks i will review all that when i have some free time 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants