goweb/static/static_test.go

34 lines
653 B
Go
Raw Permalink Normal View History

package static
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestStaticDir(t *testing.T) {
req, err := http.NewRequest("GET", "/test.txt", nil)
if err != nil {
t.Fatal(err)
}
notFound := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Error("notFound should not be invoked")
})
rr := httptest.NewRecorder()
handler := Dir("./testdata", "/", notFound)
handler.ServeHTTP(rr, req)
if g, e := rr.Code, http.StatusOK; g != e {
t.Errorf("rr.Code: got '%v', expected '%v'", g, e)
}
if g, e := rr.Body.String(), "Hello World"; g != e {
t.Errorf("rr.Body.String(): got '%v', expected '%v'", g, e)
}
}