(t *testing.T)
| 33 | } |
| 34 | |
| 35 | func 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", |
| 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: "", |
| 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", |
| 90 | wantUploaded: 1, |
| 91 | }, |
| 92 | { |
nothing calls this directly
no test coverage detected