forked from mindstand/go-cypherdsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_test.go
107 lines (84 loc) · 2.12 KB
/
create_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
package go_cypherdsl
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestNewConstraint(t *testing.T) {
req := require.New(t)
//test nil
_, err := NewConstraint(nil)
req.NotNil(err)
//test empty name, type fields
errConf := &ConstraintConfig{Name: "", Type: "s", Field: "s"}
//name empty
_, err = NewConstraint(errConf)
req.NotNil(err)
//name and type
errConf.Type = ""
_, err = NewConstraint(errConf)
req.NotNil(err)
//name type and fields
errConf.Field = ""
_, err = NewConstraint(errConf)
req.NotNil(err)
//test unique and exists both false, both true
errConf.Unique = false
errConf.Exists = false
_, err = NewConstraint(errConf)
req.NotNil(err)
errConf.Unique = true
errConf.Exists = true
_, err = NewConstraint(errConf)
req.NotNil(err)
//test unique
testConf := errConf
testConf.Exists = false
testConf.Name = "t"
testConf.Type = "s"
testConf.Field = "s"
cypher, err := NewConstraint(testConf)
req.Nil(err)
req.EqualValues("CONSTRAINT ON (t:s) ASSERT t.s IS UNIQUE", cypher.ToString())
//test exists
testConf.Exists = true
testConf.Unique = false
cypher, err = NewConstraint(testConf)
req.Nil(err)
req.EqualValues("CONSTRAINT ON (t:s) ASSERT exists(t.s)", cypher.ToString())
}
func TestNewIndex(t *testing.T) {
req := require.New(t)
//check nil
_, err := NewIndex(nil)
req.NotNil(err)
conf := &IndexConfig{Type: "", Fields: nil}
//check empty type
_, err = NewIndex(conf)
req.NotNil(err)
//check nil fields
conf.Type = "test"
_, err = NewIndex(conf)
req.NotNil(err)
//check empty fields
conf.Fields = []string{}
_, err = NewIndex(conf)
req.NotNil(err)
//check single index
conf.Fields = []string{"one"}
cypher, err := NewIndex(conf)
req.Nil(err)
req.EqualValues("INDEX ON :test(one)", cypher.ToString())
//check composite index
conf.Fields = []string{"one", "two"}
cypher, err = NewIndex(conf)
req.Nil(err)
req.EqualValues("INDEX ON :test(one,two)", cypher.ToString())
}
func TestNewNode(t *testing.T) {
req := require.New(t)
_, err := NewNode(nil)
req.NotNil(err)
query, err := NewNode(Path().V(V{}).Build())
req.Nil(err)
req.NotEqual("test", query)
}