forked from couchbase/gocbcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
83 lines (67 loc) · 1.78 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
78
79
80
81
82
83
package gocbcore
import (
"errors"
"github.com/couchbase/gocbcore/v10/memd"
)
func (suite *StandardTestSuite) TestEnhancedErrors() {
agent, s := suite.GetAgentAndHarness()
var err1, err2 error
s.PushOp(agent.Get(GetOptions{
Key: []byte("keyThatWontExist"),
}, func(res *GetResult, err error) {
s.Wrap(func() {
err1 = err
})
}))
s.Wait(0)
s.PushOp(agent.Get(GetOptions{
Key: []byte("keyThatWontExist"),
}, func(res *GetResult, err error) {
s.Wrap(func() {
err2 = err
})
}))
s.Wait(0)
if err1 == err2 {
suite.T().Fatalf("Operation error results should never return equivalent values")
}
}
func (suite *StandardTestSuite) TestEnhancedErrorOp() {
suite.EnsureSupportsFeature(TestFeatureErrMap)
if !suite.IsMockServer() {
suite.T().Skipf("only supported when testing against mock server")
}
spec := suite.StartTest(TestNameExtendedError)
h := suite.GetHarness()
agent := spec.Agent
h.PushOp(agent.GetAndLock(GetAndLockOptions{
Key: []byte("testEnhancedErrs"),
LockTime: 10,
CollectionName: spec.Collection,
ScopeName: spec.Scope,
}, func(res *GetAndLockResult, err error) {
h.Wrap(func() {
typedErr, ok := err.(*KeyValueError)
if !ok {
h.Fatalf("error should be a KeyValueError: %v", err)
}
if typedErr.Context == "" {
h.Fatalf("error should have a context")
}
if typedErr.ErrorName == "" {
h.Fatalf("error should have a name")
}
if typedErr.ErrorDescription == "" {
h.Fatalf("error should have a description")
}
if typedErr.StatusCode != memd.StatusKeyNotFound {
h.Fatalf("status code should have been StatusKeyNotFound")
}
if !errors.Is(err, ErrDocumentNotFound) {
h.Fatalf("error cause should have been ErrDocumentNotFound")
}
})
}))
h.Wait(0)
suite.EndTest(spec)
}