Skip to content

Commit

Permalink
Fix linter errors from newer versions of golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Apr 23, 2024
1 parent 0e48fa2 commit d7b37b3
Show file tree
Hide file tree
Showing 56 changed files with 143 additions and 149 deletions.
4 changes: 2 additions & 2 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newHandler(cs *v1.ControlSurface, profilingEnabled bool) http.Handler {
func injectProfilerHandler(mux *http.ServeMux, profilingEnabled bool) {
var handler http.Handler

handler = http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
handler = http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
rw.Header().Add("Content-Type", "text/plain; charset=utf-8")
_, _ = rw.Write([]byte("To enable profiling, please run k6 with the --profiling-enabled flag"))
})
Expand Down Expand Up @@ -91,7 +91,7 @@ func withLoggingHandler(l logrus.FieldLogger, next http.Handler) http.HandlerFun
}

func handlePing(logger logrus.FieldLogger) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
return http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
rw.Header().Add("Content-Type", "text/plain; charset=utf-8")
if _, err := fmt.Fprint(rw, "ok"); err != nil {
logger.WithError(err).Error("Error while printing ok")
Expand Down
6 changes: 3 additions & 3 deletions cloudapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCreateTestRun(t *testing.T) {

func TestFinished(t *testing.T) {
t.Parallel()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fprint(t, w, "")
}))
defer server.Close()
Expand All @@ -70,7 +70,7 @@ func TestFinished(t *testing.T) {
func TestAuthorizedError(t *testing.T) {
t.Parallel()
called := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
called++
w.WriteHeader(http.StatusForbidden)
fprint(t, w, `{"error": {"code": 5, "message": "Not allowed"}}`)
Expand All @@ -89,7 +89,7 @@ func TestAuthorizedError(t *testing.T) {
func TestDetailsError(t *testing.T) {
t.Parallel()
called := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
called++
w.WriteHeader(http.StatusForbidden)
fprint(t, w, `{"error": {"code": 0, "message": "Validation failed", "details": { "name": ["Shorter than minimum length 2."]}}}`)
Expand Down
2 changes: 1 addition & 1 deletion cloudapi/insights/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestClient_Dial_ReturnsNoErrorWithFailingDialer(t *testing.T) {
Block: true,
FailOnNonTempDialError: true,
Timeout: 1 * time.Second,
Dialer: func(ctx context.Context, s string) (net.Conn, error) {
Dialer: func(_ context.Context, _ string) (net.Conn, error) {
return nil, &fatalError{}
},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func getNullString(flags *pflag.FlagSet, key string) null.String {
}

func exactArgsWithMsg(n int, msg string) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, args []string) error {
if len(args) != n {
return fmt.Errorf("accepts %d arg(s), received %d: %s", n, len(args), msg)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func getCmdLogin(gs *state.GlobalState) *cobra.Command {
Logging into a service changes the default when just "-o [type]" is passed with
no parameters, you can always override the stored credentials by passing some
on the commandline.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Usage()
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/login_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func getCmdLoginCloud(gs *state.GlobalState) *cobra.Command {
This will set the default token used when just "k6 run -o cloud" is passed.`,
Example: exampleText,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
currentDiskConf, err := readDiskConfig(gs)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/login_influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func getCmdLoginInfluxDB(gs *state.GlobalState) *cobra.Command {
This will set the default server used when just "-o influxdb" is passed.`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
config, err := readDiskConfig(gs)
if err != nil {
return err
Expand All @@ -40,7 +40,7 @@ This will set the default server used when just "-o influxdb" is passed.`,
conf = conf.Apply(jsonConfParsed)
}
if len(args) > 0 {
urlConf, err := influxdb.ParseURL(args[0]) //nolint:govet
urlConf, err := influxdb.ParseURL(args[0])
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func getAllOutputConstructors() (map[string]output.Constructor, error) {
builtinOutputCloud.String(): cloud.New,
builtinOutputCSV.String(): csv.New,
builtinOutputInfluxdb.String(): influxdb.New,
builtinOutputKafka.String(): func(params output.Params) (output.Output, error) {
builtinOutputKafka.String(): func(_ output.Params) (output.Output, error) {
return nil, errors.New("the kafka output was deprecated in k6 v0.32.0 and removed in k6 v0.34.0, " +
"please use the new xk6 kafka output extension instead - https://github.com/k6io/xk6-output-kafka")
},
Expand All @@ -55,7 +55,7 @@ func getAllOutputConstructors() (map[string]output.Constructor, error) {
"more info at https://github.com/grafana/k6/issues/2982.")
return statsd.New(params)
},
builtinOutputDatadog.String(): func(params output.Params) (output.Output, error) {
builtinOutputDatadog.String(): func(_ output.Params) (output.Output, error) {
return nil, errors.New("the datadog output was deprecated in k6 v0.32.0 and removed in k6 v0.34.0, " +
"please use the statsd output with env. variable K6_STATSD_ENABLE_TAGS=true instead")
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func getCmdPause(gs *state.GlobalState) *cobra.Command {
Long: `Pause a running test.
Use the global --address flag to specify the URL to the API server.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
c, err := client.New(gs.Flags.Address)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func getCmdResume(gs *state.GlobalState) *cobra.Command {
Long: `Resume a paused test.
Use the global --address flag to specify the URL to the API server.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
c, err := client.New(gs.Flags.Address)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestPanicHandling(t *testing.T) {
rootCmd := newRootCommand(ts.GlobalState)
rootCmd.cmd.AddCommand(&cobra.Command{
Use: "panic",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
panic("oh no, oh no, oh no,no,no,no,no")
},
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func getCmdStats(gs *state.GlobalState) *cobra.Command {
Long: `Show test metrics.
Use the global --address flag to specify the URL to the API server.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
c, err := client.New(gs.Flags.Address)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func getCmdStatus(gs *state.GlobalState) *cobra.Command {
Long: `Show test status.
Use the global --address flag to specify the URL to the API server.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
c, err := client.New(gs.Flags.Address)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/tests/cmd_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

func cloudTestStartSimple(tb testing.TB, testRunID int) http.Handler {
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
return http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusOK)
_, err := fmt.Fprintf(resp, `{"reference_id": "%d"}`, testRunID)
assert.NoError(tb, err)
Expand All @@ -43,7 +43,7 @@ func getMockCloud(

srv := getTestServer(t, map[string]http.Handler{
"POST ^/v1/archive-upload$": archiveUpload,
testProgressURL: http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
testProgressURL: http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
testProgress := defaultProgress
if progressCallback != nil {
testProgress = progressCallback()
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestCloudUploadOnly(t *testing.T) {
func TestCloudWithConfigOverride(t *testing.T) {
t.Parallel()

configOverride := http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
configOverride := http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(resp, `{
"reference_id": "123",
Expand Down
7 changes: 3 additions & 4 deletions cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func getCloudTestEndChecker(

srv := getTestServer(tb, map[string]http.Handler{
"POST ^/v1/tests$": testStart,
fmt.Sprintf("POST ^/v1/tests/%d$", testRunID): http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
fmt.Sprintf("POST ^/v1/tests/%d$", testRunID): http.HandlerFunc(func(_ http.ResponseWriter, req *http.Request) {
require.NotNil(tb, req.Body)
buf := &bytes.Buffer{}
_, err := io.Copy(buf, req.Body)
Expand Down Expand Up @@ -829,7 +829,7 @@ func injectMockSignalNotifier(ts *GlobalTestState) (sendSignal chan os.Signal) {
close(sendSignal)
}()
}
ts.GlobalState.SignalStop = func(c chan<- os.Signal) { /* noop */ }
ts.GlobalState.SignalStop = func(_ chan<- os.Signal) { /* noop */ }
return sendSignal
}

Expand Down Expand Up @@ -1703,7 +1703,7 @@ func TestRunWithCloudOutputOverrides(t *testing.T) {
[]string{"-v", "--log-output=stdout", "--out=cloud", "--out", "json=results.json"}, 0,
)

configOverride := http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
configOverride := http.HandlerFunc(func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(resp, `{"reference_id": "132", "config": {"webAppURL": "https://bogus.url"}}`)
assert.NoError(t, err)
Expand Down Expand Up @@ -1841,7 +1841,6 @@ func TestPrometheusRemoteWriteOutput(t *testing.T) {
func BenchmarkReadResponseBody(b *testing.B) {
httpSrv := httpmultibin.NewHTTPMultiBin(b)

//nolint:goconst
script := httpSrv.Replacer.Replace(`
import http from "k6/http";
import { check, sleep } from "k6";
Expand Down
18 changes: 9 additions & 9 deletions cmd/tests/tracing_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestTracingModuleClient(t *testing.T) {

var gotRequests int64

tb.Mux.HandleFunc("/tracing", func(w http.ResponseWriter, r *http.Request) {
tb.Mux.HandleFunc("/tracing", func(_ http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&gotRequests, 1)
assert.NotEmpty(t, r.Header.Get("traceparent"))
assert.Len(t, r.Header.Get("traceparent"), 55)
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestTracingClient_DoesNotInterfereWithHTTPModule(t *testing.T) {
var gotRequests int64
var gotInstrumentedRequests int64

tb.Mux.HandleFunc("/tracing", func(w http.ResponseWriter, r *http.Request) {
tb.Mux.HandleFunc("/tracing", func(_ http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&gotRequests, 1)

if r.Header.Get("traceparent") != "" {
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestTracingModuleClient_HundredPercentSampling(t *testing.T) {
var gotRequests int64
var gotSampleFlags int64

tb.Mux.HandleFunc("/tracing", func(w http.ResponseWriter, r *http.Request) {
tb.Mux.HandleFunc("/tracing", func(_ http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&gotRequests, 1)

traceparent := r.Header.Get("traceparent")
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestTracingModuleClient_NoSamplingSetShouldAlwaysSample(t *testing.T) {
var gotRequests int64
var gotSampleFlags int64

tb.Mux.HandleFunc("/tracing", func(w http.ResponseWriter, r *http.Request) {
tb.Mux.HandleFunc("/tracing", func(_ http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&gotRequests, 1)

traceparent := r.Header.Get("traceparent")
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestTracingModuleClient_ZeroPercentSampling(t *testing.T) {
var gotRequests int64
var gotSampleFlags int64

tb.Mux.HandleFunc("/tracing", func(w http.ResponseWriter, r *http.Request) {
tb.Mux.HandleFunc("/tracing", func(_ http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&gotRequests, 1)

traceparent := r.Header.Get("traceparent")
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestTracingInstrumentHTTP_W3C(t *testing.T) {

var gotRequests int64

tb.Mux.HandleFunc("/tracing", func(w http.ResponseWriter, r *http.Request) {
tb.Mux.HandleFunc("/tracing", func(_ http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&gotRequests, 1)
assert.NotEmpty(t, r.Header.Get("traceparent"))
assert.Len(t, r.Header.Get("traceparent"), 55)
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestTracingInstrumentHTTP_Jaeger(t *testing.T) {

var gotRequests int64

tb.Mux.HandleFunc("/tracing", func(w http.ResponseWriter, r *http.Request) {
tb.Mux.HandleFunc("/tracing", func(_ http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&gotRequests, 1)
assert.NotEmpty(t, r.Header.Get("uber-trace-id"))
assert.Len(t, r.Header.Get("uber-trace-id"), 45)
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestTracingInstrumentHTTP_FillsParams(t *testing.T) {

var gotRequests int64

tb.Mux.HandleFunc("/tracing", func(w http.ResponseWriter, r *http.Request) {
tb.Mux.HandleFunc("/tracing", func(_ http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&gotRequests, 1)

assert.NotEmpty(t, r.Header.Get("traceparent"))
Expand Down Expand Up @@ -399,7 +399,7 @@ func TestTracingInstrummentHTTP_SupportsMultipleTestScripts(t *testing.T) {
var gotRequests int64

tb := httpmultibin.NewHTTPMultiBin(t)
tb.Mux.HandleFunc("/tracing", func(w http.ResponseWriter, r *http.Request) {
tb.Mux.HandleFunc("/tracing", func(_ http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&gotRequests, 1)

assert.NotEmpty(t, r.Header.Get("traceparent"))
Expand Down

0 comments on commit d7b37b3

Please sign in to comment.