Skip to content
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

chore(linters): Fix findings found by testifylint for Windows and enable testifylint linter in golangci-lint. #14238

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ linters:
- sqlclosecheck
- staticcheck
- tenv
- testifylint
- tparallel
- typecheck
- unconvert
Expand Down Expand Up @@ -246,6 +247,22 @@ linters-settings:
# Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
# Default: false
all: true
testifylint:
# Enable specific checkers.
# https://github.com/Antonboom/testifylint#checkers
# Default: ["bool-compare", "compares", "empty", "error-is-as", "error-nil", "expected-actual", "float-compare", "len", "require-error", "suite-dont-use-pkg", "suite-extra-assert-call"]
enable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- len
- require-error
- suite-dont-use-pkg
- suite-extra-assert-call
- suite-thelper

run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
Expand Down
4 changes: 2 additions & 2 deletions cmd/telegraf/main_win_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ func TestWindowsFlagsAreSet(t *testing.T) {
require.Equal(t, expectedString, m.serviceName)
require.Equal(t, expectedString, m.serviceDisplayName)
require.Equal(t, expectedString, m.serviceRestartDelay)
require.Equal(t, true, m.serviceAutoRestart)
require.Equal(t, true, m.console)
require.True(t, m.serviceAutoRestart)
require.True(t, m.console)
}
2 changes: 1 addition & 1 deletion plugins/inputs/ping/ping_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func TestPingBinary(t *testing.T) {
Urls: []string{"www.google.com"},
Binary: "ping6",
pingHost: func(binary string, timeout float64, args ...string) (string, error) {
require.True(t, binary == "ping6")
require.Equal(t, "ping6", binary)
return "", nil
},
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/procstat/native_finder_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestGather_RealPatternIntegration(t *testing.T) {
pids, err := pg.Pattern(`procstat`)
require.NoError(t, err)
fmt.Println(pids)
require.Equal(t, true, len(pids) > 0)
require.NotEmpty(t, pids)
}

func TestGather_RealFullPatternIntegration(t *testing.T) {
Expand All @@ -29,7 +29,7 @@ func TestGather_RealFullPatternIntegration(t *testing.T) {
pids, err := pg.FullPattern(`%procstat%`)
require.NoError(t, err)
fmt.Println(pids)
require.Equal(t, true, len(pids) > 0)
require.NotEmpty(t, pids)
}

func TestGather_RealUserIntegration(t *testing.T) {
Expand All @@ -43,5 +43,5 @@ func TestGather_RealUserIntegration(t *testing.T) {
pids, err := pg.UID(currentUser.Username)
require.NoError(t, err)
fmt.Println(pids)
require.Equal(t, true, len(pids) > 0)
require.NotEmpty(t, pids)
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ func TestWinPerformanceQueryImplIntegration(t *testing.T) {

fcounter, err := query.GetFormattedCounterValueDouble(hCounter)
require.NoError(t, err)
require.True(t, fcounter > 0)
require.Greater(t, fcounter, 0)

rcounter, err := query.GetRawCounterValue(hCounter)
require.NoError(t, err)
require.True(t, rcounter > 10000000)
require.Greater(t, rcounter, 10000000)

now := time.Now()
mtime, err := query.CollectDataWithTime()
require.NoError(t, err)
require.True(t, mtime.Sub(now) < time.Second)
require.Less(t, mtime.Sub(now), time.Second)

counterPath = "\\Process(*)\\% Processor Time"
paths, err := query.ExpandWildCardPath(counterPath)
require.NoError(t, err)
require.NotNil(t, paths)
require.True(t, len(paths) > 1)
require.Greater(t, len(paths), 1) //nolint:testifylint // https://github.com/Antonboom/testifylint/issues/6
srebhan marked this conversation as resolved.
Show resolved Hide resolved

counterPath = "\\Process(_Total)\\*"
paths, err = query.ExpandWildCardPath(counterPath)
require.NoError(t, err)
require.NotNil(t, paths)
require.True(t, len(paths) > 1)
require.Greater(t, len(paths), 1) //nolint:testifylint // https://github.com/Antonboom/testifylint/issues/6

require.NoError(t, query.Open())

Expand All @@ -104,11 +104,11 @@ func TestWinPerformanceQueryImplIntegration(t *testing.T) {
farr, err = query.GetFormattedCounterArrayDouble(hCounter)
}
require.NoError(t, err)
require.True(t, len(farr) > 0)
require.NotEmpty(t, farr)

rarr, err := query.GetRawCounterArray(hCounter)
require.NoError(t, err)
require.True(t, len(rarr) > 0, "Too")
require.NotEmpty(t, rarr, "Too")

require.NoError(t, query.Close())
}
Expand Down Expand Up @@ -559,15 +559,15 @@ func TestWinPerfCountersCollectRawIntegration(t *testing.T) {

time.Sleep(2000 * time.Millisecond)
require.NoError(t, m.Gather(&acc))
require.True(t, len(acc.Metrics) > 1)
require.Greater(t, len(acc.Metrics), 1) //nolint:testifylint // https://github.com/Antonboom/testifylint/issues/6

expectedCounter := "Percent_Idle_Time_Raw"
for _, metric := range acc.Metrics {
val, ok := metric.Fields[expectedCounter]
require.True(t, ok, "Expected presence of %s field", expectedCounter)
valInt64, ok := val.(int64)
require.True(t, ok, fmt.Sprintf("Expected int64, got %T", val))
require.True(t, valInt64 > 0, fmt.Sprintf("Expected > 0, got %d, for %#v", valInt64, metric))
require.Greater(t, valInt64, 0, fmt.Sprintf("Expected > 0, got %d, for %#v", valInt64, metric))
}

// Test *Array way
Expand All @@ -583,13 +583,13 @@ func TestWinPerfCountersCollectRawIntegration(t *testing.T) {

time.Sleep(2000 * time.Millisecond)
require.NoError(t, m.Gather(&acc2))
require.True(t, len(acc2.Metrics) > 1)
require.Greater(t, len(acc2.Metrics), 1) //nolint:testifylint // https://github.com/Antonboom/testifylint/issues/6

for _, metric := range acc2.Metrics {
val, ok := metric.Fields[expectedCounter]
require.True(t, ok, "Expected presence of %s field", expectedCounter)
valInt64, ok := val.(int64)
require.True(t, ok, fmt.Sprintf("Expected int64, got %T", val))
require.True(t, valInt64 > 0, fmt.Sprintf("Expected > 0, got %d, for %#v", valInt64, metric))
require.Greater(t, valInt64, 0, fmt.Sprintf("Expected > 0, got %d, for %#v", valInt64, metric))
}
}
Loading
Loading