Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

test(gql): Clean up facets and rdf tests. #17

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions gql/alias_order_lang_fragment_regex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,30 +577,6 @@ func TestLangsFunctionMultipleLangs(t *testing.T) {
require.Contains(t, err.Error(), "\":\"")
}

func TestParseOrderbyFacet(t *testing.T) {
query := `
query {
me(func: uid(0x1)) {
friends @facets {
name @facets(facet1)
}
hometown
age
}
}
`
res, err := Parse(Request{Str: query})
require.NoError(t, err)
require.NotNil(t, res.Query[0])
require.Equal(t, []string{"friends", "hometown", "age"}, childAttrs(res.Query[0]))
require.NotNil(t, res.Query[0].Children[0].Facets)
require.Equal(t, true, res.Query[0].Children[0].Facets.AllKeys)
require.Equal(t, []string{"name"}, childAttrs(res.Query[0].Children[0]))
require.NotNil(t, res.Query[0].Children[0].Children[0].Facets)
require.Equal(t, false, res.Query[0].Children[0].Children[0].Facets.AllKeys)
require.Equal(t, "facet1", res.Query[0].Children[0].Children[0].Facets.Param[0].Key)
}

func TestParseRegexp1(t *testing.T) {
query := `
{
Expand Down
141 changes: 0 additions & 141 deletions gql/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,126 +488,6 @@ func TestLangsFilter_error2(t *testing.T) {
"Unrecognized character in lexDirective: U+002C ','")
}

// Test facets parsing for filtering..
func TestFacetsFilterSimple(t *testing.T) {
// all friends of 0x1 who are close to him
query := `
{
me(func: uid(0x1)) {
name
friend @facets(eq(close, true)) {
name
gender
}
}
}
`

res, err := Parse(Request{Str: query})
require.NoError(t, err)
require.NotNil(t, res.Query[0])
require.Equal(t, []string{"name", "friend"}, childAttrs(res.Query[0]))
require.Nil(t, res.Query[0].Children[1].Facets)
require.NotNil(t, res.Query[0].Children[1].FacetsFilter)
require.Equal(t, `(eq close "true")`,
res.Query[0].Children[1].FacetsFilter.debugString())
}

func TestFacetsFilterAll(t *testing.T) {
// all friends of 0x1 who are close to him or are in his family
query := `
{
me(func: uid(0x1)) {
name
friend @facets(eq(close, true) or eq(family, true)) @facets(close, family, since) {
name @facets
gender
}
}
}
`

res, err := Parse(Request{Str: query})
require.NoError(t, err)
require.NotNil(t, res.Query[0])
require.Equal(t, []string{"name", "friend"}, childAttrs(res.Query[0]))
require.NotNil(t, res.Query[0].Children[1].Facets)
require.Equal(t, "close", res.Query[0].Children[1].Facets.Param[0].Key)
require.Equal(t, "family", res.Query[0].Children[1].Facets.Param[1].Key)
require.Equal(t, "since", res.Query[0].Children[1].Facets.Param[2].Key)
require.NotNil(t, res.Query[0].Children[1].FacetsFilter)
require.Equal(t, `(OR (eq close "true") (eq family "true"))`,
res.Query[0].Children[1].FacetsFilter.debugString())

require.Equal(t, []string{"name", "gender"}, childAttrs(res.Query[0].Children[1]))
nameChild := res.Query[0].Children[1].Children[0]
require.NotNil(t, nameChild)
require.NotNil(t, nameChild.Facets)
require.Nil(t, nameChild.FacetsFilter)
genderChild := res.Query[0].Children[1].Children[1]
require.NotNil(t, genderChild)
require.Nil(t, genderChild.Facets)
require.Nil(t, genderChild.FacetsFilter)
}

func TestFacetsFilterFail(t *testing.T) {
// multiple @facets and @facets(close, since) are not allowed.
query := `
{
me(func: uid(0x1)) {
name
friend @facets @facets(close, since) {
name
gender
}
}
}
`

_, err := Parse(Request{Str: query})
require.Error(t, err)
require.Contains(t, err.Error(), "Only one facets allowed")
}

func TestFacetsFilterFail2(t *testing.T) {
// multiple facets-filter not allowed
query := `
{
me(func: uid(0x1)) {
name
friend @facets(eq(close, true)) @facets(eq(family, true)) {
name
gender
}
}
}
`

_, err := Parse(Request{Str: query})
require.Error(t, err)
require.Contains(t, err.Error(), "Only one facets filter allowed")
}

func TestFacetsFilterFail3(t *testing.T) {
// vars are not allowed in facets filtering.
query := `
{
K as var(func: uid(0x0a)) {
L AS friends
}
me(func: uid(K)) {
friend @facets(uid(L)) {
name
}
}
}
`

_, err := Parse(Request{Str: query})
require.Error(t, err)
require.Contains(t, err.Error(), "variables are not allowed in facets filter")
}

func TestFacetsFilterFailRoot(t *testing.T) {
query := `
{
Expand All @@ -624,27 +504,6 @@ func TestFacetsFilterFailRoot(t *testing.T) {
require.Contains(t, err.Error(), "Unknown directive [facets]")
}

func TestFacetsFilterAtValue(t *testing.T) {
// gql parses facets at value level as well.
query := `
{
me(func: uid(0x1)) {
friend {
name @facets(eq(some.facet, true))
}
}
}
`

res, err := Parse(Request{Str: query})
require.NoError(t, err)
require.Equal(t, []string{"name"}, childAttrs(res.Query[0].Children[0]))
nameChild := res.Query[0].Children[0].Children[0]
require.NotNil(t, nameChild)
require.NotNil(t, nameChild.FacetsFilter)
require.Equal(t, `(eq some.facet "true")`, nameChild.FacetsFilter.debugString())
}

func TestHasFilterAtRoot(t *testing.T) {
query := `{
me(func: allofterms(name, "Steven Tom")) @filter(has(director.film)) {
Expand Down
19 changes: 0 additions & 19 deletions gql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
package gql

import (
"bytes"
"os"
"runtime/debug"
"testing"

"github.com/outcaste-io/dgo/v210/protos/api"
"github.com/outcaste-io/outserv/chunker"
"github.com/outcaste-io/outserv/lex"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1042,22 +1039,6 @@ func TestInvalidValUsage(t *testing.T) {
require.Contains(t, err.Error(), "Query syntax invalid.")
}

func parseNquads(b []byte) ([]*api.NQuad, error) {
var lexer lex.Lexer
var nqs []*api.NQuad
for _, line := range bytes.Split(b, []byte{'\n'}) {
nq, err := chunker.ParseRDF(string(line), &lexer)
if err == chunker.ErrEmpty {
continue
}
if err != nil {
return nil, err
}
nqs = append(nqs, &nq)
}
return nqs, nil
}

func TestUidInWithNoParseErrors(t *testing.T) {
query := `{
schoolVar as q(func: uid(5000))
Expand Down
32 changes: 0 additions & 32 deletions gql/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package gql
import (
"testing"

"github.com/outcaste-io/dgo/v210/protos/api"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -1163,37 +1162,6 @@ func TestParseMutationAndQueryWithComments(t *testing.T) {
require.Error(t, err)
}

func TestParseMutation(t *testing.T) {
m := `
{
set {
<name> <is> <something> .
<hometown> <is> <san/francisco> .
}
delete {
<name> <is> <something-else> .
}
}
`
req, err := ParseMutation(m)
require.NoError(t, err)
mu := req.Mutations[0]
require.NotNil(t, mu)
sets, err := parseNquads(mu.SetNquads)
require.NoError(t, err)
require.EqualValues(t, &api.NQuad{
Subject: "name", Predicate: "is", ObjectId: "something"},
sets[0])
require.EqualValues(t, &api.NQuad{
Subject: "hometown", Predicate: "is", ObjectId: "san/francisco"},
sets[1])
dels, err := parseNquads(mu.DelNquads)
require.NoError(t, err)
require.EqualValues(t, &api.NQuad{
Subject: "name", Predicate: "is", ObjectId: "something-else"},
dels[0])
}

func TestParseMutationTooManyBlocks(t *testing.T) {
tests := []struct {
m string
Expand Down
Loading