test: add static assets handler test
This commit is contained in:
parent
6d6856700b
commit
5014e10c7f
@ -9,5 +9,5 @@ import (
|
||||
type assets struct{}
|
||||
|
||||
func (assets) Open(p string) (fs.File, error) {
|
||||
return os.Open(path.Join("./", p))
|
||||
return os.Open(path.Join("../", p))
|
||||
}
|
||||
|
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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user