(t *testing.T)
| 171 | } |
| 172 | |
| 173 | func TestCommentableRunUploadsAndWritesBodies(t *testing.T) { |
| 174 | tests := []struct { |
| 175 | name string |
| 176 | opts CommentableOptions |
| 177 | attach []string |
| 178 | host string |
| 179 | // Empty means the default, which can upload. |
| 180 | viewerPermission string |
| 181 | repositoryDatabaseID int64 |
| 182 | uploads []attachments.UploadStub |
| 183 | // Empty means the row does not care which host was reached. |
| 184 | wantUploadHost string |
| 185 | wantQuery string |
| 186 | writeFails bool |
| 187 | wantBody string |
| 188 | wantStdout string |
| 189 | wantErr string |
| 190 | wantUploads int |
| 191 | wantOperations *attachments.UploadResult |
| 192 | }{ |
| 193 | { |
| 194 | name: "creating with no asset uploads nothing", |
| 195 | opts: CommentableOptions{Body: "just text", InputType: InputTypeInline}, |
| 196 | wantQuery: `mutation CommentCreate\b`, |
| 197 | wantBody: "just text", |
| 198 | wantStdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n", |
| 199 | }, |
| 200 | { |
| 201 | name: "creating uploads the asset and writes the reference", |
| 202 | opts: CommentableOptions{Body: "see below", InputType: InputTypeInline}, |
| 203 | attach: []string{"shot.png"}, |
| 204 | repositoryDatabaseID: 1234, |
| 205 | uploads: []attachments.UploadStub{{Name: "shot.png", Status: 201, Body: `{"url":"https://example.com/1"}`}}, |
| 206 | wantQuery: `mutation CommentCreate\b`, |
| 207 | wantBody: "see below\n\n", |
| 208 | wantStdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n", |
| 209 | wantUploads: 1, |
| 210 | wantOperations: &attachments.UploadResult{AppendOperations: 1}, |
| 211 | }, |
| 212 | { |
| 213 | name: "creating rewrites a reference relative to the body file", |
| 214 | opts: CommentableOptions{Body: "the plan ", BodyDir: "docs", InputType: InputTypeInline}, |
| 215 | attach: []string{"docs/diagram.png"}, |
| 216 | repositoryDatabaseID: 1234, |
| 217 | uploads: []attachments.UploadStub{{Name: "diagram.png", Status: 201, Body: `{"url":"https://example.com/1"}`}}, |
| 218 | wantQuery: `mutation CommentCreate\b`, |
| 219 | wantBody: "the plan ", |
| 220 | wantStdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n", |
| 221 | wantUploads: 1, |
| 222 | wantOperations: &attachments.UploadResult{ReplaceOperations: 1}, |
| 223 | }, |
| 224 | { |
| 225 | name: "creating writes what uploaded when one upload fails", |
| 226 | opts: CommentableOptions{Body: "see below", InputType: InputTypeInline}, |
| 227 | attach: []string{"a.png", "b.png"}, |
| 228 | repositoryDatabaseID: 1234, |
| 229 | uploads: []attachments.UploadStub{ |
| 230 | {Name: "a.png", Status: 201, Body: `{"url":"https://example.com/1"}`}, |
nothing calls this directly
no test coverage detected