MCPcopy Index your code
hub / github.com/cli/cli / TestFindIssuesOrPRs

Function TestFindIssuesOrPRs

pkg/cmd/issue/shared/lookup_test.go:80–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func TestFindIssuesOrPRs(t *testing.T) {
81 tests := []struct {
82 name string
83 issueNumbers []int
84 baseRepo ghrepo.Interface
85 httpStub func(*httpmock.Registry)
86 wantIssueNumbers []int
87 wantErr bool
88 }{
89 {
90 name: "multiple issues",
91 issueNumbers: []int{1, 2},
92 baseRepo: ghrepo.New("OWNER", "REPO"),
93 httpStub: func(r *httpmock.Registry) {
94 r.Register(
95 httpmock.GraphQL(`query IssueByNumber\b`),
96 httpmock.StringResponse(`{"data":{"repository":{
97 "hasIssuesEnabled": true,
98 "issue":{"number":1}
99 }}}`))
100 r.Register(
101 httpmock.GraphQL(`query IssueByNumber\b`),
102 httpmock.StringResponse(`{"data":{"repository":{
103 "hasIssuesEnabled": true,
104 "issue":{"number":2}
105 }}}`))
106 },
107 wantIssueNumbers: []int{1, 2},
108 },
109 {
110 name: "any find error results in total error",
111 issueNumbers: []int{1, 2},
112 baseRepo: ghrepo.New("OWNER", "REPO"),
113 httpStub: func(r *httpmock.Registry) {
114 r.Register(
115 httpmock.GraphQL(`query IssueByNumber\b`),
116 httpmock.StringResponse(`{"data":{"repository":{
117 "hasIssuesEnabled": true,
118 "issue":{"number":1}
119 }}}`))
120 r.Register(
121 httpmock.GraphQL(`query IssueByNumber\b`),
122 httpmock.StatusStringResponse(500, "internal server error"))
123 },
124 wantErr: true,
125 },
126 }
127 for _, tt := range tests {
128 t.Run(tt.name, func(t *testing.T) {
129 reg := &httpmock.Registry{}
130 if tt.httpStub != nil {
131 tt.httpStub(reg)
132 }
133 httpClient := &http.Client{Transport: reg}
134 issues, err := FindIssuesOrPRs(httpClient, tt.baseRepo, tt.issueNumbers, []string{"number"})
135 if (err != nil) != tt.wantErr {
136 t.Errorf("FindIssuesOrPRs() error = %v, wantErr %v", err, tt.wantErr)
137 if issues == nil {

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
StatusStringResponseFunction · 0.92
FindIssuesOrPRsFunction · 0.85
ContainsMethod · 0.80
RunMethod · 0.65
ErrorfMethod · 0.65
RegisterMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected