Skip to content

Commit

Permalink
Merge pull request #18746 from mmorel-35/golangci-lint/thelper
Browse files Browse the repository at this point in the history
fix: enable thelper linter in client directory
  • Loading branch information
ahrtr authored Oct 23, 2024
2 parents 4b59ec1 + 97c8869 commit 867bd26
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions client/internal/v2/keys_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func createTestResponse(children, size int) *Response {
}

func benchmarkResponseUnmarshalling(b *testing.B, children, size int) {
b.Helper()
header := http.Header{}
header.Add("X-Etcd-Index", "123456")
response := createTestResponse(children, size)
Expand Down
13 changes: 11 additions & 2 deletions client/pkg/fileutil/preallocate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ import (

func TestPreallocateExtend(t *testing.T) {
pf := func(f *os.File, sz int64) error { return Preallocate(f, sz, true) }
tf := func(t *testing.T, f *os.File) { testPreallocateExtend(t, f, pf) }
tf := func(t *testing.T, f *os.File) {
t.Helper()
testPreallocateExtend(t, f, pf)
}
runPreallocTest(t, tf)
}

func TestPreallocateExtendTrunc(t *testing.T) {
tf := func(t *testing.T, f *os.File) { testPreallocateExtend(t, f, preallocExtendTrunc) }
tf := func(t *testing.T, f *os.File) {
t.Helper()
testPreallocateExtend(t, f, preallocExtendTrunc)
}
runPreallocTest(t, tf)
}

func testPreallocateExtend(t *testing.T, f *os.File, pf func(*os.File, int64) error) {
t.Helper()
size := int64(64 * 1000)
require.NoError(t, pf(f, size))

Expand All @@ -45,6 +52,7 @@ func testPreallocateExtend(t *testing.T, f *os.File, pf func(*os.File, int64) er

func TestPreallocateFixed(t *testing.T) { runPreallocTest(t, testPreallocateFixed) }
func testPreallocateFixed(t *testing.T, f *os.File) {
t.Helper()
size := int64(64 * 1000)
require.NoError(t, Preallocate(f, size, false))

Expand All @@ -56,6 +64,7 @@ func testPreallocateFixed(t *testing.T, f *os.File) {
}

func runPreallocTest(t *testing.T, test func(*testing.T, *os.File)) {
t.Helper()
p := t.TempDir()

f, err := os.CreateTemp(p, "")
Expand Down
1 change: 1 addition & 0 deletions client/pkg/fileutil/read_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestReadDir(t *testing.T) {
}

func writeFunc(t *testing.T, path string) {
t.Helper()
fh, err := os.Create(path)
require.NoErrorf(t, err, "error creating file")
assert.NoErrorf(t, fh.Close(), "error closing file")
Expand Down
17 changes: 9 additions & 8 deletions client/pkg/testutil/before.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ import (
"go.etcd.io/etcd/client/pkg/v3/verify"
)

func BeforeTest(t testing.TB) {
RegisterLeakDetection(t)
func BeforeTest(tb testing.TB) {
tb.Helper()
RegisterLeakDetection(tb)

revertVerifyFunc := verify.EnableAllVerifications()

path, err := os.Getwd()
assert.NoError(t, err)
tempDir := t.TempDir()
assert.NoError(t, os.Chdir(tempDir))
t.Logf("Changing working directory to: %s", tempDir)
assert.NoError(tb, err)
tempDir := tb.TempDir()
assert.NoError(tb, os.Chdir(tempDir))
tb.Logf("Changing working directory to: %s", tempDir)

t.Cleanup(func() {
tb.Cleanup(func() {
revertVerifyFunc()
assert.NoError(t, os.Chdir(path))
assert.NoError(tb, os.Chdir(path))
})
}

Expand Down
3 changes: 3 additions & 0 deletions client/pkg/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func WaitSchedule() {
}

func MustNewURLs(t *testing.T, urls []string) []url.URL {
t.Helper()
if urls == nil {
return nil
}
Expand All @@ -42,6 +43,7 @@ func MustNewURLs(t *testing.T, urls []string) []url.URL {
}

func MustNewURL(t *testing.T, s string) *url.URL {
t.Helper()
u, err := url.Parse(s)
if err != nil {
t.Fatalf("parse %v error: %v", s, err)
Expand All @@ -51,6 +53,7 @@ func MustNewURL(t *testing.T, s string) *url.URL {

// FatalStack helps to fatal the test and print out the stacks of all running goroutines.
func FatalStack(t *testing.T, s string) {
t.Helper()
stackTrace := make([]byte, 1024*1024)
n := runtime.Stack(stackTrace, true)
t.Errorf("---> Test failed: %s", s)
Expand Down
1 change: 1 addition & 0 deletions client/pkg/tlsutil/cipher_suites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestGetCipherSuite_not_existing(t *testing.T) {
}

func CipherSuiteExpectedToExist(tb testing.TB, cipher string, expectedID uint16) {
tb.Helper()
vid, ok := GetCipherSuite(cipher)
if !ok {
tb.Errorf("Expected %v cipher to exist", cipher)
Expand Down
4 changes: 4 additions & 0 deletions client/pkg/transport/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ import (
)

func createSelfCert(t *testing.T) (*TLSInfo, error) {
t.Helper()
return createSelfCertEx(t, "127.0.0.1")
}

func createSelfCertEx(t *testing.T, host string, additionalUsages ...x509.ExtKeyUsage) (*TLSInfo, error) {
t.Helper()
d := t.TempDir()
info, err := SelfCert(zaptest.NewLogger(t), d, []string{host + ":0"}, 1, additionalUsages...)
if err != nil {
Expand Down Expand Up @@ -218,6 +220,7 @@ func TestNewListenerWithSocketOpts(t *testing.T) {
}

func testNewListenerTLSInfoAccept(t *testing.T, tlsInfo TLSInfo) {
t.Helper()
ln, err := NewListener("127.0.0.1:0", "https", &tlsInfo)
require.NoErrorf(t, err, "unexpected NewListener error")
defer ln.Close()
Expand Down Expand Up @@ -254,6 +257,7 @@ func TestNewListenerTLSInfoSkipClientSANVerify(t *testing.T) {
}

func testNewListenerTLSInfoClientCheck(t *testing.T, skipClientSANVerify, goodClientHost, acceptExpected bool) {
t.Helper()
tlsInfo, err := createSelfCert(t)
require.NoErrorf(t, err, "unable to create cert")

Expand Down
1 change: 1 addition & 0 deletions client/pkg/transport/timeout_dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type testBlockingServer struct {
}

func (ts *testBlockingServer) Start(t *testing.T) {
t.Helper()
for i := 0; i < ts.n; i++ {
conn, err := ts.ln.Accept()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions client/pkg/types/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func equal(a, b []string) bool {
}

func driveSetTests(t *testing.T, s Set) {
t.Helper()
// Verify operations on an empty set
values := s.Values()
if len(values) != 0 {
Expand Down
1 change: 1 addition & 0 deletions client/v3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
)

func NewClient(t *testing.T, cfg Config) (*Client, error) {
t.Helper()
if cfg.Logger == nil {
cfg.Logger = zaptest.NewLogger(t).Named("client")
}
Expand Down

0 comments on commit 867bd26

Please sign in to comment.