This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathset_test.go
163 lines (145 loc) · 3.17 KB
/
set_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
package go_cypherdsl
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestSetConfig_ToString(t *testing.T) {
req := require.New(t)
var err error
var cypher string
//check conditional
t1 := &SetConfig{
Operation: SetEqualTo,
Target: 1,
Member: "t",
Name: "f",
Condition: C(&ConditionConfig{
Name: "t",
Field: "s",
ConditionOperator: EqualToOperator,
Check: 4,
}),
}
cypher, err = t1.ToString()
req.Nil(err)
req.EqualValues("(CASE WHEN t.s = 4 THEN f END).t = 1", cypher)
//check labels
t2 := &SetConfig{
Name: "t",
Label: []string{"l1", "l2"},
}
cypher, err = t2.ToString()
req.Nil(err)
req.EqualValues("t:l1:l2", cypher)
//check mutate
param, err := ParamsFromMap(map[string]interface{}{
"test": 1,
})
req.Nil(err)
req.NotNil(param)
t3 := &SetConfig{
Name: "t",
Operation: SetMutate,
TargetMap: param,
}
cypher, err = t3.ToString()
req.Nil(err)
req.EqualValues("t += {test:1}", cypher)
//check set node to map
t4 := &SetConfig{
Name: "t",
Operation: SetEqualTo,
TargetMap: param,
}
cypher, err = t4.ToString()
req.Nil(err)
req.EqualValues("t = {test:1}", cypher)
//check set node member
t5 := &SetConfig{
Operation: SetEqualTo,
Target: 1,
Member: "t",
Name: "f",
}
cypher, err = t5.ToString()
req.Nil(err)
req.EqualValues("f.t = 1", cypher)
//error - name not defined
e1 := &SetConfig{}
_, err = e1.ToString()
req.NotNil(err)
//error - operation not defined
e2 := &SetConfig{Name: "asdfasd"}
_, err = e2.ToString()
req.NotNil(err)
//error - no targets defined
e3 := &SetConfig{Name: "asdfasd", Operation: SetEqualTo}
_, err = e3.ToString()
req.NotNil(err)
//error - 2 targets defined
e4 := &SetConfig{
Name: "asdfasd",
Operation: SetEqualTo,
Target: 1,
TargetMap: param,
}
_, err = e4.ToString()
req.NotNil(err)
//error - 3 targets defined
e5 := &SetConfig{
Name: "asdfasd",
Operation: SetEqualTo,
Target: 1,
TargetMap: param,
TargetFunction: &FunctionConfig{Name: "s"},
}
_, err = e5.ToString()
req.NotNil(err)
//error - trying to set labels on conditional
e6 := &SetConfig{
Condition: C(&ConditionConfig{
Name: "t",
Field: "s",
ConditionOperator: EqualToOperator,
Check: 4,
}),
Name: "check",
Label: []string{"asdfasd"},
}
_, err = e6.ToString()
req.NotNil(err)
//error - trying to set labels on mutate operation
e7 := &SetConfig{
Name: "t",
Operation: SetMutate,
Label: []string{"dasdf"},
Target: 1,
}
_, err = e7.ToString()
req.NotNil(err)
//error - trying to use member on mutate operation
e8 := &SetConfig{
Name: "t",
Operation: SetMutate,
Member: "asdfasd",
Target: 1,
}
_, err = e8.ToString()
req.NotNil(err)
//error - not using target map on mutate operation
e9 := &SetConfig{
Name: "t",
Operation: SetMutate,
Target: 1,
}
_, err = e9.ToString()
req.NotNil(err)
//error - trying to set node equal to plain target
e10 := &SetConfig{
Name: "t",
Operation: SetEqualTo,
Target: 1,
}
_, err = e10.ToString()
req.NotNil(err)
}