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: Convert explain dagscan tests to new explain setup #1474

Merged
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
168 changes: 83 additions & 85 deletions tests/integration/explain/default/dagscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ package test_explain_default
import (
"testing"

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

func TestExplainCommitsDagScan(t *testing.T) {
test := testUtils.RequestTestCase{
var dagScanPattern = dataMap{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"dagScanNode": dataMap{},
},
},
},
}

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

Description: "Explain commits query.",
Description: "Explain (default) commits query-op.",

Request: `query @explain {
commits (dockey: "bae-41598f0c-19bc-5da6-813b-e80f14a10df3", fieldId: "1") {
Expand Down Expand Up @@ -47,36 +57,33 @@ func TestExplainCommitsDagScan(t *testing.T) {
},
},

Results: []dataMap{
ExpectedPatterns: []dataMap{dagScanPattern},

ExpectedTargets: []explainUtils.PlanNodeTargetCase{
{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"dagScanNode": dataMap{
"cid": nil,
"fieldId": "1",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/1",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/2",
},
},
},
TargetNodeName: "dagScanNode",
IncludeChildNodes: true, // Shouldn't have any as this is the last node in the chain.
ExpectedAttributes: dataMap{
"cid": nil,
"fieldId": "1",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/1",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/2",
},
},
},
},
},
}

executeTestCase(t, test)
runExplainTest(t, test)
}

func TestExplainCommitsDagScanWithoutField(t *testing.T) {
test := testUtils.RequestTestCase{
func TestDefaultExplainCommitsDagScanQueryOpWithoutField(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain commits query with only dockey (no field).",
Description: "Explain (default) commits query-op with only dockey (no field).",

Request: `query @explain {
commits (dockey: "bae-41598f0c-19bc-5da6-813b-e80f14a10df3") {
Expand Down Expand Up @@ -104,36 +111,33 @@ func TestExplainCommitsDagScanWithoutField(t *testing.T) {
},
},

Results: []dataMap{
ExpectedPatterns: []dataMap{dagScanPattern},

ExpectedTargets: []explainUtils.PlanNodeTargetCase{
{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"dagScanNode": dataMap{
"cid": nil,
"fieldId": nil,
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df4",
},
},
},
TargetNodeName: "dagScanNode",
IncludeChildNodes: true, // Shouldn't have any as this is the last node in the chain.
ExpectedAttributes: dataMap{
"cid": nil,
"fieldId": nil,
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df4",
},
},
},
},
},
}

executeTestCase(t, test)
runExplainTest(t, test)
}

func TestExplainLatestCommitsDagScan(t *testing.T) {
test := testUtils.RequestTestCase{
func TestDefaultExplainLatestCommitsDagScanQueryOp(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain latestCommits query.",
Description: "Explain (default) latestCommits query-op.",

Request: `query @explain {
latestCommits(dockey: "bae-41598f0c-19bc-5da6-813b-e80f14a10df3", fieldId: "1") {
Expand Down Expand Up @@ -162,36 +166,33 @@ func TestExplainLatestCommitsDagScan(t *testing.T) {
},
},

Results: []dataMap{
ExpectedPatterns: []dataMap{dagScanPattern},

ExpectedTargets: []explainUtils.PlanNodeTargetCase{
{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"dagScanNode": dataMap{
"cid": nil,
"fieldId": "1",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/1",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/2",
},
},
},
TargetNodeName: "dagScanNode",
IncludeChildNodes: true, // Shouldn't have any as this is the last node in the chain.
ExpectedAttributes: dataMap{
"cid": nil,
"fieldId": "1",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/1",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/2",
},
},
},
},
},
}

executeTestCase(t, test)
runExplainTest(t, test)
}

func TestExplainLatestCommitsDagScanWithoutField(t *testing.T) {
test := testUtils.RequestTestCase{
func TestDefaultExplainLatestCommitsDagScanQueryOpWithoutField(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain latestCommits query with only dockey (no field).",
Description: "Explain (default) latestCommits query-op with only dockey (no field).",

Request: `query @explain {
latestCommits(dockey: "bae-41598f0c-19bc-5da6-813b-e80f14a10df3") {
Expand Down Expand Up @@ -220,36 +221,33 @@ func TestExplainLatestCommitsDagScanWithoutField(t *testing.T) {
},
},

Results: []dataMap{
ExpectedPatterns: []dataMap{dagScanPattern},

ExpectedTargets: []explainUtils.PlanNodeTargetCase{
{
"explain": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"filter": nil,
"dagScanNode": dataMap{
"cid": nil,
"fieldId": "C",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/C",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/D",
},
},
},
TargetNodeName: "dagScanNode",
IncludeChildNodes: true, // Shouldn't have any as this is the last node in the chain.
ExpectedAttributes: dataMap{
"cid": nil,
"fieldId": "C",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/C",
"end": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/D",
},
},
},
},
},
}

executeTestCase(t, test)
runExplainTest(t, test)
}

func TestExplainLatestCommitsDagScanWithoutDocKey_Failure(t *testing.T) {
test := testUtils.RequestTestCase{
func TestDefaultExplainLatestCommitsDagScanWithoutDocKey_Failure(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain latestCommits query without DocKey.",
Description: "Explain (default) latestCommits query without DocKey.",

Request: `query @explain {
latestCommits(fieldId: "1") {
Expand All @@ -263,13 +261,13 @@ func TestExplainLatestCommitsDagScanWithoutDocKey_Failure(t *testing.T) {
ExpectedError: "Field \"latestCommits\" argument \"dockey\" of type \"ID!\" is required but not provided.",
}

executeTestCase(t, test)
runExplainTest(t, test)
}

func TestExplainLatestCommitsDagScanWithoutAnyArguments_Failure(t *testing.T) {
test := testUtils.RequestTestCase{
func TestDefaultExplainLatestCommitsDagScanWithoutAnyArguments_Failure(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{

Description: "Explain latestCommits query without any arguments.",
Description: "Explain (default) latestCommits query without any arguments.",

Request: `query @explain {
latestCommits {
Expand All @@ -283,5 +281,5 @@ func TestExplainLatestCommitsDagScanWithoutAnyArguments_Failure(t *testing.T) {
ExpectedError: "Field \"latestCommits\" argument \"dockey\" of type \"ID!\" is required but not provided.",
}

executeTestCase(t, test)
runExplainTest(t, test)
}
6 changes: 3 additions & 3 deletions tests/integration/explain/default/invalid_type_arg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ package test_explain_default
import (
"testing"

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

func TestInvalidExplainRequestTypeReturnsError(t *testing.T) {
test := testUtils.RequestTestCase{
test := explainUtils.ExplainRequestTestCase{
Description: "Invalid type of explain request should error.",

Request: `query @explain(type: invalid) {
Expand All @@ -40,5 +40,5 @@ func TestInvalidExplainRequestTypeReturnsError(t *testing.T) {
ExpectedError: "Argument \"type\" has invalid value invalid.\nExpected type \"ExplainType\", found invalid.",
}

executeTestCase(t, test)
runExplainTest(t, test)
}
66 changes: 10 additions & 56 deletions tests/integration/explain/default/with_limit_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (
explainUtils "github.com/sourcenetwork/defradb/tests/integration/explain"
)

func TestExplainQueryWithMultipleConflictingInnerLimits(t *testing.T) {
func TestDefaultExplainRequestWithOnlyLimitOnRelatedChildWithCount(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{
Description: "Explain Query With multiple conflicting inner limit nodes.",

Description: "Explain (default) request with limit on related child with count.",

Request: `query @explain {
Author {
Expand Down Expand Up @@ -128,34 +129,10 @@ func TestExplainQueryWithMultipleConflictingInnerLimits(t *testing.T) {
"selectNode": dataMap{
"parallelNode": []dataMap{
{
"typeIndexJoin": dataMap{
"root": dataMap{
"scanNode": dataMap{},
},
"subType": dataMap{
"selectTopNode": dataMap{
"limitNode": dataMap{
"selectNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
},
"typeIndexJoin": limitTypeJoinPattern,
},
{
"typeIndexJoin": dataMap{
"root": dataMap{
"scanNode": dataMap{},
},
"subType": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
"typeIndexJoin": normalTypeJoinPattern,
},
},
},
Expand Down Expand Up @@ -192,9 +169,10 @@ func TestExplainQueryWithMultipleConflictingInnerLimits(t *testing.T) {
runExplainTest(t, test)
}

func TestExplainQueryWithMultipleConflictingInnerLimitsAndOuterLimit(t *testing.T) {
func TestDefaultExplainRequestWithLimitArgsOnParentAndRelatedChildWithCount(t *testing.T) {
test := explainUtils.ExplainRequestTestCase{
Description: "Explain Query With multiple conflicting inner limit nodes and an outer limit.",

Description: "Explain (default) request with limit args on parent and related child with count.",

Request: `query @explain {
Author(limit: 3, offset: 1) {
Expand Down Expand Up @@ -305,34 +283,10 @@ func TestExplainQueryWithMultipleConflictingInnerLimitsAndOuterLimit(t *testing.
"selectNode": dataMap{
"parallelNode": []dataMap{
{
"typeIndexJoin": dataMap{
"root": dataMap{
"scanNode": dataMap{},
},
"subType": dataMap{
"selectTopNode": dataMap{
"limitNode": dataMap{
"selectNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
},
"typeIndexJoin": limitTypeJoinPattern,
},
{
"typeIndexJoin": dataMap{
"root": dataMap{
"scanNode": dataMap{},
},
"subType": dataMap{
"selectTopNode": dataMap{
"selectNode": dataMap{
"scanNode": dataMap{},
},
},
},
},
"typeIndexJoin": normalTypeJoinPattern,
},
},
},
Expand Down
Loading