CI: golangci-lint 1.63 (#3396)

This commit is contained in:
mmetc 2025-01-16 13:22:08 +01:00 committed by GitHub
parent 9ef5f58f88
commit 6529215775
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 33 additions and 29 deletions

View file

@ -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

View file

@ -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

View file

@ -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.*"

View file

@ -12,19 +12,22 @@ import (
)
func TestListFilesAtPath(t *testing.T) {
dir, err := os.MkdirTemp("", "test-listfiles")
dir := t.TempDir()
f, err := os.Create(filepath.Join(dir, "notification-gitter"))
require.NoError(t, err)
t.Cleanup(func() {
os.RemoveAll(dir)
})
_, 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

View file

@ -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)

View file

@ -3,7 +3,6 @@ package exprhelpers
import (
"context"
"errors"
"os"
"testing"
"time"
@ -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)

View file

@ -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)

View file

@ -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)
@ -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)
@ -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)
@ -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)
@ -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)
@ -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)
@ -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)
@ -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)
@ -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)
@ -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)