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