You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
697 B
Go
29 lines
697 B
Go
package api
|
|
|
|
import (
|
|
stderrors "errors"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/pagefaultgames/rogueserver/errors"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestStatusCodeFromError(t *testing.T) {
|
|
t.Run("nil", func(t *testing.T) {
|
|
code := statusCodeFromError(nil)
|
|
assert.Equal(t, http.StatusInternalServerError, code)
|
|
})
|
|
t.Run("http error", func(t *testing.T) {
|
|
err := errors.NewHttpError(http.StatusTeapot, "teapot")
|
|
code := statusCodeFromError(err)
|
|
assert.Equal(t, http.StatusTeapot, code)
|
|
})
|
|
|
|
t.Run("standard error", func(t *testing.T) {
|
|
err := stderrors.New("standard error")
|
|
code := statusCodeFromError(err)
|
|
assert.Equal(t, http.StatusInternalServerError, code)
|
|
})
|
|
}
|