1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
package middleware
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/go-openapi/runtime"
"github.com/stretchr/testify/require"
)
func TestErrorResponder(t *testing.T) {
resp := Error(http.StatusBadRequest, map[string]string{"message": "this is the error body"})
rec := httptest.NewRecorder()
resp.WriteResponse(rec, runtime.JSONProducer())
require.Equal(t, http.StatusBadRequest, rec.Code)
require.Equal(t, "{\"message\":\"this is the error body\"}\n", rec.Body.String())
}
|