Update linting (#851)

This commit is contained in:
Erik Dubbelboer
2020-07-17 14:22:28 +02:00
committed by GitHub
parent 4cffe1a510
commit 34a61fe63f
15 changed files with 47 additions and 37 deletions
+5 -1
View File
@@ -6,5 +6,9 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: GolangCI-Lint Action
uses: actions-contrib/golangci-lint@v0.1.0
uses: actions-contrib/golangci-lint@v1
with:
golangci_lint_version: v1.28.3
+1 -1
View File
@@ -78,7 +78,7 @@ func TestAllocationURI(t *testing.T) {
n := testing.AllocsPerRun(100, func() {
u := AcquireURI()
u.Parse(nil, uri)
u.Parse(nil, uri) //nolint:errcheck
ReleaseURI(u)
})
+2 -2
View File
@@ -336,8 +336,8 @@ func testCopyTo(t *testing.T, a *Args) {
var b Args
a.CopyTo(&b)
if !reflect.DeepEqual(*a, b) { //nolint:govet
t.Fatalf("ArgsCopyTo fail, a: \n%+v\nb: \n%+v\n", *a, b) //nolint:govet
if !reflect.DeepEqual(*a, b) { //nolint
t.Fatalf("ArgsCopyTo fail, a: \n%+v\nb: \n%+v\n", *a, b) //nolint
}
b.VisitAll(func(k, v []byte) {
+1 -1
View File
@@ -915,7 +915,7 @@ func doRequestFollowRedirectsBuffer(req *Request, dst []byte, url string, c clie
oldBody := bodyBuf.B
bodyBuf.B = dst
statusCode, body, err = doRequestFollowRedirects(req, resp, url, defaultMaxRedirectsCount, c)
statusCode, _, err = doRequestFollowRedirects(req, resp, url, defaultMaxRedirectsCount, c)
body = bodyBuf.B
bodyBuf.B = oldBody
+3 -3
View File
@@ -84,7 +84,7 @@ func TestClientInvalidURI(t *testing.T) {
atomic.AddInt64(&requests, 1)
},
}
go s.Serve(ln)
go s.Serve(ln) //nolint:errcheck
c := &Client{
Dial: func(addr string) (net.Conn, error) {
return ln.Dial()
@@ -113,10 +113,10 @@ func TestClientGetWithBody(t *testing.T) {
s := &Server{
Handler: func(ctx *RequestCtx) {
body := ctx.Request.Body()
ctx.Write(body)
ctx.Write(body) //nolint:errcheck
},
}
go s.Serve(ln)
go s.Serve(ln) //nolint:errcheck
c := &Client{
Dial: func(addr string) (net.Conn, error) {
return ln.Dial()
+1 -1
View File
@@ -144,7 +144,7 @@ func setContextValueMiddleware(next fasthttp.RequestHandler, key string, value i
func TestContentType(t *testing.T) {
nethttpH := func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("<!doctype html><html>"))
w.Write([]byte("<!doctype html><html>")) //nolint:errcheck
}
fasthttpH := NewFastHTTPHandler(http.HandlerFunc(nethttpH))
+11 -11
View File
@@ -21,29 +21,29 @@ func TestInmemoryListener(t *testing.T) {
go func(n int) {
conn, err := ln.Dial()
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
defer conn.Close()
req := fmt.Sprintf("request_%d", n)
nn, err := conn.Write([]byte(req))
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
if nn != len(req) {
t.Fatalf("unexpected number of bytes written: %d. Expecting %d", nn, len(req))
t.Errorf("unexpected number of bytes written: %d. Expecting %d", nn, len(req))
}
buf := make([]byte, 30)
nn, err = conn.Read(buf)
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
buf = buf[:nn]
resp := fmt.Sprintf("response_%d", n)
if nn != len(resp) {
t.Fatalf("unexpected number of bytes read: %d. Expecting %d", nn, len(resp))
t.Errorf("unexpected number of bytes read: %d. Expecting %d", nn, len(resp))
}
if string(buf) != resp {
t.Fatalf("unexpected response %q. Expecting %q", buf, resp)
t.Errorf("unexpected response %q. Expecting %q", buf, resp)
}
ch <- struct{}{}
}(i)
@@ -61,19 +61,19 @@ func TestInmemoryListener(t *testing.T) {
buf := make([]byte, 30)
n, err := conn.Read(buf)
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
buf = buf[:n]
if !bytes.HasPrefix(buf, []byte("request_")) {
t.Fatalf("unexpected request prefix %q. Expecting %q", buf, "request_")
t.Errorf("unexpected request prefix %q. Expecting %q", buf, "request_")
}
resp := fmt.Sprintf("response_%s", buf[len("request_"):])
n, err = conn.Write([]byte(resp))
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
if n != len(resp) {
t.Fatalf("unexpected number of bytes written: %d. Expecting %d", n, len(resp))
t.Errorf("unexpected number of bytes written: %d. Expecting %d", n, len(resp))
}
}
}()
@@ -129,7 +129,7 @@ func testInmemoryListenerHTTP(t *testing.T, f func(t *testing.T, client *http.Cl
go func() {
if err := server.Serve(ln); err != nil && err != http.ErrServerClosed {
t.Fatalf("unexpected error: %s", err)
t.Errorf("unexpected error: %s", err)
}
}()
@@ -143,7 +143,7 @@ func benchmarkExt(b *testing.B, h fasthttp.RequestHandler, bc *benchConfig) {
serverLn = tls.NewListener(serverLn, serverTLSConfig)
}
if err := fasthttp.Serve(serverLn, h); err != nil {
b.Fatalf("unexpected error in server: %s", err)
b.Errorf("unexpected error in server: %s", err)
}
close(serverStopCh)
}()
+1 -1
View File
@@ -725,7 +725,7 @@ func swapResponseBody(a, b *Response) {
// URI returns request URI
func (req *Request) URI() *URI {
req.parseURI()
req.parseURI() //nolint:errcheck
return &req.uri
}
+1 -1
View File
@@ -21,7 +21,7 @@ func TestFragmentInURIRequest(t *testing.T) {
req.SetRequestURI("https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#events")
var b bytes.Buffer
req.WriteTo(&b)
req.WriteTo(&b) //nolint:errcheck
got := b.String()
expected := "GET /ee/user/project/integrations/webhooks.html HTTP/1.1\r\nHost: docs.gitlab.com\r\n\r\n"
+1 -1
View File
@@ -66,7 +66,7 @@ func testNewListener(t *testing.T, network, addr string, serversCount, requestsC
ch := make(chan struct{})
go func() {
if resp, err = ioutil.ReadAll(c); err != nil {
t.Fatalf("%d. unexpected error when reading response: %s", i, err)
t.Errorf("%d. unexpected error when reading response: %s", i, err)
}
close(ch)
}()
+8 -2
View File
@@ -1575,7 +1575,10 @@ func (s *Server) ServeTLS(ln net.Listener, certFile, keyFile string) error {
if s.tlsConfig == nil {
return errNoCertOrKeyProvided
}
s.tlsConfig.BuildNameToCertificate()
// BuildNameToCertificate has been deprecated since 1.14.
// But since we also support older versions we'll keep this here.
s.tlsConfig.BuildNameToCertificate() //nolint:staticcheck
return s.Serve(
tls.NewListener(ln, s.tlsConfig),
@@ -1596,7 +1599,10 @@ func (s *Server) ServeTLSEmbed(ln net.Listener, certData, keyData []byte) error
if s.tlsConfig == nil {
return errNoCertOrKeyProvided
}
s.tlsConfig.BuildNameToCertificate()
// BuildNameToCertificate has been deprecated since 1.14.
// But since we also support older versions we'll keep this here.
s.tlsConfig.BuildNameToCertificate() //nolint:staticcheck
return s.Serve(
tls.NewListener(ln, s.tlsConfig),
+2 -2
View File
@@ -2293,7 +2293,7 @@ func TestRequestCtxNoHijackNoResponse(t *testing.T) {
s := &Server{
Handler: func(ctx *RequestCtx) {
io.WriteString(ctx, "test")
io.WriteString(ctx, "test") //nolint:errcheck
ctx.HijackSetNoResponse(true)
},
}
@@ -2319,7 +2319,7 @@ func TestRequestCtxNoHijackNoResponse(t *testing.T) {
strings.NewReader(rw.w.String()),
)
resp := AcquireResponse()
resp.Read(bf)
resp.Read(bf) //nolint:errcheck
if got := string(resp.Body()); got != "test" {
t.Errorf(`expected "test", got %q`, got)
}
+7 -7
View File
@@ -56,7 +56,7 @@ func testURIAcquireRelease(t *testing.T) {
host := fmt.Sprintf("host.%d.com", i*23)
path := fmt.Sprintf("/foo/%d/bar", i*17)
queryArgs := "?foo=bar&baz=aass"
u.Parse([]byte(host), []byte(path+queryArgs))
u.Parse([]byte(host), []byte(path+queryArgs)) //nolint:errcheck
if string(u.Host()) != host {
t.Fatalf("unexpected host %q. Expecting %q", u.Host(), host)
}
@@ -133,7 +133,7 @@ func TestURIUpdate(t *testing.T) {
func testURIUpdate(t *testing.T, base, update, result string) {
var u URI
u.Parse(nil, []byte(base))
u.Parse(nil, []byte(base)) //nolint:errcheck
u.Update(update)
s := u.String()
if s != result {
@@ -190,7 +190,7 @@ func TestURIPathNormalize(t *testing.T) {
}
func testURIPathNormalize(t *testing.T, u *URI, requestURI, expectedPath string) {
u.Parse(nil, []byte(requestURI))
u.Parse(nil, []byte(requestURI)) //nolint:errcheck
if string(u.Path()) != expectedPath {
t.Fatalf("Unexpected path %q. Expected %q. requestURI=%q", u.Path(), expectedPath, requestURI)
}
@@ -201,7 +201,7 @@ func TestURINoNormalization(t *testing.T) {
var u URI
irregularPath := "/aaa%2Fbbb%2F%2E.%2Fxxx"
u.Parse(nil, []byte(irregularPath))
u.Parse(nil, []byte(irregularPath)) //nolint:errcheck
u.DisablePathNormalizing = true
if string(u.RequestURI()) != irregularPath {
t.Fatalf("Unexpected path %q. Expected %q.", u.Path(), irregularPath)
@@ -250,7 +250,7 @@ func TestURIFullURI(t *testing.T) {
// test with empty args and non-empty query string
var u URI
u.Parse([]byte("google.com"), []byte("/foo?bar=baz&baraz#qqqq"))
u.Parse([]byte("google.com"), []byte("/foo?bar=baz&baraz#qqqq")) //nolint:errcheck
uri := u.FullURI()
expectedURI := "http://google.com/foo?bar=baz&baraz#qqqq"
if string(uri) != expectedURI {
@@ -287,7 +287,7 @@ func TestURIParseNilHost(t *testing.T) {
func testURIParseScheme(t *testing.T, uri, expectedScheme, expectedHost, expectedRequestURI, expectedHash string) {
var u URI
u.Parse(nil, []byte(uri))
u.Parse(nil, []byte(uri)) //nolint:errcheck
if string(u.Scheme()) != expectedScheme {
t.Fatalf("Unexpected scheme %q. Expecting %q for uri %q", u.Scheme(), expectedScheme, uri)
}
@@ -361,7 +361,7 @@ func TestURIParse(t *testing.T) {
func testURIParse(t *testing.T, u *URI, host, uri,
expectedURI, expectedHost, expectedPath, expectedPathOriginal, expectedArgs, expectedHash string) {
u.Parse([]byte(host), []byte(uri))
u.Parse([]byte(host), []byte(uri)) //nolint:errcheck
if !bytes.Equal(u.FullURI(), []byte(expectedURI)) {
t.Fatalf("Unexpected uri %q. Expected %q. host=%q, uri=%q", u.FullURI(), expectedURI, host, uri)
+2 -2
View File
@@ -27,7 +27,7 @@ func BenchmarkURIFullURI(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
var u URI
u.Parse(host, requestURI)
u.Parse(host, requestURI) //nolint:errcheck
for pb.Next() {
uri := u.FullURI()
if len(uri) != uriLen {
@@ -43,7 +43,7 @@ func benchmarkURIParse(b *testing.B, host, uri string) {
b.RunParallel(func(pb *testing.PB) {
var u URI
for pb.Next() {
u.Parse(strHost, strURI)
u.Parse(strHost, strURI) //nolint:errcheck
}
})
}