forked from slicebit/qb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors_test.go
51 lines (41 loc) · 1.39 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
48
49
50
51
package qb
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestErrorMessages(t *testing.T) {
var tests = []struct {
code ErrorCode
expected string
}{
{ErrAny, "Uncategorized error: xxx"},
{ErrInterface, "Interface error: xxx"},
{ErrDatabase, "Database error: xxx"},
{ErrData, "Database data error: xxx"},
{ErrOperational, "Database operational error: xxx"},
{ErrIntegrity, "Database integrity error: xxx"},
{ErrInternal, "Database internal error: xxx"},
{ErrProgramming, "Database programming error: xxx"},
{54, "xxx"},
}
for _, tt := range tests {
assert.Equal(t, tt.expected, Error{Code: tt.code, Orig: errors.New("xxx")}.Error())
}
}
func TestErrorCode(t *testing.T) {
assert.True(t, ErrInterface.IsInterfaceError())
assert.False(t, ErrInterface.IsDatabaseError())
assert.True(t, ErrDatabase.IsDatabaseError())
assert.False(t, ErrDatabase.IsInterfaceError())
assert.True(t, ErrData.IsDatabaseError())
assert.False(t, ErrData.IsInterfaceError())
assert.True(t, ErrOperational.IsDatabaseError())
assert.False(t, ErrOperational.IsInterfaceError())
assert.True(t, ErrIntegrity.IsDatabaseError())
assert.False(t, ErrIntegrity.IsInterfaceError())
assert.True(t, ErrInternal.IsDatabaseError())
assert.False(t, ErrInternal.IsInterfaceError())
assert.True(t, ErrProgramming.IsDatabaseError())
assert.False(t, ErrProgramming.IsInterfaceError())
}