Skip to content

Commit 37da4c1

Browse files
Merge pull request #1052 from dolthub/andy/parameterize-query-plan-tests
enginetest: Parameterize query plan tests
2 parents 1adb1db + a2b74bd commit 37da4c1

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

enginetest/enginetests.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ func TestReadOnlyDatabases(t *testing.T, harness Harness) {
245245

246246
// Tests generating the correct query plans for various queries using databases and tables provided by the given
247247
// harness.
248-
func TestQueryPlans(t *testing.T, harness Harness) {
248+
func TestQueryPlans(t *testing.T, harness Harness, planTests []queries.QueryPlanTest) {
249249
harness.Setup(setup.SimpleSetup...)
250250
e := mustNewEngine(t, harness)
251251
defer e.Close()
252-
for _, tt := range queries.PlanTests {
252+
for _, tt := range planTests {
253253
TestQueryPlan(t, harness, e, tt.Query, tt.ExpectedPlan)
254254
}
255255
}
@@ -351,7 +351,7 @@ func TestQueryPlan(t *testing.T, harness Harness, e *sqle.Engine, query string,
351351
}
352352
}
353353

354-
assert.Equal(t, expectedPlan, extractQueryNode(node).String(), "Unexpected result for query: "+query)
354+
assert.Equal(t, expectedPlan, ExtractQueryNode(node).String(), "Unexpected result for query: "+query)
355355
})
356356

357357
}
@@ -371,7 +371,7 @@ func TestQueryPlanWithEngine(t *testing.T, harness Harness, e *sqle.Engine, tt q
371371
}
372372
}
373373

374-
assert.Equal(t, tt.ExpectedPlan, extractQueryNode(node).String(), "Unexpected result for query: "+tt.Query)
374+
assert.Equal(t, tt.ExpectedPlan, ExtractQueryNode(node).String(), "Unexpected result for query: "+tt.Query)
375375
})
376376

377377
}

enginetest/evaluation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,12 @@ func assertSchemasEqualWithDefaults(t *testing.T, expected, actual sql.Schema) b
691691
return assert.Equal(t, ec, ac)
692692
}
693693

694-
func extractQueryNode(node sql.Node) sql.Node {
694+
func ExtractQueryNode(node sql.Node) sql.Node {
695695
switch node := node.(type) {
696696
case *plan.QueryProcess:
697-
return extractQueryNode(node.Child())
697+
return ExtractQueryNode(node.Child())
698698
case *analyzer.Releaser:
699-
return extractQueryNode(node.Child)
699+
return ExtractQueryNode(node.Child)
700700
default:
701701
return node
702702
}

enginetest/memory_engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func TestQueryPlans(t *testing.T) {
320320
harness := enginetest.NewMemoryHarness(indexInit.name, 1, 2, indexInit.nativeIndexes, indexInit.driverInitializer)
321321
// The IN expression requires mergeable indexes meaning that an unmergeable index returns a different result, so we skip this test
322322
harness.QueriesToSkip("SELECT a.* FROM mytable a inner join mytable b on (a.i = b.s) WHERE a.i in (1, 2, 3, 4)")
323-
enginetest.TestQueryPlans(t, harness)
323+
enginetest.TestQueryPlans(t, harness, queries.PlanTests)
324324
})
325325
}
326326
}

enginetest/testgen_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestWriteQueryPlans(t *testing.T) {
4545

4646
node, err := engine.Analyzer.Analyze(ctx, parsed, nil)
4747
require.NoError(t, err)
48-
planString := extractQueryNode(node).String()
48+
planString := ExtractQueryNode(node).String()
4949

5050
if strings.Contains(tt.Query, "`") {
5151
_, _ = w.WriteString(fmt.Sprintf(`Query: "%s",`, tt.Query))
@@ -102,7 +102,7 @@ func TestWriteIndexQueryPlans(t *testing.T) {
102102

103103
node, err := engine.Analyzer.Analyze(ctx, parsed, nil)
104104
require.NoError(t, err)
105-
planString := extractQueryNode(node).String()
105+
planString := ExtractQueryNode(node).String()
106106

107107
if strings.Contains(tt.Query, "`") {
108108
_, _ = w.WriteString(fmt.Sprintf(`Query: "%s",`, tt.Query))

0 commit comments

Comments
 (0)