Fix ping handler integration test after change prototool by buf
@@ -4,6 +4,7 @@ package handlers
import (
"context"
+ "encoding/json"
"net/http"
"net/http/httptest"
"testing"
@@ -41,7 +42,11 @@ func TestPingHandler(t *testing.T) {
require.Equal(t, 200, rr.Code)
bodyString := rr.Body.String()
- require.Equal(t, "{\"message\":\"pong\"}", bodyString)
+ var body map[string]interface{}
+ err = json.Unmarshal([]byte(bodyString), &body)
+
+ require.NoError(t, err)
+ require.Equal(t, "pong", body["message"])
})
t.Run("with invalid request method", func(t *testing.T) {
@@ -66,9 +71,13 @@ func TestPingHandler(t *testing.T) {
mux.ServeHTTP(rr, req)
- require.Equal(t, 405, rr.Code)
+ require.Equal(t, 501, rr.Code)
bodyString := rr.Body.String()
- require.Equal(t, "Method Not Allowed\n", bodyString)
+ var body map[string]interface{}
+ err = json.Unmarshal([]byte(bodyString), &body)
+
+ require.NoError(t, err)
+ require.Equal(t, "Method Not Allowed", body["message"])
})
t.Run("with invalid request path", func(t *testing.T) {
@@ -95,6 +104,10 @@ func TestPingHandler(t *testing.T) {
require.Equal(t, 404, rr.Code)
bodyString := rr.Body.String()
- require.Equal(t, "Not Found\n", bodyString)
+ var body map[string]interface{}
+ err = json.Unmarshal([]byte(bodyString), &body)
+
+ require.NoError(t, err)
+ require.Equal(t, "Not Found", body["message"])
})
}
