Skip to content

Conversation

mtardy
Copy link
Member

@mtardy mtardy commented May 26, 2025

Fun time!

This fixes many swapping between "expected" and "actual" values which should be nice for debugging and also encourage to use the correct methods (Len/Empty/etc) for more context on debugging. It also fixes a few issues and potential mistakes.

mtardy added 2 commits May 26, 2025 19:14
Issues were fixed using 'golangci-lint run --fix'.

Signed-off-by: Mahe Tardy <[email protected]>
Fixes testifylint require-error: for error assertions use require.
Ignore the linter in three weird cases and simplify one case.

Signed-off-by: Mahe Tardy <[email protected]>
@mtardy mtardy added the release-note/misc This PR makes changes that have no direct user impact. label May 26, 2025
@mtardy mtardy requested a review from will-isovalent May 26, 2025 17:15
mtardy added 3 commits May 26, 2025 19:25
Fixes errors:
	testifylint  len: use require.Len
	testifylint  empty: use assert.NotEmpty
	testifylint  empty: use assert.Empty

Signed-off-by: Mahe Tardy <[email protected]>
Fixes:
	pkg/policyconf/test/mode_test.go:96:3                  testifylint  formatter: remove unnecessary fmt.Sprintf
	pkg/policyconf/test/mode_test.go:113:3                 testifylint  formatter: remove unnecessary fmt.Sprintf
	pkg/policyconf/test/mode_test.go:193:3                 testifylint  formatter: remove unnecessary fmt.Sprintf
	pkg/policyconf/test/mode_test.go:222:3                 testifylint  formatter: remove unnecessary fmt.Sprintf

Signed-off-by: Mahe Tardy <[email protected]>
Fixes:
	pkg/sensors/exec/cgroups_test.go:800:2                 testifylint  useless-assert: meaningless assertion

Signed-off-by: Mahe Tardy <[email protected]>
@mtardy mtardy force-pushed the pr/mtardy/golangci-lint-testifylint branch from 1016b8b to 09db951 Compare May 26, 2025 17:27
@mtardy
Copy link
Member Author

mtardy commented May 26, 2025

For some I blindly replaced assert.NoError with require.NoError while some might have been legit, too lazy to check one by one we have hundreds.

@mtardy mtardy force-pushed the pr/mtardy/golangci-lint-testifylint branch 4 times, most recently from 167810c to 431f0f5 Compare May 27, 2025 09:49
@mtardy mtardy marked this pull request as ready for review May 27, 2025 10:30
@mtardy mtardy requested a review from a team as a code owner May 27, 2025 10:30
@mtardy mtardy requested review from tixxdz and kkourt May 27, 2025 10:30
mtardy and others added 4 commits May 28, 2025 11:15
Fixes:
	pkg/ratelimit/ratelimit_test.go:19:2                   testifylint  float-compare: use assert.InEpsilon (or InDelta)
	pkg/ratelimit/ratelimit_test.go:20:2                   testifylint  float-compare: use assert.InEpsilon (or InDelta)
	pkg/ratelimit/ratelimit_test.go:21:2                   testifylint  float-compare: use assert.InEpsilon (or InDelta)
	pkg/ratelimit/ratelimit_test.go:22:2                   testifylint  float-compare: use assert.InEpsilon (or InDelta)
	pkg/ratelimit/ratelimit_test.go:24:2                   testifylint  float-compare: use assert.InEpsilon (or InDelta)
	pkg/ratelimit/ratelimit_test.go:26:2                   testifylint  float-compare: use assert.InEpsilon (or InDelta)
	pkg/ratelimit/ratelimit_test.go:29:2                   testifylint  float-compare: use assert.InEpsilon (or InDelta)
	pkg/ratelimit/ratelimit_test.go:30:2                   testifylint  float-compare: use assert.InEpsilon (or InDelta)

Co-authored-by: Kevin Sheldrake <[email protected]>
Signed-off-by: Mahe Tardy <[email protected]>
Fixes:
	cmd/tetragon/main_test.go:69:3                         testifylint  go-require: require must only be used in the goroutine running the test function
	pkg/sensors/manager_test.go:297:4                      testifylint  go-require: require must only be used in the goroutine running the test function
	pkg/sensors/manager_test.go:326:4                      testifylint  go-require: require must only be used in the goroutine running the test function
	pkg/sensors/manager_test.go:327:4                      testifylint  go-require: require must only be used in the goroutine running the test function
	pkg/sensors/manager_test.go:351:4                      testifylint  go-require: require must only be used in the goroutine running the test function
	pkg/sensors/manager_test.go:352:4                      testifylint  go-require: require must only be used in the goroutine running the test function

Signed-off-by: Mahe Tardy <[email protected]>
Fixes:
	pkg/errmetrics/err_msg_windows_test.go:16:2  testifylint  bool-compare: use assert.True
	pkg/errmetrics/err_msg_windows_test.go:19:2  testifylint  bool-compare: use assert.True
	pkg/ktime/ktime_windows_test.go:16:2         testifylint  negative-positive: use assert.Positive
	pkg/ktime/ktime_windows_test.go:27:2         testifylint  negative-positive: use assert.Positive
	pkg/ktime/ktime_windows_test.go:32:2         testifylint  expected-actual: need to reverse actual and expected values
	pkg/reader/proc/proc_windows_test.go:21:2    testifylint  error-nil: use assert.NoError
	pkg/reader/proc/proc_windows_test.go:31:2    testifylint  error-nil: use assert.NoError
	pkg/reader/proc/proc_windows_test.go:36:2    testifylint  error-nil: use assert.NoError
	pkg/reader/proc/proc_windows_test.go:41:2    testifylint  error-nil: use assert.NoError
	pkg/reader/proc/proc_windows_test.go:46:2    testifylint  error-nil: use assert.NoError
	pkg/reader/proc/proc_windows_test.go:21:2  testifylint  require-error: for error assertions use require
	pkg/reader/proc/proc_windows_test.go:31:2  testifylint  require-error: for error assertions use require
	pkg/reader/proc/proc_windows_test.go:36:2  testifylint  require-error: for error assertions use require
	pkg/reader/proc/proc_windows_test.go:41:2  testifylint  require-error: for error assertions use require
	pkg/reader/proc/proc_windows_test.go:46:2  testifylint  require-error: for error assertions use require

Signed-off-by: Mahe Tardy <[email protected]>
@mtardy mtardy force-pushed the pr/mtardy/golangci-lint-testifylint branch from 431f0f5 to b3dc487 Compare May 28, 2025 09:17
@mtardy mtardy requested a review from kevsecurity May 28, 2025 09:33
@mtardy mtardy merged commit a12ea07 into main May 28, 2025
50 checks passed
@mtardy mtardy deleted the pr/mtardy/golangci-lint-testifylint branch May 28, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants