(t *testing.T, wantSearchText string, wantSort string, wantPerPage string, responseRepos []*Repository)
| 470 | } |
| 471 | |
| 472 | func createFakeSearchReposServer(t *testing.T, wantSearchText string, wantSort string, wantPerPage string, responseRepos []*Repository) *httptest.Server { |
| 473 | return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 474 | if r.URL.Path != "/search/repositories" { |
| 475 | t.Error("Incorrect path") |
| 476 | return |
| 477 | } |
| 478 | |
| 479 | query := r.URL.Query() |
| 480 | got := fmt.Sprintf("q=%q sort=%s per_page=%s", query.Get("q"), query.Get("sort"), query.Get("per_page")) |
| 481 | want := fmt.Sprintf("q=%q sort=%s per_page=%s", wantSearchText+" in:name", wantSort, wantPerPage) |
| 482 | if got != want { |
| 483 | t.Errorf("for query, got %s, want %s", got, want) |
| 484 | return |
| 485 | } |
| 486 | |
| 487 | response := struct { |
| 488 | Items []*Repository `json:"items"` |
| 489 | }{ |
| 490 | responseRepos, |
| 491 | } |
| 492 | |
| 493 | if err := json.NewEncoder(w).Encode(response); err != nil { |
| 494 | t.Error(err) |
| 495 | } |
| 496 | })) |
| 497 | } |
| 498 | |
| 499 | func runRepoSearchTest(t *testing.T, searchText, wantQueryText, wantSort, wantMaxRepos string) { |
| 500 | wantRepoNames := []string{"repo1", "repo2"} |
no test coverage detected