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