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

Function TestUploaderUploadAndAttach

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

Source from the content-addressed store, hash-verified

33}
34
35func TestUploaderUploadAndAttach(t *testing.T) {
36 // Each upload response is consumed in the order the assets were
37 // written, so a status here is a status for that asset.
38 type upload struct {
39 status int
40 response string
41 }
42
43 tests := []struct {
44 name string
45 files []string
46 args []string
47 body string
48 uploads []upload
49 wantBody string
50 wantUploaded int
51 wantAppend int
52 wantReplace int
53 wantErr string
54 }{
55 {
56 name: "appends an image to a body",
57 files: []string{"login.png"},
58 args: []string{"./login.png"},
59 body: "See below",
60 uploads: []upload{{201, `{"url":"https://github.com/user-attachments/assets/1"}`}},
61 wantBody: "See below\n\n![login](https://github.com/user-attachments/assets/1)",
62 wantUploaded: 1,
63 wantAppend: 1,
64 },
65 {
66 name: "appends a video as a paragraph of its own",
67 files: []string{"repro.mp4"},
68 args: []string{"./repro.mp4"},
69 body: "Watch this:",
70 uploads: []upload{{201, `{"url":"https://github.com/user-attachments/assets/2"}`}},
71 // A bare URL only renders as a player when nothing shares its
72 // paragraph, so it must not land on the end of the line above.
73 wantBody: "Watch this:\n\nhttps://github.com/user-attachments/assets/2",
74 wantUploaded: 1,
75 wantAppend: 1,
76 },
77 {
78 name: "appends to an empty body without leading blank lines",
79 files: []string{"login.png"},
80 args: []string{"./login.png"},
81 body: "",
82 uploads: []upload{{201, `{"url":"https://github.com/user-attachments/assets/1"}`}},
83 wantBody: "![login](https://github.com/user-attachments/assets/1)",
84 wantUploaded: 1,
85 wantAppend: 1,
86 },
87 {
88 name: "does not stack blank lines on a body that ends with them",
89 files: []string{"login.png"},
90 args: []string{"./login.png"},
91 body: "See below\n\n\n",
92 uploads: []upload{{201, `{"url":"https://github.com/user-attachments/assets/1"}`}},

Callers

nothing calls this directly

Calls 14

VerifyMethod · 0.95
RegisterMethod · 0.95
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
writeFilesFunction · 0.85
assetsFromArgsFunction · 0.85
testUploaderFunction · 0.85
UploadAndAttachMethod · 0.80
EqualMethod · 0.80
EmptyMethod · 0.80
RunMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected