Skip to content

Commit

Permalink
Merge pull request #24957 from Luap99/lint
Browse files Browse the repository at this point in the history
update golangci/golangci-lint to v1.63.4
  • Loading branch information
openshift-merge-bot[bot] authored Jan 7, 2025
2 parents c7882f0 + e9fb805 commit 564b8f3
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ BUILDTAGS += ${EXTRA_BUILDTAGS}
# N/B: This value is managed by Renovate, manual changes are
# possible, as long as they don't disturb the formatting
# (i.e. DO NOT ADD A 'v' prefix!)
GOLANGCI_LINT_VERSION := 1.62.2
GOLANGCI_LINT_VERSION := 1.63.4
PYTHON ?= $(shell command -v python3 python|head -n1)
PKG_MANAGER ?= $(shell command -v dnf yum|head -n1)
# ~/.local/bin is not in PATH on all systems
Expand Down
20 changes: 4 additions & 16 deletions cmd/quadlet/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,15 @@ func TestUnitDirs(t *testing.T) {
unitDirs = getUnitDirs(false)
assert.Equal(t, []string{}, unitDirs)

name, err := os.MkdirTemp("", "dir")
assert.Nil(t, err)
// remove the temporary directory at the end of the program
defer os.RemoveAll(name)

name := t.TempDir()
t.Setenv("QUADLET_UNIT_DIRS", name)
unitDirs = getUnitDirs(false)
assert.Equal(t, []string{name}, unitDirs, "rootful should use environment variable")

unitDirs = getUnitDirs(true)
assert.Equal(t, []string{name}, unitDirs, "rootless should use environment variable")

symLinkTestBaseDir, err := os.MkdirTemp("", "podman-symlinktest")
assert.Nil(t, err)
// remove the temporary directory at the end of the program
defer os.RemoveAll(symLinkTestBaseDir)
symLinkTestBaseDir := t.TempDir()

actualDir := filepath.Join(symLinkTestBaseDir, "actual")
err = os.Mkdir(actualDir, 0755)
Expand Down Expand Up @@ -152,10 +145,7 @@ func TestUnitDirs(t *testing.T) {
assert.Nil(t, err)
}

symLinkRecursiveTestBaseDir, err := os.MkdirTemp("", "podman-symlink-recursive-test")
assert.Nil(t, err)
// remove the temporary directory at the end of the program
defer os.RemoveAll(symLinkRecursiveTestBaseDir)
symLinkRecursiveTestBaseDir := t.TempDir()

expectedDirs := make([]string, 0)
// Create <BASE>/unitDir
Expand Down Expand Up @@ -214,9 +204,7 @@ func TestUnitDirs(t *testing.T) {
} else {
fmt.Println(os.Args)

symLinkTestBaseDir, err := os.MkdirTemp("", "podman-symlinktest2")
assert.Nil(t, err)
defer os.RemoveAll(symLinkTestBaseDir)
symLinkTestBaseDir := t.TempDir()
rootF, err := os.Open("/")
assert.Nil(t, err)
defer rootF.Close()
Expand Down
12 changes: 6 additions & 6 deletions libpod/events/logfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func TestRotateLog(t *testing.T) {
{1000, 600, 1500, true},
}

tmpDir := t.TempDir()
for _, test := range tests {
tmp, err := os.CreateTemp("", "log-rotation-")
tmp, err := os.CreateTemp(tmpDir, "log-rotation-")
require.NoError(t, err)
defer os.Remove(tmp.Name())
defer tmp.Close()

// Create dummy file and content.
Expand Down Expand Up @@ -80,9 +80,8 @@ func TestTruncationOutput(t *testing.T) {
10
`
// Create dummy file
tmp, err := os.CreateTemp("", "log-rotation")
tmp, err := os.CreateTemp(t.TempDir(), "log-rotation")
require.NoError(t, err)
defer os.Remove(tmp.Name())
defer tmp.Close()

// Write content before truncation to dummy file
Expand Down Expand Up @@ -114,10 +113,11 @@ func TestRenameLog(t *testing.T) {
4
5
`
tmpDir := t.TempDir()
// Create two dummy files
source, err := os.CreateTemp("", "removing")
source, err := os.CreateTemp(tmpDir, "removing")
require.NoError(t, err)
target, err := os.CreateTemp("", "renaming")
target, err := os.CreateTemp(tmpDir, "renaming")
require.NoError(t, err)

// Write to source dummy file
Expand Down
2 changes: 1 addition & 1 deletion libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/fs"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -44,7 +45,6 @@ import (
jsoniter "github.com/json-iterator/go"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
)

// Set up the JSON library for all of Libpod
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/compat/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"net"
"net/http"

Expand All @@ -18,7 +19,6 @@ import (
"github.com/containers/podman/v5/pkg/domain/entities"
"github.com/containers/podman/v5/pkg/domain/infra/abi"
"github.com/containers/podman/v5/pkg/util"
"golang.org/x/exp/maps"

dockerNetwork "github.com/docker/docker/api/types/network"
"github.com/sirupsen/logrus"
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/libpod/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"net/http"
"net/url"
"os"
Expand All @@ -33,7 +34,6 @@ import (
"github.com/gorilla/schema"
"github.com/opencontainers/go-digest"
"github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
)

func ManifestCreate(w http.ResponseWriter, r *http.Request) {
Expand Down
20 changes: 8 additions & 12 deletions pkg/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ var largeAuthFileValues = map[string]types.DockerAuthConfig{
// systemContextForAuthFile returns a types.SystemContext with AuthFilePath pointing
// to a temporary file with fileContents, or nil if fileContents is empty; and a cleanup
// function the caller must arrange to call.
func systemContextForAuthFile(t *testing.T, fileContents string) (*types.SystemContext, func()) {
func systemContextForAuthFile(t *testing.T, fileContents string) *types.SystemContext {
if fileContents == "" {
return nil, func() {}
return nil
}

f, err := os.CreateTemp("", "auth.json")
f, err := os.CreateTemp(t.TempDir(), "auth.json")
require.NoError(t, err)
path := f.Name()
err = os.WriteFile(path, []byte(fileContents), 0700)
require.NoError(t, err)
return &types.SystemContext{AuthFilePath: path}, func() { os.Remove(path) }
return &types.SystemContext{AuthFilePath: path}
}

// Test that GetCredentials() correctly parses what MakeXRegistryConfigHeader() produces
Expand Down Expand Up @@ -78,8 +78,7 @@ func TestMakeXRegistryConfigHeaderGetCredentialsRoundtrip(t *testing.T) {
expectedFileValues: largeAuthFileValues,
},
} {
sys, cleanup := systemContextForAuthFile(t, tc.fileContents)
defer cleanup()
sys := systemContextForAuthFile(t, tc.fileContents)
headers, err := MakeXRegistryConfigHeader(sys, tc.username, tc.password)
require.NoError(t, err)
req, err := http.NewRequest(http.MethodPost, "/", nil)
Expand Down Expand Up @@ -130,8 +129,7 @@ func TestMakeXRegistryAuthHeaderGetCredentialsRoundtrip(t *testing.T) {
expectedFileValues: largeAuthFileValues,
},
} {
sys, cleanup := systemContextForAuthFile(t, tc.fileContents)
defer cleanup()
sys := systemContextForAuthFile(t, tc.fileContents)
headers, err := MakeXRegistryAuthHeader(sys, tc.username, tc.password)
require.NoError(t, err)
req, err := http.NewRequest(http.MethodPost, "/", nil)
Expand Down Expand Up @@ -205,8 +203,7 @@ func TestMakeXRegistryConfigHeader(t *testing.T) {
}`,
},
} {
sys, cleanup := systemContextForAuthFile(t, tc.fileContents)
defer cleanup()
sys := systemContextForAuthFile(t, tc.fileContents)
res, err := MakeXRegistryConfigHeader(sys, tc.username, tc.password)
if tc.shouldErr {
assert.Error(t, err, tc.name)
Expand Down Expand Up @@ -268,8 +265,7 @@ func TestMakeXRegistryAuthHeader(t *testing.T) {
}`,
},
} {
sys, cleanup := systemContextForAuthFile(t, tc.fileContents)
defer cleanup()
sys := systemContextForAuthFile(t, tc.fileContents)
res, err := MakeXRegistryAuthHeader(sys, tc.username, tc.password)
if tc.shouldErr {
assert.Error(t, err, tc.name)
Expand Down
7 changes: 3 additions & 4 deletions pkg/ctime/ctime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import (
func TestCreated(t *testing.T) {
before := time.Now()

fileA, err := os.CreateTemp("", "ctime-test-")
tmpDir := t.TempDir()
fileA, err := os.CreateTemp(tmpDir, "ctime-test-")
if err != nil {
t.Error(err)
}
defer os.Remove(fileA.Name())

fileB, err := os.CreateTemp("", "ctime-test-")
fileB, err := os.CreateTemp(tmpDir, "ctime-test-")
if err != nil {
t.Error(err)
}
defer os.Remove(fileB.Name())

after := time.Now()

Expand Down
3 changes: 1 addition & 2 deletions pkg/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ package env
import (
"bufio"
"fmt"
"maps"
"os"
"strings"

"golang.org/x/exp/maps"
)

const whiteSpaces = " \t"
Expand Down
24 changes: 6 additions & 18 deletions pkg/machine/compression/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package compression

import (
"os"
"path/filepath"
"testing"

crcOs "github.com/crc-org/crc/v2/pkg/os"
Expand All @@ -11,39 +10,28 @@ import (
func TestCopyFile(t *testing.T) {
testStr := "test-machine"

srcFile, err := os.CreateTemp("", "machine-test-")
if err != nil {
t.Fatal(err)
}
srcFi, err := srcFile.Stat()
tmpDir := t.TempDir()

srcFile, err := os.CreateTemp(tmpDir, "machine-test-")
if err != nil {
t.Fatal(err)
}

_, _ = srcFile.Write([]byte(testStr)) //nolint:mirror
srcFile.Close()

srcFilePath := filepath.Join(os.TempDir(), srcFi.Name())

destFile, err := os.CreateTemp("", "machine-copy-test-")
if err != nil {
t.Fatal(err)
}

destFi, err := destFile.Stat()
destFile, err := os.CreateTemp(tmpDir, "machine-copy-test-")
if err != nil {
t.Fatal(err)
}

destFile.Close()

destFilePath := filepath.Join(os.TempDir(), destFi.Name())

if err := crcOs.CopyFile(srcFilePath, destFilePath); err != nil {
if err := crcOs.CopyFile(srcFile.Name(), destFile.Name()); err != nil {
t.Fatal(err)
}

data, err := os.ReadFile(destFilePath)
data, err := os.ReadFile(destFile.Name())
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 564b8f3

Please sign in to comment.