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: enable usetesting linter #21935

Merged
merged 1 commit into from
Feb 21, 2025
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
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ linters:
- unparam
- unused
- usestdlibvars
- usetesting
- whitespace
linters-settings:
gocritic:
Expand Down Expand Up @@ -149,5 +150,7 @@ linters-settings:
enable-all: true
disable:
- go-require
usetesting:
os-mkdir-temp: false
run:
timeout: 50m
5 changes: 2 additions & 3 deletions common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package common
import (
"context"
"fmt"
"os"
"strconv"
"testing"
"time"
Expand All @@ -29,7 +28,7 @@ func Test_GRPCKeepAliveMinNotSet(t *testing.T) {
// Test valid env var set for EnvGRPCKeepAliveMin
func Test_GRPCKeepAliveMinIsSet(t *testing.T) {
numSeconds := 15
os.Setenv(EnvGRPCKeepAliveMin, fmt.Sprintf("%ds", numSeconds))
t.Setenv(EnvGRPCKeepAliveMin, fmt.Sprintf("%ds", numSeconds))

grpcKeepAliveMin := GetGRPCKeepAliveEnforcementMinimum()
grpcKeepAliveExpectedMin := time.Duration(numSeconds) * time.Second
Expand All @@ -42,7 +41,7 @@ func Test_GRPCKeepAliveMinIsSet(t *testing.T) {
// Test invalid env var set for EnvGRPCKeepAliveMin
func Test_GRPCKeepAliveMinIncorrectlySet(t *testing.T) {
numSeconds := 15
os.Setenv(EnvGRPCKeepAliveMin, strconv.Itoa(numSeconds))
t.Setenv(EnvGRPCKeepAliveMin, strconv.Itoa(numSeconds))

grpcKeepAliveMin := GetGRPCKeepAliveEnforcementMinimum()
grpcKeepAliveExpectedMin := defaultGRPCKeepAliveEnforcementMinimum
Expand Down
2 changes: 1 addition & 1 deletion reposerver/metrics/githandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestEdgeCasesAndErrorHandling(t *testing.T) {
}

func TestSemaphoreFunctionality(t *testing.T) {
os.Setenv("ARGOCD_GIT_LSREMOTE_PARALLELISM_LIMIT", "1")
t.Setenv("ARGOCD_GIT_LSREMOTE_PARALLELISM_LIMIT", "1")

tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion reposerver/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ func TestGenerateHelmWithValuesDirectoryTraversalOutsideRepo(t *testing.T) {
func TestGenerateHelmWithAbsoluteFileParameter(t *testing.T) {
service := newService(t, "../..")

file, err := os.CreateTemp("", "external-secret.txt")
file, err := os.CreateTemp(t.TempDir(), "external-secret.txt")
require.NoError(t, err)
externalSecretPath := file.Name()
defer func() { _ = os.RemoveAll(externalSecretPath) }()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app_management_ns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ metadata:
`
s := fmt.Sprintf(existingNs, updatedNamespace)

tmpFile, err := os.CreateTemp("", "")
tmpFile, err := os.CreateTemp(t.TempDir(), "")
errors.CheckError(err)
_, err = tmpFile.Write([]byte(s))
errors.CheckError(err)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,14 +916,14 @@ func EnsureCleanState(t *testing.T, opts ...TestOption) {
return err
}
prevGnuPGHome := os.Getenv("GNUPGHOME")
os.Setenv("GNUPGHOME", TmpDir+"/gpg")
t.Setenv("GNUPGHOME", TmpDir+"/gpg")
//nolint:errcheck
Run("", "pkill", "-9", "gpg-agent")
_, err = Run("", "gpg", "--import", "../fixture/gpg/signingkey.asc")
if err != nil {
return err
}
os.Setenv("GNUPGHOME", prevGnuPGHome)
t.Setenv("GNUPGHOME", prevGnuPGHome)

// recreate GPG directories
if IsLocal() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func TestHelmRepoDiffLocal(t *testing.T) {
Expect(HealthIs(health.HealthStatusHealthy)).
Expect(SyncStatusIs(SyncStatusCodeSynced)).
And(func(app *Application) {
_ = os.Setenv("XDG_CONFIG_HOME", helmTmp)
t.Setenv("XDG_CONFIG_HOME", helmTmp)
FailOnErr(fixture.Run("", "helm", "repo", "add", "custom-repo", fixture.GetEnvWithDefault("ARGOCD_E2E_HELM_SERVICE", fixture.RepoURL(fixture.RepoURLTypeHelm)),
"--username", fixture.GitUsername,
"--password", fixture.GitPassword,
Expand Down
3 changes: 1 addition & 2 deletions util/db/gpgkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package db

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -258,7 +257,7 @@ func Test_AddGPGPublicKey(t *testing.T) {
}

func Test_DeleteGPGPublicKey(t *testing.T) {
defer os.Setenv("GNUPGHOME", "")
defer t.Setenv("GNUPGHOME", "")

t.Run("good case", func(t *testing.T) {
clientset := getGPGKeysClientset(gpgCMMultiGoodPubkey)
Expand Down
2 changes: 1 addition & 1 deletion util/gpg/gpg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func Test_GPG_InitializeGnuPG(t *testing.T) {
assert.Equal(t, "ultimate", keys[0].Trust)

t.Run("GNUPGHOME is a file", func(t *testing.T) {
f, err := os.CreateTemp("", "gpg-test")
f, err := os.CreateTemp(t.TempDir(), "gpg-test")
require.NoError(t, err)
defer os.Remove(f.Name())

Expand Down
2 changes: 1 addition & 1 deletion util/profile/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestRegisterProfile_FileExist(t *testing.T) {
srv := httptest.NewServer(mux)
defer srv.Close()

f, err := os.CreateTemp("", "test")
f, err := os.CreateTemp(t.TempDir(), "test")
require.NoError(t, err)
_, err = f.WriteString("true")
require.NoError(t, err)
Expand Down
Loading