forked from couchbase/gocb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bucket_subdoc_test.go
57 lines (49 loc) · 1.4 KB
/
bucket_subdoc_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
package gocb
import "testing"
func TestSubDocXattrs(t *testing.T) {
itemMap := make(map[string]string)
itemMap["x"] = "x value 1"
_, err := globalBucket.Upsert("subDocXattrs", itemMap, 0)
if err != nil {
t.Fatalf("Failed to setup main document %v", err)
}
_, err = globalBucket.MutateIn("subDocXattrs", 0, 0).
UpsertEx("xatest.test", "test value", SubdocFlagXattr|SubdocFlagCreatePath).
UpsertEx("x", "x value 2", SubdocFlagNone).
Execute()
if err != nil {
t.Fatalf("Failed to sub-doc mutate (%s)", err)
}
_, err = globalBucket.MutateInEx("subDocMkDoc", SubdocDocFlagMkDoc, 0, 0).
UpsertEx("x", "x value 4", SubdocFlagNone).
Execute()
if err != nil {
t.Fatalf("Failed to sub-doc mkdoc mutate (%s)", err)
}
res, err := globalBucket.LookupIn("subDocXattrs").
GetEx("xatest", SubdocFlagXattr).
GetEx("x", SubdocFlagNone).
Execute()
if err != nil {
t.Fatalf("Failed to sub-doc lookup (%s)", err)
}
var xatest map[string]string
err = res.Content("xatest", &xatest)
if err != nil {
t.Fatalf("Failed to get xatest xattr contents (%s)", err)
}
if len(xatest) != 1 {
t.Fatalf("xatest xattr had wrong len")
}
if xatest["test"] != "test value" {
t.Fatalf("xatest test attribute had wrong value")
}
var x string
err = res.Content("x", &x)
if err != nil {
t.Fatalf("Failed to get x contents (%s)", err)
}
if x != "x value 2" {
t.Fatalf("document x attribute had wrong value")
}
}