Skip to content
Myr

ci(lint): enable perfsprint linter (#4090)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Matthieu MOREL · committed by GitHub · parent f875d87 · Browse files · 7 files+31 added−22 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

Diff stats

7 files+31 added−22 removed

  • other:+31 added−22 removed

7 files+31 added−22 removed

modified:binding/form_mapping_test.go+4 added-4 removed
4 unmodified lines
5package binding67import (8 "encoding/hex"9 "fmt"9 "errors"10 "mime/multipart"11 "reflect"12 "strconv"13 "strings"
479 unmodified lines
493494func (f *customUnmarshalParamType) UnmarshalParam(param string) error {495 parts := strings.Split(param, ":")496 if len(parts) != 3 {497 return fmt.Errorf("invalid format")497 return errors.New("invalid format")498 }499 f.Protocol = parts[0]500 f.Path = parts[1]501 f.Name = parts[2]
53 unmodified lines
555func (p *customPath) UnmarshalParam(param string) error {556 elems := strings.Split(param, "/")557 n := len(elems)558 if n < 2 {559 return fmt.Errorf("invalid format")559 return errors.New("invalid format")560 }561562 *p = elems563 return nil
35 unmodified lines
599600func convertTo(s string) (objectID, error) {601 var nilObjectID objectID602 if len(s) != 24 {603 return nilObjectID, fmt.Errorf("invalid format")603 return nilObjectID, errors.New("invalid format")604 }605606 var oid [12]byte607 _, err := hex.Decode(oid[:], []byte(s))
30 unmodified lines
modified:.golangci.yml+8 added
modified:context_test.go+3 added-2 removed
16 unmodified lines
17 "net/http/httptest"18 "net/url"19 "os"20 "reflect"21 "strconv"22 "strings"23 "sync"24 "testing"25 "time"
2607 unmodified lines
26332634 assert.Equal(t, http.StatusOK, w.Code)2635 assert.Equal(t, body, w.Body.String())2636 assert.Equal(t, contentType, w.Header().Get("Content-Type"))2636 assert.Equal(t, fmt.Sprintf("%d", contentLength), w.Header().Get("Content-Length"))2637 assert.Equal(t, strconv.FormatInt(contentLength, 10), w.Header().Get("Content-Length"))2638 assert.Equal(t, extraHeaders["Content-Disposition"], w.Header().Get("Content-Disposition"))2639}26402641func TestContextRenderDataFromReaderNoHeaders(t *testing.T) {
9 unmodified lines
26512652 assert.Equal(t, http.StatusOK, w.Code)2653 assert.Equal(t, body, w.Body.String())2654 assert.Equal(t, contentType, w.Header().Get("Content-Type"))2654 assert.Equal(t, fmt.Sprintf("%d", contentLength), w.Header().Get("Content-Length"))2655 assert.Equal(t, strconv.FormatInt(contentLength, 10), w.Header().Get("Content-Length"))2656}26572658type TestResponseRecorder struct {2659 *httptest.ResponseRecorder
425 unmodified lines
modified:gin_test.go+10 added-10 removed
71 unmodified lines
72 },73 )74 defer ts.Close()7576 res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))76 res, err := http.Get(ts.URL + "/test")77 if err != nil {78 t.Error(err)79 }80
49 unmodified lines
130 },131 )132 defer ts.Close()133134 res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))134 res, err := http.Get(ts.URL + "/test")135 if err != nil {136 t.Error(err)137 }138
11 unmodified lines
150 },151 )152 defer ts.Close()153154 res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))154 res, err := http.Get(ts.URL + "/test")155 if err != nil {156 t.Error(err)157 }158
18 unmodified lines
177 InsecureSkipVerify: true,178 },179 }180 client := &http.Client{Transport: tr}181 res, err := client.Get(fmt.Sprintf("%s/test", ts.URL))181 res, err := client.Get(ts.URL + "/test")182 if err != nil {183 t.Error(err)184 }185
11 unmodified lines
197 },198 )199 defer ts.Close()200201 res, err := http.Get(fmt.Sprintf("%s/raw", ts.URL))201 res, err := http.Get(ts.URL + "/raw")202 if err != nil {203 t.Error(err)204 }205
22 unmodified lines
228 },229 )230 defer ts.Close()231232 res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))232 res, err := http.Get(ts.URL + "/test")233 if err != nil {234 t.Error(err)235 }236
11 unmodified lines
248 },249 )250 defer ts.Close()251252 res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))252 res, err := http.Get(ts.URL + "/test")253 if err != nil {254 t.Error(err)255 }256
11 unmodified lines
268 },269 )270 defer ts.Close()271272 res, err := http.Get(fmt.Sprintf("%s/test", ts.URL))272 res, err := http.Get(ts.URL + "/test")273 if err != nil {274 t.Error(err)275 }276
18 unmodified lines
295 InsecureSkipVerify: true,296 },297 }298 client := &http.Client{Transport: tr}299 res, err := client.Get(fmt.Sprintf("%s/test", ts.URL))299 res, err := client.Get(ts.URL + "/test")300 if err != nil {301 t.Error(err)302 }303
11 unmodified lines
315 },316 )317 defer ts.Close()318319 res, err := http.Get(fmt.Sprintf("%s/raw", ts.URL))319 res, err := http.Get(ts.URL + "/raw")320 if err != nil {321 t.Error(err)322 }323
445 unmodified lines
modified:githubapi_test.go+3 added-2 removed
8 unmodified lines
9 "math/rand"10 "net/http"11 "net/http/httptest"12 "os"13 "strconv"14 "strings"15 "testing"1617 "github.com/stretchr/testify/assert"
393 unmodified lines
411 start = i + 1412 }413 if start >= 0 {414 if c == '/' {414 value := fmt.Sprint(rand.Intn(100000))415 value := strconv.Itoa(rand.Intn(100000))416 params = append(params, Param{417 Key: path[start:i],418 Value: value,419 })
5 unmodified lines
425 output.WriteRune(c)426 }427 }428 if start >= 0 {428 value := fmt.Sprint(rand.Intn(100000))429 value := strconv.Itoa(rand.Intn(100000))430 params = append(params, Param{431 Key: path[start:],432 Value: value,433 })
43 unmodified lines
modified:recovery_test.go+1 added-2 removed
3 unmodified lines
45package gin67import (8 "fmt"8 "net"9 "net/http"10 "os"11 "strings"
19 unmodified lines
31 Value: "www.google.com",32 },33 header{34 Key: "Authorization",36 Value: fmt.Sprintf("Bearer %s", password),35 Value: "Bearer " + password,36 },37 header{38 Key: "Content-Type",39 Value: "application/json",
208 unmodified lines
modified:routes_test.go+2 added-2 removed
558 unmodified lines
559 for _, tr := range testRoutes {560 w := PerformRequest(router, "GET", tr.route)561 assert.Equal(t, tr.code, w.Code)562 if w.Code != http.StatusNotFound {563 assert.Equal(t, tr.location, fmt.Sprint(w.Header().Get("Location")))563 assert.Equal(t, tr.location, w.Header().Get("Location"))564 }565 }566}567
21 unmodified lines
589 for _, tr := range testRoutes {590 w := PerformRequest(router, http.MethodGet, tr.route)591 assert.Equal(t, tr.code, w.Code)592 if w.Code != http.StatusNotFound {593 assert.Equal(t, tr.location, fmt.Sprint(w.Header().Get("Location")))593 assert.Equal(t, tr.location, w.Header().Get("Location"))594 }595 }596597 // Test custom not found handler
194 unmodified lines