You've already forked Go-Template
Future self, please forgive me and don't hit me with the baseball bat again!
This commit is contained in:
29
http_handlers/errors/badrequest_test.go
Normal file
29
http_handlers/errors/badrequest_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package errors
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewBadRequestError(t *testing.T) {
|
||||
e := echo.New()
|
||||
req := httptest.NewRequest(http.MethodPost, "/", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
c := e.NewContext(req, rec)
|
||||
|
||||
fields := map[string]string{"field1": "error1", "field2": "error2"}
|
||||
err := NewBadRequestError(c, fields)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusBadRequest, rec.Code)
|
||||
|
||||
var resp map[string]interface{}
|
||||
b := json.Unmarshal(rec.Body.Bytes(), &resp)
|
||||
assert.NoError(t, b)
|
||||
assert.Equal(t, "Bad Request", resp["error"])
|
||||
assert.Equal(t, map[string]interface{}{"field1": "error1", "field2": "error2"}, resp["fields"])
|
||||
}
|
||||
Reference in New Issue
Block a user