1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
package sockjs
import (
"net/http"
"net/http/httptest"
"regexp"
"testing"
)
func TestSockJS_ServeHTTP(t *testing.T) {
m := Handler{mappings: make([]*mapping, 0)}
m.mappings = []*mapping{
{"POST", regexp.MustCompile("/foo/.*"), []http.HandlerFunc{func(http.ResponseWriter, *http.Request) {}}},
}
req, _ := http.NewRequest("GET", "/foo/bar", nil)
rec := httptest.NewRecorder()
m.ServeHTTP(rec, req)
if rec.Code != http.StatusMethodNotAllowed {
t.Errorf("Unexpected response status, got '%d' expected '%d'", rec.Code, http.StatusMethodNotAllowed)
}
req, _ = http.NewRequest("GET", "/bar", nil)
rec = httptest.NewRecorder()
m.ServeHTTP(rec, req)
if rec.Code != http.StatusNotFound {
t.Errorf("Unexpected response status, got '%d' expected '%d'", rec.Code, http.StatusNotFound)
}
}
|