Test ListOrgRepos handles pagination and filters archived repos.
(t *testing.T)
| 43 | |
| 44 | // Test ListOrgRepos handles pagination and filters archived repos. |
| 45 | func TestListOrgRepos_PaginationAndArchived(t *testing.T) { |
| 46 | t.Parallel() |
| 47 | // Single page: one archived repo and two active repos; expect active ones returned. |
| 48 | body := `[ |
| 49 | {"html_url": "https://github.com/owner/repo1", "archived": true}, |
| 50 | {"html_url": "https://github.com/owner/repo2", "archived": false}, |
| 51 | {"html_url": "https://github.com/owner/repo3", "archived": false} |
| 52 | ]` |
| 53 | |
| 54 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 55 | if _, err := w.Write([]byte(body)); err != nil { |
| 56 | t.Fatalf("failed to write response: %v", err) |
| 57 | } |
| 58 | })) |
| 59 | defer srv.Close() |
| 60 | |
| 61 | // Override TransportFactory to redirect requests to our test server. |
| 62 | rt := roundTripperToServer(srv.URL) |
| 63 | |
| 64 | repos, err := ListOrgRepos(context.Background(), "owner", rt) |
| 65 | if err != nil { |
| 66 | t.Fatalf("ListOrgRepos returned error: %v", err) |
| 67 | } |
| 68 | // Expect repo2 and repo3 (repo1 archived) |
| 69 | if len(repos) != 2 { |
| 70 | t.Fatalf("expected 2 repos, got %d: %v", len(repos), repos) |
| 71 | } |
| 72 | if !strings.Contains(repos[0], "repo2") || !strings.Contains(repos[1], "repo3") { |
| 73 | t.Fatalf("unexpected repos: %v", repos) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // roundTripperToServer returns an http.RoundTripper that rewrites requests |
| 78 | // to the given serverURL, keeping the path and query intact. |
nothing calls this directly
no test coverage detected