From bc11a46806c8d7e72777fe1180979ff584e4262c Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 23 Jul 2023 23:26:35 +0400 Subject: [PATCH] Added a test for paths. --- httpr_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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") + } +}