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

Function TestCommentableRunUploadsAndWritesBodies

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

Source from the content-addressed store, hash-verified

173}
174
175func TestCommentableRunUploadsAndWritesBodies(t *testing.T) {
176 tests := []struct {
177 name string
178 opts CommentableOptions
179 attach []string
180 host string
181 hostTokens map[string]string
182 // Empty means the default, which can upload.
183 viewerPermission string
184 repositoryDatabaseID int64
185 uploads []attachments.UploadStub
186 wantQuery string
187 writeFails bool
188 wantBody string
189 wantStdout string
190 wantErr string
191 wantUploads int
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 },
211 {
212 name: "creating writes what uploaded when one upload fails",
213 opts: CommentableOptions{Body: "see below", InputType: InputTypeInline},
214 attach: []string{"a.png", "b.png"},
215 repositoryDatabaseID: 1234,
216 uploads: []attachments.UploadStub{
217 {Name: "a.png", Status: 201, Body: `{"url":"https://example.com/1"}`},
218 {Name: "b.png", Status: 404, Body: `{"message":"Not Found"}`},
219 },
220 wantQuery: `mutation CommentCreate\b`,
221 wantBody: "see below\n\n![a](https://example.com/1)",
222 wantStdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n",
223 wantErr: "could not upload ./b.png: attaching files requires write access to the repository",
224 wantUploads: 2,
225 },
226 {
227 name: "creating writes nothing when every upload fails",
228 opts: CommentableOptions{Body: "", InputType: InputTypeInline},
229 attach: []string{"a.png"},
230 repositoryDatabaseID: 1234,
231 uploads: []attachments.UploadStub{{Name: "a.png", Status: 404, Body: `{"message":"Not Found"}`}},
232 wantErr: "could not upload ./a.png: attaching files requires write access to the repository\nno comment was posted",

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
NewMockConfigFromStringFunction · 0.92
NewWithHostFunction · 0.92
CommentableRunFunction · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected