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

Function TestProjectsService_ListOrganizationProjects

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

Source from the content-addressed store, hash-verified

15)
16
17func TestProjectsService_ListOrganizationProjects(t *testing.T) {
18 t.Parallel()
19 client, mux, _ := setup(t)
20
21 // Combined handler: supports initial test case and dual before/after validation scenario.
22 mux.HandleFunc("/orgs/o/projectsV2", func(w http.ResponseWriter, r *http.Request) {
23 testMethod(t, r, "GET")
24 q := r.URL.Query()
25 if q.Get("before") == "b" && q.Get("after") == "a" {
26 fmt.Fprint(w, `[]`)
27 return
28 }
29 // default expectation for main part of test
30 testFormValues(t, r, values{"q": "alpha", "after": "2", "before": "1"})
31 fmt.Fprint(w, `[{"id":1,"title":"T1","created_at":"2011-01-02T15:04:05Z","updated_at":"2012-01-02T15:04:05Z"}]`)
32 })
33
34 opts := &ListProjectsOptions{Query: "alpha", ListProjectsPaginationOptions: ListProjectsPaginationOptions{After: "2", Before: "1"}}
35 ctx := t.Context()
36 projects, _, err := client.Projects.ListOrganizationProjects(ctx, "o", opts)
37 if err != nil {
38 t.Fatalf("Projects.ListOrganizationProjects returned error: %v", err)
39 }
40 if len(projects) != 1 || projects[0].GetID() != 1 || projects[0].GetTitle() != "T1" {
41 t.Fatalf("Projects.ListOrganizationProjects returned %+v", projects)
42 }
43
44 const methodName = "ListOrganizationProjects"
45 testBadOptions(t, methodName, func() (err error) {
46 _, _, err = client.Projects.ListOrganizationProjects(ctx, "\n", opts)
47 return err
48 })
49
50 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
51 got, resp, err := client.Projects.ListOrganizationProjects(ctx, "o", opts)
52 if got != nil {
53 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
54 }
55 return resp, err
56 })
57
58 // still allow both set (no validation enforced) – ensure it does not error
59 ctxBypass := context.WithValue(t.Context(), BypassRateLimitCheck, true)
60 if _, _, err = client.Projects.ListOrganizationProjects(ctxBypass, "o", &ListProjectsOptions{ListProjectsPaginationOptions: ListProjectsPaginationOptions{Before: "b", After: "a"}}); err != nil {
61 t.Fatalf("unexpected error when both before/after set: %v", err)
62 }
63}
64
65func TestProjectsService_GetOrganizationProject(t *testing.T) {
66 t.Parallel()

Callers

nothing calls this directly

Calls 9

testMethodFunction · 0.85
testFormValuesFunction · 0.85
testBadOptionsFunction · 0.85
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…