Skip to content

Commit

Permalink
wip: Add tests for explaination of renderLimitNode attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Jul 9, 2022
1 parent 4d1e860 commit de97dc2
Showing 1 changed file with 357 additions and 0 deletions.
357 changes: 357 additions & 0 deletions tests/integration/query/explain/with_render_limit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,357 @@
// Copyright 2022 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package test_explain

import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestExplainQueryWithOnlyRenderLimitNode(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain Query With Only renderLimitNode.",

Query: `query @explain {
author {
numberOfArts: _count(articles: {})
articles(limit: 2) {
name
}
}
}`,

Docs: map[int][]string{
// articles
0: {
`{
"name": "After Guantánamo, Another Injustice",
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3"
}`,

`{
"name": "To my dear readers",
"author_id": "bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04"
}`,

`{
"name": "Twinklestar's Favourite Xmas Cookie",
"author_id": "bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04"
}`,

`{
"name": "C++ 100",
"author_id": "bae-aa839756-588e-5b57-887d-33689a06e375"
}`,

`{
"name": "C++ 101",
"author_id": "bae-aa839756-588e-5b57-887d-33689a06e375"
}`,

`{
"name": "C++ 200",
"author_id": "bae-aa839756-588e-5b57-887d-33689a06e375"
}`,

`{
"name": "C++ 202",
"author_id": "bae-aa839756-588e-5b57-887d-33689a06e375"
}`,

`{
"name": "Rust 100",
"author_id": "bae-e7e87bbb-1079-59db-b4b9-0e14b24d5b69"
}`,

`{
"name": "Rust 101",
"author_id": "bae-e7e87bbb-1079-59db-b4b9-0e14b24d5b69"
}`,

`{
"name": "Rust 200",
"author_id": "bae-e7e87bbb-1079-59db-b4b9-0e14b24d5b69"
}`,

`{
"name": "Rust 202",
"author_id": "bae-e7e87bbb-1079-59db-b4b9-0e14b24d5b69"
}`,
},

// authors
2: {
// _key: bae-41598f0c-19bc-5da6-813b-e80f14a10df3
`{
"name": "John Grisham",
"age": 65,
"verified": true
}`,

// _key: bae-aa839756-588e-5b57-887d-33689a06e375
`{
"name": "Shahzad Sisley",
"age": 26,
"verified": true
}`,

// _key: bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04
`{
"name": "Cornelia Funke",
"age": 62,
"verified": false
}`,

// _key: bae-e7e87bbb-1079-59db-b4b9-0e14b24d5b69
`{
"name": "Andrew Lone",
"age": 28,
"verified": true
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"countNode": dataMap{
"sources": []dataMap{
{
"fieldName": "articles",
"filter": nil,
},
},
"selectNode": dataMap{
"filter": nil,
"typeIndexJoin": dataMap{
"joinType": "typeJoinMany",
"rootName": "author",
"root": dataMap{
"scanNode": dataMap{
"collectionID": "3",
"collectionName": "author",
"filter": nil,
"spans": []dataMap{
{
"end": "/4",
"start": "/3",
},
},
},
},
"subTypeName": "articles",
"subType": dataMap{
"selectTopNode": dataMap{
"renderLimitNode": dataMap{
"limit": int64(2),
"offset": int64(0),
"selectNode": dataMap{
"filter": nil,
"scanNode": dataMap{
"collectionID": "1",
"collectionName": "article",
"filter": nil,
"spans": []dataMap{
{
"end": "/2",
"start": "/1",
},
},
},
},
},
},
},
},
},
},
},
},
},
},
}

executeTestCase(t, test)
}

func TestExplainQueryWithRenderLimitNodeAndHardLimitNode(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain Query With renderLimitNode & hardLimitNode.",

Query: `query @explain {
author(limit: 3, offset: 1) {
numberOfArts: _count(articles: {})
articles(limit: 2) {
name
}
}
}`,

Docs: map[int][]string{
// articles
0: {
`{
"name": "After Guantánamo, Another Injustice",
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3"
}`,

`{
"name": "To my dear readers",
"author_id": "bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04"
}`,

`{
"name": "Twinklestar's Favourite Xmas Cookie",
"author_id": "bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04"
}`,

`{
"name": "C++ 100",
"author_id": "bae-aa839756-588e-5b57-887d-33689a06e375"
}`,

`{
"name": "C++ 101",
"author_id": "bae-aa839756-588e-5b57-887d-33689a06e375"
}`,

`{
"name": "C++ 200",
"author_id": "bae-aa839756-588e-5b57-887d-33689a06e375"
}`,

`{
"name": "C++ 202",
"author_id": "bae-aa839756-588e-5b57-887d-33689a06e375"
}`,

`{
"name": "Rust 100",
"author_id": "bae-e7e87bbb-1079-59db-b4b9-0e14b24d5b69"
}`,

`{
"name": "Rust 101",
"author_id": "bae-e7e87bbb-1079-59db-b4b9-0e14b24d5b69"
}`,

`{
"name": "Rust 200",
"author_id": "bae-e7e87bbb-1079-59db-b4b9-0e14b24d5b69"
}`,

`{
"name": "Rust 202",
"author_id": "bae-e7e87bbb-1079-59db-b4b9-0e14b24d5b69"
}`,
},

// authors
2: {
// _key: bae-41598f0c-19bc-5da6-813b-e80f14a10df3
`{
"name": "John Grisham",
"age": 65,
"verified": true
}`,

// _key: bae-aa839756-588e-5b57-887d-33689a06e375
`{
"name": "Shahzad Sisley",
"age": 26,
"verified": true
}`,

// _key: bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04
`{
"name": "Cornelia Funke",
"age": 62,
"verified": false
}`,

// _key: bae-e7e87bbb-1079-59db-b4b9-0e14b24d5b69
`{
"name": "Andrew Lone",
"age": 28,
"verified": true
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"hardLimitNode": dataMap{
"limit": int64(3),
"offset": int64(1),
"countNode": dataMap{
"sources": []dataMap{
{
"fieldName": "articles",
"filter": nil,
},
},
"selectNode": dataMap{
"filter": nil,
"typeIndexJoin": dataMap{
"joinType": "typeJoinMany",
"rootName": "author",
"root": dataMap{
"scanNode": dataMap{
"collectionID": "3",
"collectionName": "author",
"filter": nil,
"spans": []dataMap{
{
"end": "/4",
"start": "/3",
},
},
},
},
"subTypeName": "articles",
"subType": dataMap{
"selectTopNode": dataMap{
"renderLimitNode": dataMap{
"limit": int64(2),
"offset": int64(0),
"selectNode": dataMap{
"filter": nil,
"scanNode": dataMap{
"collectionID": "1",
"collectionName": "article",
"filter": nil,
"spans": []dataMap{
{
"end": "/2",
"start": "/1",
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
}

executeTestCase(t, test)
}

0 comments on commit de97dc2

Please sign in to comment.