Skip to content

Commit

Permalink
Update test to have different responses per route
Browse files Browse the repository at this point in the history
  • Loading branch information
euank committed Oct 17, 2019
1 parent 7b0a1dc commit ac8a272
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mux_httpserver_test.go
Expand Up @@ -13,14 +13,14 @@ import (
func TestSchemeMatchers(t *testing.T) {
httpRouter := NewRouter()
httpRouter.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
rw.Write([]byte("hello world"))
rw.Write([]byte("hello http world"))
}).Schemes("http")
httpsRouter := NewRouter()
httpsRouter.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
rw.Write([]byte("hello world"))
rw.Write([]byte("hello https world"))
}).Schemes("https")

assertHelloWorldResponse := func(t *testing.T, s *httptest.Server) {
assertResponseBody := func(t *testing.T, s *httptest.Server, expectedBody string) {
resp, err := s.Client().Get(s.URL)
if err != nil {
t.Fatalf("unexpected error getting from server: %v", err)
Expand All @@ -32,19 +32,19 @@ func TestSchemeMatchers(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error reading body: %v", err)
}
if !bytes.Equal(body, []byte("hello world")) {
if !bytes.Equal(body, []byte(expectedBody)) {
t.Fatalf("response should be hello world, was: %q", string(body))
}
}

t.Run("httpServer", func(t *testing.T) {
s := httptest.NewServer(httpRouter)
defer s.Close()
assertHelloWorldResponse(t, s)
assertResponseBody(t, s, "hello http world")
})
t.Run("httpsServer", func(t *testing.T) {
s := httptest.NewTLSServer(httpsRouter)
defer s.Close()
assertHelloWorldResponse(t, s)
assertResponseBody(t, s, "hello https world")
})
}

0 comments on commit ac8a272

Please sign in to comment.