(t *testing.T)
| 478 | } |
| 479 | |
| 480 | func 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 | |
| 522 | func TestSearchService_Code_coverage(t *testing.T) { |
| 523 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…