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

Function TestUploaderUploadAndAttach

internal/attachments/attach_test.go:35–227  ·  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 // What a caller keys on to decide whether a body is worth writing.
51 wantUploaded int
52 wantErr string
53 }{
54 {
55 name: "appends an image to a body",
56 files: []string{"login.png"},
57 args: []string{"./login.png"},
58 body: "See below",
59 uploads: []upload{{201, `{"url":"https://github.com/user-attachments/assets/1"}`}},
60 wantBody: "See below\n\n![login](https://github.com/user-attachments/assets/1)",
61 wantUploaded: 1,
62 },
63 {
64 name: "appends a video as a paragraph of its own",
65 files: []string{"repro.mp4"},
66 args: []string{"./repro.mp4"},
67 body: "Watch this:",
68 uploads: []upload{{201, `{"url":"https://github.com/user-attachments/assets/2"}`}},
69 // A bare URL only renders as a player when nothing shares its
70 // paragraph, so it must not land on the end of the line above.
71 wantBody: "Watch this:\n\nhttps://github.com/user-attachments/assets/2",
72 wantUploaded: 1,
73 },
74 {
75 name: "appends to an empty body without leading blank lines",
76 files: []string{"login.png"},
77 args: []string{"./login.png"},
78 body: "",
79 uploads: []upload{{201, `{"url":"https://github.com/user-attachments/assets/1"}`}},
80 wantBody: "![login](https://github.com/user-attachments/assets/1)",
81 wantUploaded: 1,
82 },
83 {
84 name: "does not stack blank lines on a body that ends with them",
85 files: []string{"login.png"},
86 args: []string{"./login.png"},
87 body: "See below\n\n\n",
88 uploads: []upload{{201, `{"url":"https://github.com/user-attachments/assets/1"}`}},
89 wantBody: "See below\n\n![login](https://github.com/user-attachments/assets/1)",
90 wantUploaded: 1,
91 },
92 {

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