Skip to content

Commit 57a2590

Browse files
committed
Add thelper linter and fixes
Signed-off-by: Jaime Caamaño Ruiz <[email protected]>
1 parent 866e65f commit 57a2590

File tree

7 files changed

+32
-22
lines changed

7 files changed

+32
-22
lines changed

go-controller/.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters:
1818
- revive
1919
- staticcheck
2020
- testifylint
21+
- thelper
2122
- typecheck
2223
- unused
2324

go-controller/pkg/clustermanager/pod/allocator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type testPod struct {
4545
}
4646

4747
func (p testPod) getPod(t *testing.T) *corev1.Pod {
48-
48+
t.Helper()
4949
pod := &corev1.Pod{
5050
ObjectMeta: metav1.ObjectMeta{
5151
Name: "pod",

go-controller/pkg/cni/cniserver_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
)
3030

3131
func clientDoCNI(t *testing.T, client *http.Client, req *Request) ([]byte, int) {
32+
t.Helper()
3233
data, err := json.Marshal(req)
3334
if err != nil {
3435
t.Fatalf("failed to marshal CNI request %v: %v", req, err)

go-controller/pkg/kube/healthcheck/healthcheck_test.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestServer(t *testing.T) {
161161
t.Errorf("expected port :9376 to be open\n%#v", listener.openPorts)
162162
}
163163
// test the handler
164-
testHandler(hcs, nsn, http.StatusServiceUnavailable, 0, t)
164+
testHandler(t, hcs, nsn, http.StatusServiceUnavailable, 0)
165165

166166
// sync an endpoint
167167
err = hcs.SyncEndpoints(map[types.NamespacedName]int{nsn: 18})
@@ -175,7 +175,7 @@ func TestServer(t *testing.T) {
175175
t.Errorf("expected 18 endpoints, got %d", hcs.services[nsn].endpoints)
176176
}
177177
// test the handler
178-
testHandler(hcs, nsn, http.StatusOK, 18, t)
178+
testHandler(t, hcs, nsn, http.StatusOK, 18)
179179

180180
// sync zero endpoints
181181
err = hcs.SyncEndpoints(map[types.NamespacedName]int{nsn: 0})
@@ -189,7 +189,7 @@ func TestServer(t *testing.T) {
189189
t.Errorf("expected 0 endpoints, got %d", hcs.services[nsn].endpoints)
190190
}
191191
// test the handler
192-
testHandler(hcs, nsn, http.StatusServiceUnavailable, 0, t)
192+
testHandler(t, hcs, nsn, http.StatusServiceUnavailable, 0)
193193

194194
// put the endpoint back
195195
err = hcs.SyncEndpoints(map[types.NamespacedName]int{nsn: 11})
@@ -214,7 +214,7 @@ func TestServer(t *testing.T) {
214214
t.Errorf("expected 0 endpoints, got %d", hcs.services[nsn].endpoints)
215215
}
216216
// test the handler
217-
testHandler(hcs, nsn, http.StatusServiceUnavailable, 0, t)
217+
testHandler(t, hcs, nsn, http.StatusServiceUnavailable, 0)
218218

219219
// put the endpoint back
220220
err = hcs.SyncEndpoints(map[types.NamespacedName]int{nsn: 18})
@@ -265,9 +265,9 @@ func TestServer(t *testing.T) {
265265
t.Errorf("expected 3 open ports, got %d\n%#v", len(listener.openPorts), listener.openPorts)
266266
}
267267
// test the handlers
268-
testHandler(hcs, nsn1, http.StatusServiceUnavailable, 0, t)
269-
testHandler(hcs, nsn2, http.StatusServiceUnavailable, 0, t)
270-
testHandler(hcs, nsn3, http.StatusServiceUnavailable, 0, t)
268+
testHandler(t, hcs, nsn1, http.StatusServiceUnavailable, 0)
269+
testHandler(t, hcs, nsn2, http.StatusServiceUnavailable, 0)
270+
testHandler(t, hcs, nsn3, http.StatusServiceUnavailable, 0)
271271

272272
// sync endpoints
273273
err = hcs.SyncEndpoints(map[types.NamespacedName]int{
@@ -291,9 +291,9 @@ func TestServer(t *testing.T) {
291291
t.Errorf("expected 7 endpoints, got %d", hcs.services[nsn3].endpoints)
292292
}
293293
// test the handlers
294-
testHandler(hcs, nsn1, http.StatusOK, 9, t)
295-
testHandler(hcs, nsn2, http.StatusOK, 3, t)
296-
testHandler(hcs, nsn3, http.StatusOK, 7, t)
294+
testHandler(t, hcs, nsn1, http.StatusOK, 9)
295+
testHandler(t, hcs, nsn2, http.StatusOK, 3)
296+
testHandler(t, hcs, nsn3, http.StatusOK, 7)
297297

298298
// sync new services
299299
err = hcs.SyncServices(map[types.NamespacedName]uint16{
@@ -318,9 +318,9 @@ func TestServer(t *testing.T) {
318318
t.Errorf("expected 0 endpoints, got %d", hcs.services[nsn4].endpoints)
319319
}
320320
// test the handlers
321-
testHandler(hcs, nsn2, http.StatusOK, 3, t)
322-
testHandler(hcs, nsn3, http.StatusServiceUnavailable, 0, t)
323-
testHandler(hcs, nsn4, http.StatusServiceUnavailable, 0, t)
321+
testHandler(t, hcs, nsn2, http.StatusOK, 3)
322+
testHandler(t, hcs, nsn3, http.StatusServiceUnavailable, 0)
323+
testHandler(t, hcs, nsn4, http.StatusServiceUnavailable, 0)
324324

325325
// sync endpoints
326326
err = hcs.SyncEndpoints(map[types.NamespacedName]int{
@@ -345,9 +345,9 @@ func TestServer(t *testing.T) {
345345
t.Errorf("expected 6 endpoints, got %d", hcs.services[nsn4].endpoints)
346346
}
347347
// test the handlers
348-
testHandler(hcs, nsn2, http.StatusOK, 3, t)
349-
testHandler(hcs, nsn3, http.StatusOK, 7, t)
350-
testHandler(hcs, nsn4, http.StatusOK, 6, t)
348+
testHandler(t, hcs, nsn2, http.StatusOK, 3)
349+
testHandler(t, hcs, nsn3, http.StatusOK, 7)
350+
testHandler(t, hcs, nsn4, http.StatusOK, 6)
351351

352352
// sync endpoints, missing nsn2
353353
err = hcs.SyncEndpoints(map[types.NamespacedName]int{
@@ -370,12 +370,13 @@ func TestServer(t *testing.T) {
370370
t.Errorf("expected 6 endpoints, got %d", hcs.services[nsn4].endpoints)
371371
}
372372
// test the handlers
373-
testHandler(hcs, nsn2, http.StatusServiceUnavailable, 0, t)
374-
testHandler(hcs, nsn3, http.StatusOK, 7, t)
375-
testHandler(hcs, nsn4, http.StatusOK, 6, t)
373+
testHandler(t, hcs, nsn2, http.StatusServiceUnavailable, 0)
374+
testHandler(t, hcs, nsn3, http.StatusOK, 7)
375+
testHandler(t, hcs, nsn4, http.StatusOK, 6)
376376
}
377377

378-
func testHandler(hcs *server, nsn types.NamespacedName, status int, endpoints int, t *testing.T) {
378+
func testHandler(t *testing.T, hcs *server, nsn types.NamespacedName, status int, endpoints int) {
379+
t.Helper()
379380
handler := hcs.services[nsn].server.(*fakeHTTPServer).handler
380381
req, err := http.NewRequest("GET", "/healthz", nil)
381382
if err != nil {

go-controller/pkg/libovsdb/ops/model_client_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type OperationModelTestCase struct {
4444
}
4545

4646
func runTestCase(t *testing.T, tCase OperationModelTestCase) error {
47+
t.Helper()
4748
dbSetup := libovsdbtest.TestSetup{
4849
NBData: tCase.initialDB,
4950
}

go-controller/pkg/node/ovspinning/ovspinning_linux_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func TestPrintCPUSetRanges(t *testing.T) {
161161
}
162162

163163
func mockOvsdbProcess(t *testing.T) (int, func()) {
164+
t.Helper()
164165
ctx, stopCmd := context.WithCancel(context.Background())
165166

166167
cmd := exec.CommandContext(ctx, "sleep", "10")
@@ -180,6 +181,7 @@ func mockOvsdbProcess(t *testing.T) (int, func()) {
180181
}
181182

182183
func mockOvsVSwitchdProcess(t *testing.T) (int, func()) {
184+
t.Helper()
183185
ctx, stopCmd := context.WithCancel(context.Background())
184186

185187
cmd := exec.CommandContext(ctx, "go", "run", "testdata/fake_thread_process.go")
@@ -214,7 +216,7 @@ func setTickDuration(d time.Duration) func() {
214216
}
215217

216218
func mockFeatureEnableFile(t *testing.T, data string) func() {
217-
219+
t.Helper()
218220
f, err := os.CreateTemp("", "enable_dynamic_cpu_affinity")
219221
require.NoError(t, err)
220222

@@ -231,6 +233,7 @@ func mockFeatureEnableFile(t *testing.T, data string) func() {
231233
}
232234

233235
func assertPIDHasSchedAffinity(t *testing.T, pid int, expectedCPUSet unix.CPUSet) {
236+
t.Helper()
234237
var actual unix.CPUSet
235238
assert.Eventually(t, func() bool {
236239
err := unix.SchedGetaffinity(pid, &actual)
@@ -251,6 +254,7 @@ func assertPIDHasSchedAffinity(t *testing.T, pid int, expectedCPUSet unix.CPUSet
251254
}
252255

253256
func assertNeverPIDHasSchedAffinity(t *testing.T, pid int, targetCPUSet unix.CPUSet) {
257+
t.Helper()
254258
var actual unix.CPUSet
255259
assert.Never(t, func() bool {
256260
err := unix.SchedGetaffinity(pid, &actual)

go-controller/pkg/ovndbmanager/ovndbmanager_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ func keyForArgs(args ...string) string {
773773

774774
// create file with name, fail on error or if the file already exists
775775
func createDbFile(t *testing.T, name string) {
776+
t.Helper()
776777
_, err := os.Stat(name)
777778
if os.IsNotExist(err) {
778779
f, err := os.OpenFile(name, os.O_RDONLY|os.O_CREATE, 0o644)
@@ -788,6 +789,7 @@ func createDbFile(t *testing.T, name string) {
788789
// failOnErrorMismatch fails either if an error is seen but not expected
789790
// or if an error is expected but when the substring does not match the error
790791
func failOnErrorMismatch(t *testing.T, receivedErr error, expectedErrorString string) {
792+
t.Helper()
791793
if receivedErr != nil {
792794
if expectedErrorString == "" {
793795
t.Errorf("No error expected. However, received '%v' from method under test.", receivedErr)

0 commit comments

Comments
 (0)