| 466 | } |
| 467 | |
| 468 | func TestGroup_StaticMultiTest(t *testing.T) { |
| 469 | var testCases = []struct { |
| 470 | name string |
| 471 | givenPrefix string |
| 472 | givenRoot string |
| 473 | whenURL string |
| 474 | expectHeaderLocation string |
| 475 | expectBodyStartsWith string |
| 476 | expectBodyNotContains string |
| 477 | expectStatus int |
| 478 | }{ |
| 479 | { |
| 480 | name: "ok", |
| 481 | givenPrefix: "/images", |
| 482 | givenRoot: "_fixture/images", |
| 483 | whenURL: "/test/images/walle.png", |
| 484 | expectStatus: http.StatusOK, |
| 485 | expectBodyStartsWith: string([]byte{0x89, 0x50, 0x4e, 0x47}), |
| 486 | }, |
| 487 | { |
| 488 | name: "ok, without prefix", |
| 489 | givenPrefix: "", |
| 490 | givenRoot: "_fixture/images", |
| 491 | whenURL: "/testwalle.png", // `/test` + `*` creates route `/test*` witch matches `/testwalle.png` |
| 492 | expectStatus: http.StatusOK, |
| 493 | expectBodyStartsWith: string([]byte{0x89, 0x50, 0x4e, 0x47}), |
| 494 | }, |
| 495 | { |
| 496 | name: "nok, without prefix does not serve dir index", |
| 497 | givenPrefix: "", |
| 498 | givenRoot: "_fixture/images", |
| 499 | whenURL: "/test/", // `/test` + `*` creates route `/test*` |
| 500 | expectStatus: http.StatusNotFound, |
| 501 | expectBodyStartsWith: "{\"message\":\"Not Found\"}\n", |
| 502 | }, |
| 503 | { |
| 504 | name: "No file", |
| 505 | givenPrefix: "/images", |
| 506 | givenRoot: "_fixture/scripts", |
| 507 | whenURL: "/test/images/bolt.png", |
| 508 | expectStatus: http.StatusNotFound, |
| 509 | expectBodyStartsWith: "{\"message\":\"Not Found\"}\n", |
| 510 | }, |
| 511 | { |
| 512 | name: "Directory", |
| 513 | givenPrefix: "/images", |
| 514 | givenRoot: "_fixture/images", |
| 515 | whenURL: "/test/images/", |
| 516 | expectStatus: http.StatusNotFound, |
| 517 | expectBodyStartsWith: "{\"message\":\"Not Found\"}\n", |
| 518 | }, |
| 519 | { |
| 520 | name: "Directory Redirect", |
| 521 | givenPrefix: "/", |
| 522 | givenRoot: "_fixture", |
| 523 | whenURL: "/test/folder", |
| 524 | expectStatus: http.StatusMovedPermanently, |
| 525 | expectHeaderLocation: "/test/folder/", |