Skip to content

Commit 4415424

Browse files
jbapull[bot]
authored andcommitted
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>
1 parent 3473db9 commit 4415424

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/net/http/server.go

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import (
3333
"golang.org/x/net/http/httpguts"
3434
)
3535

36-
// TODO(jba): test
37-
3836
// Errors used by the HTTP server.
3937
var (
4038
// ErrBodyNotAllowed is returned by ResponseWriter.Write calls

src/net/http/server_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ func TestFindHandler(t *testing.T) {
118118
}
119119
}
120120

121+
func TestEmptyServeMux(t *testing.T) {
122+
// Verify that a ServeMux with nothing registered
123+
// doesn't panic.
124+
mux := NewServeMux()
125+
var r Request
126+
r.Method = "GET"
127+
r.Host = "example.com"
128+
r.URL = &url.URL{Path: "/"}
129+
_, p := mux.Handler(&r)
130+
if p != "" {
131+
t.Errorf(`got %q, want ""`, p)
132+
}
133+
}
134+
121135
func TestRegisterErr(t *testing.T) {
122136
mux := NewServeMux()
123137
h := &handler{}

0 commit comments

Comments
 (0)