MCPcopy Index your code
hub / github.com/google/go-github / TestSearchService_Code

Function TestSearchService_Code

github/search_test.go:480–520  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

478}
479
480func TestSearchService_Code(t *testing.T) {
481 t.Parallel()
482 client, mux, _ := setup(t)
483
484 mux.HandleFunc("/search/code", func(w http.ResponseWriter, r *http.Request) {
485 testMethod(t, r, "GET")
486 testFormValues(t, r, values{
487 "q": "blah",
488 "sort": "forks",
489 "order": "desc",
490 "page": "2",
491 "per_page": "2",
492 })
493
494 fmt.Fprint(w, `{"total_count": 4, "incomplete_results": false, "items": [{"name":"1"},{"name":"2"}]}`)
495 })
496
497 opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
498 ctx := t.Context()
499 result, _, err := client.Search.Code(ctx, "blah", opts)
500 if err != nil {
501 t.Errorf("Search.Code returned error: %v", err)
502 }
503
504 want := &CodeSearchResult{
505 Total: Ptr(4),
506 IncompleteResults: Ptr(false),
507 CodeResults: []*CodeResult{{Name: Ptr("1")}, {Name: Ptr("2")}},
508 }
509 if !cmp.Equal(result, want) {
510 t.Errorf("Search.Code returned %+v, want %+v", result, want)
511 }
512 const methodName = "Code"
513 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
514 got, resp, err := client.Search.Code(ctx, "blah", opts)
515 if got != nil {
516 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
517 }
518 return resp, err
519 })
520}
521
522func TestSearchService_Code_coverage(t *testing.T) {
523 t.Parallel()

Callers

nothing calls this directly

Calls 7

testMethodFunction · 0.85
testFormValuesFunction · 0.85
CodeMethod · 0.80
EqualMethod · 0.80
setupFunction · 0.70
PtrFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…