Skip to content

Commit

Permalink
test: Convert explain join tests to new explain setup (sourcenetwork#…
Browse files Browse the repository at this point in the history
…1476)

## Relevant issue(s)
- Part of sourcenetwork#953
- Resolves sourcenetwork#1475

## Description
Continue converting explain tests to the new explain setup before we can
integrate the entire setup to the new action based testing setup. sourcenetwork#953
Has a lot more detail on the entire plan.

- Splits type join one tests into a separate file.
- Added some type join many tests into a separate file.
- This PR converts all the default typeJoin explain tests to the new
explain setup.
- Keeps the mixed test that use both type of joins in the original file.
  • Loading branch information
shahzadlone committed May 10, 2023
1 parent f1d1931 commit 4303c1a
Show file tree
Hide file tree
Showing 4 changed files with 762 additions and 405 deletions.
186 changes: 186 additions & 0 deletions tests/integration/explain/default/type_join_many_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// Copyright 2023 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_default

import (
"testing"

explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain"
)

func TestDefaultExplainRequestWithAOneToManyJoin(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain (default) request with a 1-to-M join.",

Request: `query @explain {
Author {
articles {
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"
}`,
},
// books
1: {
`{
"name": "Painted House",
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3"
}`,
`{
"name": "A Time for Mercy",
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3"
}`,
`{
"name": "Theif Lord",
"author_id": "bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04"
}`,
},
// authors
2: {
// _key: bae-41598f0c-19bc-5da6-813b-e80f14a10df3
`{
"name": "John Grisham",
"age": 65,
"verified": true,
"contact_id": "bae-1fe427b8-ab8d-56c3-9df2-826a6ce86fed"
}`,
// _key: bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04
`{
"name": "Cornelia Funke",
"age": 62,
"verified": false,
"contact_id": "bae-c0960a29-b704-5c37-9c2e-59e1249e4559"
}`,
},
// contact
3: {
// _key: bae-1fe427b8-ab8d-56c3-9df2-826a6ce86fed
// "author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3"
`{
"cell": "5197212301",
"email": "[email protected]",
"address_id": "bae-c8448e47-6cd1-571f-90bd-364acb80da7b"
}`,

// _key: bae-c0960a29-b704-5c37-9c2e-59e1249e4559
// "author_id": "bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04"
`{
"cell": "5197212302",
"email": "[email protected]",
"address_id": "bae-c0960a29-b704-5c37-9c2e-59e1249e4559"
}`,
},

// address
4: {
// _key: bae-c8448e47-6cd1-571f-90bd-364acb80da7b
// "contact_id": "bae-1fe427b8-ab8d-56c3-9df2-826a6ce86fed"
`{
"city": "Waterloo",
"country": "Canada"
}`,

// _key: bae-f01bf83f-1507-5fb5-a6a3-09ecffa3c692
// "contact_id": "bae-c0960a29-b704-5c37-9c2e-59e1249e4559"
`{
"city": "Brampton",
"country": "Canada"
}`,
},
},

ExpectedPatterns: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"typeIndexJoin": normalTypeJoinPattern,
},
},
},
},
},

ExpectedTargets: []explainUtils.PlanNodeTargetCase{
{
TargetNodeName: "typeIndexJoin",
IncludeChildNodes: false,
ExpectedAttributes: dataMap{
"joinType": "typeJoinMany",
"rootName": "author",
"subTypeName": "articles",
},
},
{
// Note: `root` is not a node but is a special case because for typeIndexJoin we
// restructure to show both `root` and `subType` at the same level.
TargetNodeName: "root",
IncludeChildNodes: true, // We care about checking children nodes.
ExpectedAttributes: dataMap{
"scanNode": dataMap{
"filter": nil,
"collectionID": "3",
"collectionName": "Author",
"spans": []dataMap{
{
"start": "/3",
"end": "/4",
},
},
},
},
},
{
// Note: `subType` is not a node but is a special case because for typeIndexJoin we
// restructure to show both `root` and `subType` at the same level.
TargetNodeName: "subType",
IncludeChildNodes: true, // We care about checking children nodes.
ExpectedAttributes: dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"scanNode": dataMap{
"filter": nil,
"collectionID": "1",
"collectionName": "Article",
"spans": []dataMap{
{
"start": "/1",
"end": "/2",
},
},
},
},
},
},
},
},
}

runExplainTest(t, test)
}
Loading

0 comments on commit 4303c1a

Please sign in to comment.