From ac8a272dc87fb425116b274c92adc60fe11944c8 Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Wed, 16 Oct 2019 23:25:07 -0700 Subject: [PATCH] Update test to have different responses per route --- mux_httpserver_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mux_httpserver_test.go b/mux_httpserver_test.go index d5e35e9e..7b8c959e 100644 --- a/mux_httpserver_test.go +++ b/mux_httpserver_test.go @@ -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) @@ -32,7 +32,7 @@ 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)) } } @@ -40,11 +40,11 @@ func TestSchemeMatchers(t *testing.T) { 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") }) }