-
Notifications
You must be signed in to change notification settings - Fork 19
/
error_test.go
65 lines (57 loc) · 1.38 KB
/
error_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
64
65
package anthropic_test
import (
"testing"
"github.com/liushuangls/go-anthropic/v2"
)
func TestIsXError(t *testing.T) {
countBool := func(bools []bool) int {
count := 0
for _, b := range bools {
if b {
count++
}
}
return count
}
errTypes := []anthropic.ErrType{
anthropic.ErrTypeInvalidRequest,
anthropic.ErrTypeAuthentication,
anthropic.ErrTypePermission,
anthropic.ErrTypeNotFound,
anthropic.ErrTypeTooLarge,
anthropic.ErrTypeRateLimit,
anthropic.ErrTypeApi,
anthropic.ErrTypeOverloaded,
}
isErrFuncs := func(e anthropic.APIError) []bool {
return []bool{
e.IsInvalidRequestErr(),
e.IsAuthenticationErr(),
e.IsPermissionErr(),
e.IsNotFoundErr(),
e.IsTooLargeErr(),
e.IsRateLimitErr(),
e.IsApiErr(),
e.IsOverloadedErr(),
}
}
apiErrors := []anthropic.APIError{}
for _, errType := range errTypes {
apiErrors = append(apiErrors, anthropic.APIError{
Type: errType,
Message: "fake message",
})
}
for i, e := range apiErrors {
isErrorType := isErrFuncs(e)
// Expect only one error type to be true for each error
numErrorType := countBool(isErrorType)
if numErrorType != 1 {
t.Errorf("Expected 1 error type to be true, got %d, for error %d", numErrorType, i)
}
// Expect the error type to be true for the correct error
if !isErrorType[i] {
t.Errorf("Expected error type %T to be true, got false", e)
}
}
}