diff --git a/httpr_test.go b/httpr_test.go index 860d46a..f05ae1f 100644 --- a/httpr_test.go +++ b/httpr_test.go @@ -2,7 +2,9 @@ package httpr_test import ( "net/http" + "net/http/httptest" "os" + "strings" "testing" "git.arav.su/Arav/httpr" @@ -47,3 +49,38 @@ func Test(t *testing.T) { } } + +func TestPaths(t *testing.T) { + found := false + + r := httpr.New() + + err := r.Handler(http.MethodGet, "/:lel", func(w http.ResponseWriter, r *http.Request) { found = true }) + if err != nil { + t.Fatal(err) + } + + r.NotFoundHandler = func(w http.ResponseWriter, r *http.Request) { found = false } + + w := httptest.NewRecorder() + p := "/xmpp://me@arav.su" + req := httptest.NewRequest(http.MethodGet, p, strings.NewReader("")) + r.ServeHTTP(w, req) + if found { + t.Error("Path", p, "should return 404") + } + + p = "/lel" + req = httptest.NewRequest(http.MethodGet, p, strings.NewReader("")) + r.ServeHTTP(w, req) + if !found { + t.Error("Path", p, "should return 200") + } + + p = "/lel/lol" + req = httptest.NewRequest(http.MethodGet, p, strings.NewReader("")) + r.ServeHTTP(w, req) + if found { + t.Error("Path", p, "should return 404") + } +}