-
Notifications
You must be signed in to change notification settings - Fork 16
/
exists_test.go
60 lines (49 loc) · 1.25 KB
/
exists_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
package tests
import (
"testing"
"github.com/stretchr/testify/assert"
)
func existsTestCheckIfDocumentExists(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
{
session := openSessionMust(t, store)
assert.NoError(t, err)
idan := &User{}
idan.setName("Idan")
shalom := &User{}
shalom.setName("Shalom")
err = session.StoreWithID(idan, "users/1")
assert.NoError(t, err)
err = session.StoreWithID(shalom, "users/2")
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
{
session := openSessionMust(t, store)
assert.NoError(t, err)
ok, err := session.Advanced().Exists("users/1")
assert.NoError(t, err)
assert.True(t, ok)
ok, err = session.Advanced().Exists("users/10")
assert.NoError(t, err)
assert.False(t, ok)
var user *User
err = session.Load(&user, "users/2")
assert.NoError(t, err)
assert.NotNil(t, user)
ok, err = session.Advanced().Exists("users/2")
assert.NoError(t, err)
assert.True(t, ok)
session.Close()
}
}
func TestExists(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
existsTestCheckIfDocumentExists(t, driver)
}