@@ -430,18 +430,29 @@ func Test_SearchCode(t *testing.T) {
430430 IncompleteResults : github .Ptr (false ),
431431 CodeResults : []* github.CodeResult {
432432 {
433- Name : github .Ptr ("file1.go" ),
434- Path : github .Ptr ("path/to/file1.go" ),
435- SHA : github .Ptr ("abc123def456" ),
436- HTMLURL : github .Ptr ("https://github.com/owner/repo/blob/main/path/to/file1.go" ),
437- Repository : & github.Repository {Name : github .Ptr ("repo" ), FullName : github .Ptr ("owner/repo" )},
433+ Name : github .Ptr ("file1.go" ),
434+ Path : github .Ptr ("path/to/file1.go" ),
435+ SHA : github .Ptr ("abc123def456" ),
436+ HTMLURL : github .Ptr ("https://github.com/owner/repo/blob/main/path/to/file1.go" ),
437+ Repository : & github.Repository {
438+ Name : github .Ptr ("repo" ),
439+ FullName : github .Ptr ("owner/repo" ),
440+ },
441+ TextMatches : []* github.TextMatch {
442+ {
443+ Fragment : github .Ptr ("func main() { fmt.Println(\" hello\" ) }" ),
444+ },
445+ },
438446 },
439447 {
440- Name : github .Ptr ("file2.go" ),
441- Path : github .Ptr ("path/to/file2.go" ),
442- SHA : github .Ptr ("def456abc123" ),
443- HTMLURL : github .Ptr ("https://github.com/owner/repo/blob/main/path/to/file2.go" ),
444- Repository : & github.Repository {Name : github .Ptr ("repo" ), FullName : github .Ptr ("owner/repo" )},
448+ Name : github .Ptr ("file2.go" ),
449+ Path : github .Ptr ("path/to/file2.go" ),
450+ SHA : github .Ptr ("def456abc123" ),
451+ HTMLURL : github .Ptr ("https://github.com/owner/repo/blob/main/path/to/file2.go" ),
452+ Repository : & github.Repository {
453+ Name : github .Ptr ("repo" ),
454+ FullName : github .Ptr ("owner/repo" ),
455+ },
445456 },
446457 },
447458 }
@@ -540,19 +551,28 @@ func Test_SearchCode(t *testing.T) {
540551 // Parse the result and get the text content if no error
541552 textContent := getTextResult (t , result )
542553
543- // Unmarshal and verify the result
544- var returnedResult github. CodeSearchResult
554+ // Unmarshal and verify the minimal result
555+ var returnedResult MinimalCodeSearchResult
545556 err = json .Unmarshal ([]byte (textContent .Text ), & returnedResult )
546557 require .NoError (t , err )
547- assert .Equal (t , * tc .expectedResult .Total , * returnedResult .Total )
548- assert .Equal (t , * tc .expectedResult .IncompleteResults , * returnedResult .IncompleteResults )
549- assert .Len (t , returnedResult .CodeResults , len (tc .expectedResult .CodeResults ))
550- for i , code := range returnedResult .CodeResults {
551- assert .Equal (t , * tc .expectedResult .CodeResults [i ].Name , * code .Name )
552- assert .Equal (t , * tc .expectedResult .CodeResults [i ].Path , * code .Path )
553- assert .Equal (t , * tc .expectedResult .CodeResults [i ].SHA , * code .SHA )
554- assert .Equal (t , * tc .expectedResult .CodeResults [i ].HTMLURL , * code .HTMLURL )
555- assert .Equal (t , * tc .expectedResult .CodeResults [i ].Repository .FullName , * code .Repository .FullName )
558+ assert .Equal (t , * tc .expectedResult .Total , returnedResult .TotalCount )
559+ assert .Equal (t , * tc .expectedResult .IncompleteResults , returnedResult .IncompleteResults )
560+ assert .Len (t , returnedResult .Items , len (tc .expectedResult .CodeResults ))
561+ for i , code := range returnedResult .Items {
562+ assert .Equal (t , tc .expectedResult .CodeResults [i ].GetName (), code .Name )
563+ assert .Equal (t , tc .expectedResult .CodeResults [i ].GetPath (), code .Path )
564+ assert .Equal (t , tc .expectedResult .CodeResults [i ].GetSHA (), code .SHA )
565+ assert .Equal (t , tc .expectedResult .CodeResults [i ].GetHTMLURL (), code .HTMLURL )
566+ assert .Equal (t , tc .expectedResult .CodeResults [i ].Repository .GetFullName (), code .Repository )
567+ }
568+
569+ // Verify text matches are included when present
570+ if len (tc .expectedResult .CodeResults [0 ].TextMatches ) > 0 {
571+ require .NotEmpty (t , returnedResult .Items [0 ].TextMatches )
572+ assert .Equal (t ,
573+ tc .expectedResult .CodeResults [0 ].TextMatches [0 ].GetFragment (),
574+ returnedResult .Items [0 ].TextMatches [0 ].GetFragment (),
575+ )
556576 }
557577 })
558578 }
0 commit comments