-
Notifications
You must be signed in to change notification settings - Fork 1
/
query_worker_test.go
91 lines (73 loc) · 2.23 KB
/
query_worker_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
package query_worker
import (
"github.com/marvin-hansen/goC8"
"github.com/marvin-hansen/goC8/examples/sample_data"
conf "github.com/marvin-hansen/goC8/tests/conf"
"github.com/marvin-hansen/goC8/types"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
const (
verbose = true
silent = true
fabric = "SouthEastAsia"
collectionTeachers = "teachers"
workerName = "getAllTeachers"
)
func TestSetup(t *testing.T) {
c := goC8.NewClient(conf.GetDefaultConfig())
goC8.CreateCollection(c, fabric, collectionTeachers, types.DocumentCollectionType, false)
goC8.ImportCollectionData(c, fabric, collectionTeachers, sample_data.GetTeacherData(), silent)
}
func TestCreateQueryWorker(t *testing.T) {
c := goC8.NewClient(conf.GetDefaultConfig())
query := "for t in teachers return t"
bindVars := ""
res, err := c.QueryWorker.CreateQueryWorker(fabric, workerName, query, bindVars)
wait()
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
}
func TestRunQueryWorker(t *testing.T) {
c := goC8.NewClient(conf.GetDefaultConfig())
bindVars := ""
res, err := c.QueryWorker.RunQueryWorker(fabric, workerName, bindVars)
wait()
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintJsonRes(res, verbose)
}
func TestReadAllQueryWorkers(t *testing.T) {
c := goC8.NewClient(conf.GetDefaultConfig())
res, err := c.QueryWorker.ReadAllQueryWorkers(fabric)
wait()
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
}
func TestUpdateQueryWorker(t *testing.T) {
c := goC8.NewClient(conf.GetDefaultConfig())
newQuery := "for t in testCollection return t"
newBindVars := ""
res, err := c.QueryWorker.UpdateQueryWorker(fabric, workerName, newQuery, newBindVars)
wait()
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
}
func TestDeleteQueryWorker(t *testing.T) {
c := goC8.NewClient(conf.GetDefaultConfig())
err := c.QueryWorker.DeleteQueryWorker(fabric, workerName)
wait()
assert.NoError(t, err)
}
func TestTeardown(t *testing.T) {
c := goC8.NewClient(conf.GetDefaultConfig())
goC8.TeardownCollection(c, fabric, collectionTeachers)
}
func wait() {
// tests randomly fail without the wait time.
time.Sleep(time.Millisecond * 250)
}