Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make httpserver test use more specific scheme matchers
  • Loading branch information
euank committed Jul 3, 2019
1 parent 8af972a commit 8981322
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions mux_httpserver_test.go
Expand Up @@ -11,10 +11,14 @@ import (
)

func TestSchemeMatchers(t *testing.T) {
router := NewRouter()
router.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
httpRouter := NewRouter()
httpRouter.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
rw.Write([]byte("hello world"))
}).Schemes("http", "https")
}).Schemes("http")
httpsRouter := NewRouter()
httpsRouter.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
rw.Write([]byte("hello world"))
}).Schemes("https")

assertHelloWorldResponse := func(t *testing.T, s *httptest.Server) {
resp, err := s.Client().Get(s.URL)
Expand All @@ -34,12 +38,12 @@ func TestSchemeMatchers(t *testing.T) {
}

t.Run("httpServer", func(t *testing.T) {
s := httptest.NewServer(router)
s := httptest.NewServer(httpRouter)
defer s.Close()
assertHelloWorldResponse(t, s)
})
t.Run("httpsServer", func(t *testing.T) {
s := httptest.NewTLSServer(router)
s := httptest.NewTLSServer(httpsRouter)
defer s.Close()
assertHelloWorldResponse(t, s)
})
Expand Down

0 comments on commit 8981322

Please sign in to comment.