-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathnormalize_feature_flag_test.go
111 lines (101 loc) · 3.06 KB
/
normalize_feature_flag_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
//go:build integration2
/*
* SPDX-FileCopyrightText: © Hypermode Inc. <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/
package query
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/dgraph-io/dgo/v250/protos/api"
"github.com/hypermodeinc/dgraph/v25/dgraphtest"
)
func TestNormalizeDirectiveWithNoListResponse(t *testing.T) {
conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).
WithReplicas(1).WithNormalizeCompatibilityMode("v20")
c, err := dgraphtest.NewLocalCluster(conf)
require.NoError(t, err)
defer func() { c.Cleanup(t.Failed()) }()
require.NoError(t, c.Start())
gc, cleanup, err := c.Client()
require.NoError(t, err)
defer cleanup()
require.NoError(t, c.AssignUids(gc.Dgraph, 100))
const dataSchema = `
friend : [uid] @reverse @count .
name : string @index(term, exact, trigram) @count @lang .
dob : dateTime @index(year) .`
require.NoError(t, gc.SetupSchema(dataSchema))
triples := []byte(`
<1> <friend> <23> .
<1> <friend> <24> .
<1> <friend> <25> .
<1> <friend> <31> .
<1> <friend> <101>.
<23> <friend> <1> .
<31> <friend> <1> .
<31> <friend> <25> .
<1> <dob> "1910-01-01" .
<23> <dob> "1910-01-02" .
<24> <dob> "1909-05-05" .
<25> <dob> "1909-01-10" .
<31> <dob> "1901-01-15" .
<1> <name> "Michonne" .
<23> <name> "Rick Grimes" .
<24> <name> "Glenn Rhee" .`)
_, err = gc.Mutate(&api.Mutation{SetNquads: triples, CommitNow: true})
require.NoError(t, err)
query := `
{
me(func: uid(0x01)) @recurse @normalize {
n: name
d: dob
friend
}
}`
js, err := gc.Query(query)
require.NoError(t, err)
require.JSONEq(t, `
{
"me": [
{
"n": "Michonne",
"d": "1910-01-01T00:00:00Z",
"n": "Rick Grimes",
"d": "1910-01-02T00:00:00Z",
"n": "Michonne",
"d": "1910-01-01T00:00:00Z"
},
{
"n": "Michonne",
"d": "1910-01-01T00:00:00Z",
"n": "Glenn Rhee",
"d": "1909-05-05T00:00:00Z"
},
{
"n": "Michonne",
"d": [
"1910-01-01T00:00:00Z",
"1909-01-10T00:00:00Z"
]
},
{
"n": "Michonne",
"d": [
"1910-01-01T00:00:00Z",
"1901-01-15T00:00:00Z"
],
"n": "Michonne",
"d": "1910-01-01T00:00:00Z"
},
{
"n": "Michonne",
"d": [
"1910-01-01T00:00:00Z",
"1901-01-15T00:00:00Z",
"1909-01-10T00:00:00Z"
]
}
]
}`, string(js.Json))
}