mirror of
https://github.com/golang/go
synced 2024-11-05 15:16:11 -07:00
net/http: add a test for an empty ServeMux
Make sure a ServeMux with no patterns is well-behaved. Updates #61410. Change-Id: Ib3eb85b384e1309e785663902d2c45ae01e64807 Reviewed-on: https://go-review.googlesource.com/c/go/+/530479 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
eb070d7483
commit
32b6d2d9a8
@ -33,8 +33,6 @@ import (
|
|||||||
"golang.org/x/net/http/httpguts"
|
"golang.org/x/net/http/httpguts"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO(jba): test
|
|
||||||
|
|
||||||
// Errors used by the HTTP server.
|
// Errors used by the HTTP server.
|
||||||
var (
|
var (
|
||||||
// ErrBodyNotAllowed is returned by ResponseWriter.Write calls
|
// ErrBodyNotAllowed is returned by ResponseWriter.Write calls
|
||||||
|
@ -118,6 +118,20 @@ func TestFindHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyServeMux(t *testing.T) {
|
||||||
|
// Verify that a ServeMux with nothing registered
|
||||||
|
// doesn't panic.
|
||||||
|
mux := NewServeMux()
|
||||||
|
var r Request
|
||||||
|
r.Method = "GET"
|
||||||
|
r.Host = "example.com"
|
||||||
|
r.URL = &url.URL{Path: "/"}
|
||||||
|
_, p := mux.Handler(&r)
|
||||||
|
if p != "" {
|
||||||
|
t.Errorf(`got %q, want ""`, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRegisterErr(t *testing.T) {
|
func TestRegisterErr(t *testing.T) {
|
||||||
mux := NewServeMux()
|
mux := NewServeMux()
|
||||||
h := &handler{}
|
h := &handler{}
|
||||||
|
Loading…
Reference in New Issue
Block a user