forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathravendb_903_test.go
109 lines (88 loc) · 2.64 KB
/
ravendb_903_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
package tests
import (
"testing"
ravendb "github.com/ravendb/ravendb-go-client"
"github.com/stretchr/testify/assert"
)
// unique name that doesn't conflict with Product in hi_lo_test.go
type Product2 struct {
Name string `json:"name"`
Description string `json:"description"`
}
func ravendb903Test1(t *testing.T, driver *RavenTestDriver) {
fn := func(session *ravendb.DocumentSession, index *ravendb.IndexCreationTask) *ravendb.DocumentQuery {
q := session.Advanced().QueryIndex(index.IndexName)
q = q.Search("description", "Hello")
q = q.Intersect()
q = q.WhereEquals("name", "Bar")
return q
}
ravendb903DoTest(t, driver, fn)
}
func ravendb903Test2(t *testing.T, driver *RavenTestDriver) {
fn := func(session *ravendb.DocumentSession, index *ravendb.IndexCreationTask) *ravendb.DocumentQuery {
q := session.Advanced().QueryIndex(index.IndexName)
q = q.WhereEquals("name", "Bar")
q = q.Intersect()
q = q.Search("description", "Hello")
return q
}
ravendb903DoTest(t, driver, fn)
}
func ravendb903DoTest(t *testing.T, driver *RavenTestDriver, queryFunction func(*ravendb.DocumentSession, *ravendb.IndexCreationTask) *ravendb.DocumentQuery) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
index := NewTestIndex()
err = store.ExecuteIndex(index, "")
assert.NoError(t, err)
{
session := openSessionMust(t, store)
product1 := &Product2{
Name: "Foo",
Description: "Hello World",
}
product2 := &Product2{
Name: "Bar",
Description: "Hello World",
}
product3 := &Product2{
Name: "Bar",
Description: "Goodbye World",
}
err = session.Store(product1)
assert.NoError(t, err)
err = session.Store(product2)
assert.NoError(t, err)
err = session.Store(product3)
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
err = driver.waitForIndexing(store, "", 0)
assert.NoError(t, err)
{
var products []*Product2
session := openSessionMust(t, store)
query := queryFunction(session, index)
err = query.GetResults(&products)
assert.NoError(t, err)
assert.Equal(t, len(products), 1)
session.Close()
}
}
func NewTestIndex() *ravendb.IndexCreationTask {
res := ravendb.NewIndexCreationTask("TestIndex")
res.Map = "from product in docs.Product2s select new { product.name, product.description }"
res.Index("description", ravendb.FieldIndexingSearch)
return res
}
func TestRavenDB903(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
// matches the order of Java tests
ravendb903Test1(t, driver)
ravendb903Test2(t, driver)
}