1
0
Fork 0

Added a test for paths.

This commit is contained in:
Alexander Andreev 2023-07-23 23:26:35 +04:00
parent 33de30fe23
commit bc11a46806
Signed by: Arav
GPG Key ID: D22A817D95815393
1 changed files with 37 additions and 0 deletions

View File

@ -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")
}
}