MCPcopy
hub / github.com/cli/cli / createFakeSearchReposServer

Function createFakeSearchReposServer

internal/codespaces/api/api_test.go:472–497  ·  view source on GitHub ↗
(t *testing.T, wantSearchText string, wantSort string, wantPerPage string, responseRepos []*Repository)

Source from the content-addressed store, hash-verified

470}
471
472func 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
499func runRepoSearchTest(t *testing.T, searchText, wantQueryText, wantSort, wantMaxRepos string) {
500 wantRepoNames := []string{"repo1", "repo2"}

Callers 1

runRepoSearchTestFunction · 0.85

Calls 4

QueryMethod · 0.65
GetMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected