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

Function TestUploaderUploadAndAttach

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

Source from the content-addressed store, hash-verified

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

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