Add a test.
This commit is contained in:
parent
2bfaae11f2
commit
fcbd09506a
49
httpr_test.go
Normal file
49
httpr_test.go
Normal file
@ -0,0 +1,49 @@
|
||||
package httpr_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.arav.su/Arav/httpr"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) {
|
||||
r := httpr.New()
|
||||
|
||||
err := r.Handler(http.MethodGet, "/", func(w http.ResponseWriter, r *http.Request) {})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Handler(http.MethodGet, "/", func(w http.ResponseWriter, r *http.Request) {})
|
||||
if err == nil {
|
||||
t.Fatal("path redefinition wasn't catched")
|
||||
}
|
||||
|
||||
err = r.Handler(http.MethodGet, "/a/b", func(w http.ResponseWriter, r *http.Request) {})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Handler(http.MethodGet, "/:a/:b", func(w http.ResponseWriter, r *http.Request) {})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Handler(http.MethodGet, "/:a/:lol", func(w http.ResponseWriter, r *http.Request) {})
|
||||
if err == nil {
|
||||
t.Fatal("here is a different last param name is supplied, should be catched")
|
||||
}
|
||||
|
||||
err = r.ServeStatic("/assets/*filepath", http.FS(os.DirFS(".")))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.ServeStatic("/assets/*filepath/*filepath", nil)
|
||||
if err == nil {
|
||||
t.Fatal("multiple catch-all params wasn't catched")
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user