Files
Go-Template/http_handlers/errors/notfound_test.go

28 lines
587 B
Go

package errors
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)
func TestNewNotFoundError(t *testing.T) {
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/notfound", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
err := NewNotFoundError(c)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotFound, rec.Code)
var resp map[string]string
e2 := json.Unmarshal(rec.Body.Bytes(), &resp)
assert.NoError(t, e2)
assert.Equal(t, "Not Found", resp["error"])
}