Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add new setup for testing explain functionality #949

Merged
merged 7 commits into from
Nov 27, 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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ endif
test:
gotestsum --format pkgname -- ./... -race -shuffle=on

# Only build the tests (don't execute them).
.PHONY: test\:build
test\:build:
gotestsum --format pkgname -- ./... -race -shuffle=on -run=nope

.PHONY: test\:ci
test\:ci:
DEFRA_BADGER_MEMORY=true DEFRA_BADGER_FILE=true $(MAKE) test:names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package simple
package test_explain_simple

import (
"testing"
Expand All @@ -22,18 +22,18 @@ func TestExplainQuerySimpleOnFieldDirective_BadUsage(t *testing.T) {
Description: "Explain a query by providing the directive on wrong location (field).",

Query: `query {
users @explain {
_key
Name
Age
}
}`,
author @explain {
_key
name
age
}
}`,

Docs: map[int][]string{
0: {
2: {
`{
"Name": "John",
"Age": 21
"name": "John",
"age": 21
}`,
},
},
Expand All @@ -48,21 +48,24 @@ func TestExplainQuerySimpleOnFieldDirective_BadUsage(t *testing.T) {
func TestExplainQuerySimple(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain a query with no filter",

Query: `query @explain {
users {
_key
Name
Age
}
}`,
author {
_key
name
age
}
}`,

Docs: map[int][]string{
0: {
2: {
`{
"Name": "John",
"Age": 21
"name": "John",
"age": 21
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
Expand All @@ -71,12 +74,12 @@ func TestExplainQuerySimple(t *testing.T) {
"filter": nil,
"scanNode": dataMap{
"filter": nil,
"collectionID": "1",
"collectionName": "users",
"collectionID": "3",
"collectionName": "author",
"spans": []dataMap{
{
"start": "/1",
"end": "/2",
"start": "/3",
"end": "/4",
},
},
},
Expand All @@ -93,20 +96,23 @@ func TestExplainQuerySimple(t *testing.T) {
func TestExplainQuerySimpleWithAlias(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain a query with alias, no filter",

Query: `query @explain {
users {
username: Name
age: Age
}
}`,
author {
username: name
age: age
}
}`,

Docs: map[int][]string{
0: {
2: {
`{
"Name": "John",
"Age": 21
"name": "John",
"age": 21
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
Expand All @@ -115,12 +121,12 @@ func TestExplainQuerySimpleWithAlias(t *testing.T) {
"filter": nil,
"scanNode": dataMap{
"filter": nil,
"collectionID": "1",
"collectionName": "users",
"collectionID": "3",
"collectionName": "author",
"spans": []dataMap{
{
"start": "/1",
"end": "/2",
"start": "/3",
"end": "/4",
},
},
},
Expand All @@ -137,24 +143,27 @@ func TestExplainQuerySimpleWithAlias(t *testing.T) {
func TestExplainQuerySimpleWithMultipleRows(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain a query with no filter, mutiple rows",

Query: `query @explain {
users {
Name
Age
}
}`,
author {
name
age
}
}`,

Docs: map[int][]string{
0: {
2: {
`{
"Name": "John",
"Age": 21
"name": "John",
"age": 21
}`,
`{
"Name": "Bob",
"Age": 27
"name": "Bob",
"age": 27
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
Expand All @@ -163,12 +172,12 @@ func TestExplainQuerySimpleWithMultipleRows(t *testing.T) {
"filter": nil,
"scanNode": dataMap{
"filter": nil,
"collectionID": "1",
"collectionName": "users",
"collectionID": "3",
"collectionName": "author",
"spans": []dataMap{
{
"start": "/1",
"end": "/2",
"start": "/3",
"end": "/4",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,41 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package create
package test_explain_simple

import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/simple"
)

type dataMap = map[string]any

func TestExplainMutationCreateSimple(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain simple create mutation.",

Query: `mutation @explain {
create_user(data: "{\"name\": \"John\",\"age\": 27,\"points\": 42.1,\"verified\": true}") {
_key
name
age
}
}`,
create_author(data: "{\"name\": \"Shahzad Lone\",\"age\": 27,\"verified\": true}") {
_key
name
age
}
}`,

Results: []dataMap{
{
"explain": dataMap{
"createNode": dataMap{
"data": dataMap{
"age": float64(27),
"name": "John",
"points": 42.1,
"name": "Shahzad Lone",
"verified": true,
},
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"scanNode": dataMap{
"collectionID": "1",
"collectionName": "user",
"collectionID": "3",
"collectionName": "author",
"filter": nil,
"spans": []dataMap{},
},
Expand All @@ -60,25 +56,25 @@ func TestExplainMutationCreateSimple(t *testing.T) {
ExpectedError: "",
}

simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestExplainMutationCreateSimpleDoesNotCreateDocGivenDuplicate(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain simple create mutation, where document already exists.",

Query: `mutation @explain {
create_user(data: "{\"name\": \"John\",\"age\": 27}") {
_key
name
age
}
}`,
create_author(data: "{\"name\": \"Shahzad Lone\",\"age\": 27}") {
_key
name
age
}
}`,

Docs: map[int][]string{
0: {
2: {
`{
"name": "John",
"name": "Shahzad Lone",
"age": 27
}`,
},
Expand All @@ -90,14 +86,14 @@ func TestExplainMutationCreateSimpleDoesNotCreateDocGivenDuplicate(t *testing.T)
"createNode": dataMap{
"data": dataMap{
"age": float64(27),
"name": "John",
"name": "Shahzad Lone",
},
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"scanNode": dataMap{
"collectionID": "1",
"collectionName": "user",
"collectionID": "3",
"collectionName": "author",
"filter": nil,
"spans": []dataMap{},
},
Expand All @@ -111,5 +107,5 @@ func TestExplainMutationCreateSimpleDoesNotCreateDocGivenDuplicate(t *testing.T)
ExpectedError: "",
}

simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package test_explain
package test_explain_simple

import (
"testing"
Expand Down
Loading