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

Function TestUploaderUploadAndAttachDocuments

internal/attachments/attach_test.go:259–506  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

257}
258
259func TestUploaderUploadAndAttachDocuments(t *testing.T) {
260 const (
261 url1 = "https://github.com/user-attachments/assets/1"
262 url2 = "https://github.com/user-attachments/assets/2"
263 )
264 okUpload := func(name, url string) UploadStub {
265 return UploadStub{Name: name, Status: 201, Body: `{"url":"` + url + `"}`}
266 }
267
268 type wantDocument struct {
269 markdown string
270 uploaded []string
271 appended int
272 replaced int
273 err string
274 }
275
276 tests := []struct {
277 name string
278 files []string
279 args []string
280 docs []Document
281 // Each file is stubbed by name and every stub answers once. Any other
282 // upload, such as a second one of the same file, fails the test.
283 uploads []UploadStub
284 want []wantDocument
285 wantErr string
286 wantUnreferenced []string
287 }{
288 {
289 name: "uploads a file once for every document that references it",
290 files: []string{"signin-flow.png"},
291 args: []string{"./signin-flow.png"},
292 docs: []Document{
293 {Markdown: "# Sign-in plan\n\n![Sign-in flow](./signin-flow.png)"},
294 {Markdown: "# Barista notes\n\n![The new sign-in](./signin-flow.png)"},
295 },
296 uploads: []UploadStub{okUpload("signin-flow.png", url1)},
297 want: []wantDocument{
298 {markdown: "# Sign-in plan\n\n![Sign-in flow](" + url1 + ")", uploaded: []string{"./signin-flow.png"}, replaced: 1},
299 {markdown: "# Barista notes\n\n![The new sign-in](" + url1 + ")", uploaded: []string{"./signin-flow.png"}, replaced: 1},
300 },
301 },
302 {
303 name: "resolves each document's references against its own directory",
304 files: []string{"plans/signin-flow.png", "notes/signin-flow.png"},
305 args: []string{"./plans/signin-flow.png", "./notes/signin-flow.png"},
306 docs: []Document{
307 {Markdown: "![Sign-in flow](./signin-flow.png)", Dir: "plans"},
308 {Markdown: "![Sign-in flow](./signin-flow.png)", Dir: "notes"},
309 },
310 uploads: []UploadStub{okUpload("signin-flow.png", url1), okUpload("signin-flow.png", url2)},
311 want: []wantDocument{
312 {markdown: "![Sign-in flow](" + url1 + ")", uploaded: []string{"./plans/signin-flow.png"}, replaced: 1},
313 {markdown: "![Sign-in flow](" + url2 + ")", uploaded: []string{"./notes/signin-flow.png"}, replaced: 1},
314 },
315 },
316 {

Callers

nothing calls this directly

Calls 14

VerifyMethod · 0.95
ExcludeMethod · 0.95
RESTFunction · 0.92
writeFilesFunction · 0.85
assetsFromArgsFunction · 0.85
StubUploadFunction · 0.85
testUploaderFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
LenMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected