forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_all_starting_with_test.go
73 lines (60 loc) · 1.47 KB
/
load_all_starting_with_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
package tests
import (
"reflect"
"testing"
ravendb "github.com/ravendb/ravendb-go-client"
"github.com/stretchr/testify/assert"
)
type Abc struct {
ID string
}
type Xyz struct {
ID string
}
func loadAllStartingWithLoadAllStartingWith(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
doc1 := &Abc{
ID: "abc/1",
}
doc2 := &Xyz{
ID: "xyz/1",
}
{
session := openSessionMust(t, store)
err = session.Store(doc1)
assert.NoError(t, err)
err = session.Store(doc2)
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
}
{
session := openSessionMust(t, store)
args := &ravendb.StartsWithArgs{
StartsWith: "abc/",
}
testClasses := session.Advanced().Lazily().LoadStartingWith(args)
v := map[string]*Abc{}
err = testClasses.GetValue(v)
assert.NoError(t, err)
assert.Equal(t, len(v), 1)
assert.Equal(t, v["abc/1"].ID, "abc/1")
q := session.QueryCollectionForType(reflect.TypeOf(&Xyz{}))
test2Classes, err := q.WaitForNonStaleResults(0).Lazily()
assert.NoError(t, err)
var v2 []*Xyz
err = test2Classes.GetValue(&v2)
assert.NoError(t, err)
assert.Equal(t, len(v2), 1)
assert.Equal(t, v2[0].ID, "xyz/1")
}
}
func TestLoadAllStartingWith(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
// matches order of Java tests
loadAllStartingWithLoadAllStartingWith(t, driver)
}