MCPcopy
hub / github.com/cli/cli / TestCloseRun

Function TestCloseRun

pkg/cmd/issue/close/close_test.go:113–399  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

111}
112
113func TestCloseRun(t *testing.T) {
114 tests := []struct {
115 name string
116 opts *CloseOptions
117 httpStubs func(*httpmock.Registry)
118 wantStderr string
119 wantErr bool
120 errMsg string
121 }{
122 {
123 name: "close issue by number",
124 opts: &CloseOptions{
125 IssueNumber: 13,
126 },
127 httpStubs: func(reg *httpmock.Registry) {
128 reg.Register(
129 httpmock.GraphQL(`query IssueByNumber\b`),
130 httpmock.StringResponse(`
131 { "data": { "repository": {
132 "hasIssuesEnabled": true,
133 "issue": { "id": "THE-ID", "number": 13, "title": "The title of the issue"}
134 } } }`),
135 )
136 reg.Register(
137 httpmock.GraphQL(`mutation IssueClose\b`),
138 httpmock.GraphQLMutation(`{"id": "THE-ID"}`,
139 func(inputs map[string]interface{}) {
140 assert.Equal(t, "THE-ID", inputs["issueId"])
141 }),
142 )
143 },
144 wantStderr: "✓ Closed issue OWNER/REPO#13 (The title of the issue)\n",
145 },
146 {
147 name: "close issue with comment",
148 opts: &CloseOptions{
149 IssueNumber: 13,
150 Comment: "closing comment",
151 },
152 httpStubs: func(reg *httpmock.Registry) {
153 reg.Register(
154 httpmock.GraphQL(`query IssueByNumber\b`),
155 httpmock.StringResponse(`
156 { "data": { "repository": {
157 "hasIssuesEnabled": true,
158 "issue": { "id": "THE-ID", "number": 13, "title": "The title of the issue"}
159 } } }`),
160 )
161 reg.Register(
162 httpmock.GraphQL(`mutation CommentCreate\b`),
163 httpmock.GraphQLMutation(`
164 { "data": { "addComment": { "commentEdge": { "node": {
165 "url": "https://github.com/OWNER/REPO/issues/123#issuecomment-456"
166 } } } } }`,
167 func(inputs map[string]interface{}) {
168 assert.Equal(t, "THE-ID", inputs["subjectId"])
169 assert.Equal(t, "closing comment", inputs["body"])
170 }),

Callers

nothing calls this directly

Calls 11

RegisterMethod · 0.95
VerifyMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
GraphQLMutationFunction · 0.92
TestFunction · 0.92
FromFullNameFunction · 0.92
EqualMethod · 0.80
closeRunFunction · 0.70
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected