test: add static assets handler test
This commit is contained in:
35
handlers/static_test.go
Normal file
35
handlers/static_test.go
Normal file
@ -0,0 +1,35 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/rramiachraf/dumb/utils"
|
||||
)
|
||||
|
||||
func TestStaticAssets(t *testing.T) {
|
||||
r, err := http.NewRequest(http.MethodGet, "/static/style.css", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
l := utils.NewLogger(os.Stdout)
|
||||
m := New(l, &assets{})
|
||||
|
||||
m.ServeHTTP(rr, r)
|
||||
|
||||
contentType := rr.Header().Get("content-type")
|
||||
expectedContentType := mime.TypeByExtension(".css")
|
||||
|
||||
if contentType != expectedContentType {
|
||||
t.Fatalf("expected %q, got %q", expectedContentType, contentType)
|
||||
}
|
||||
|
||||
if rr.Code != 200 {
|
||||
t.Fatalf("expected %d, got %d", 200, rr.Code)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user