MCPcopy Index your code
hub / github.com/google/go-github / TestProjectsService_ListUserProjects

Function TestProjectsService_ListUserProjects

github/projects_test.go:93–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestProjectsService_ListUserProjects(t *testing.T) {
94 t.Parallel()
95 client, mux, _ := setup(t)
96
97 // Combined handler: supports initial test case and dual before/after scenario.
98 mux.HandleFunc("/users/u/projectsV2", func(w http.ResponseWriter, r *http.Request) {
99 testMethod(t, r, "GET")
100 q := r.URL.Query()
101 if q.Get("before") == "b" && q.Get("after") == "a" {
102 fmt.Fprint(w, `[]`)
103 return
104 }
105 testFormValues(t, r, values{"q": "beta", "before": "1", "after": "2", "per_page": "2"})
106 fmt.Fprint(w, `[{"id":2,"title":"UProj","created_at":"2011-01-02T15:04:05Z","updated_at":"2012-01-02T15:04:05Z"}]`)
107 })
108
109 opts := &ListProjectsOptions{Query: "beta", ListProjectsPaginationOptions: ListProjectsPaginationOptions{Before: "1", After: "2", PerPage: 2}}
110 ctx := t.Context()
111 var ctxBypass context.Context
112 projects, _, err := client.Projects.ListUserProjects(ctx, "u", opts)
113 if err != nil {
114 t.Fatalf("Projects.ListUserProjects returned error: %v", err)
115 }
116 if len(projects) != 1 || projects[0].GetID() != 2 || projects[0].GetTitle() != "UProj" {
117 t.Fatalf("Projects.ListUserProjects returned %+v", projects)
118 }
119
120 const methodName = "ListUserProjects"
121 testBadOptions(t, methodName, func() (err error) {
122 _, _, err = client.Projects.ListUserProjects(ctx, "\n", opts)
123 return err
124 })
125
126 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
127 got, resp, err := client.Projects.ListUserProjects(ctx, "u", opts)
128 if got != nil {
129 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
130 }
131 return resp, err
132 })
133
134 // still allow both set (no validation enforced) – ensure it does not error
135 ctxBypass = context.WithValue(t.Context(), BypassRateLimitCheck, true)
136 if _, _, err = client.Projects.ListUserProjects(ctxBypass, "u", &ListProjectsOptions{ListProjectsPaginationOptions: ListProjectsPaginationOptions{Before: "b", After: "a"}}); err != nil {
137 t.Fatalf("unexpected error when both before/after set: %v", err)
138 }
139}
140
141func TestProjectsService_GetUserProject(t *testing.T) {
142 t.Parallel()

Callers

nothing calls this directly

Calls 9

testMethodFunction · 0.85
testFormValuesFunction · 0.85
testBadOptionsFunction · 0.85
ListUserProjectsMethod · 0.80
setupFunction · 0.70
GetMethod · 0.45
GetIDMethod · 0.45
GetTitleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…