Skip to content

Commit

Permalink
CI: golangci-lint 1.63 (#3396)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc authored Jan 16, 2025
1 parent 9ef5f58 commit 6529215
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-tests-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.62
version: v1.63
args: --issues-exit-code=1 --timeout 10m
only-new-issues: false
2 changes: 1 addition & 1 deletion .github/workflows/go-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,6 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.62
version: v1.63
args: --issues-exit-code=1 --timeout 10m
only-new-issues: false
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,14 @@ issues:
- revive
path: "pkg/types/utils.go"
text: "argument-limit: .*"

# need some cleanup first: to create db in memory and share the client, not the config
- linters:
- usetesting
path: "pkg/apiserver/(.+)_test.go"
text: "os.MkdirTemp.* could be replaced by t.TempDir.*"

- linters:
- usetesting
path: "pkg/apiserver/(.+)_test.go"
text: "os.CreateTemp.* could be replaced by os.CreateTemp.*"
19 changes: 11 additions & 8 deletions pkg/csplugin/listfiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ import (
)

func TestListFilesAtPath(t *testing.T) {
dir, err := os.MkdirTemp("", "test-listfiles")
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(dir)
})
_, err = os.Create(filepath.Join(dir, "notification-gitter"))
dir := t.TempDir()

f, err := os.Create(filepath.Join(dir, "notification-gitter"))
require.NoError(t, err)
_, err = os.Create(filepath.Join(dir, "slack"))
require.NoError(t, f.Close())

f, err = os.Create(filepath.Join(dir, "slack"))
require.NoError(t, err)
require.NoError(t, f.Close())

err = os.Mkdir(filepath.Join(dir, "somedir"), 0o755)
require.NoError(t, err)
_, err = os.Create(filepath.Join(dir, "somedir", "inner"))

f, err = os.Create(filepath.Join(dir, "somedir", "inner"))
require.NoError(t, err)
require.NoError(t, f.Close())

tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewClient(ctx context.Context, config *csconfig.DatabaseCfg) (*Client, erro
return nil, err // unsupported database caught here
}

if config.Type == "sqlite" {
if config.Type == "sqlite" && config.DbPath != ":memory:" {
/*if it's the first startup, we want to touch and chmod file*/
if _, err = os.Stat(config.DbPath); os.IsNotExist(err) {
f, err := os.OpenFile(config.DbPath, os.O_CREATE|os.O_RDWR, 0o600)
Expand Down
6 changes: 1 addition & 5 deletions pkg/exprhelpers/exprlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package exprhelpers
import (
"context"
"errors"
"os"
"testing"
"time"

Expand All @@ -26,15 +25,12 @@ const TestFolder = "tests"
func getDBClient(t *testing.T) *database.Client {
t.Helper()

dbPath, err := os.CreateTemp("", "*sqlite")
require.NoError(t, err)

ctx := context.Background()

testDBClient, err := database.NewClient(ctx, &csconfig.DatabaseCfg{
Type: "sqlite",
DbName: "crowdsec",
DbPath: dbPath.Name(),
DbPath: ":memory:",
})
require.NoError(t, err)

Expand Down
4 changes: 1 addition & 3 deletions pkg/fflag/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,9 @@ func TestSetFromYaml(t *testing.T) {
}

func TestSetFromYamlFile(t *testing.T) {
tmpfile, err := os.CreateTemp("", "test")
tmpfile, err := os.CreateTemp(t.TempDir(), "test")
require.NoError(t, err)

defer os.Remove(tmpfile.Name())

// write the config file
_, err = tmpfile.WriteString("- experimental1")
require.NoError(t, err)
Expand Down
16 changes: 6 additions & 10 deletions pkg/setup/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ func TestSetupHelperProcess(t *testing.T) {
func tempYAML(t *testing.T, content string) os.File {
t.Helper()
require := require.New(t)
file, err := os.CreateTemp("", "")
file, err := os.CreateTemp(t.TempDir(), "")
require.NoError(err)

t.Cleanup(func() {
require.NoError(file.Close())
require.NoError(os.Remove(file.Name()))
})

_, err = file.WriteString(dedent.Dedent(content))
require.NoError(err)

Expand Down Expand Up @@ -249,7 +254,6 @@ func TestListSupported(t *testing.T) {
t.Parallel()

f := tempYAML(t, tc.yml)
defer os.Remove(f.Name())

supported, err := setup.ListSupported(&f)
cstest.RequireErrorContains(t, err, tc.expectedErr)
Expand Down Expand Up @@ -375,7 +379,6 @@ func TestDetectSimpleRule(t *testing.T) {
- false
ugly:
`)
defer os.Remove(f.Name())

detected, err := setup.Detect(&f, setup.DetectOptions{})
require.NoError(err)
Expand Down Expand Up @@ -421,7 +424,6 @@ detect:
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
f := tempYAML(t, tc.config)
defer os.Remove(f.Name())

detected, err := setup.Detect(&f, setup.DetectOptions{})
cstest.RequireErrorContains(t, err, tc.expectedErr)
Expand Down Expand Up @@ -514,7 +516,6 @@ detect:
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
f := tempYAML(t, tc.config)
defer os.Remove(f.Name())

detected, err := setup.Detect(&f, setup.DetectOptions{})
cstest.RequireErrorContains(t, err, tc.expectedErr)
Expand Down Expand Up @@ -542,7 +543,6 @@ func TestDetectForcedUnit(t *testing.T) {
journalctl_filter:
- _SYSTEMD_UNIT=crowdsec-setup-forced.service
`)
defer os.Remove(f.Name())

detected, err := setup.Detect(&f, setup.DetectOptions{ForcedUnits: []string{"crowdsec-setup-forced.service"}})
require.NoError(err)
Expand Down Expand Up @@ -580,7 +580,6 @@ func TestDetectForcedProcess(t *testing.T) {
when:
- ProcessRunning("foobar")
`)
defer os.Remove(f.Name())

detected, err := setup.Detect(&f, setup.DetectOptions{ForcedProcesses: []string{"foobar"}})
require.NoError(err)
Expand Down Expand Up @@ -610,7 +609,6 @@ func TestDetectSkipService(t *testing.T) {
when:
- ProcessRunning("foobar")
`)
defer os.Remove(f.Name())

detected, err := setup.Detect(&f, setup.DetectOptions{ForcedProcesses: []string{"foobar"}, SkipServices: []string{"wizard"}})
require.NoError(err)
Expand Down Expand Up @@ -825,7 +823,6 @@ func TestDetectForcedOS(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
f := tempYAML(t, tc.config)
defer os.Remove(f.Name())

detected, err := setup.Detect(&f, setup.DetectOptions{ForcedOS: tc.forced})
cstest.RequireErrorContains(t, err, tc.expectedErr)
Expand Down Expand Up @@ -1009,7 +1006,6 @@ func TestDetectDatasourceValidation(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
f := tempYAML(t, tc.config)
defer os.Remove(f.Name())
detected, err := setup.Detect(&f, setup.DetectOptions{})
cstest.RequireErrorContains(t, err, tc.expectedErr)
require.Equal(tc.expected, detected)
Expand Down

0 comments on commit 6529215

Please sign in to comment.