-
Notifications
You must be signed in to change notification settings - Fork 1
/
index_test.go
169 lines (140 loc) · 4.45 KB
/
index_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
157
158
159
160
161
162
163
164
165
166
167
168
169
package index
import (
"github.com/marvin-hansen/goC8"
config "github.com/marvin-hansen/goC8/tests/conf"
"github.com/marvin-hansen/goC8/types"
"github.com/stretchr/testify/assert"
"testing"
)
const (
verbose = true
fabric = "SouthEastAsia"
graph = "airline"
citiesCollection = "cities"
textCollection = "textCollection"
collType = types.DocumentCollectionType
)
// We need to store the index name when creating it to delete it later
var sharedIndexName string = ""
func TestSetup(t *testing.T) {
c := goC8.NewClient(config.GetDefaultConfig())
// test if city collection exists
exists, err := c.Collection.CheckCollectionExists(fabric, citiesCollection)
assert.NoError(t, err)
if !exists {
// if not create collection
err = c.Collection.CreateNewCollection(fabric, citiesCollection, false, collType)
assert.NoError(t, err)
}
// test if text collection exists
exists, err = c.Collection.CheckCollectionExists(fabric, textCollection)
assert.NoError(t, err)
if !exists {
// if not create collection
err = c.Collection.CreateNewCollection(fabric, textCollection, false, collType)
assert.NoError(t, err)
}
}
func TestGetIndexes(t *testing.T) {
c := goC8.NewClient(config.GetDefaultConfig())
res, err := c.Index.GetIndexes(fabric, citiesCollection)
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
}
func TestCreateFulltextIndex(t *testing.T) {
c := goC8.NewClient(config.GetDefaultConfig())
field := "Summary"
minLength := 3
res, err := c.Index.CreateFulltextIndex(fabric, textCollection, field, minLength)
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
sharedIndexName = res.Name
}
func TestCreateGeoIndex(t *testing.T) {
c := goC8.NewClient(config.GetDefaultConfig())
field := "location"
geoJson := true
res, err := c.Index.CreateGeoIndex(fabric, citiesCollection, field, geoJson)
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
}
func TestCreateHashIndex(t *testing.T) {
c := goC8.NewClient(config.GetDefaultConfig())
field := "Text"
deduplicate := true
sparse := true
unique := true
res, err := c.Index.CreateHashIndex(fabric, textCollection, field, deduplicate, sparse, unique)
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
}
func TestCreatePersistentIndex(t *testing.T) {
c := goC8.NewClient(config.GetDefaultConfig())
field := "Keywords"
deduplicate := true
sparse := true
unique := true
res, err := c.Index.CreatePersistentIndex(fabric, textCollection, field, deduplicate, sparse, unique)
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
}
func TestCreateSkipListIndex(t *testing.T) {
c := goC8.NewClient(config.GetDefaultConfig())
field := "SkipText"
deduplicate := true
sparse := false
unique := true
res, err := c.Index.CreateSkipListIndex(fabric, textCollection, field, deduplicate, sparse, unique)
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
}
func TestCreateTTLIndex(t *testing.T) {
c := goC8.NewClient(config.GetDefaultConfig())
field := "requests"
expiration := 10
res, err := c.Index.CreateTTLIndex(fabric, textCollection, field, expiration)
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
}
func TestDeleteIndex(t *testing.T) {
c := goC8.NewClient(config.GetDefaultConfig())
indexName := sharedIndexName
res, err := c.Index.DeleteIndex(fabric, textCollection, indexName)
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
}
func TestTeardown(t *testing.T) {
c := goC8.NewClient(config.GetDefaultConfig())
// test if graph exists
exists, err := c.Graph.CheckGraphExists(fabric, graph)
assert.NoError(t, err)
if exists {
// if so delete graph
_, delErr := c.Graph.DeleteGraph(fabric, graph, true)
assert.NoError(t, delErr)
}
existsCol, errCol := c.Collection.CheckCollectionExists(fabric, textCollection)
assert.NoError(t, errCol)
if existsCol {
errDel := c.Collection.DeleteCollection(fabric, textCollection, false)
assert.NoError(t, errDel)
}
// It's possible that the graph has been deleted without dropCollections,
// but the underlying collections still exists. Let's check one by one.
// test if city collection exists
exists, err = c.Collection.CheckCollectionExists(fabric, citiesCollection)
assert.NoError(t, err)
if exists {
// if so, delete
err = c.Collection.DeleteCollection(fabric, citiesCollection, false)
assert.NoError(t, err)
}
}