chore: fix unused parameter lint in new golangcilint version

This commit is contained in:
Malte Poll 2024-02-21 13:30:31 +01:00
parent 68fc2b0811
commit 65903459a0
35 changed files with 92 additions and 92 deletions

View File

@ -29,7 +29,7 @@ type CloudKubeAPIWaiter struct{}
// Wait waits for the Kubernetes API to be available.
// Note that the kubernetesClient must have the kubeconfig already set.
func (w *CloudKubeAPIWaiter) Wait(ctx context.Context, kubernetesClient KubernetesClient) error {
funcAlwaysRetriable := func(err error) bool { return true }
funcAlwaysRetriable := func(_ error) bool { return true }
doer := &kubeDoer{kubeClient: kubernetesClient}
retrier := retry.NewIntervalRetrier(doer, 5*time.Second, funcAlwaysRetriable)

View File

@ -54,7 +54,7 @@ func TestTFPlan(t *testing.T) {
wantBackup: true,
},
"workspace is empty": {
prepareFs: func(require *require.Assertions) file.Handler {
prepareFs: func(_ *require.Assertions) file.Handler {
return file.NewHandler(afero.NewMemMapFs())
},
tf: &stubUpgradePlanner{},

View File

@ -238,7 +238,7 @@ func TestSkipPhases(t *testing.T) {
}
func TestValidateInputs(t *testing.T) {
defaultConfig := func(csp cloudprovider.Provider) func(require *require.Assertions, fh file.Handler) {
defaultConfig := func(csp cloudprovider.Provider) func(require *require.Assertions, _ file.Handler) {
return func(require *require.Assertions, fh file.Handler) {
cfg := defaultConfigWithExpectedMeasurements(t, config.Default(), csp)
@ -261,7 +261,7 @@ func TestValidateInputs(t *testing.T) {
require.NoError(fh.WriteYAML(constants.ConfigFilename, cfg))
}
}
preInitState := func(csp cloudprovider.Provider) func(require *require.Assertions, fh file.Handler) {
preInitState := func(csp cloudprovider.Provider) func(_ *require.Assertions, _ file.Handler) {
return func(require *require.Assertions, fh file.Handler) {
stateFile := defaultStateFile(csp)
stateFile.ClusterValues = state.ClusterValues{}
@ -332,7 +332,7 @@ func TestValidateInputs(t *testing.T) {
wantPhases: newPhases(skipInitPhase, skipImagePhase), // No image upgrades on QEMU
},
"no config file errors": {
createConfig: func(require *require.Assertions, fh file.Handler) {},
createConfig: func(_ *require.Assertions, _ file.Handler) {},
createState: postInitState(cloudprovider.GCP),
createMasterSecret: defaultMasterSecret,
createAdminConfig: defaultAdminConfig,
@ -344,7 +344,7 @@ func TestValidateInputs(t *testing.T) {
createConfig: defaultConfig(cloudprovider.GCP),
createState: preInitState(cloudprovider.GCP),
createMasterSecret: defaultMasterSecret,
createAdminConfig: func(require *require.Assertions, fh file.Handler) {},
createAdminConfig: func(_ *require.Assertions, _ file.Handler) {},
createTfState: defaultTfState,
flags: applyFlags{},
wantErr: true,
@ -352,8 +352,8 @@ func TestValidateInputs(t *testing.T) {
"[init] no admin config file, no master secret": {
createConfig: defaultConfig(cloudprovider.GCP),
createState: preInitState(cloudprovider.GCP),
createMasterSecret: func(require *require.Assertions, fh file.Handler) {},
createAdminConfig: func(require *require.Assertions, fh file.Handler) {},
createMasterSecret: func(_ *require.Assertions, _ file.Handler) {},
createAdminConfig: func(_ *require.Assertions, _ file.Handler) {},
createTfState: defaultTfState,
flags: applyFlags{},
wantPhases: newPhases(skipImagePhase, skipK8sPhase),
@ -363,16 +363,16 @@ func TestValidateInputs(t *testing.T) {
createState: preInitState(cloudprovider.GCP),
createMasterSecret: defaultMasterSecret,
createAdminConfig: defaultAdminConfig,
createTfState: func(require *require.Assertions, fh file.Handler) {},
createTfState: func(_ *require.Assertions, _ file.Handler) {},
flags: applyFlags{},
wantErr: true,
},
"[create] only config, skip everything but infrastructure": {
createConfig: defaultConfig(cloudprovider.GCP),
createState: func(require *require.Assertions, fh file.Handler) {},
createMasterSecret: func(require *require.Assertions, fh file.Handler) {},
createAdminConfig: func(require *require.Assertions, fh file.Handler) {},
createTfState: func(require *require.Assertions, fh file.Handler) {},
createState: func(_ *require.Assertions, _ file.Handler) {},
createMasterSecret: func(_ *require.Assertions, _ file.Handler) {},
createAdminConfig: func(_ *require.Assertions, _ file.Handler) {},
createTfState: func(_ *require.Assertions, _ file.Handler) {},
flags: applyFlags{
skipPhases: newPhases(skipInitPhase, skipAttestationConfigPhase, skipCertSANsPhase, skipHelmPhase, skipK8sPhase, skipImagePhase),
},
@ -380,19 +380,19 @@ func TestValidateInputs(t *testing.T) {
},
"[create + init] only config file": {
createConfig: defaultConfig(cloudprovider.GCP),
createState: func(require *require.Assertions, fh file.Handler) {},
createMasterSecret: func(require *require.Assertions, fh file.Handler) {},
createAdminConfig: func(require *require.Assertions, fh file.Handler) {},
createTfState: func(require *require.Assertions, fh file.Handler) {},
createState: func(_ *require.Assertions, _ file.Handler) {},
createMasterSecret: func(_ *require.Assertions, _ file.Handler) {},
createAdminConfig: func(_ *require.Assertions, _ file.Handler) {},
createTfState: func(_ *require.Assertions, _ file.Handler) {},
flags: applyFlags{},
wantPhases: newPhases(skipImagePhase, skipK8sPhase),
},
"[init] self-managed: config and state file exist, skip-phases=infrastructure": {
createConfig: defaultConfig(cloudprovider.GCP),
createState: preInitState(cloudprovider.GCP),
createMasterSecret: func(require *require.Assertions, fh file.Handler) {},
createAdminConfig: func(require *require.Assertions, fh file.Handler) {},
createTfState: func(require *require.Assertions, fh file.Handler) {},
createMasterSecret: func(_ *require.Assertions, _ file.Handler) {},
createAdminConfig: func(_ *require.Assertions, _ file.Handler) {},
createTfState: func(_ *require.Assertions, _ file.Handler) {},
flags: applyFlags{
skipPhases: newPhases(skipInfrastructurePhase),
},
@ -414,7 +414,7 @@ func TestValidateInputs(t *testing.T) {
createTfState: defaultTfState,
stdin: "y\n",
wantPhases: newPhases(skipInitPhase, skipK8sPhase),
assert: func(require *require.Assertions, assert *assert.Assertions, conf *config.Config, stateFile *state.State) {
assert: func(_ *require.Assertions, assert *assert.Assertions, conf *config.Config, _ *state.State) {
assert.NotEmpty(conf.KubernetesVersion)
_, err := versions.NewValidK8sVersion(string(conf.KubernetesVersion), true)
assert.NoError(err)

View File

@ -196,7 +196,7 @@ func TestNoValidProviderAttestationCombination(t *testing.T) {
{cloudprovider.OpenStack, variant.AWSNitroTPM{}},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
t.Run("", func(_ *testing.T) {
_, err := createConfigWithAttestationVariant(test.provider, "", test.attestation)
assert.Error(err)
})

View File

@ -122,7 +122,7 @@ func TestCreate(t *testing.T) {
wantErr: true,
},
"config does not exist": {
setupFs: func(a *require.Assertions, p cloudprovider.Provider) afero.Fs { return afero.NewMemMapFs() },
setupFs: func(_ *require.Assertions, _ cloudprovider.Provider) afero.Fs { return afero.NewMemMapFs() },
creator: &stubCloudCreator{
state: infraState,
planDiff: true,

View File

@ -67,7 +67,7 @@ func TestParseIDFile(t *testing.T) {
func TestIAMCreateAWS(t *testing.T) {
defaultFs := createFSWithConfig(*createConfig(cloudprovider.AWS))
readOnlyFs := func(require *require.Assertions, provider cloudprovider.Provider, existingConfigFiles []string, existingDirs []string) afero.Fs {
readOnlyFs := func(_ *require.Assertions, _ cloudprovider.Provider, _ []string, _ []string) afero.Fs {
fs := afero.NewReadOnlyFs(afero.NewMemMapFs())
return fs
}
@ -257,7 +257,7 @@ func TestIAMCreateAWS(t *testing.T) {
func TestIAMCreateAzure(t *testing.T) {
defaultFs := createFSWithConfig(*createConfig(cloudprovider.Azure))
readOnlyFs := func(require *require.Assertions, provider cloudprovider.Provider, existingConfigFiles []string, existingDirs []string) afero.Fs {
readOnlyFs := func(_ *require.Assertions, _ cloudprovider.Provider, _ []string, _ []string) afero.Fs {
fs := afero.NewReadOnlyFs(afero.NewMemMapFs())
return fs
}
@ -434,7 +434,7 @@ func TestIAMCreateAzure(t *testing.T) {
func TestIAMCreateGCP(t *testing.T) {
defaultFs := createFSWithConfig(*createConfig(cloudprovider.GCP))
readOnlyFs := func(require *require.Assertions, provider cloudprovider.Provider, existingConfigFiles []string, existingDirs []string) afero.Fs {
readOnlyFs := func(_ *require.Assertions, _ cloudprovider.Provider, _ []string, _ []string) afero.Fs {
fs := afero.NewReadOnlyFs(afero.NewMemMapFs())
return fs
}
@ -684,7 +684,7 @@ func TestValidateConfigWithFlagCompatibility(t *testing.T) {
}
func createFSWithConfig(cfg config.Config) func(require *require.Assertions, provider cloudprovider.Provider, existingConfigFiles []string, existingDirs []string) afero.Fs {
return func(require *require.Assertions, provider cloudprovider.Provider, existingConfigFiles []string, existingDirs []string) afero.Fs {
return func(require *require.Assertions, _ cloudprovider.Provider, existingConfigFiles []string, existingDirs []string) afero.Fs {
fs := afero.NewMemMapFs()
fileHandler := file.NewHandler(fs)
for _, f := range existingConfigFiles {

View File

@ -438,12 +438,12 @@ func TestGenerateMasterSecret(t *testing.T) {
wantErr: true,
},
"file does not exist": {
createFileFunc: func(handler file.Handler) error { return nil },
createFileFunc: func(_ file.Handler) error { return nil },
fs: afero.NewMemMapFs,
wantErr: false,
},
"file not writeable": {
createFileFunc: func(handler file.Handler) error { return nil },
createFileFunc: func(_ file.Handler) error { return nil },
fs: func() afero.Fs { return afero.NewReadOnlyFs(afero.NewMemMapFs()) },
wantErr: true,
},

View File

@ -23,7 +23,7 @@ func NewMaaPatchCmd() *cobra.Command {
Long: "Patch the MAA's attestation policy.",
Args: cobra.MatchAll(
cobra.ExactArgs(1),
func(cmd *cobra.Command, args []string) error {
func(_ *cobra.Command, args []string) error {
if _, err := url.Parse(args[0]); err != nil {
return fmt.Errorf("argument %s is not a valid URL: %w", args[0], err)
}

View File

@ -104,7 +104,7 @@ func TestTerminate(t *testing.T) {
},
"missing id file does not error": {
stateFile: state.New(),
setupFs: func(require *require.Assertions, stateFile *state.State) afero.Fs {
setupFs: func(require *require.Assertions, _ *state.State) afero.Fs {
fs := afero.NewMemMapFs()
fileHandler := file.NewHandler(fs)
require.NoError(fileHandler.Write(constants.AdminConfFilename, []byte{1, 2}, file.OptNone))

View File

@ -254,7 +254,7 @@ func TestUpgradeApply(t *testing.T) {
log: logger.NewTest(t),
spinner: &nopSpinner{},
merger: &stubMerger{},
newInfraApplier: func(ctx context.Context) (cloudApplier, func(), error) {
newInfraApplier: func(_ context.Context) (cloudApplier, func(), error) {
return tc.terraformUpgrader, func() {}, nil
},
applier: &stubConstellApplier{

View File

@ -23,7 +23,7 @@ func TestAskToConfirm(t *testing.T) {
cmd := &cobra.Command{
Use: "test",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
ok, err := askToConfirm(cmd, "777")
if err != nil {
return err

View File

@ -14,7 +14,7 @@ import (
)
func isCloudProvider(arg int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, args []string) error {
if provider := cloudprovider.FromString(args[arg]); provider == cloudprovider.Unknown {
return fmt.Errorf("argument %s isn't a valid cloud provider", args[arg])
}

View File

@ -852,7 +852,7 @@ func TestCleanupWorkspace(t *testing.T) {
},
"no error if files do not exist": {
provider: cloudprovider.QEMU,
prepareFS: func(f file.Handler) error { return nil },
prepareFS: func(_ file.Handler) error { return nil },
},
}

View File

@ -81,7 +81,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{},
kms: &fakeKMS{},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: false,
},
"success with error on Load": {
@ -89,7 +89,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{loadErr: assert.AnError},
kms: &fakeKMS{},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: false,
},
"success with integrity": {
@ -98,7 +98,7 @@ func TestOpenCryptDevice(t *testing.T) {
integrity: true,
mapper: &stubCryptDevice{loadErr: assert.AnError},
kms: &fakeKMS{},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: false,
},
"error on Init": {
@ -106,7 +106,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{initErr: assert.AnError},
kms: &fakeKMS{},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: true,
},
"error on Format": {
@ -114,7 +114,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{loadErr: assert.AnError, formatErr: assert.AnError},
kms: &fakeKMS{},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: true,
},
"error on Activate": {
@ -122,7 +122,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{activatePassErr: assert.AnError},
kms: &fakeKMS{},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: true,
},
"error on diskInfo": {
@ -130,7 +130,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{loadErr: assert.AnError},
kms: &fakeKMS{},
diskInfo: func(disk string) (string, error) { return "", assert.AnError },
diskInfo: func(_ string) (string, error) { return "", assert.AnError },
wantErr: true,
},
"disk is already formatted": {
@ -138,7 +138,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{loadErr: assert.AnError},
kms: &fakeKMS{},
diskInfo: func(disk string) (string, error) { return "ext4", nil },
diskInfo: func(_ string) (string, error) { return "ext4", nil },
wantErr: true,
},
"error with integrity on wipe": {
@ -147,7 +147,7 @@ func TestOpenCryptDevice(t *testing.T) {
integrity: true,
mapper: &stubCryptDevice{loadErr: assert.AnError, wipeErr: assert.AnError},
kms: &fakeKMS{},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: true,
},
"error on adding keyslot": {
@ -155,7 +155,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{loadErr: assert.AnError, keySlotAddErr: assert.AnError},
kms: &fakeKMS{},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: true,
},
"incorrect key length": {
@ -163,7 +163,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{},
kms: &fakeKMS{presetKey: []byte{0x1, 0x2, 0x3}},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: true,
},
"incorrect key length with error on Load": {
@ -171,7 +171,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{loadErr: assert.AnError},
kms: &fakeKMS{presetKey: []byte{0x1, 0x2, 0x3}},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: true,
},
"getKey fails": {
@ -179,7 +179,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{},
kms: &fakeKMS{getDEKErr: assert.AnError},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: true,
},
"getKey fails with error on Load": {
@ -187,7 +187,7 @@ func TestOpenCryptDevice(t *testing.T) {
volumeID: "volume0",
mapper: &stubCryptDevice{loadErr: assert.AnError},
kms: &fakeKMS{getDEKErr: assert.AnError},
diskInfo: func(disk string) (string, error) { return "", nil },
diskInfo: func(_ string) (string, error) { return "", nil },
wantErr: true,
},
}

View File

@ -147,7 +147,7 @@ func TestRecover(t *testing.T) {
}
func newStubKMS(setupErr, getDEKErr error) kmsFactory {
return func(ctx context.Context, storageURI string, kmsURI string) (kms.CloudKMS, error) {
return func(_ context.Context, _ string, _ string) (kms.CloudKMS, error) {
if setupErr != nil {
return nil, setupErr
}

View File

@ -15,7 +15,7 @@ import (
)
func isCloudProvider(arg int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, args []string) error {
if provider := cloudprovider.FromString(args[arg]); provider == cloudprovider.Unknown {
return fmt.Errorf("argument %s isn't a valid cloud provider", args[arg])
}
@ -24,7 +24,7 @@ func isCloudProvider(arg int) cobra.PositionalArgs {
}
func isValidKind(arg int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, args []string) error {
if kind := kindFromString(args[arg]); kind == unknown {
return fmt.Errorf("argument %s isn't a valid kind", args[arg])
}

View File

@ -96,7 +96,7 @@ func getATLSConfigForClientFunc(issuer Issuer, validators []Validator) (func(*tl
}
// this function will be called once for every client
return func(chi *tls.ClientHelloInfo) (*tls.Config, error) {
return func(_ *tls.ClientHelloInfo) (*tls.Config, error) {
// generate nonce for this connection
serverNonce, err := crypto.GenerateRandomBytes(crypto.RNGLengthDefault)
if err != nil {

View File

@ -142,7 +142,7 @@ func TestTLSConfig(t *testing.T) {
serverConfig, err := CreateAttestationServerTLSConfig(tc.serverIssuer, tc.serverValidators)
require.NoError(err)
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = io.WriteString(w, "hello")
}))
server.TLS = serverConfig
@ -196,7 +196,7 @@ func TestClientConnectionConcurrency(t *testing.T) {
serverCfg, err := CreateAttestationServerTLSConfig(NewFakeIssuer(variant.Dummy{}), NewFakeValidators(variant.Dummy{}))
require.NoError(err)
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = io.WriteString(w, "hello")
}))
server.TLS = serverCfg
@ -270,7 +270,7 @@ func TestServerConnectionConcurrency(t *testing.T) {
require.NoError(err)
for i := 0; i < serverCount; i++ {
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = io.WriteString(w, "hello")
}))
server.TLS = serverCfg

View File

@ -57,7 +57,7 @@ func TestNewValidator(t *testing.T) {
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
t.Run(name, func(_ *testing.T) {
validator := NewValidator(tc.cfg, tc.logger)
require.NotNil(validator)
require.NotNil(validator.log)

View File

@ -91,7 +91,7 @@ func TestIMDSGetQuote(t *testing.T) {
wantErr bool
}{
"success": {
client: newTestClient(func(req *http.Request) *http.Response {
client: newTestClient(func(_ *http.Request) *http.Response {
quote := quoteResponse{
Quote: "test",
}
@ -106,7 +106,7 @@ func TestIMDSGetQuote(t *testing.T) {
wantErr: false,
},
"bad status code": {
client: newTestClient(func(req *http.Request) *http.Response {
client: newTestClient(func(_ *http.Request) *http.Response {
return &http.Response{
StatusCode: http.StatusInternalServerError,
Body: io.NopCloser(bytes.NewBufferString("")),
@ -116,7 +116,7 @@ func TestIMDSGetQuote(t *testing.T) {
wantErr: true,
},
"bad json": {
client: newTestClient(func(req *http.Request) *http.Response {
client: newTestClient(func(_ *http.Request) *http.Response {
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString("")),

View File

@ -104,7 +104,7 @@ func TestGetAttestationCert(t *testing.T) {
wantValidateErr bool
}{
"success": {
crlServer: func(req *http.Request) *http.Response {
crlServer: func(_ *http.Request) *http.Response {
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader(intermediateCert.Raw)),
@ -136,14 +136,14 @@ func TestGetAttestationCert(t *testing.T) {
},
},
"intermediate cert cannot be fetched": {
crlServer: func(req *http.Request) *http.Response {
crlServer: func(_ *http.Request) *http.Response {
return &http.Response{StatusCode: http.StatusNotFound}
},
getAkCert: defaultAkCertFunc,
wantIssueErr: true,
},
"intermediate cert is not signed by root cert": {
crlServer: func(req *http.Request) *http.Response {
crlServer: func(_ *http.Request) *http.Response {
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader(rootCert.Raw)),
@ -153,7 +153,7 @@ func TestGetAttestationCert(t *testing.T) {
wantValidateErr: true,
},
"ak does not match ak cert public key": {
crlServer: func(req *http.Request) *http.Response {
crlServer: func(_ *http.Request) *http.Response {
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader(intermediateCert.Raw)),

View File

@ -176,7 +176,7 @@ type fakeInstanceClient struct {
}
func prepareFakeClient(ident *computepb.ShieldedInstanceIdentity, newErr, getIdentErr error) func(ctx context.Context, opts ...option.ClientOption) (gcpRestClient, error) {
return func(ctx context.Context, opts ...option.ClientOption) (gcpRestClient, error) {
return func(_ context.Context, _ ...option.ClientOption) (gcpRestClient, error) {
return &fakeInstanceClient{
getIdentErr: getIdentErr,
ident: ident,

View File

@ -308,7 +308,7 @@ func TestFailIssuer(t *testing.T) {
"fail getAttestationKey": {
issuer: NewIssuer(
newSimTPMWithEventLog,
func(tpm io.ReadWriter) (*tpmclient.Key, error) {
func(_ io.ReadWriter) (*tpmclient.Key, error) {
return nil, errors.New("failure")
},
fakeGetInstanceInfo,
@ -320,7 +320,7 @@ func TestFailIssuer(t *testing.T) {
"fail Attest": {
issuer: NewIssuer(
newSimTPMWithEventLog,
func(tpm io.ReadWriter) (*tpmclient.Key, error) {
func(_ io.ReadWriter) (*tpmclient.Key, error) {
return &tpmclient.Key{}, nil
},
fakeGetInstanceInfo,

View File

@ -185,7 +185,7 @@ func TestIMDSClient(t *testing.T) {
wantTags: defaultWantTags,
},
"invalid imds response detected": {
server: newHTTPBufconnServer(func(writer http.ResponseWriter, request *http.Request) {
server: newHTTPBufconnServer(func(writer http.ResponseWriter, _ *http.Request) {
fmt.Fprintln(writer, "invalid-result")
}),
wantProviderIDErr: true,

View File

@ -28,7 +28,7 @@ type retrieableApplier interface {
// retryApply retries the given retriable action.
func retryApply(ctx context.Context, action retrieableApplier, retryInterval time.Duration, log debugLog) error {
var retries int
retriable := func(err error) bool {
retriable := func(_ error) bool {
// abort after maximumRetryAttempts tries.
if retries >= maximumRetryAttempts {
return false

View File

@ -66,7 +66,7 @@ func TestATLSCredentials(t *testing.T) {
go func() {
var err error
defer func() { errChan <- err }()
conn, err := grpc.DialContext(context.Background(), "", grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
conn, err := grpc.DialContext(context.Background(), "", grpc.WithContextDialer(func(_ context.Context, _ string) (net.Conn, error) {
return lis.Dial()
}), grpc.WithTransportCredentials(clientCreds))
require.NoError(err)

View File

@ -80,7 +80,7 @@ func TestInstall(t *testing.T) {
wantFiles: map[string][]byte{"/destination": []byte("file-contents")},
},
"download fails": {
server: newHTTPBufconnServer(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) }),
server: newHTTPBufconnServer(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(500) }),
component: &components.Component{
Url: serverURL,
Hash: "sha256:abc",
@ -89,7 +89,7 @@ func TestInstall(t *testing.T) {
wantErr: true,
},
"dataurl works": {
server: newHTTPBufconnServer(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) }),
server: newHTTPBufconnServer(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(500) }),
component: &components.Component{
Url: "data:text/plain,file-contents",
Hash: "",
@ -98,7 +98,7 @@ func TestInstall(t *testing.T) {
wantFiles: map[string][]byte{"/destination": []byte("file-contents")},
},
"broken dataurl fails": {
server: newHTTPBufconnServer(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) }),
server: newHTTPBufconnServer(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(500) }),
component: &components.Component{
Url: "data:file-contents",
Hash: "",
@ -129,7 +129,7 @@ func TestInstall(t *testing.T) {
fs: &afero.Afero{Fs: afero.NewMemMapFs()},
hClient: &hClient,
clock: testclock.NewFakeClock(time.Time{}),
retriable: func(err error) bool { return false },
retriable: func(_ error) bool { return false },
}
err := inst.Install(context.Background(), tc.component)
@ -388,7 +388,7 @@ func TestDownloadToTempDir(t *testing.T) {
wantFile: []byte("file-contents"),
},
"download fails": {
server: newHTTPBufconnServer(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) }),
server: newHTTPBufconnServer(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(500) }),
wantErr: true,
},
"creating temp file fails on RO fs": {
@ -397,7 +397,7 @@ func TestDownloadToTempDir(t *testing.T) {
wantErr: true,
},
"content length mismatch": {
server: newHTTPBufconnServer(func(writer http.ResponseWriter, request *http.Request) {
server: newHTTPBufconnServer(func(writer http.ResponseWriter, _ *http.Request) {
writer.Header().Set("Content-Length", "1337")
writer.WriteHeader(200)
}),
@ -607,7 +607,7 @@ func newHTTPBufconnServer(handlerFunc http.HandlerFunc) httpBufconnServer {
}
func newHTTPBufconnServerWithBody(body []byte) httpBufconnServer {
return newHTTPBufconnServer(func(writer http.ResponseWriter, request *http.Request) {
return newHTTPBufconnServer(func(writer http.ResponseWriter, _ *http.Request) {
if _, err := writer.Write(body); err != nil {
panic(err)
}
@ -615,7 +615,7 @@ func newHTTPBufconnServerWithBody(body []byte) httpBufconnServer {
}
func newHTTPBufconnServerWithState(state chan int, body []byte) httpBufconnServer {
return newHTTPBufconnServer(func(w http.ResponseWriter, r *http.Request) {
return newHTTPBufconnServer(func(w http.ResponseWriter, _ *http.Request) {
switch <-state {
case 500:
w.WriteHeader(500)

View File

@ -69,7 +69,7 @@ func GetClientStreamInterceptor(l *slog.Logger) grpc.DialOption {
}
func middlewareLogger(l *slog.Logger) logging.Logger {
return logging.LoggerFunc(func(ctx context.Context, lvl logging.Level, msg string, fields ...any) {
return logging.LoggerFunc(func(_ context.Context, lvl logging.Level, msg string, fields ...any) {
var pcs [1]uintptr
runtime.Callers(2, pcs[:]) // skip [Callers, LoggerFunc]

View File

@ -165,7 +165,7 @@ func TestNotEmptySlice(t *testing.T) {
}
func TestAll(t *testing.T) {
c := func(i int, s string) *Constraint {
c := func(_ int, s string) *Constraint {
return Equal(s, "abc")
}
testCases := map[string]struct {

View File

@ -138,7 +138,7 @@ func TestUpdate(t *testing.T) {
// create tls config and start the server
serverConfig, err := atls.CreateAttestationServerTLSConfig(nil, []atls.Validator{validator})
require.NoError(err)
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = io.WriteString(w, "hello")
}))
server.TLS = serverConfig

View File

@ -175,7 +175,7 @@ func (r *AutoscalingStrategyReconciler) findObjectsForDeployment(ctx context.Con
// scalingGroupChangePredicate filters events on scaling group resources.
func scalingGroupChangePredicate() predicate.Predicate {
return predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
CreateFunc: func(_ event.CreateEvent) bool {
return true
},
UpdateFunc: func(e event.UpdateEvent) bool {
@ -198,10 +198,10 @@ func scalingGroupChangePredicate() predicate.Predicate {
return false
}
},
DeleteFunc: func(e event.DeleteEvent) bool {
DeleteFunc: func(_ event.DeleteEvent) bool {
return true
},
GenericFunc: func(e event.GenericEvent) bool {
GenericFunc: func(_ event.GenericEvent) bool {
return false
},
}

View File

@ -165,7 +165,7 @@ func (r *PendingNodeReconciler) SetupWithManager(mgr ctrl.Manager) error {
// joining, leaving, node becoming ready or node receiving a provider id.
func nodeStateChangePredicate() predicate.Predicate {
return predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
CreateFunc: func(_ event.CreateEvent) bool {
return true
},
UpdateFunc: func(e event.UpdateEvent) bool {
@ -181,10 +181,10 @@ func nodeStateChangePredicate() predicate.Predicate {
receivedProviderID := len(oldNode.Spec.ProviderID) == 0 && len(newNode.Spec.ProviderID) != 0
return becameReady || receivedProviderID
},
DeleteFunc: func(e event.DeleteEvent) bool {
DeleteFunc: func(_ event.DeleteEvent) bool {
return true
},
GenericFunc: func(e event.GenericEvent) bool {
GenericFunc: func(_ event.GenericEvent) bool {
return false
},
}

View File

@ -252,7 +252,7 @@ func TestCreateNode(t *testing.T) {
getErr: tc.getSKUCapacityErr,
updateErr: tc.updateScaleSetErr,
},
capacityPollerGenerator: func(resourceGroup, scaleSet string, wantedCapacity int64) capacityPoller {
capacityPollerGenerator: func(_, _ string, _ int64) capacityPoller {
return poller
},
}

View File

@ -55,7 +55,7 @@ func (w *NodeJoinWatcher) SetupWithManager(mgr ctrl.Manager) error {
Named("node-join-watcher").
Watches(
client.Object(&corev1.Node{}),
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []ctrl.Request {
handler.EnqueueRequestsFromMapFunc(func(_ context.Context, obj client.Object) []ctrl.Request {
return []ctrl.Request{{
NamespacedName: types.NamespacedName{Name: obj.GetName()},
}}
@ -70,7 +70,7 @@ func nodeJoinLeavePredicate() predicate.Predicate {
return predicate.Funcs{
// CreateFunc is not specified => never filter out create events
// DeleteFunc is not specified => never filter out delete events
UpdateFunc: func(e event.UpdateEvent) bool { return false },
GenericFunc: func(e event.GenericEvent) bool { return false },
UpdateFunc: func(_ event.UpdateEvent) bool { return false },
GenericFunc: func(_ event.GenericEvent) bool { return false },
}
}

View File

@ -428,7 +428,7 @@ func (r *ClusterResource) Configure(_ context.Context, req resource.ConfigureReq
return dialer.New(nil, validator, &net.Dialer{})
}
r.newApplier = func(ctx context.Context, validator atls.Validator) *constellation.Applier {
r.newApplier = func(ctx context.Context, _ atls.Validator) *constellation.Applier {
return constellation.NewApplier(&tfContextLogger{ctx: ctx}, &nopSpinner{}, constellation.ApplyContextTerraform, newDialer)
}
}