Skip to content

Commit 57710ec

Browse files
committed
fix lint errors
1 parent c5aeed5 commit 57710ec

File tree

6 files changed

+52
-52
lines changed

6 files changed

+52
-52
lines changed

pkg/client/client_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ func TestWritePumpContextCancellation(t *testing.T) {
24742474
// Should exit with context error
24752475
select {
24762476
case err := <-errCh:
2477-
if err != context.Canceled {
2477+
if !errors.Is(err, context.Canceled) {
24782478
t.Errorf("Expected context.Canceled, got: %v", err)
24792479
}
24802480
case <-time.After(1 * time.Second):
@@ -2523,11 +2523,9 @@ func TestReadEventsContextCancellation(t *testing.T) {
25232523
ticker := time.NewTicker(100 * time.Millisecond)
25242524
defer ticker.Stop()
25252525
for range 30 { // Try for 3 seconds max
2526-
select {
2527-
case <-ticker.C:
2528-
msg := map[string]string{"type": "ping"}
2529-
_ = websocket.JSON.Send(ws, msg)
2530-
}
2526+
<-ticker.C
2527+
msg := map[string]string{"type": "ping"}
2528+
_ = websocket.JSON.Send(ws, msg)
25312529
}
25322530
}))
25332531
defer srv.Close()
@@ -2560,7 +2558,7 @@ func TestReadEventsContextCancellation(t *testing.T) {
25602558
// Should exit when context times out
25612559
select {
25622560
case err := <-errCh:
2563-
if err != nil && err != context.DeadlineExceeded {
2561+
if err != nil && !errors.Is(err, context.DeadlineExceeded) {
25642562
t.Logf("readEvents exited with: %v (acceptable)", err)
25652563
}
25662564
case <-time.After(1 * time.Second):
@@ -2699,7 +2697,6 @@ func TestConnectWithWSSOrigin(t *testing.T) {
26992697
_ = client.Start(ctx)
27002698
}
27012699

2702-
27032700
// TestConnectEventTypesWildcard tests connecting with wildcard event type.
27042701
func TestConnectEventTypesWildcard(t *testing.T) {
27052702
srv := newMockServer(t, true)
@@ -2769,7 +2766,7 @@ func TestWriteChannelBackpressure(t *testing.T) {
27692766
"message": "Connected",
27702767
})
27712768

2772-
for i := 0; i < 200; i++ {
2769+
for i := range 200 {
27732770
event := map[string]any{
27742771
"type": "event",
27752772
"event_type": "push",
@@ -2883,7 +2880,7 @@ func TestWriteChannelClosedDuringOperation(t *testing.T) {
28832880
"message": "Connected",
28842881
})
28852882

2886-
for i := 0; i < 100; i++ {
2883+
for i := range 100 {
28872884
event := map[string]any{
28882885
"type": "event",
28892886
"event_type": "push",
@@ -2962,7 +2959,7 @@ func TestReadTimeoutDuringGracefulShutdown(t *testing.T) {
29622959
func TestConcurrentWebSocketClose(t *testing.T) {
29632960
t.Parallel()
29642961

2965-
for i := 0; i < 10; i++ {
2962+
for range 10 {
29662963
srv := httptest.NewServer(websocket.Handler(func(ws *websocket.Conn) {
29672964
var sub map[string]any
29682965
_ = websocket.JSON.Receive(ws, &sub)

pkg/github/client_test.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"io"
87
"net/http"
98
"net/http/httptest"
109
"strings"
@@ -107,8 +106,8 @@ func TestAuthenticatedUser_RateLimit(t *testing.T) {
107106
attempts := 0
108107
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
109108
attempts++
110-
w.Header().Set("X-RateLimit-Remaining", "0")
111-
w.Header().Set("X-RateLimit-Reset", "1234567890")
109+
w.Header().Set("X-RateLimit-Remaining", "0") //nolint:canonicalheader // GitHub API header
110+
w.Header().Set("X-RateLimit-Reset", "1234567890") //nolint:canonicalheader // GitHub API header
112111
w.WriteHeader(http.StatusForbidden)
113112
_, _ = w.Write([]byte(`{"message":"API rate limit exceeded"}`))
114113
}))
@@ -841,16 +840,6 @@ func TestLargeResponseBody(t *testing.T) {
841840
}
842841

843842
// TestBrokenPipeError simulates a broken pipe during response read.
844-
type brokenReader struct{}
845-
846-
func (b *brokenReader) Read(p []byte) (n int, err error) {
847-
return 0, io.ErrUnexpectedEOF
848-
}
849-
850-
func (b *brokenReader) Close() error {
851-
return nil
852-
}
853-
854843
// TestUnexpectedStatusCodes tests handling of various unexpected status codes.
855844
func TestUnexpectedStatusCodes(t *testing.T) {
856845
t.Parallel()
@@ -869,6 +858,7 @@ func TestUnexpectedStatusCodes(t *testing.T) {
869858

870859
for _, tc := range testCases {
871860
t.Run(tc.name, func(t *testing.T) {
861+
t.Parallel()
872862
attempts := 0
873863
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
874864
attempts++
@@ -903,6 +893,7 @@ func TestMockClient(t *testing.T) {
903893
t.Parallel()
904894

905895
t.Run("UserAndOrgs success", func(t *testing.T) {
896+
t.Parallel()
906897
mock := &MockClient{
907898
Username: "testuser",
908899
Orgs: []string{"org1", "org2"},
@@ -926,6 +917,7 @@ func TestMockClient(t *testing.T) {
926917
})
927918

928919
t.Run("UserAndOrgs error", func(t *testing.T) {
920+
t.Parallel()
929921
mockErr := fmt.Errorf("mock error")
930922
mock := &MockClient{
931923
Err: mockErr,
@@ -943,6 +935,7 @@ func TestMockClient(t *testing.T) {
943935
})
944936

945937
t.Run("ValidateOrgMembership success", func(t *testing.T) {
938+
t.Parallel()
946939
mock := &MockClient{
947940
Username: "testuser",
948941
Orgs: []string{"org1", "org2"},
@@ -969,6 +962,7 @@ func TestMockClient(t *testing.T) {
969962
})
970963

971964
t.Run("ValidateOrgMembership not member", func(t *testing.T) {
965+
t.Parallel()
972966
mock := &MockClient{
973967
Username: "testuser",
974968
Orgs: []string{"org1", "org2"},
@@ -993,6 +987,7 @@ func TestMockClient(t *testing.T) {
993987
})
994988

995989
t.Run("ValidateOrgMembership error", func(t *testing.T) {
990+
t.Parallel()
996991
mockErr := fmt.Errorf("mock validation error")
997992
mock := &MockClient{
998993
Err: mockErr,
@@ -1010,6 +1005,7 @@ func TestMockClient(t *testing.T) {
10101005
})
10111006

10121007
t.Run("multiple calls tracking", func(t *testing.T) {
1008+
t.Parallel()
10131009
mock := &MockClient{
10141010
Username: "testuser",
10151011
Orgs: []string{"org1"},
@@ -1462,13 +1458,15 @@ func TestUserAndOrgs_TokenTypeDetection(t *testing.T) {
14621458

14631459
for _, tt := range tests {
14641460
t.Run(tt.name, func(t *testing.T) {
1461+
t.Parallel()
14651462
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1466-
if r.URL.Path == "/installation/repositories" {
1463+
switch r.URL.Path {
1464+
case "/installation/repositories":
14671465
w.WriteHeader(http.StatusNotFound)
1468-
} else if r.URL.Path == "/user" {
1466+
case "/user":
14691467
w.WriteHeader(http.StatusOK)
14701468
_ = json.NewEncoder(w).Encode(User{Login: "testuser"})
1471-
} else if r.URL.Path == "/user/orgs" {
1469+
case "/user/orgs":
14721470
w.WriteHeader(http.StatusOK)
14731471
_ = json.NewEncoder(w).Encode([]Organization{})
14741472
}

pkg/logger/logger_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,28 +369,28 @@ func TestAllFunctionsWithNilContext(t *testing.T) {
369369
SetLogger(logger)
370370

371371
// Test Info with nil context
372-
Info(nil, "info with nil context", Fields{"key": "value"})
372+
Info(context.TODO(), "info with nil context", Fields{"key": "value"})
373373
if !strings.Contains(buf.String(), "info with nil context") {
374374
t.Error("Info did not handle nil context")
375375
}
376376

377377
// Test Warn with nil context
378378
buf.Reset()
379-
Warn(nil, "warn with nil context", Fields{"key": "value"})
379+
Warn(context.TODO(), "warn with nil context", Fields{"key": "value"})
380380
if !strings.Contains(buf.String(), "warn with nil context") {
381381
t.Error("Warn did not handle nil context")
382382
}
383383

384384
// Test Error with nil context
385385
buf.Reset()
386386
err := errors.New("test error")
387-
Error(nil, "error with nil context", err, Fields{"key": "value"})
387+
Error(context.TODO(), "error with nil context", err, Fields{"key": "value"})
388388
if !strings.Contains(buf.String(), "error with nil context") {
389389
t.Error("Error did not handle nil context")
390390
}
391391

392392
// Test Debug with nil context
393393
buf.Reset()
394-
Debug(nil, "debug with nil context", Fields{"key": "value"})
394+
Debug(context.TODO(), "debug with nil context", Fields{"key": "value"})
395395
// Debug is filtered by default, just ensure no panic
396396
}

pkg/security/security_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func TestConnectionLimiterReservationMaxIPEntries(t *testing.T) {
361361

362362
// Fill up to near-max entries to trigger eviction logic
363363
// maxIPEntries is 10000, so we create many inactive entries
364-
for i := 0; i < 10005; i++ {
364+
for i := range 10005 {
365365
ip := fmt.Sprintf("192.168.%d.%d", i/256, i%256)
366366
// Create reservation then cancel to make it inactive
367367
token := limiter.Reserve(ip)
@@ -404,7 +404,7 @@ func TestConnectionLimiterEvictWithAllActive(t *testing.T) {
404404
defer limiter.Stop()
405405

406406
// Create many active connections (no inactive to evict)
407-
for i := 0; i < 10005; i++ {
407+
for i := range 10005 {
408408
ip := fmt.Sprintf("192.168.%d.%d", i/256, i%256)
409409
token := limiter.Reserve(ip)
410410
if token != "" {

pkg/srv/websocket_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,6 +2548,7 @@ func TestWebSocketCloseErrors(t *testing.T) {
25482548
t.Parallel()
25492549

25502550
t.Run("close already closed connection", func(t *testing.T) {
2551+
t.Parallel()
25512552
server := httptest.NewServer(websocket.Handler(func(ws *websocket.Conn) {
25522553
time.Sleep(50 * time.Millisecond)
25532554
}))
@@ -2567,6 +2568,7 @@ func TestWebSocketCloseErrors(t *testing.T) {
25672568
})
25682569

25692570
t.Run("close with broken pipe", func(t *testing.T) {
2571+
t.Parallel()
25702572
// Simulate broken pipe by forcefully closing underlying connection
25712573
server := httptest.NewServer(websocket.Handler(func(ws *websocket.Conn) {
25722574
time.Sleep(20 * time.Millisecond)
@@ -2675,7 +2677,7 @@ func TestConcurrentClientCloseOperations(t *testing.T) {
26752677
go hub.Run(ctx)
26762678
defer hub.Stop()
26772679

2678-
for i := 0; i < 50; i++ {
2680+
for i := range 50 {
26792681
client := &Client{
26802682
ID: fmt.Sprintf("test-client-%d", i),
26812683
send: make(chan Event, 10),
@@ -2685,7 +2687,7 @@ func TestConcurrentClientCloseOperations(t *testing.T) {
26852687

26862688
// Trigger multiple concurrent closes
26872689
var wg sync.WaitGroup
2688-
for j := 0; j < 5; j++ {
2690+
for range 5 {
26892691
wg.Add(1)
26902692
go func() {
26912693
defer wg.Done()
@@ -2758,9 +2760,9 @@ func TestValidateAuthConcurrentAccess(t *testing.T) {
27582760

27592761
// Create many concurrent WebSocket connections
27602762
var wg sync.WaitGroup
2761-
for i := 0; i < 20; i++ {
2763+
for range 20 {
27622764
wg.Add(1)
2763-
go func(id int) {
2765+
go func() {
27642766
defer wg.Done()
27652767

27662768
server := httptest.NewServer(websocket.Handler(func(ws *websocket.Conn) {
@@ -2780,7 +2782,7 @@ func TestValidateAuthConcurrentAccess(t *testing.T) {
27802782
}
27812783

27822784
_, _ = handler.validateAuth(ctx, ws, sub, "test-token", "127.0.0.1")
2783-
}(i)
2785+
}()
27842786
}
27852787
wg.Wait()
27862788
}
@@ -2799,7 +2801,7 @@ func TestHandleRapidDisconnectReconnect(t *testing.T) {
27992801

28002802
handler := NewWebSocketHandlerForTest(hub, connLimiter, nil)
28012803

2802-
for i := 0; i < 30; i++ {
2804+
for range 30 {
28032805
server := httptest.NewServer(websocket.Handler(handler.Handle))
28042806

28052807
wsURL := "ws" + strings.TrimPrefix(server.URL, "http")

pkg/webhook/handler_test.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"net/http"
1111
"net/http/httptest"
12+
"strings"
1213
"testing"
1314

1415
"github.com/codeGROOVE-dev/sprinkler/pkg/srv"
@@ -608,7 +609,7 @@ func TestExtractPRURLVariations(t *testing.T) {
608609
// - Include commit SHA so clients can look up the PR later
609610
// - Org-based subscriptions still work with repo URL
610611
// - Only drop event if we can't extract ANY repository information
611-
func TestCheckEventRaceCondition(t *testing.T) {
612+
func TestCheckEventRaceCondition(t *testing.T) { //nolint:gocognit,maintidx // Test requires comprehensive validation
612613
ctx, cancel := context.WithCancel(context.Background())
613614
defer cancel()
614615

@@ -764,8 +765,8 @@ func TestCheckEventRaceCondition(t *testing.T) {
764765
}
765766

766767
req := httptest.NewRequest(http.MethodPost, "/webhook", bytes.NewReader(body))
767-
req.Header.Set("X-GitHub-Event", tt.eventType) //nolint:canonicalheader // GitHub webhook header
768-
req.Header.Set("X-GitHub-Delivery", "test-delivery-"+tt.name)
768+
req.Header.Set("X-GitHub-Event", tt.eventType) //nolint:canonicalheader // GitHub webhook header
769+
req.Header.Set("X-GitHub-Delivery", "test-delivery-"+tt.name) //nolint:canonicalheader // GitHub webhook header
769770

770771
// Add valid signature
771772
mac := hmac.New(sha256.New, []byte(secret))
@@ -787,7 +788,8 @@ func TestCheckEventRaceCondition(t *testing.T) {
787788
ctx := context.Background()
788789
extractedURL := ExtractPRURL(ctx, tt.eventType, tt.payload)
789790

790-
if tt.expectRepoURL {
791+
switch {
792+
case tt.expectRepoURL:
791793
// ExtractPRURL should return empty (no PR URL)
792794
if extractedURL != "" {
793795
t.Errorf("Expected ExtractPRURL to return empty (triggering repo fallback), got %q", extractedURL)
@@ -798,18 +800,18 @@ func TestCheckEventRaceCondition(t *testing.T) {
798800
t.Fatal("Test setup error: repository.html_url missing")
799801
}
800802
// Repo URL should NOT contain /pull/
801-
if contains := bytes.Contains([]byte(repoURL), []byte("/pull/")); contains {
803+
if contains := strings.Contains(repoURL, "/pull/"); contains {
802804
t.Errorf("Repo URL should not contain /pull/, got %q", repoURL)
803805
}
804-
} else if tt.expectBroadcast {
806+
case tt.expectBroadcast:
805807
// Should have PR URL (normal case)
806808
if extractedURL == "" {
807809
t.Error("Expected PR URL but got empty string")
808810
}
809-
if contains := bytes.Contains([]byte(extractedURL), []byte("/pull/")); !contains {
811+
if contains := strings.Contains(extractedURL, "/pull/"); !contains {
810812
t.Errorf("Expected PR URL with /pull/, got %q", extractedURL)
811813
}
812-
} else {
814+
default:
813815
// Event should be dropped, no URL
814816
if extractedURL != "" {
815817
t.Errorf("Expected empty URL for dropped event, got %q", extractedURL)
@@ -824,11 +826,12 @@ func TestCheckEventRaceCondition(t *testing.T) {
824826
}
825827
// Verify it matches the SHA in payload
826828
var expectedSHA string
827-
if tt.eventType == "check_run" {
829+
switch tt.eventType {
830+
case "check_run":
828831
if checkRun, ok := tt.payload["check_run"].(map[string]any); ok {
829832
expectedSHA, _ = checkRun["head_sha"].(string)
830833
}
831-
} else if tt.eventType == "check_suite" {
834+
case "check_suite":
832835
if checkSuite, ok := tt.payload["check_suite"].(map[string]any); ok {
833836
expectedSHA, _ = checkSuite["head_sha"].(string)
834837
}
@@ -877,8 +880,8 @@ func TestCheckEventRaceConditionEndToEnd(t *testing.T) {
877880
}
878881

879882
req := httptest.NewRequest(http.MethodPost, "/webhook", bytes.NewReader(body))
880-
req.Header.Set("X-GitHub-Event", "check_run")
881-
req.Header.Set("X-GitHub-Delivery", "race-test-delivery-123")
883+
req.Header.Set("X-GitHub-Event", "check_run") //nolint:canonicalheader // GitHub webhook header
884+
req.Header.Set("X-GitHub-Delivery", "race-test-delivery-123") //nolint:canonicalheader // GitHub webhook header
882885

883886
mac := hmac.New(sha256.New, []byte(secret))
884887
mac.Write(body)
@@ -914,7 +917,7 @@ func TestCheckEventRaceConditionEndToEnd(t *testing.T) {
914917

915918
// Verify the repo URL is NOT a PR URL (no /pull/ in path)
916919
// This confirms the handler will use repo URL as fallback, not a PR URL
917-
if contains := bytes.Contains([]byte(repoURL), []byte("/pull/")); contains {
920+
if contains := strings.Contains(repoURL, "/pull/"); contains {
918921
t.Errorf("Repo URL should not contain /pull/, got %q", repoURL)
919922
}
920923
}

0 commit comments

Comments
 (0)