test: add more tests (#1163)

* chore: reverse the order of stopping services

* chore: reverse the order of stopping services

* test: add more tests
This commit is contained in:
Kevin Wan
2021-10-25 21:10:08 +08:00
committed by GitHub
parent 7109d6d635
commit 496a2f341e
2 changed files with 148 additions and 61 deletions

View File

@@ -105,19 +105,22 @@ func TestPatRouter(t *testing.T) {
t.Run(test.method+":"+test.path, func(t *testing.T) {
routed := false
router := NewRouter()
err := router.Handle(test.method, "/a/:b", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
routed = true
assert.Equal(t, 1, len(pathvar.Vars(r)))
}))
err := router.Handle(test.method, "/a/:b", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
routed = true
assert.Equal(t, 1, len(pathvar.Vars(r)))
}))
assert.Nil(t, err)
err = router.Handle(test.method, "/a/b/c", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
routed = true
assert.Nil(t, pathvar.Vars(r))
}))
err = router.Handle(test.method, "/a/b/c", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
routed = true
assert.Nil(t, pathvar.Vars(r))
}))
assert.Nil(t, err)
err = router.Handle(test.method, "/b/c", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
routed = true
}))
err = router.Handle(test.method, "/b/c", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
routed = true
}))
assert.Nil(t, err)
w := new(mockedResponseWriter)