(t *testing.T, searchText, wantQueryText, wantSort, wantMaxRepos string)
| 497 | } |
| 498 | |
| 499 | func runRepoSearchTest(t *testing.T, searchText, wantQueryText, wantSort, wantMaxRepos string) { |
| 500 | wantRepoNames := []string{"repo1", "repo2"} |
| 501 | |
| 502 | apiResponseRepositories := make([]*Repository, 0) |
| 503 | for _, name := range wantRepoNames { |
| 504 | apiResponseRepositories = append(apiResponseRepositories, &Repository{FullName: name}) |
| 505 | } |
| 506 | |
| 507 | svr := createFakeSearchReposServer(t, wantQueryText, wantSort, wantMaxRepos, apiResponseRepositories) |
| 508 | defer svr.Close() |
| 509 | |
| 510 | api := API{ |
| 511 | githubAPI: svr.URL, |
| 512 | client: createHttpClient, |
| 513 | } |
| 514 | |
| 515 | ctx := context.Background() |
| 516 | |
| 517 | searchParameters := RepoSearchParameters{} |
| 518 | if len(wantSort) > 0 { |
| 519 | searchParameters.Sort = wantSort |
| 520 | } |
| 521 | if len(wantMaxRepos) > 0 { |
| 522 | searchParameters.MaxRepos, _ = strconv.Atoi(wantMaxRepos) |
| 523 | } |
| 524 | |
| 525 | gotRepoNames, err := api.GetCodespaceRepoSuggestions(ctx, searchText, searchParameters) |
| 526 | if err != nil { |
| 527 | t.Fatal(err) |
| 528 | } |
| 529 | |
| 530 | gotNamesStr := fmt.Sprintf("%v", gotRepoNames) |
| 531 | wantNamesStr := fmt.Sprintf("%v", wantRepoNames) |
| 532 | if gotNamesStr != wantNamesStr { |
| 533 | t.Fatalf("got repo names %s, want %s", gotNamesStr, wantNamesStr) |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | func TestRetries(t *testing.T) { |
| 538 | var callCount int |
no test coverage detected