Added a test for paths.
This commit is contained in:
parent
33de30fe23
commit
bc11a46806
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user