MCPcopy Create free account
hub / github.com/coder/coder / TestServingBin

Function TestServingBin

site/site_test.go:571–803  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

569}
570
571func 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"]),

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewFunction · 0.92
NewNoopFunction · 0.92
sampleBinFSFunction · 0.85
NotEmptyMethod · 0.80
RunMethod · 0.65
TempDirMethod · 0.65
CopyMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected