forked from cshum/imagor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
47 lines (34 loc) · 1.13 KB
/
errors_test.go
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
package imagor
import (
"context"
"errors"
"github.com/cshum/imagor/imagorpath"
"github.com/stretchr/testify/assert"
"net"
"net/http"
"net/url"
"testing"
)
func TestWrapError(t *testing.T) {
var err error
var e Error
assert.Equal(t, WrapError(nil), ErrInternal)
assert.Equal(t, ErrMethodNotAllowed, WrapError(ErrMethodNotAllowed))
err = NewError("errorrrr", 167)
assert.Equal(t, WrapError(errors.New(err.Error())), err)
assert.Equal(t, ErrTimeout, WrapError(context.DeadlineExceeded))
assert.Equal(t, true, ErrTimeout.Timeout())
assert.Equal(t, ErrTimeout, WrapError(&url.Error{Err: context.DeadlineExceeded}))
err = errors.New("asdfsdfsaf")
e = WrapError(err)
assert.Equal(t, 500, e.Code)
assert.Contains(t, e.Error(), err.Error())
e = NewErrorFromStatusCode(403)
assert.Equal(t, 403, e.Code)
assert.Contains(t, e.Error(), http.StatusText(403))
err = &net.DNSError{IsTimeout: true}
assert.Equal(t, ErrTimeout, WrapError(err))
err = ErrForward{imagorpath.Params{Width: 167, Height: 169, Image: "foo"}}
assert.Equal(t, "imagor: forward 167x169/foo", err.Error())
assert.Equal(t, ErrUnsupportedFormat, WrapError(err))
}