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

Function TestCommentableRunUploadsAndWritesBodies

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected