Skip to content

Commit 92b9799

Browse files
committed
Respond to PR feedback.
1 parent 0dc98df commit 92b9799

File tree

6 files changed

+39
-27
lines changed

6 files changed

+39
-27
lines changed

enginetest/enginetests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func TestBrokenQueries(t *testing.T, harness Harness) {
263263
// queries during debugging.
264264
func RunQueryTests(t *testing.T, harness Harness, queries []queries.QueryTest) {
265265
for _, tt := range queries {
266-
testQuery(t, harness, tt.Query, tt.Expected, tt.ExpectedColumns, nil, !tt.DontUnwrap)
266+
testQuery(t, harness, tt.Query, tt.Expected, tt.ExpectedColumns, nil, tt.WrapBehavior)
267267
}
268268
}
269269

enginetest/evaluation.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ func TestTransactionScriptWithEngine(t *testing.T, e QueryEngine, harness Harnes
326326
// TestQuery runs a query on the engine given and asserts that results are as expected.
327327
// TODO: this should take en engine
328328
func TestQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]sqlparser.Expr) {
329-
testQuery(t, harness, q, expected, expectedCols, bindings, true)
329+
testQuery(t, harness, q, expected, expectedCols, bindings, queries.WrapBehavior_Unwrap)
330330
}
331331

332-
func testQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]sqlparser.Expr, unwrapValues bool) {
332+
func testQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]sqlparser.Expr, wrapBehavior queries.WrapBehavior) {
333333
t.Run(q, func(t *testing.T) {
334334
if sh, ok := harness.(SkippingHarness); ok {
335335
if sh.SkipQueryTest(q) {
@@ -340,7 +340,7 @@ func testQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expe
340340
e := mustNewEngine(t, harness)
341341
defer e.Close()
342342
ctx := NewContext(harness)
343-
testQueryWithContext(t, ctx, e, harness, q, expected, expectedCols, bindings, nil, unwrapValues)
343+
testQueryWithContext(t, ctx, e, harness, q, expected, expectedCols, bindings, nil, wrapBehavior)
344344
})
345345
}
346346

@@ -383,7 +383,7 @@ func TestQueryWithContext(
383383
bindings map[string]sqlparser.Expr,
384384
qFlags *sql.QueryFlags,
385385
) {
386-
testQueryWithContext(t, ctx, e, harness, q, expected, expectedCols, bindings, qFlags, true)
386+
testQueryWithContext(t, ctx, e, harness, q, expected, expectedCols, bindings, qFlags, queries.WrapBehavior_Unwrap)
387387
}
388388

389389
func testQueryWithContext(
@@ -396,7 +396,7 @@ func testQueryWithContext(
396396
expectedCols []*sql.Column,
397397
bindings map[string]sqlparser.Expr,
398398
qFlags *sql.QueryFlags,
399-
unwrapValues bool,
399+
wrapBehavior queries.WrapBehavior,
400400
) {
401401
ctx = ctx.WithQuery(q)
402402
require := require.New(t)
@@ -412,7 +412,7 @@ func testQueryWithContext(
412412
require.NoError(err, "Unexpected error for query %s: %s", q, err)
413413

414414
if expected != nil {
415-
checkResults(t, harness, expected, expectedCols, sch, rows, q, e, unwrapValues)
415+
checkResults(t, harness, expected, expectedCols, sch, rows, q, e, wrapBehavior)
416416
}
417417

418418
require.Equal(
@@ -531,7 +531,7 @@ func CheckResults(
531531
q string,
532532
e QueryEngine,
533533
) {
534-
checkResults(t, h, expected, expectedCols, sch, rows, q, e, true)
534+
checkResults(t, h, expected, expectedCols, sch, rows, q, e, queries.WrapBehavior_Unwrap)
535535
}
536536

537537
func checkResults(
@@ -543,12 +543,12 @@ func checkResults(
543543
rows []sql.Row,
544544
q string,
545545
e QueryEngine,
546-
unwrapValues bool,
546+
wrapBehavior queries.WrapBehavior,
547547
) {
548548
if reh, ok := h.(ResultEvaluationHarness); ok {
549-
reh.EvaluateQueryResults(t, expected, expectedCols, sch, rows, q, unwrapValues)
549+
reh.EvaluateQueryResults(t, expected, expectedCols, sch, rows, q, wrapBehavior)
550550
} else {
551-
checkResultsDefault(t, expected, expectedCols, sch, rows, q, e, unwrapValues)
551+
checkResultsDefault(t, expected, expectedCols, sch, rows, q, e, wrapBehavior)
552552
}
553553
}
554554

@@ -713,7 +713,7 @@ func checkResultsDefault(
713713
rows []sql.Row,
714714
q string,
715715
e QueryEngine,
716-
unwrapValues bool,
716+
wrapBehavior queries.WrapBehavior,
717717
) {
718718
widenedRows := WidenRows(t, sch, rows)
719719
widenedExpected := WidenRows(t, sch, expected)
@@ -751,11 +751,12 @@ func checkResultsDefault(
751751
}
752752
}
753753
case sql.AnyWrapper:
754-
if unwrapValues {
754+
switch wrapBehavior {
755+
case queries.WrapBehavior_Unwrap:
755756
var err error
756757
widenedRow[i], err = sql.UnwrapAny(context.Background(), v)
757758
require.NoError(t, err)
758-
} else {
759+
case queries.WrapBehavior_Hash:
759760
widenedRow[i] = v.Hash()
760761
}
761762
}
@@ -1198,12 +1199,12 @@ func RunWriteQueryTestWithEngine(t *testing.T, harness Harness, e QueryEngine, t
11981199
}
11991200

12001201
ctx := NewContext(harness)
1201-
testQueryWithContext(t, ctx, e, harness, tt.WriteQuery, tt.ExpectedWriteResult, nil, nil, nil, !tt.DontUnwrap)
1202+
testQueryWithContext(t, ctx, e, harness, tt.WriteQuery, tt.ExpectedWriteResult, nil, nil, nil, tt.WrapBehavior)
12021203
expectedSelect := tt.ExpectedSelect
12031204
if IsServerEngine(e) && tt.SkipServerEngine {
12041205
expectedSelect = nil
12051206
}
1206-
testQueryWithContext(t, ctx, e, harness, tt.SelectQuery, expectedSelect, nil, nil, nil, !tt.DontUnwrap)
1207+
testQueryWithContext(t, ctx, e, harness, tt.SelectQuery, expectedSelect, nil, nil, nil, tt.WrapBehavior)
12071208
}
12081209

12091210
func supportedDialect(harness Harness, dialect string) bool {

enginetest/harness.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package enginetest
1616

1717
import (
18+
"github.com/dolthub/go-mysql-server/enginetest/queries"
1819
"testing"
1920

2021
"gopkg.in/src-d/go-errors.v1"
@@ -162,7 +163,7 @@ type ResultEvaluationHarness interface {
162163
expectdSch sql.Schema,
163164
actualRows []sql.Row,
164165
query string,
165-
unwrapValues bool,
166+
wrapBehavior queries.WrapBehavior,
166167
)
167168

168169
// EvaluateExpectedError compares expected error strings to actual errors and emits failed test assertions in the

enginetest/queries/queries.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ import (
2929
"github.com/dolthub/go-mysql-server/sql/types"
3030
)
3131

32+
// WrapBehavior determines how the test engine will process sql.AnyWrapper values in query results before comparing them to expected results.
33+
type WrapBehavior int
34+
35+
const (
36+
// WrapBehavior_Unwrap causes the engine to return the unwrapped value. Use this for tests that verify the semantic meaning of the result. (Most tests)
37+
WrapBehavior_Unwrap = iota
38+
// WrapBehavior_Hash causes the engine to return the result of the wrapper's Hash() function. Use this for tests that verify the specific representation of the result.
39+
WrapBehavior_Hash
40+
)
41+
3242
type QueryTest struct {
3343
// Query is the query string to execute
3444
Query string
@@ -47,10 +57,10 @@ type QueryTest struct {
4757
// Dialect is the supported dialect for this query, which must match the dialect of the harness if specified.
4858
// The query is skipped if the dialect doesn't match.
4959
Dialect string
50-
// DontUnwrap indicates whether to skip normalizing the select results via unwrapping wrapped values.
51-
// Instead, the test engine will replace wrapped values with their hash (as determined by sql.AnyWrapped.Hash).
52-
// Set this to test the exact encodings being returned by the query.
53-
DontUnwrap bool
60+
// WrapBehavior indicates whether to normalize the select results via unwrapping wrapped values (the default),
61+
// or replace wrapped values with their hash as determined by sql.AnyWrapped.Hash.
62+
// Set this to WrapBehvior_Hash to test the exact encodings being returned by the query.
63+
WrapBehavior WrapBehavior
5464
}
5565

5666
type QueryPlanTest struct {
@@ -11391,10 +11401,10 @@ type WriteQueryTest struct {
1139111401
// Dialect is the supported dialect for this test, which must match the dialect of the harness if specified.
1139211402
// The script is skipped if the dialect doesn't match.
1139311403
Dialect string
11394-
// DontUnwrap indicates whether to skip normalizing the select results via unwrapping wrapped values.
11395-
// Instead, the test engine will replace wrapped values with their hash (as determined by sql.AnyWrapped.Hash).
11396-
// Set this to test the exact encodings being returned by the query.
11397-
DontUnwrap bool
11404+
// WrapBehavior indicates whether to normalize the select results via unwrapping wrapped values (the default),
11405+
// or replace wrapped values with their hash as determined by sql.AnyWrapped.Hash.
11406+
// Set this to WrapBehvior_Hash to test the exact encodings being returned by the query.
11407+
WrapBehavior WrapBehavior
1139811408
}
1139911409

1140011410
// GenericErrorQueryTest is a query test that is used to assert an error occurs for some query, without specifying what

enginetest/wrapper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (w ErrorWrapper[T]) IsExactLength() bool {
6767
}
6868

6969
func (w ErrorWrapper[T]) Hash() interface{} {
70-
return nil
70+
panic("not implemented")
7171
}
7272

7373
func setupWrapperTests(t *testing.T) (*sql.Context, *memory.Database, *MemoryHarness, *sqle.Engine) {

memory/wrapper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (w ErrorWrapper[T]) IsExactLength() bool {
136136
}
137137

138138
func (w ErrorWrapper[T]) Hash() interface{} {
139-
return nil
139+
panic("not implemented")
140140
}
141141

142142
// TestWrapperCompare tests that a wrapped value can be used in comparisons.

0 commit comments

Comments
 (0)