Skip to content

Commit fe09410

Browse files
authored
chore: replace deprecated tenv linter with usetesting (#8504)
1 parent e5072f1 commit fe09410

File tree

150 files changed

+366
-509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+366
-509
lines changed

.golangci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ linters:
114114
- misspell
115115
- perfsprint
116116
- revive
117-
- tenv
117+
- usetesting
118118
- testifylint
119119
- typecheck
120120
- unconvert

pkg/attestation/sbom/rekor_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package sbom_test
22

33
import (
4-
"context"
54
"testing"
65

76
"github.com/stretchr/testify/assert"
@@ -41,7 +40,7 @@ func TestRekor_RetrieveSBOM(t *testing.T) {
4140
rc, err := sbom.NewRekor(ts.URL())
4241
require.NoError(t, err)
4342

44-
got, err := rc.RetrieveSBOM(context.Background(), tt.digest)
43+
got, err := rc.RetrieveSBOM(t.Context(), tt.digest)
4544
if tt.wantErr != "" {
4645
assert.ErrorContains(t, err, tt.wantErr)
4746
return

pkg/commands/auth/run_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package auth_test
22

33
import (
4-
"context"
54
"os"
65
"path/filepath"
76
"strings"
@@ -103,7 +102,7 @@ func TestLogin(t *testing.T) {
103102
t.Setenv("DOCKER_CONFIG", filepath.Join(t.TempDir(), "config.json"))
104103

105104
reg := lo.Ternary(tt.args.registry == "", strings.TrimPrefix(tr.URL, "http://"), tt.args.registry)
106-
err := auth.Login(context.Background(), reg, tt.args.opts)
105+
err := auth.Login(t.Context(), reg, tt.args.opts)
107106
if tt.wantErr != "" {
108107
require.ErrorContains(t, err, tt.wantErr)
109108
return
@@ -124,19 +123,19 @@ func TestLogout(t *testing.T) {
124123
err := os.WriteFile(configFile, []byte(`{"auths": {"auth.test": {"auth": "dXNlcjpwYXNz"}}}`), 0600)
125124
require.NoError(t, err)
126125

127-
err = auth.Logout(context.Background(), "auth.test")
126+
err = auth.Logout(t.Context(), "auth.test")
128127
require.NoError(t, err)
129128
b, err := os.ReadFile(configFile)
130129
require.NoError(t, err)
131130
require.JSONEq(t, `{"auths": {}}`, string(b))
132131
})
133132
t.Run("not found", func(t *testing.T) {
134-
err := auth.Logout(context.Background(), "notfound.test")
133+
err := auth.Logout(t.Context(), "notfound.test")
135134
require.NoError(t, err) // Return an error if "credsStore" is "osxkeychain".
136135
})
137136

138137
t.Run("invalid registry", func(t *testing.T) {
139-
err := auth.Logout(context.Background(), "aaa://invalid.test")
138+
err := auth.Logout(t.Context(), "aaa://invalid.test")
140139
require.ErrorContains(t, err, "registries must be valid RFC 3986 URI authorities")
141140
})
142141
}

pkg/commands/clean/run_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package clean_test
22

33
import (
4-
"context"
54
"os"
65
"path/filepath"
76
"testing"
@@ -130,7 +129,7 @@ func TestRun(t *testing.T) {
130129
CleanOptions: tt.cleanOpts,
131130
}
132131

133-
err := clean.Run(context.Background(), opts)
132+
err := clean.Run(t.Context(), opts)
134133

135134
if tt.wantErr {
136135
assert.Error(t, err)

pkg/compliance/report/table_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package report_test
22

33
import (
44
"bytes"
5-
"context"
65
"os"
76
"path/filepath"
87
"testing"
@@ -73,7 +72,7 @@ func TestTableWriter_Write(t *testing.T) {
7372
Report: tt.reportType,
7473
Output: buf,
7574
}
76-
err := tr.Write(context.Background(), tt.input)
75+
err := tr.Write(t.Context(), tt.input)
7776
require.NoError(t, err)
7877

7978
want, err := os.ReadFile(tt.want)

pkg/db/db_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package db_test
22

33
import (
4-
"context"
54
"fmt"
65
"testing"
76
"time"
@@ -147,7 +146,7 @@ func TestClient_NeedsUpdate(t *testing.T) {
147146
}
148147

149148
// Set a fake time
150-
ctx := clock.With(context.Background(), time.Date(2019, 10, 1, 0, 0, 0, 0, time.UTC))
149+
ctx := clock.With(t.Context(), time.Date(2019, 10, 1, 0, 0, 0, 0, time.UTC))
151150

152151
client := db.NewClient(dbDir, true)
153152
needsUpdate, err := client.NeedsUpdate(ctx, "test", tt.skip)
@@ -191,7 +190,7 @@ func TestClient_Download(t *testing.T) {
191190
for _, tt := range tests {
192191
t.Run(tt.name, func(t *testing.T) {
193192
// Set a fake time
194-
ctx := clock.With(context.Background(), time.Date(2019, 10, 1, 0, 0, 0, 0, time.UTC))
193+
ctx := clock.With(t.Context(), time.Date(2019, 10, 1, 0, 0, 0, 0, time.UTC))
195194

196195
// Fake DB
197196
art := dbtest.NewFakeDB(t, tt.input, dbtest.FakeDBOptions{})

pkg/detector/ospkg/alma/alma_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package alma_test
22

33
import (
4-
"context"
54
"testing"
65
"time"
76

@@ -215,7 +214,7 @@ func TestScanner_IsSupportedVersion(t *testing.T) {
215214
}
216215
for _, tt := range tests {
217216
t.Run(tt.name, func(t *testing.T) {
218-
ctx := clock.With(context.Background(), tt.now)
217+
ctx := clock.With(t.Context(), tt.now)
219218
s := alma.NewScanner()
220219
got := s.IsSupportedVersion(ctx, tt.args.osFamily, tt.args.osVer)
221220
assert.Equal(t, tt.want, got)

pkg/detector/ospkg/alpine/alpine_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package alpine_test
22

33
import (
4-
"context"
54
"sort"
65
"testing"
76
"time"
@@ -326,7 +325,7 @@ func TestScanner_IsSupportedVersion(t *testing.T) {
326325
}
327326
for _, tt := range tests {
328327
t.Run(tt.name, func(t *testing.T) {
329-
ctx := clock.With(context.Background(), tt.now)
328+
ctx := clock.With(t.Context(), tt.now)
330329
s := alpine.NewScanner()
331330
got := s.IsSupportedVersion(ctx, tt.args.osFamily, tt.args.osVer)
332331
assert.Equal(t, tt.want, got)

pkg/detector/ospkg/amazon/amazon_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package amazon_test
22

33
import (
4-
"context"
54
"testing"
65
"time"
76

@@ -248,7 +247,7 @@ func TestScanner_IsSupportedVersion(t *testing.T) {
248247
}
249248
for _, tt := range tests {
250249
t.Run(tt.name, func(t *testing.T) {
251-
ctx := clock.With(context.Background(), tt.now)
250+
ctx := clock.With(t.Context(), tt.now)
252251
s := amazon.NewScanner()
253252
got := s.IsSupportedVersion(ctx, tt.args.osFamily, tt.args.osVer)
254253
assert.Equal(t, tt.want, got)

pkg/detector/ospkg/debian/debian_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package debian_test
22

33
import (
4-
"context"
54
"sort"
65
"testing"
76
"time"
@@ -172,7 +171,7 @@ func TestScanner_IsSupportedVersion(t *testing.T) {
172171
}
173172
for _, tt := range tests {
174173
t.Run(tt.name, func(t *testing.T) {
175-
ctx := clock.With(context.Background(), tt.now)
174+
ctx := clock.With(t.Context(), tt.now)
176175
s := debian.NewScanner()
177176
got := s.IsSupportedVersion(ctx, tt.args.osFamily, tt.args.osVer)
178177
assert.Equal(t, tt.want, got)

pkg/detector/ospkg/oracle/oracle_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package oracle
22

33
import (
4-
"context"
54
"testing"
65
"time"
76

@@ -83,7 +82,7 @@ func TestScanner_IsSupportedVersion(t *testing.T) {
8382
for testName, tt := range tests {
8483
s := NewScanner()
8584
t.Run(testName, func(t *testing.T) {
86-
ctx := clock.With(context.Background(), tt.now)
85+
ctx := clock.With(t.Context(), tt.now)
8786
actual := s.IsSupportedVersion(ctx, tt.osFamily, tt.osVersion)
8887
if actual != tt.expected {
8988
t.Errorf("[%s] got %v, want %v", testName, actual, tt.expected)

pkg/detector/ospkg/photon/photon_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package photon_test
22

33
import (
4-
"context"
54
"testing"
65
"time"
76

@@ -147,7 +146,7 @@ func TestScanner_IsSupportedVersion(t *testing.T) {
147146
}
148147
for _, tt := range tests {
149148
t.Run(tt.name, func(t *testing.T) {
150-
ctx := clock.With(context.Background(), tt.now)
149+
ctx := clock.With(t.Context(), tt.now)
151150
s := photon.NewScanner()
152151
got := s.IsSupportedVersion(ctx, tt.args.osFamily, tt.args.osVer)
153152
assert.Equal(t, tt.want, got)

pkg/detector/ospkg/redhat/redhat_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package redhat_test
22

33
import (
4-
"context"
54
"os"
65
"testing"
76
"time"
@@ -494,7 +493,7 @@ func TestScanner_IsSupportedVersion(t *testing.T) {
494493
}
495494
for _, tt := range tests {
496495
t.Run(tt.name, func(t *testing.T) {
497-
ctx := clock.With(context.Background(), tt.now)
496+
ctx := clock.With(t.Context(), tt.now)
498497
s := redhat.NewScanner()
499498
got := s.IsSupportedVersion(ctx, tt.args.osFamily, tt.args.osVer)
500499
assert.Equal(t, tt.want, got)

pkg/detector/ospkg/rocky/rocky_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package rocky_test
22

33
import (
4-
"context"
54
"testing"
65
"time"
76

@@ -175,7 +174,7 @@ func TestScanner_IsSupportedVersion(t *testing.T) {
175174
}
176175
for _, tt := range tests {
177176
t.Run(tt.name, func(t *testing.T) {
178-
ctx := clock.With(context.Background(), tt.now)
177+
ctx := clock.With(t.Context(), tt.now)
179178
s := rocky.NewScanner()
180179
got := s.IsSupportedVersion(ctx, tt.args.osFamily, tt.args.osVer)
181180
assert.Equal(t, tt.want, got)

pkg/detector/ospkg/suse/suse_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package suse_test
22

33
import (
4-
"context"
54
"testing"
65
"time"
76

@@ -283,7 +282,7 @@ func TestScanner_IsSupportedVersion(t *testing.T) {
283282
}
284283
for _, tt := range tests {
285284
t.Run(tt.name, func(t *testing.T) {
286-
ctx := clock.With(context.Background(), tt.now)
285+
ctx := clock.With(t.Context(), tt.now)
287286
s := suse.NewScanner(tt.distribution)
288287
got := s.IsSupportedVersion(ctx, tt.args.osFamily, tt.args.osVer)
289288
assert.Equal(t, tt.want, got)

pkg/detector/ospkg/ubuntu/ubuntu_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ubuntu_test
22

33
import (
4-
"context"
54
"sort"
65
"testing"
76
"time"
@@ -253,7 +252,7 @@ func TestScanner_IsSupportedVersion(t *testing.T) {
253252
}
254253
for _, tt := range tests {
255254
t.Run(tt.name, func(t *testing.T) {
256-
ctx := clock.With(context.Background(), tt.now)
255+
ctx := clock.With(t.Context(), tt.now)
257256
s := ubuntu.NewScanner()
258257
got := s.IsSupportedVersion(ctx, tt.args.osFamily, tt.args.osVer)
259258
assert.Equal(t, tt.want, got)

pkg/downloader/downloader_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package downloader_test
22

33
import (
4-
"context"
54
"net/http"
65
"net/http/httptest"
76
"os"
@@ -44,7 +43,7 @@ func TestDownload(t *testing.T) {
4443
dst := t.TempDir()
4544

4645
// Execute the download
47-
_, err := downloader.Download(context.Background(), server.URL, dst, "", downloader.Options{
46+
_, err := downloader.Download(t.Context(), server.URL, dst, "", downloader.Options{
4847
Insecure: tt.insecure,
4948
})
5049

pkg/fanal/analyzer/analyzer_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package analyzer_test
22

33
import (
4-
"context"
54
"os"
65
"sync"
76
"testing"
@@ -529,7 +528,7 @@ func TestAnalyzerGroup_AnalyzeFile(t *testing.T) {
529528
info, err := os.Stat(tt.args.testFilePath)
530529
require.NoError(t, err)
531530

532-
ctx := context.Background()
531+
ctx := t.Context()
533532
err = a.AnalyzeFile(ctx, &wg, limit, got, "", tt.args.filePath, info,
534533
func() (xio.ReadSeekCloserAt, error) {
535534
if tt.args.testFilePath == "testdata/error" {
@@ -625,7 +624,7 @@ func TestAnalyzerGroup_PostAnalyze(t *testing.T) {
625624
javadb.Init("./language/java/jar/testdata", []name.Reference{repo}, true, false, types.RegistryOptions{Insecure: false})
626625
}
627626

628-
ctx := context.Background()
627+
ctx := t.Context()
629628
got := new(analyzer.AnalysisResult)
630629
err = a.PostAnalyze(ctx, composite, got, analyzer.AnalysisOptions{})
631630
require.NoError(t, err)

pkg/fanal/analyzer/buildinfo/content_manifest_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package buildinfo
22

33
import (
4-
"context"
54
"os"
65
"testing"
76

@@ -49,7 +48,7 @@ func Test_contentManifestAnalyzer_Analyze(t *testing.T) {
4948
defer f.Close()
5049

5150
a := contentManifestAnalyzer{}
52-
got, err := a.Analyze(context.Background(), analyzer.AnalysisInput{
51+
got, err := a.Analyze(t.Context(), analyzer.AnalysisInput{
5352
FilePath: tt.input,
5453
Content: f,
5554
})

pkg/fanal/analyzer/buildinfo/dockerfile_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package buildinfo
22

33
import (
4-
"context"
54
"os"
65
"testing"
76

@@ -52,7 +51,7 @@ func Test_dockerfileAnalyzer_Analyze(t *testing.T) {
5251
defer f.Close()
5352

5453
a := dockerfileAnalyzer{}
55-
got, err := a.Analyze(context.Background(), analyzer.AnalysisInput{
54+
got, err := a.Analyze(t.Context(), analyzer.AnalysisInput{
5655
FilePath: tt.inputFile,
5756
Content: f,
5857
})

pkg/fanal/analyzer/config/config_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config_test
22

33
import (
4-
"context"
54
"os"
65
"testing"
76

@@ -94,7 +93,7 @@ func TestAnalyzer_PostAnalyze(t *testing.T) {
9493
a, err := config.NewAnalyzer(tt.fields.typ, 0, tt.fields.fileType, tt.fields.opts)
9594
require.NoError(t, err)
9695

97-
got, err := a.PostAnalyze(context.Background(), analyzer.PostAnalysisInput{
96+
got, err := a.PostAnalyze(t.Context(), analyzer.PostAnalysisInput{
9897
FS: os.DirFS(tt.dir),
9998
})
10099
if tt.wantErr != "" {

pkg/fanal/analyzer/config_analyzer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func TestAnalyzeConfig(t *testing.T) {
116116
DisabledAnalyzers: tt.args.disabledAnalyzers,
117117
})
118118
require.NoError(t, err)
119-
got := a.AnalyzeImageConfig(context.Background(), tt.args.targetOS, tt.args.config)
119+
got := a.AnalyzeImageConfig(t.Context(), tt.args.targetOS, tt.args.config)
120120
assert.Equal(t, tt.want, got)
121121
})
122122
}

0 commit comments

Comments
 (0)