ci(lint): refactor test assertions and linter configuration (#4436)

- Update golangci-lint GitHub Action version from v2.1.6 to v2.6
- Remove the gci formatter and exclusions for third_party, builtin, and examples from the linter config
- Fix argument order for assert.EqualValues and assert.Exactly in context tests for clarity
- Refactor integration tests to build response strings using strings.Builder instead of direct concatenation for improved performance and readability

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2025-11-15 19:21:42 +08:00 committed by GitHub
parent 19c2d5c0d1
commit fb27ef26c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 13 deletions

View File

@ -26,7 +26,7 @@ jobs:
- name: Setup golangci-lint - name: Setup golangci-lint
uses: golangci/golangci-lint-action@v9 uses: golangci/golangci-lint-action@v9
with: with:
version: v2.1.6 version: v2.6
args: --verbose args: --verbose
test: test:
needs: lint needs: lint

View File

@ -68,7 +68,6 @@ linters:
- examples$ - examples$
formatters: formatters:
enable: enable:
- gci
- gofmt - gofmt
- gofumpt - gofumpt
- goimports - goimports
@ -80,7 +79,4 @@ formatters:
exclusions: exclusions:
generated: lax generated: lax
paths: paths:
- third_party$
- builtin$
- examples$
- gin.go - gin.go

View File

@ -292,7 +292,7 @@ func TestContextReset(t *testing.T) {
assert.Empty(t, c.Errors.Errors()) assert.Empty(t, c.Errors.Errors())
assert.Empty(t, c.Errors.ByType(ErrorTypeAny)) assert.Empty(t, c.Errors.ByType(ErrorTypeAny))
assert.Empty(t, c.Params) assert.Empty(t, c.Params)
assert.EqualValues(t, c.index, -1) assert.EqualValues(t, -1, c.index)
assert.Equal(t, c.Writer.(*responseWriter), &c.writermem) assert.Equal(t, c.Writer.(*responseWriter), &c.writermem)
} }
@ -384,7 +384,7 @@ func TestContextSetGetValues(t *testing.T) {
c.Set("intInterface", a) c.Set("intInterface", a)
assert.Exactly(t, "this is a string", c.MustGet("string").(string)) assert.Exactly(t, "this is a string", c.MustGet("string").(string))
assert.Exactly(t, c.MustGet("int32").(int32), int32(-42)) assert.Exactly(t, int32(-42), c.MustGet("int32").(int32))
assert.Exactly(t, int64(42424242424242), c.MustGet("int64").(int64)) assert.Exactly(t, int64(42424242424242), c.MustGet("int64").(int64))
assert.Exactly(t, uint64(42), c.MustGet("uint64").(uint64)) assert.Exactly(t, uint64(42), c.MustGet("uint64").(uint64))
assert.InDelta(t, float32(4.2), c.MustGet("float32").(float32), 0.01) assert.InDelta(t, float32(4.2), c.MustGet("float32").(float32), 0.01)

View File

@ -16,6 +16,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -261,10 +262,11 @@ func TestUnixSocket(t *testing.T) {
fmt.Fprint(c, "GET /example HTTP/1.0\r\n\r\n") fmt.Fprint(c, "GET /example HTTP/1.0\r\n\r\n")
scanner := bufio.NewScanner(c) scanner := bufio.NewScanner(c)
var response string var responseBuilder strings.Builder
for scanner.Scan() { for scanner.Scan() {
response += scanner.Text() responseBuilder.WriteString(scanner.Text())
} }
response := responseBuilder.String()
assert.Contains(t, response, "HTTP/1.0 200", "should get a 200") assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")
assert.Contains(t, response, "it worked", "resp body should match") assert.Contains(t, response, "it worked", "resp body should match")
} }
@ -322,10 +324,11 @@ func TestFileDescriptor(t *testing.T) {
fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n") fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")
scanner := bufio.NewScanner(c) scanner := bufio.NewScanner(c)
var response string var responseBuilder strings.Builder
for scanner.Scan() { for scanner.Scan() {
response += scanner.Text() responseBuilder.WriteString(scanner.Text())
} }
response := responseBuilder.String()
assert.Contains(t, response, "HTTP/1.0 200", "should get a 200") assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")
assert.Contains(t, response, "it worked", "resp body should match") assert.Contains(t, response, "it worked", "resp body should match")
} }
@ -354,10 +357,11 @@ func TestListener(t *testing.T) {
fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n") fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")
scanner := bufio.NewScanner(c) scanner := bufio.NewScanner(c)
var response string var responseBuilder strings.Builder
for scanner.Scan() { for scanner.Scan() {
response += scanner.Text() responseBuilder.WriteString(scanner.Text())
} }
response := responseBuilder.String()
assert.Contains(t, response, "HTTP/1.0 200", "should get a 200") assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")
assert.Contains(t, response, "it worked", "resp body should match") assert.Contains(t, response, "it worked", "resp body should match")
} }