Skip to content
Myr

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

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

- 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

authored by Bo-Yi Wu · committed by GitHub · parent 19c2d5c · Browse files · 4 files+13 added−13 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: appleboy <appleboy.tw@gmail.com>

Diff stats

4 files+13 added−13 removed

  • other:+13 added−13 removed

4 files+13 added−13 removed

modified:.github/workflows/gin.yml+1 added-1 removed
modified:.golangci.yml-4 removed
modified:context_test.go+2 added-2 removed
290 unmodified lines
291 assert.Empty(t, c.Errors)292 assert.Empty(t, c.Errors.Errors())293 assert.Empty(t, c.Errors.ByType(ErrorTypeAny))294 assert.Empty(t, c.Params)295 assert.EqualValues(t, c.index, -1)295 assert.EqualValues(t, -1, c.index)296 assert.Equal(t, c.Writer.(*responseWriter), &c.writermem)297}298299func TestContextHandlers(t *testing.T) {
83 unmodified lines
383 var a any = 1384 c.Set("intInterface", a)385386 assert.Exactly(t, "this is a string", c.MustGet("string").(string))387 assert.Exactly(t, c.MustGet("int32").(int32), int32(-42))387 assert.Exactly(t, int32(-42), c.MustGet("int32").(int32))388 assert.Exactly(t, int64(42424242424242), c.MustGet("int64").(int64))389 assert.Exactly(t, uint64(42), c.MustGet("uint64").(uint64))390 assert.InDelta(t, float32(4.2), c.MustGet("float32").(float32), 0.01)391 assert.InDelta(t, 4.2, c.MustGet("float64").(float64), 0.01)
3288 unmodified lines
modified:gin_integration_test.go+10 added-6 removed
14 unmodified lines
15 "net/http/httptest"16 "os"17 "path/filepath"18 "runtime"19 "strings"20 "sync"21 "testing"22 "time"23
237 unmodified lines
261 require.NoError(t, err)262263 fmt.Fprint(c, "GET /example HTTP/1.0\r\n\r\n")264 scanner := bufio.NewScanner(c)264 var response string265 var responseBuilder strings.Builder266 for scanner.Scan() {266 response += scanner.Text()267 responseBuilder.WriteString(scanner.Text())268 }269 response := responseBuilder.String()270 assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")271 assert.Contains(t, response, "it worked", "resp body should match")272}273
49 unmodified lines
323 require.NoError(t, err)324325 fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")326 scanner := bufio.NewScanner(c)325 var response string327 var responseBuilder strings.Builder328 for scanner.Scan() {327 response += scanner.Text()329 responseBuilder.WriteString(scanner.Text())330 }331 response := responseBuilder.String()332 assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")333 assert.Contains(t, response, "it worked", "resp body should match")334}335
20 unmodified lines
356 require.NoError(t, err)357358 fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")359 scanner := bufio.NewScanner(c)357 var response string360 var responseBuilder strings.Builder361 for scanner.Scan() {359 response += scanner.Text()362 responseBuilder.WriteString(scanner.Text())363 }364 response := responseBuilder.String()365 assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")366 assert.Contains(t, response, "it worked", "resp body should match")367}368
236 unmodified lines