forked from couchbase/gocb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
77 lines (61 loc) · 1.83 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
66
67
68
69
70
71
72
73
74
75
76
77
package gocb
import (
"testing"
"github.com/couchbase/gocbcore/v8"
)
func TestIsCasMismatchError(t *testing.T) {
err := &gocbcore.KvError{
Code: gocbcore.StatusKeyExists,
}
mismatchErr := maybeEnhanceKVErr(err, "myfakekey", true)
if IsCasMismatchError(mismatchErr) {
t.Fatalf("Error should not have been cas mismatch")
}
notMismatchErr := maybeEnhanceKVErr(err, "myfakekey", false)
if !IsCasMismatchError(notMismatchErr) {
t.Fatalf("Error should have been cas mismatch")
}
errValTooLarge := &gocbcore.KvError{
Code: gocbcore.StatusTooBig,
}
notMismatchErr = maybeEnhanceKVErr(errValTooLarge, "myfakekey", true)
if IsCasMismatchError(notMismatchErr) {
t.Fatalf("Error should not have been cas mismatch")
}
}
func TestNilEnhanceError(t *testing.T) {
enhancedErr := maybeEnhanceKVErr(nil, "myfakekey", false)
if enhancedErr != nil {
t.Fatalf("Expected enhanced error to be nil but was %v", enhancedErr)
}
}
func TestKVIsRetryable(t *testing.T) {
err := &gocbcore.KvError{
Code: gocbcore.StatusTmpFail,
}
enhancedErr := maybeEnhanceKVErr(err, "myfakekey", false)
if !IsRetryableError(enhancedErr) {
t.Fatalf("StatusTmpFail error should have been retryable")
}
err = &gocbcore.KvError{
Code: gocbcore.StatusOutOfMemory,
}
enhancedErr = maybeEnhanceKVErr(err, "myfakekey", false)
if !IsRetryableError(enhancedErr) {
t.Fatalf("StatusOutOfMemory error should have been retryable")
}
err = &gocbcore.KvError{
Code: gocbcore.StatusBusy,
}
enhancedErr = maybeEnhanceKVErr(err, "myfakekey", false)
if !IsRetryableError(enhancedErr) {
t.Fatalf("StatusBusy error should have been retryable")
}
err = &gocbcore.KvError{
Code: gocbcore.StatusTooBig,
}
enhancedErr = maybeEnhanceKVErr(err, "myfakekey", false)
if IsRetryableError(enhancedErr) {
t.Fatalf("StatusTooBig error should not have been retryable")
}
}