MCPcopy
hub / github.com/ossf/scorecard / TestListOrgRepos_PaginationAndArchived

Function TestListOrgRepos_PaginationAndArchived

cmd/internal/org/org_test.go:45–75  ·  view source on GitHub ↗

Test ListOrgRepos handles pagination and filters archived repos.

(t *testing.T)

Source from the content-addressed store, hash-verified

43
44// Test ListOrgRepos handles pagination and filters archived repos.
45func 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.

Callers

nothing calls this directly

Calls 4

roundTripperToServerFunction · 0.85
ListOrgReposFunction · 0.85
WriteMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected