Skip to content
Snippets Groups Projects
Unverified Commit f8f07de1 authored by Ashish Negi's avatar Ashish Negi
Browse files

Add failing test for non-indexed query. Fixes #610

parent e19b90df
No related branches found
No related tags found
No related merge requests found
...@@ -46,6 +46,10 @@ func IndexTokens(attr string, src types.Val) ([]string, error) { ...@@ -46,6 +46,10 @@ func IndexTokens(attr string, src types.Val) ([]string, error) {
if err != nil || !schemaType.IsScalar() { if err != nil || !schemaType.IsScalar() {
return nil, x.Errorf("Cannot index attribute %s of type object.", attr) return nil, x.Errorf("Cannot index attribute %s of type object.", attr)
} }
if !schema.State().IsIndexed(attr) {
return nil, x.Errorf("Attribute %s is not indexed.", attr)
}
s := schemaType s := schemaType
sv, err := types.Convert(src, s) sv, err := types.Convert(src, s)
if err != nil { if err != nil {
......
...@@ -151,18 +151,26 @@ func addGeoData(t *testing.T, ps *store.Store, uid uint64, p geom.T, name string ...@@ -151,18 +151,26 @@ func addGeoData(t *testing.T, ps *store.Store, uid uint64, p geom.T, name string
addEdgeToTypedValue(t, "name", uid, types.StringID, []byte(name), nil) addEdgeToTypedValue(t, "name", uid, types.StringID, []byte(name), nil)
} }
func processToFastJSON(t *testing.T, query string) string { func processToFastJsonReq(t *testing.T, query string) (string, error) {
res, err := gql.Parse(query) res, err := gql.Parse(query)
require.NoError(t, err) if err != nil {
return "", err
}
var l Latency var l Latency
ctx := context.Background() ctx := context.Background()
sgl, err := ProcessQuery(ctx, res, &l) sgl, err := ProcessQuery(ctx, res, &l)
require.NoError(t, err) if err != nil {
return "", err
}
var buf bytes.Buffer var buf bytes.Buffer
require.NoError(t, ToJson(&l, sgl, &buf, nil)) err = ToJson(&l, sgl, &buf, nil)
return string(buf.Bytes()) return string(buf.Bytes()), err
}
func processToFastJSON(t *testing.T, query string) string {
res, err := processToFastJsonReq(t, query)
require.NoError(t, err)
return res
} }
func processToPB(t *testing.T, query string, debug bool) *graph.Node { func processToPB(t *testing.T, query string, debug bool) *graph.Node {
......
...@@ -241,6 +241,7 @@ func TestGetUID(t *testing.T) { ...@@ -241,6 +241,7 @@ func TestGetUID(t *testing.T) {
`{"me":[{"_uid_":"0x1","alive":true,"friend":[{"_uid_":"0x17","name":"Rick Grimes"},{"_uid_":"0x18","name":"Glenn Rhee"},{"_uid_":"0x19","name":"Daryl Dixon"},{"_uid_":"0x1f","name":"Andrea"},{"_uid_":"0x65"}],"gender":"female","name":"Michonne"}]}`, `{"me":[{"_uid_":"0x1","alive":true,"friend":[{"_uid_":"0x17","name":"Rick Grimes"},{"_uid_":"0x18","name":"Glenn Rhee"},{"_uid_":"0x19","name":"Daryl Dixon"},{"_uid_":"0x1f","name":"Andrea"},{"_uid_":"0x65"}],"gender":"female","name":"Michonne"}]}`,
js) js)
} }
func TestReturnUids(t *testing.T) { func TestReturnUids(t *testing.T) {
populateGraph(t) populateGraph(t)
query := ` query := `
...@@ -3531,3 +3532,21 @@ func TestMain(m *testing.M) { ...@@ -3531,3 +3532,21 @@ func TestMain(m *testing.M) {
os.Exit(m.Run()) os.Exit(m.Run())
} }
func TestFilterNonIndexedPredicateFail(t *testing.T) {
populateGraph(t)
// filtering on non indexing predicate fails
query := `
{
me(id:0x01) {
friend @filter(leq(age, 30)) {
_uid_
name
age
}
}
}
`
_, err := processToFastJsonReq(t, query)
require.Error(t, err)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment