-
Notifications
You must be signed in to change notification settings - Fork 16
/
ravendb_10641_test.go
126 lines (98 loc) · 2.59 KB
/
ravendb_10641_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package tests
import (
"testing"
"github.com/ravendb/ravendb-go-client"
"github.com/stretchr/testify/assert"
)
func ravendb10641canEditObjectsInMetadata(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
{
session := openSessionMust(t, store)
v := &Document{}
err = session.StoreWithID(v, "items/first")
assert.NoError(t, err)
items := map[string]string{
"lang": "en",
}
var meta *ravendb.MetadataAsDictionary
meta, err = session.Advanced().GetMetadataFor(v)
assert.NoError(t, err)
meta.Put("Items", items)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
{
session := openSessionMust(t, store)
var v *Document
err = session.Load(&v, "items/first")
assert.NoError(t, err)
var m *ravendb.MetadataAsDictionary
m, err = session.Advanced().GetMetadataFor(v)
assert.NoError(t, err)
metadataI, ok := m.Get("Items")
assert.True(t, ok)
metadata := metadataI.(map[string]interface{})
metadata["lang"] = "sv"
// Note: unlike Java we can't intercept modifications so we have to
// manually mark as dirty
m.MarkDirty()
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
{
session := openSessionMust(t, store)
var v *Document
err = session.Load(&v, "items/first")
assert.NoError(t, err)
var metadata *ravendb.MetadataAsDictionary
metadata, err = session.Advanced().GetMetadataFor(v)
assert.NoError(t, err)
metadata.Put("test", "123")
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
{
session := openSessionMust(t, store)
var v *Document
err = session.Load(&v, "items/first")
assert.NoError(t, err)
_, err = session.Advanced().GetMetadataFor(v)
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
{
session := openSessionMust(t, store)
var v *Document
err = session.Load(&v, "items/first")
assert.NoError(t, err)
metadata, err := session.Advanced().GetMetadataFor(v)
assert.NoError(t, err)
mI, ok := metadata.Get("Items")
assert.True(t, ok)
m := mI.(map[string]interface{})
val := m["lang"]
assert.Equal(t, val, "sv")
val, ok = metadata.Get("test")
assert.True(t, ok)
assert.Equal(t, val, "123")
session.Close()
}
}
type Document struct {
ID string `json:"ID"`
Name string `json:"Name"`
}
func TestRavenDB10641(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
// matches the order of Java tests
ravendb10641canEditObjectsInMetadata(t, driver)
}