-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathrdf_result_test.go
230 lines (213 loc) · 4.83 KB
/
rdf_result_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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//go:build integration || cloud || upgrade
/*
* SPDX-FileCopyrightText: © Hypermode Inc. <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/
package query
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestRDFResult(t *testing.T) {
query := `{
friends_15_and_19(func: uid(1)) {
name
friend @filter(ge(age, 15) AND lt(age, 19)) {
name
age
}
}
}`
rdf, err := processQueryRDF(context.Background(), query)
require.NoError(t, err)
require.Equal(t, rdf, `<0x1> <name> "Michonne" .
<0x1> <friend> <0x17> .
<0x1> <friend> <0x18> .
<0x1> <friend> <0x19> .
<0x17> <name> "Rick Grimes" .
<0x18> <name> "Glenn Rhee" .
<0x19> <name> "Daryl Dixon" .
<0x17> <age> "15" .
<0x18> <age> "15" .
<0x19> <age> "17" .
`)
}
func TestRDFNormalize(t *testing.T) {
query := `
{
me(func: uid(0x01)) @normalize {
mn: name
gender
friend {
n: name
d: dob
friend {
fn : name
}
}
son {
sn: name
}
}
}`
_, err := processQueryRDF(context.Background(), query)
require.Error(t, err, "normalize directive is not supported in the rdf output format")
}
func TestRDFGroupBy(t *testing.T) {
query := `
{
me(func: uid(1, 23, 24, 25, 31)) @groupby(age) {
count(uid)
}
}`
_, err := processQueryRDF(context.Background(), query)
require.Contains(t, err.Error(), "groupby is not supported in rdf output format")
}
func TestRDFUidCount(t *testing.T) {
query := `
{
me(func: gt(count(friend), 0)) {
count(uid)
}
}`
_, err := processQueryRDF(context.Background(), query)
require.Contains(t, err.Error(), "uid count is not supported in the rdf output format")
}
func TestRDFIngoreReflex(t *testing.T) {
query := `
{
me(func:anyofterms(name, "Michonne Rick Daryl")) @ignoreReflex {
name
friend {
name
friend {
name
}
}
}
}`
_, err := processQueryRDF(context.Background(), query)
require.Contains(t, err.Error(),
"ignorereflex directive is not supported in the rdf output format")
}
func TestRDFRecurse(t *testing.T) {
query := `
{
me(func: anyofterms(name, "Michonne Rick Daryl")) @recurse(depth: 1, loop: true) {
name
friend
}
}`
rdf, err := processQueryRDF(context.Background(), query)
require.NoError(t, err)
require.Equal(t, rdf, `<0x1> <name> "Michonne" .
<0x17> <name> "Rick Grimes" .
<0x19> <name> "Daryl Dixon" .
`)
}
func TestRDFIgnoreUid(t *testing.T) {
query := `
{
me(func: anyofterms(name, "Michonne Rick Daryl")) {
uid
name
}
}`
rdf, err := processQueryRDF(context.Background(), query)
require.NoError(t, err)
require.Equal(t, rdf, `<0x1> <name> "Michonne" .
<0x17> <name> "Rick Grimes" .
<0x19> <name> "Daryl Dixon" .
`)
}
func TestRDFCheckPwd(t *testing.T) {
query := `
{
me(func: uid(0x01)) {
expand(_all_)
checkpwd(password, "12345")
}
}
`
_, err := processQueryRDF(context.Background(), query)
require.Contains(t, err.Error(),
"chkpwd function is not supported in the rdf output format")
}
func TestRDFPredicateCount(t *testing.T) {
query := `
{
me(func:anyofterms(name, "Michonne Rick Daryl")) {
name
count(friend)
friend {
name
}
}
}
`
rdf, err := processQueryRDF(context.Background(), query)
require.NoError(t, err)
require.Equal(t, `<0x1> <name> "Michonne" .
<0x17> <name> "Rick Grimes" .
<0x19> <name> "Daryl Dixon" .
<0x1> <count(friend)> "5" .
<0x17> <count(friend)> "1" .
<0x19> <count(friend)> "0" .
<0x1> <friend> <0x17> .
<0x1> <friend> <0x18> .
<0x1> <friend> <0x19> .
<0x1> <friend> <0x1f> .
<0x1> <friend> <0x65> .
<0x17> <friend> <0x1> .
<0x1> <name> "Michonne" .
<0x17> <name> "Rick Grimes" .
<0x18> <name> "Glenn Rhee" .
<0x19> <name> "Daryl Dixon" .
<0x1f> <name> "Andrea" .
`, rdf)
}
func TestRDFFacets(t *testing.T) {
query := `
{
shortest(from: 1, to:1001, numpaths: 4) {
path @facets(weight)
}
}`
_, err := processQueryRDF(context.Background(), query)
require.Contains(t, err.Error(),
"facets are not supported in the rdf output format")
}
func TestDateRDF(t *testing.T) {
query := `
{
me(func: uid(0x01)) {
name
gender
friend(orderdesc: film.film.initial_release_date) {
name
film.film.initial_release_date
}
}
}
`
rdf, err := processQueryRDF(context.Background(), query)
require.NoError(t, err)
expected := `<0x1> <name> "Michonne" .
<0x1> <gender> "female" .
<0x1> <friend> <0x19> .
<0x1> <friend> <0x18> .
<0x1> <friend> <0x17> .
<0x1> <friend> <0x1f> .
<0x1> <friend> <0x65> .
<0x17> <name> "Rick Grimes" .
<0x18> <name> "Glenn Rhee" .
<0x19> <name> "Daryl Dixon" .
<0x1f> <name> "Andrea" .
<0x17> <film.film.initial_release_date> "1900-01-02T00:00:00Z" .
<0x18> <film.film.initial_release_date> "1909-05-05T00:00:00Z" .
<0x19> <film.film.initial_release_date> "1929-01-10T00:00:00Z" .
<0x1f> <film.film.initial_release_date> "1801-01-15T00:00:00Z" .
`
require.Equal(t, expected, rdf)
}