Skip to content

Commit

Permalink
Merge 253d4b0 into 87f97e0
Browse files Browse the repository at this point in the history
  • Loading branch information
codebien committed Feb 21, 2023
2 parents 87f97e0 + 253d4b0 commit 90b9784
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 45 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
# up this to 1.19.x when we update the version of golangci-lint to latest
go-version: 1.18.x
go-version: 1.20.x
check-latest: true
- name: Retrieve golangci-lint version
run: |
Expand Down
9 changes: 4 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v1.47.2
# v1.51.2
# Please don't remove the first line. It uses in CI to determine the golangci version
run:
deadline: 5m
Expand Down Expand Up @@ -68,7 +68,6 @@ linters:
- bodyclose
- contextcheck
- cyclop
- deadcode
- depguard
- dogsled
- dupl
Expand All @@ -82,6 +81,7 @@ linters:
- forbidigo
- forcetypeassert
- funlen
- gocheckcompilerdirectives
- gochecknoglobals
- gocognit
- goconst
Expand All @@ -94,7 +94,6 @@ linters:
- gosec
- gosimple
- govet
- ifshort
- importas
- ineffassign
- lll
Expand All @@ -112,18 +111,18 @@ linters:
- predeclared
- promlinter
- revive
- reassign
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
- stylecheck
- tenv
- tparallel
- typecheck
- unconvert
- unparam
- unused
- varcheck
- usestdlibvars
- wastedassign
- whitespace
fast: false
2 changes: 1 addition & 1 deletion api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestPing(t *testing.T) {
mux := handlePing(logger)

rw := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/ping", nil)
r := httptest.NewRequest(http.MethodGet, "/ping", nil)
mux.ServeHTTP(rw, r)

res := rw.Result()
Expand Down
4 changes: 2 additions & 2 deletions cloudapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *Client) StartCloudTestRun(name string, projectID int64, arc *lib.Archiv
return nil, err
}

req, err := http.NewRequest("POST", requestUrl, &buf)
req, err := http.NewRequest(http.MethodPost, requestUrl, &buf) //nolint:noctx
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (c *Client) TestFinished(referenceID string, thresholds ThresholdResult, ta

func (c *Client) GetTestProgress(referenceID string) (*TestProgressResponse, error) {
url := fmt.Sprintf("%s/test-progress/%s", c.baseURL, referenceID)
req, err := c.NewRequest("GET", url, nil)
req, err := c.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cloudapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestClientRetry(t *testing.T) {
assert.NotEmpty(t, gotK6IdempotencyKey)
assert.Equal(t, idempotencyKey, gotK6IdempotencyKey)
called++
w.WriteHeader(500)
w.WriteHeader(http.StatusInternalServerError)
}))
defer server.Close()

Expand Down Expand Up @@ -143,7 +143,7 @@ func TestClientRetrySuccessOnSecond(t *testing.T) {
fprintf(t, w, `{"reference_id": "1"}`)
return
}
w.WriteHeader(500)
w.WriteHeader(http.StatusInternalServerError)
}))
defer server.Close()

Expand Down
3 changes: 2 additions & 1 deletion converter/har/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"net/http"
"net/url"
"sort"
"strings"
Expand Down Expand Up @@ -183,7 +184,7 @@ func Convert(h HAR, options lib.Options, minSleep, maxSleep uint, enableChecks b
fprintf(w, "%q", e.Request.URL)
}

if e.Request.Method != "GET" {
if e.Request.Method != http.MethodGet {
if correlate && e.Request.PostData != nil && strings.Contains(e.Request.PostData.MimeType, "json") {
requestMap := map[string]interface{}{}

Expand Down
8 changes: 4 additions & 4 deletions js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ func TestRequest(t *testing.T) {
}

http.SetCookie(w, &cookie)
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
}))
cookieJar, err := cookiejar.New(nil)
require.NoError(t, err)
Expand Down Expand Up @@ -1721,11 +1721,11 @@ func TestErrorCodes(t *testing.T) {

// Handple paths with custom logic
tb.Mux.HandleFunc("/no-location-redirect", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(302)
w.WriteHeader(http.StatusFound)
}))
tb.Mux.HandleFunc("/bad-location-redirect", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Location", "h\t:/") // \n is forbidden
w.WriteHeader(302)
w.WriteHeader(http.StatusFound)
}))

testCases := []struct {
Expand Down Expand Up @@ -2338,7 +2338,7 @@ func GenerateTLSCertificate(t *testing.T, host string, notBefore time.Time, vali
func GetTestServerWithCertificate(t *testing.T, certPem, key []byte, suitesIds ...uint16) (*httptest.Server, *http.Client) {
server := &http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
}),
ReadHeaderTimeout: time.Second,
ReadTimeout: time.Second,
Expand Down
6 changes: 3 additions & 3 deletions js/modules/k6/http/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,23 @@ func myFormHandler(w http.ResponseWriter, r *http.Request) {
body = []byte(testGetFormHTML)
}
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(body)))
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
_, _ = w.Write(body)
}

func jsonHandler(w http.ResponseWriter, r *http.Request) {
body := []byte(jsonData)
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(body)))
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
_, _ = w.Write(body)
}

func invalidJSONHandler(w http.ResponseWriter, r *http.Request) {
body := []byte(invalidJSONData)
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(body)))
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
_, _ = w.Write(body)
}

Expand Down
2 changes: 1 addition & 1 deletion js/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ func GenerateTLSCertificate(t *testing.T, host string, notBefore time.Time, vali
func GetTestServerWithCertificate(t *testing.T, certPem, key []byte) *httptest.Server {
server := &http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
}),
ReadHeaderTimeout: time.Second,
ReadTimeout: time.Second,
Expand Down
6 changes: 3 additions & 3 deletions lib/netext/httpext/error_codes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestHTTP2StreamError(t *testing.T) {

tb.Mux.HandleFunc("/tsr", func(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Content-Length", "100000")
rw.WriteHeader(200)
rw.WriteHeader(http.StatusOK)

rw.(http.Flusher).Flush()
time.Sleep(time.Millisecond * 2)
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestX509HostnameError(t *testing.T) {
badHostname: *badHost,
})
require.NoError(t, err)
req, err := http.NewRequestWithContext(context.Background(), "GET", tb.Replacer.Replace("https://"+badHostname+":HTTPSBIN_PORT/get"), nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, tb.Replacer.Replace("https://"+badHostname+":HTTPSBIN_PORT/get"), nil)
require.NoError(t, err)
res, err := client.Do(req) //nolint:bodyclose
require.Nil(t, res)
Expand All @@ -243,7 +243,7 @@ func TestX509UnknownAuthorityError(t *testing.T) {
DialContext: tb.HTTPTransport.DialContext,
},
}
req, err := http.NewRequestWithContext(context.Background(), "GET", tb.Replacer.Replace("HTTPSBIN_URL/get"), nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, tb.Replacer.Replace("HTTPSBIN_URL/get"), nil)
require.NoError(t, err)
res, err := client.Do(req) //nolint:bodyclose
require.Nil(t, res)
Expand Down
18 changes: 9 additions & 9 deletions lib/netext/httpext/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestMakeRequestError(t *testing.T) {

t.Run("bad compression algorithm body", func(t *testing.T) {
t.Parallel()
req, err := http.NewRequest("GET", "https://wont.be.used", nil)
req, err := http.NewRequest(http.MethodGet, "https://wont.be.used", nil)

require.NoError(t, err)
badCompressionType := CompressionType(13)
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestMakeRequestError(t *testing.T) {
Logger: logger,
Tags: lib.NewVUStateTags(metrics.NewRegistry().RootTagSet()),
}
req, _ := http.NewRequest("GET", srv.URL, nil)
req, _ := http.NewRequest(http.MethodGet, srv.URL, nil)
preq := &ParsedHTTPRequest{
Req: req,
URL: &URL{u: req.URL},
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestResponseStatus(t *testing.T) {
BuiltinMetrics: metrics.RegisterBuiltinMetrics(registry),
Tags: lib.NewVUStateTags(registry.RootTagSet()),
}
req, err := http.NewRequest("GET", server.URL, nil)
req, err := http.NewRequest(http.MethodGet, server.URL, nil)
require.NoError(t, err)

preq := &ParsedHTTPRequest{
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestMakeRequestTimeoutInTheMiddle(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Length", "100000")
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
if f, ok := w.(http.Flusher); ok {
f.Flush()
}
Expand All @@ -260,7 +260,7 @@ func TestMakeRequestTimeoutInTheMiddle(t *testing.T) {
BuiltinMetrics: metrics.RegisterBuiltinMetrics(registry),
Tags: lib.NewVUStateTags(registry.RootTagSet()),
}
req, _ := http.NewRequest("GET", srv.URL, nil)
req, _ := http.NewRequest(http.MethodGet, srv.URL, nil)
preq := &ParsedHTTPRequest{
Req: req,
URL: &URL{u: req.URL, URL: srv.URL},
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestTrailFailed(t *testing.T) {
BuiltinMetrics: metrics.RegisterBuiltinMetrics(registry),
Tags: lib.NewVUStateTags(registry.RootTagSet()),
}
req, _ := http.NewRequest("GET", srv.URL, nil)
req, _ := http.NewRequest(http.MethodGet, srv.URL, nil)
preq := &ParsedHTTPRequest{
Req: req,
URL: &URL{u: req.URL, URL: srv.URL},
Expand Down Expand Up @@ -405,7 +405,7 @@ func TestMakeRequestDialTimeout(t *testing.T) {
Tags: lib.NewVUStateTags(registry.RootTagSet()),
}

req, _ := http.NewRequest("GET", "http://"+addr.String(), nil)
req, _ := http.NewRequest(http.MethodGet, "http://"+addr.String(), nil)
preq := &ParsedHTTPRequest{
Req: req,
URL: &URL{u: req.URL, URL: req.URL.String()},
Expand Down Expand Up @@ -460,7 +460,7 @@ func TestMakeRequestTimeoutInTheBegining(t *testing.T) {
BuiltinMetrics: metrics.RegisterBuiltinMetrics(registry),
Tags: lib.NewVUStateTags(registry.RootTagSet()),
}
req, _ := http.NewRequest("GET", srv.URL, nil)
req, _ := http.NewRequest(http.MethodGet, srv.URL, nil)
preq := &ParsedHTTPRequest{
Req: req,
URL: &URL{u: req.URL, URL: srv.URL},
Expand Down Expand Up @@ -541,7 +541,7 @@ func TestMakeRequestRPSLimit(t *testing.T) {
assert.InDelta(t, val, 3, 3)
return
default:
req, _ := http.NewRequest("GET", ts.URL, nil)
req, _ := http.NewRequest(http.MethodGet, ts.URL, nil)
preq := &ParsedHTTPRequest{
Req: req,
URL: &URL{u: req.URL, URL: ts.URL, Name: ts.URL},
Expand Down
8 changes: 4 additions & 4 deletions lib/netext/httpext/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestTracer(t *testing.T) { //nolint:tparallel
for tnum, isReuse := range []bool{false, true, true} { //nolint:paralleltest
t.Run(fmt.Sprintf("Test #%d", tnum), func(t *testing.T) {
// Do not enable parallel testing, test relies on sequential execution
req, err := http.NewRequest("GET", srv.URL+"/get", nil)
req, err := http.NewRequest(http.MethodGet, srv.URL+"/get", nil)
require.NoError(t, err)

tracer, ct := getTestTracer(t)
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestTracerNegativeHttpSendingValues(t *testing.T) {
return failingConn{conn}, err
}

req, err := http.NewRequest("GET", srv.URL+"/get", nil)
req, err := http.NewRequest(http.MethodGet, srv.URL+"/get", nil)
require.NoError(t, err)

{
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestTracerError(t *testing.T) {
defer srv.Close()

tracer := &Tracer{}
req, err := http.NewRequest("GET", srv.URL+"/get", nil)
req, err := http.NewRequest(http.MethodGet, srv.URL+"/get", nil)
require.NoError(t, err)

_, err = http.DefaultTransport.RoundTrip(
Expand All @@ -261,7 +261,7 @@ func TestCancelledRequest(t *testing.T) {

cancelTest := func(t *testing.T) {
tracer := &Tracer{}
req, err := http.NewRequestWithContext(context.Background(), "GET", srv.URL+"/delay/1", nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, srv.URL+"/delay/1", nil)
require.NoError(t, err)

ctx, cancel := context.WithCancel(httptrace.WithClientTrace(req.Context(), tracer.Trace()))
Expand Down
2 changes: 1 addition & 1 deletion lib/netext/httpext/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func BenchmarkMeasureAndEmitMetrics(b *testing.B) {
unfRequest := &unfinishedRequest{
tracer: &Tracer{},
response: &http.Response{
StatusCode: 200,
StatusCode: http.StatusOK,
},
request: &http.Request{
URL: &url.URL{
Expand Down
4 changes: 2 additions & 2 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ func fetch(logger logrus.FieldLogger, u string) ([]byte, error) {
}
defer func() { _ = res.Body.Close() }()

if res.StatusCode != 200 {
if res.StatusCode != http.StatusOK {
switch res.StatusCode {
case 404:
case http.StatusNotFound:
return nil, fmt.Errorf("not found: %s", u)
default:
return nil, fmt.Errorf("wrong status code (%d) for: %s", res.StatusCode, u)
Expand Down
4 changes: 2 additions & 2 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ func TestLoad(t *testing.T) {
const responseStr = "export function fn() {\r\n return 1234;\r\n}"
tb.Mux.HandleFunc("/raw/something", func(w http.ResponseWriter, r *http.Request) {
if _, ok := r.URL.Query()["_k6"]; ok {
http.Error(w, "Internal server error", 500)
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
_, err := fmt.Fprint(w, responseStr)
assert.NoError(t, err)
})

tb.Mux.HandleFunc("/invalid", func(w http.ResponseWriter, _ *http.Request) {
http.Error(w, "Internal server error", 500)
http.Error(w, "Internal server error", http.StatusInternalServerError)
})

t.Run("Local", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion output/cloud/metrics_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (mc *MetricsClient) PushMetric(referenceID string, s []*Sample) error {
jsonTime := time.Since(jsonStart)

// TODO: change the context, maybe to one with a timeout
req, err := http.NewRequestWithContext(context.Background(), "POST", url, nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, url, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion output/influxdb/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func benchmarkInfluxdb(b *testing.B, t time.Duration) {
break
}
}
rw.WriteHeader(204)
rw.WriteHeader(http.StatusNoContent)
}, func(tb testing.TB, c *Output) {
b = tb.(*testing.B)
b.ResetTimer()
Expand Down

0 comments on commit 90b9784

Please sign in to comment.