MCPcopy Create free account
hub / github.com/cli/cli / TestCommentableRunUploadsAndWritesBodies

Function TestCommentableRunUploadsAndWritesBodies

pkg/cmd/pr/shared/commentable_test.go:173–522  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

171}
172
173func TestCommentableRunUploadsAndWritesBodies(t *testing.T) {
174 tests := []struct {
175 name string
176 opts CommentableOptions
177 attach []string
178 host string
179 // Empty means the default, which can upload.
180 viewerPermission string
181 repositoryDatabaseID int64
182 uploads []attachments.UploadStub
183 // Empty means the row does not care which host was reached.
184 wantUploadHost string
185 wantQuery string
186 writeFails bool
187 wantBody string
188 wantStdout string
189 wantErr string
190 wantUploads int
191 wantOperations *attachments.UploadResult
192 }{
193 {
194 name: "creating with no asset uploads nothing",
195 opts: CommentableOptions{Body: "just text", InputType: InputTypeInline},
196 wantQuery: `mutation CommentCreate\b`,
197 wantBody: "just text",
198 wantStdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n",
199 },
200 {
201 name: "creating uploads the asset and writes the reference",
202 opts: CommentableOptions{Body: "see below", InputType: InputTypeInline},
203 attach: []string{"shot.png"},
204 repositoryDatabaseID: 1234,
205 uploads: []attachments.UploadStub{{Name: "shot.png", Status: 201, Body: `{"url":"https://example.com/1"}`}},
206 wantQuery: `mutation CommentCreate\b`,
207 wantBody: "see below\n\n![shot](https://example.com/1)",
208 wantStdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n",
209 wantUploads: 1,
210 wantOperations: &attachments.UploadResult{AppendOperations: 1},
211 },
212 {
213 name: "creating rewrites a reference relative to the body file",
214 opts: CommentableOptions{Body: "the plan ![diagram](./diagram.png)", BodyDir: "docs", InputType: InputTypeInline},
215 attach: []string{"docs/diagram.png"},
216 repositoryDatabaseID: 1234,
217 uploads: []attachments.UploadStub{{Name: "diagram.png", Status: 201, Body: `{"url":"https://example.com/1"}`}},
218 wantQuery: `mutation CommentCreate\b`,
219 wantBody: "the plan ![diagram](https://example.com/1)",
220 wantStdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n",
221 wantUploads: 1,
222 wantOperations: &attachments.UploadResult{ReplaceOperations: 1},
223 },
224 {
225 name: "creating writes what uploaded when one upload fails",
226 opts: CommentableOptions{Body: "see below", InputType: InputTypeInline},
227 attach: []string{"a.png", "b.png"},
228 repositoryDatabaseID: 1234,
229 uploads: []attachments.UploadStub{
230 {Name: "a.png", Status: 201, Body: `{"url":"https://example.com/1"}`},

Callers

nothing calls this directly

Calls 15

VerifyMethod · 0.95
RegisterMethod · 0.95
TestFunction · 0.92
StubUploadToHostFunction · 0.92
StubUploadFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
GraphQLMutationFunction · 0.92
NewTestAssetsFunction · 0.92
BeginTelemetryFunction · 0.92
NewWithHostFunction · 0.92

Tested by

no test coverage detected