(t *testing.T)
| 257 | } |
| 258 | |
| 259 | func TestUploaderUploadAndAttachDocuments(t *testing.T) { |
| 260 | const ( |
| 261 | url1 = "https://github.com/user-attachments/assets/1" |
| 262 | url2 = "https://github.com/user-attachments/assets/2" |
| 263 | ) |
| 264 | okUpload := func(name, url string) UploadStub { |
| 265 | return UploadStub{Name: name, Status: 201, Body: `{"url":"` + url + `"}`} |
| 266 | } |
| 267 | |
| 268 | type wantDocument struct { |
| 269 | markdown string |
| 270 | uploaded []string |
| 271 | appended int |
| 272 | replaced int |
| 273 | err string |
| 274 | } |
| 275 | |
| 276 | tests := []struct { |
| 277 | name string |
| 278 | files []string |
| 279 | args []string |
| 280 | docs []Document |
| 281 | // Each file is stubbed by name and every stub answers once. Any other |
| 282 | // upload, such as a second one of the same file, fails the test. |
| 283 | uploads []UploadStub |
| 284 | want []wantDocument |
| 285 | wantErr string |
| 286 | wantUnreferenced []string |
| 287 | }{ |
| 288 | { |
| 289 | name: "uploads a file once for every document that references it", |
| 290 | files: []string{"signin-flow.png"}, |
| 291 | args: []string{"./signin-flow.png"}, |
| 292 | docs: []Document{ |
| 293 | {Markdown: "# Sign-in plan\n\n"}, |
| 294 | {Markdown: "# Barista notes\n\n"}, |
| 295 | }, |
| 296 | uploads: []UploadStub{okUpload("signin-flow.png", url1)}, |
| 297 | want: []wantDocument{ |
| 298 | {markdown: "# Sign-in plan\n\n", uploaded: []string{"./signin-flow.png"}, replaced: 1}, |
| 299 | {markdown: "# Barista notes\n\n", uploaded: []string{"./signin-flow.png"}, replaced: 1}, |
| 300 | }, |
| 301 | }, |
| 302 | { |
| 303 | name: "resolves each document's references against its own directory", |
| 304 | files: []string{"plans/signin-flow.png", "notes/signin-flow.png"}, |
| 305 | args: []string{"./plans/signin-flow.png", "./notes/signin-flow.png"}, |
| 306 | docs: []Document{ |
| 307 | {Markdown: "", Dir: "plans"}, |
| 308 | {Markdown: "", Dir: "notes"}, |
| 309 | }, |
| 310 | uploads: []UploadStub{okUpload("signin-flow.png", url1), okUpload("signin-flow.png", url2)}, |
| 311 | want: []wantDocument{ |
| 312 | {markdown: "", uploaded: []string{"./plans/signin-flow.png"}, replaced: 1}, |
| 313 | {markdown: "", uploaded: []string{"./notes/signin-flow.png"}, replaced: 1}, |
| 314 | }, |
| 315 | }, |
| 316 | { |
nothing calls this directly
no test coverage detected