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