(t *testing.T)
| 569 | } |
| 570 | |
| 571 | func TestServingBin(t *testing.T) { |
| 572 | t.Parallel() |
| 573 | |
| 574 | // Create a misc rootfs for realistic test. |
| 575 | rootFS := fstest.MapFS{ |
| 576 | "index.html": &fstest.MapFile{ |
| 577 | Data: []byte("index-bytes"), |
| 578 | }, |
| 579 | "favicon.ico": &fstest.MapFile{ |
| 580 | Data: []byte("favicon-bytes"), |
| 581 | }, |
| 582 | "dashboard.js": &fstest.MapFile{ |
| 583 | Data: []byte("dashboard-js-bytes"), |
| 584 | }, |
| 585 | "dashboard.css": &fstest.MapFile{ |
| 586 | Data: []byte("dashboard-css-bytes"), |
| 587 | }, |
| 588 | } |
| 589 | |
| 590 | sampleBinFSCorrupted := sampleBinFS() |
| 591 | copy(sampleBinFSCorrupted[binCoderTarZstd].Data[10:], bytes.Repeat([]byte{0}, 10)) // Zero portion of archive. |
| 592 | |
| 593 | sampleBinFSMissingSha256 := sampleBinFS() |
| 594 | delete(sampleBinFSMissingSha256, binCoderSha1) |
| 595 | |
| 596 | type req struct { |
| 597 | url string |
| 598 | ifNoneMatch string |
| 599 | wantStatus int |
| 600 | wantBody []byte |
| 601 | wantOriginalSize int |
| 602 | wantEtag string |
| 603 | compression bool |
| 604 | } |
| 605 | tests := []struct { |
| 606 | name string |
| 607 | fs fstest.MapFS |
| 608 | reqs []req |
| 609 | wantErr bool |
| 610 | }{ |
| 611 | { |
| 612 | name: "Extract and serve bin", |
| 613 | fs: sampleBinFS(), |
| 614 | reqs: []req{ |
| 615 | { |
| 616 | url: "/bin/coder-linux-amd64", |
| 617 | wantStatus: http.StatusOK, |
| 618 | wantBody: []byte("compressed"), |
| 619 | wantOriginalSize: 10, |
| 620 | wantEtag: fmt.Sprintf("%q", sampleBinSHAs["coder-linux-amd64"]), |
| 621 | }, |
| 622 | // Test ETag support. |
| 623 | { |
| 624 | url: "/bin/coder-linux-amd64", |
| 625 | ifNoneMatch: fmt.Sprintf("%q", sampleBinSHAs["coder-linux-amd64"]), |
| 626 | wantStatus: http.StatusNotModified, |
| 627 | wantOriginalSize: 10, |
| 628 | wantEtag: fmt.Sprintf("%q", sampleBinSHAs["coder-linux-amd64"]), |
nothing calls this directly
no test coverage detected