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

Function TestUploaderUploadAndAttach

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

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
BaseMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected