simpleserve/main_test.go

36 lines
670 B
Go

package main
import (
"local/simpleserve/simpleserve"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestSetContentType(t *testing.T) {
t.Parallel()
cases := map[string]struct {
path string
want string
}{
"css with multi .": {
path: "/static/css/main.2145ce41.chunk.css",
want: "text/css",
},
}
for name, d := range cases {
c := d
t.Run(name, func(t *testing.T) {
r := &http.Request{URL: &url.URL{Path: c.path}}
w := httptest.NewRecorder()
simpleserve.SetContentTypeIfMedia(w, r)
if ct := w.Header().Get("Content-Type"); ct != c.want {
t.Errorf("wrong content type: want %q, got %q", c.want, ct)
}
})
}
}