-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_router_test.go
More file actions
56 lines (46 loc) · 1.46 KB
/
errors_router_test.go
File metadata and controls
56 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package forge
import (
"errors"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/xraph/go-utils/errs"
)
func TestHTTPError_Error(t *testing.T) {
err := NewHTTPError(404, "not found")
assert.Equal(t, "not found", err.Error())
}
func TestHTTPError_Error_NoMessage(t *testing.T) {
err := &HTTPError{HttpStatusCode: 500}
assert.Equal(t, http.StatusText(http.StatusInternalServerError), err.Error())
}
func TestHTTPError_Error_WithErr(t *testing.T) {
err := errs.NewHTTPError(500, "inner error")
assert.Equal(t, "inner error", err.Error())
}
func TestBadRequest(t *testing.T) {
err := BadRequest("bad request")
assert.Equal(t, http.StatusBadRequest, err.StatusCode())
// assert.Equal(t, "bad request", err.Message)
}
func TestUnauthorized(t *testing.T) {
err := Unauthorized("unauthorized")
assert.Equal(t, http.StatusUnauthorized, err.StatusCode())
// assert.Equal(t, "unauthorized", err.Message)
}
func TestForbidden(t *testing.T) {
err := Forbidden("forbidden")
assert.Equal(t, http.StatusForbidden, err.StatusCode())
// assert.Equal(t, "forbidden", err.Message)
}
func TestNotFound(t *testing.T) {
err := NotFound("not found")
assert.Equal(t, http.StatusNotFound, err.StatusCode())
// assert.Equal(t, "not found", err.Message)
}
func TestInternalError(t *testing.T) {
innerErr := errors.New("internal")
err := InternalError(innerErr)
assert.Equal(t, http.StatusInternalServerError, err.StatusCode())
// assert.Equal(t, innerErr, err.Err)
}