-
Notifications
You must be signed in to change notification settings - Fork 1
/
collection_bulk_test.go
74 lines (61 loc) · 1.42 KB
/
collection_bulk_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
package gocb
import (
"fmt"
"testing"
)
func TestUpsertGetBulk(t *testing.T) {
var ops []BulkOp
for i := 0; i < 20; i++ {
ops = append(ops, &UpsertOp{
ID: fmt.Sprintf("%d", i),
Value: "test",
Expiry: 20,
})
}
err := globalCollection.Do(ops, nil)
if err != nil {
t.Fatalf("Expected Do to not error for upserts %v", err)
}
for _, op := range ops {
upsertOp, ok := op.(*UpsertOp)
if !ok {
t.Fatalf("Could not type assert BulkOp into UpsertOp")
}
if upsertOp.Err != nil {
t.Fatalf("Expected UpsertOp Err to be nil but was %v", upsertOp.Err)
}
if upsertOp.Result.Cas() == 0 {
t.Fatalf("Expected UpsertOp Cas to be non zero")
}
}
var getOps []BulkOp
for i := 0; i < 20; i++ {
getOps = append(getOps, &GetOp{
ID: fmt.Sprintf("%d", i),
})
}
err = globalCollection.Do(getOps, nil)
if err != nil {
t.Fatalf("Expected Do to not error for gets %v", err)
}
for _, op := range getOps {
getOp, ok := op.(*GetOp)
if !ok {
t.Fatalf("Could not type assert BulkOp into GetOp")
}
if getOp.Err != nil {
t.Fatalf("Expected GetOp Err to be nil but was %v", getOp.Err)
}
if getOp.Result.Cas() == 0 {
t.Fatalf("Expected GetOp Cas to be non zero")
}
var val string
err = getOp.Result.Content(&val)
if err != nil {
t.Fatalf("Failed to get content from GetOp %v", err)
}
if val != "test" {
t.Fatalf("Expected GetOp value to be test but was %s", val)
}
}
}