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