-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_exhausted_test.go
63 lines (48 loc) · 1.48 KB
/
resource_exhausted_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package zerrors
import (
"errors"
"github.com/samber/oops"
"testing"
"github.com/stretchr/testify/assert"
)
func TestToResourceExhaustedOnNil(t *testing.T) {
err := ToResourceExhausted(nil, "id")
ok := IsResourceExhausted(err)
assert.False(t, ok)
assert.Equal(t, err, nil)
}
func TestToResourceExhausted(t *testing.T) {
err := ToResourceExhausted(errors.New("not domain"), "id")
assert.True(t, IsResourceExhausted(err))
var e oops.OopsError
ok := errors.As(err, &e)
assert.True(t, ok)
assert.Equal(t, ErrResourceExhausted, e.Code())
}
func TestIsResourceExhaustedOnNonDomain(t *testing.T) {
err := errors.New("I am found!")
ok := IsResourceExhausted(err)
assert.False(t, ok)
}
func TestThrowResourceExhausted(t *testing.T) {
err := ThrowResourceExhausted("create", "user", "sam")
ok := IsResourceExhausted(err)
assert.True(t, ok)
assert.Equal(t, err.Error(), "cannot create 'sam' of kind 'user'")
}
func TestResourceExhaustedf(t *testing.T) {
err := ResourceExhaustedf("something happened: %s", "reason")
ok := IsResourceExhausted(err)
assert.True(t, ok)
assert.Equal(t, err.Error(), "something happened: reason")
}
func TestToResourceExhaustedf(t *testing.T) {
err := ToResourceExhaustedf(errors.New("something happened"), "key: %s", "value")
ok := IsResourceExhausted(err)
assert.True(t, ok)
var e oops.OopsError
ok = errors.As(err, &e)
assert.True(t, ok)
assert.Equal(t, ErrResourceExhausted, e.Code())
assert.Equal(t, err.Error(), "key: value: something happened")
}