forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext_and_seed_identities_test.go
156 lines (126 loc) · 3.86 KB
/
next_and_seed_identities_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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package tests
import (
"testing"
"github.com/ravendb/ravendb-go-client"
"github.com/stretchr/testify/assert"
)
func nextAndSeedIdentitiesTestNextIdentityFor(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
{
session := openSessionMust(t, store)
user := &User{}
user.setLastName("Adi")
err = session.StoreWithID(user, "users|")
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
command := ravendb.NewNextIdentityForCommand("users")
err = store.GetRequestExecutor("").ExecuteCommand(command, nil)
assert.NoError(t, err)
{
session := openSessionMust(t, store)
user := &User{}
user.setLastName("Avivi")
err = session.StoreWithID(user, "users|")
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
{
var entityWithId1, entityWithId2, entityWithId3, entityWithId4 *User
session := openSessionMust(t, store)
err = session.Load(&entityWithId1, "users/1")
assert.NoError(t, err)
err = session.Load(&entityWithId2, "users/2")
assert.NoError(t, err)
err = session.Load(&entityWithId3, "users/3")
assert.NoError(t, err)
err = session.Load(&entityWithId4, "users/4")
assert.NoError(t, err)
assert.NotNil(t, entityWithId1)
assert.NotNil(t, entityWithId3)
assert.Nil(t, entityWithId2)
assert.Nil(t, entityWithId4)
assert.Equal(t, *entityWithId1.LastName, "Adi")
assert.Equal(t, *entityWithId3.LastName, "Avivi")
session.Close()
}
}
func nextAndSeedIdentitiesTestSeedIdentityFor(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
{
session := openSessionMust(t, store)
user := &User{}
user.setLastName("Adi")
err = session.StoreWithID(user, "users|")
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
command, err := ravendb.NewSeedIdentityForCommand("users", 1990, false)
assert.NoError(t, err)
err = store.GetRequestExecutor("").ExecuteCommand(command, nil)
assert.NoError(t, err)
result := command.Result
assert.Equal(t, result, 1990)
{
session := openSessionMust(t, store)
user := &User{}
user.setLastName("Avivi")
err = session.StoreWithID(user, "users|")
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
{
session := openSessionMust(t, store)
var entityWithId1, entityWithId2, entityWithId1990, entityWithId1991, entityWithId1992 *User
err = session.Load(&entityWithId1, "users/1")
assert.NoError(t, err)
err = session.Load(&entityWithId2, "users/2")
assert.NoError(t, err)
err = session.Load(&entityWithId1990, "users/1990")
assert.NoError(t, err)
err = session.Load(&entityWithId1991, "users/1991")
assert.NoError(t, err)
err = session.Load(&entityWithId1992, "users/1992")
assert.NoError(t, err)
assert.NotNil(t, entityWithId1)
assert.NotNil(t, entityWithId1991)
assert.Nil(t, entityWithId2)
assert.Nil(t, entityWithId1990)
assert.Nil(t, entityWithId1992)
assert.Equal(t, *entityWithId1.LastName, "Adi")
assert.Equal(t, *entityWithId1991.LastName, "Avivi")
session.Close()
}
command, err = ravendb.NewSeedIdentityForCommand("users", 1975, false)
assert.NoError(t, err)
err = store.GetRequestExecutor("").ExecuteCommand(command, nil)
assert.NoError(t, err)
assert.Equal(t, command.Result, 1991)
{
op := ravendb.NewGetIdentitiesOperation()
err = store.Maintenance().Send(op)
assert.NoError(t, err)
identites := op.Command.Result
n := identites["users|"]
assert.Equal(t, n, 1991)
}
}
func TestNextAndSeedIdentities(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
nextAndSeedIdentitiesTestNextIdentityFor(t, driver)
nextAndSeedIdentitiesTestSeedIdentityFor(t, driver)
}