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>
"golang.org/x/net/http/httpguts"
)
-// TODO(jba): test
-
// Errors used by the HTTP server.
var (
// ErrBodyNotAllowed is returned by ResponseWriter.Write calls
}
}
+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) {
mux := NewServeMux()
h := &handler{}