add errors unit test

This commit is contained in:
qpismont 2025-02-25 21:32:32 +00:00
parent edb59bd472
commit 604f705662

View file

@ -0,0 +1,23 @@
package core
import (
"errors"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewError(t *testing.T) {
err := NewHTTPError(http.StatusBadRequest, "MyError", errors.New("test"))
assert.Equal(t, http.StatusBadRequest, err.Code)
assert.Equal(t, "MyError", err.Error())
assert.Equal(t, errors.New("test"), err.Unwrap())
}
func TestNewInternalServerError(t *testing.T) {
err := NewInternalServerError(errors.New("test"))
assert.Equal(t, http.StatusInternalServerError, err.Code)
assert.Equal(t, "Internal server error", err.Error())
assert.Equal(t, errors.New("test"), err.Unwrap())
}