Skip to content

Commit

Permalink
golangci-lint: enable copyloopvar & address issues
Browse files Browse the repository at this point in the history
Add the copyloopvar linter, which enforces not creating explicit copies
of the for loop iterator variable, which is no longer necessary as of
Go 1.22.

Signed-off-by: Carlo Teubner <[email protected]>
  • Loading branch information
c4rlo committed Jan 17, 2025
1 parent 23b5243 commit 53b30d2
Show file tree
Hide file tree
Showing 111 changed files with 1 addition and 277 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ linters:
- intrange
- whitespace
- gocritic
- copyloopvar
- wastedassign
- nolintlint

Expand Down
8 changes: 0 additions & 8 deletions cmd/spire-agent/cli/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ func TestDownloadTrustBundle(t *testing.T) {
}

for _, testCase := range cases {
testCase := testCase

t.Run(testCase.msg, func(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -629,8 +627,6 @@ func TestMergeInput(t *testing.T) {
cases = append(cases, mergeInputCasesOS()...)

for _, testCase := range cases {
testCase := testCase

fileInput := &Config{Agent: &agentConfig{}}
cliInput := &agentConfig{}

Expand Down Expand Up @@ -1042,8 +1038,6 @@ func TestNewAgentConfig(t *testing.T) {
}
cases = append(cases, newAgentConfigCasesOS(t)...)
for _, testCase := range cases {
testCase := testCase

input := defaultValidConfig()

testCase.input(input)
Expand Down Expand Up @@ -1206,8 +1200,6 @@ func TestWarnOnUnknownConfig(t *testing.T) {
}

for _, testCase := range cases {
testCase := testCase

c, err := ParseFile(filepath.Join(testFileDir, testCase.confFile), false)
require.NoError(t, err)

Expand Down
1 change: 0 additions & 1 deletion cmd/spire-server/cli/entry/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestParseEntryJSON(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
p := testCase.testDataPath

Expand Down
1 change: 0 additions & 1 deletion cmd/spire-server/cli/logger/printers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Launch Level : info
expectedError: errors.New("internal error: unexpected type *types.Entry returned; please report this as a bug"),
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
tt.env = &commoncli.Env{
Stdout: &tt.outWriter,
Expand Down
8 changes: 0 additions & 8 deletions cmd/spire-server/cli/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,6 @@ func TestMergeInput(t *testing.T) {
cases = append(cases, mergeInputCasesOS(t)...)

for _, testCase := range cases {
testCase := testCase

fileInput := &Config{Server: &serverConfig{}}

testCase.fileInput(fileInput)
Expand Down Expand Up @@ -1213,8 +1211,6 @@ func TestNewServerConfig(t *testing.T) {
cases = append(cases, newServerConfigCasesOS(t)...)

for _, testCase := range cases {
testCase := testCase

input := defaultValidConfig()

testCase.input(input)
Expand Down Expand Up @@ -1337,7 +1333,6 @@ func TestValidateConfig(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
conf := defaultValidConfig()
testCase.applyConf(conf)
Expand Down Expand Up @@ -1550,8 +1545,6 @@ func TestWarnOnUnknownConfig(t *testing.T) {
}

for _, testCase := range cases {
testCase := testCase

c, err := ParseFile(filepath.Join(testFileDir, testCase.confFile), false)
require.NoError(t, err)

Expand Down Expand Up @@ -1759,7 +1752,6 @@ func TestHasCompatibleTTLs(t *testing.T) {
}

for _, testCase := range cases {
testCase := testCase
if testCase.caTTL == 0 {
testCase.caTTL = credtemplate.DefaultX509CATTL
}
Expand Down
1 change: 0 additions & 1 deletion pkg/agent/api/debug/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func TestGetInfo(t *testing.T) {
err: "failed to verify agent SVID: x509svid: could not get leaf SPIFFE ID: certificate contains no URI SAN",
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
test := setupServiceTest(t)
defer test.Cleanup()
Expand Down
4 changes: 0 additions & 4 deletions pkg/agent/api/delegatedidentity/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ func TestSubscribeToX509SVIDs(t *testing.T) {
expectMetrics: generateSubscribeToX509SVIDMetrics(),
},
} {
tt := tt
t.Run(tt.testName, func(t *testing.T) {
metrics := fakemetrics.New()
params := testParams{
Expand Down Expand Up @@ -423,7 +422,6 @@ func TestSubscribeToX509Bundles(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.testName, func(t *testing.T) {
params := testParams{
CA: ca,
Expand Down Expand Up @@ -663,7 +661,6 @@ func TestFetchJWTSVIDs(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.testName, func(t *testing.T) {
params := testParams{
CA: ca,
Expand Down Expand Up @@ -764,7 +761,6 @@ func TestSubscribeToJWTBundles(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.testName, func(t *testing.T) {
params := testParams{
CA: ca,
Expand Down
1 change: 0 additions & 1 deletion pkg/agent/api/health/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func TestServiceCheck(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
log, logHook := test.NewNullLogger()

Expand Down
3 changes: 0 additions & 3 deletions pkg/agent/attestor/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ func TestAttestor(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
require := require.New(t)

Expand Down Expand Up @@ -527,7 +525,6 @@ func TestIsSVIDExpired(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.Desc, func(t *testing.T) {
isExpired := attestor.IsSVIDExpired(tt.SVID, func() time.Time { return now })
require.Equal(t, tt.ExpectExpired, isExpired)
Expand Down
3 changes: 0 additions & 3 deletions pkg/agent/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ func TestRenewSVID(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
logHook.Reset()
tc.agentServer.err = tt.agentErr
Expand Down Expand Up @@ -757,7 +756,6 @@ func TestFetchUpdatesReleaseConnectionIfItFailsToFetch(t *testing.T) {
err: "failed to fetch bundle: rpc error: code = Unknown desc = an error",
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
client, tc := createClient(t)
tt.setupTest(tc)
Expand Down Expand Up @@ -969,7 +967,6 @@ func TestFetchJWTSVID(t *testing.T) {
fetchErr: status.Error(codes.Internal, "NewJWTSVID fails"),
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
tt.setupTest(tt.fetchErr)
resp, err := client.NewJWTSVID(ctx, "entry-id", []string{"myAud"})
Expand Down
1 change: 0 additions & 1 deletion pkg/agent/common/sigstore/sigstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ func TestVerify(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion pkg/agent/endpoints/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func TestEndpoints(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
log, hook := test.NewNullLogger()
metrics := fakemetrics.New()
Expand Down
5 changes: 0 additions & 5 deletions pkg/agent/endpoints/workload/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ func TestFetchX509SVID(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
params := testParams{
CA: ca,
Expand Down Expand Up @@ -425,7 +424,6 @@ func TestFetchX509Bundles(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.testName, func(t *testing.T) {
params := testParams{
CA: ca,
Expand Down Expand Up @@ -837,7 +835,6 @@ func TestFetchJWTSVID(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
params := testParams{
CA: ca,
Expand Down Expand Up @@ -1042,7 +1039,6 @@ func TestFetchJWTBundles(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
params := testParams{
CA: ca,
Expand Down Expand Up @@ -1476,7 +1472,6 @@ func TestValidateJWTSVID(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
params := testParams{
Updates: tt.updates,
Expand Down
1 change: 0 additions & 1 deletion pkg/agent/manager/cache/jwt_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ func TestJWTSVIDCache(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
cache := NewJWTSVIDCache(log, fakeMetrics, 8)
if tt.setJWTSVIDsCached != nil {
Expand Down
2 changes: 0 additions & 2 deletions pkg/agent/manager/storecache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,6 @@ func TestUpdateEntries(t *testing.T) {
},
},
} {
tt := tt

t.Run(tt.name, func(t *testing.T) {
log, hook := test.NewNullLogger()
log.Level = logrus.DebugLevel
Expand Down
1 change: 0 additions & 1 deletion pkg/agent/plugin/keymanager/test/keymanagertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ func assertRSAKey(t *testing.T, key keymanager.Key, bits int) {

func testSignCertificates(t *testing.T, key keymanager.Key, signatureAlgorithms []x509.SignatureAlgorithm) {
for _, signatureAlgorithm := range signatureAlgorithms {
signatureAlgorithm := signatureAlgorithm
t.Run("sign data "+signatureAlgorithm.String(), func(t *testing.T) {
assertSignCertificate(t, key, signatureAlgorithm)
})
Expand Down
4 changes: 0 additions & 4 deletions pkg/agent/plugin/keymanager/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func TestV1GenerateKey(t *testing.T) {
expectCode: codes.OK,
},
} {
tt := tt
t.Run(tt.test, func(t *testing.T) {
plugin := fakeV1Plugin{
generateKeyResponse: &keymanagerv1.GenerateKeyResponse{
Expand Down Expand Up @@ -137,7 +136,6 @@ func TestV1GetKey(t *testing.T) {
expectCode: codes.OK,
},
} {
tt := tt
t.Run(tt.test, func(t *testing.T) {
plugin := fakeV1Plugin{
getPublicKeyResponse: &keymanagerv1.GetPublicKeyResponse{
Expand Down Expand Up @@ -194,7 +192,6 @@ func TestV1GetKeys(t *testing.T) {
expectCode: codes.OK,
},
} {
tt := tt
t.Run(tt.test, func(t *testing.T) {
resp := &keymanagerv1.GetPublicKeysResponse{}
if tt.publicKey != nil {
Expand Down Expand Up @@ -291,7 +288,6 @@ func TestV1SignData(t *testing.T) {
expectCode: codes.OK,
},
} {
tt := tt
t.Run(tt.test, func(t *testing.T) {
plugin := fakeV1Plugin{
expectSignerOpts: tt.expectSignerOpts,
Expand Down
1 change: 0 additions & 1 deletion pkg/agent/plugin/nodeattestor/gcpiit/iit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func TestRetrieveIdentity(t *testing.T) {
}

for _, tt := range tests {
tt := tt // alias loop variable as it is used in the closure
t.Run(tt.msg, func(t *testing.T) {
url := tt.url
if tt.handleFunc != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func TestConfigureCommon(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
plugin := newPlugin()

Expand Down Expand Up @@ -85,7 +84,6 @@ func TestAidAttestationFailures(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
var err error
p := loadAndConfigurePlugin(t, tt.trustDomain, tt.config)
Expand Down Expand Up @@ -194,7 +192,6 @@ func TestAidAttestationSucceeds(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
var err error
expectPayload, err := json.Marshal(&tt.attestationData)
Expand Down
4 changes: 0 additions & 4 deletions pkg/agent/plugin/nodeattestor/tpmdevid/devid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func TestConfigureCommon(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
tpmdevid.AutoDetectTPMPath = func(string) (string, error) {
if isWindows {
Expand Down Expand Up @@ -265,7 +264,6 @@ func TestConfigurePosix(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
tpmdevid.AutoDetectTPMPath = func(string) (string, error) {
if tt.autoDetectTPMFails {
Expand Down Expand Up @@ -359,7 +357,6 @@ func TestConfigureWindows(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
tpmdevid.AutoDetectTPMPath = func(string) (string, error) {
return "", errors.New("autodetect is not supported on windows")
Expand Down Expand Up @@ -477,7 +474,6 @@ func TestAidAttestationFailures(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
sim := setupSimulator(t)

Expand Down
Loading

0 comments on commit 53b30d2

Please sign in to comment.