1
0
mirror of https://github.com/golang/go synced 2024-11-18 13:54:59 -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:
Jonathan Amsterdam 2023-09-25 09:46:32 -04:00
parent eb070d7483
commit 32b6d2d9a8
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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{}