@@ -75,6 +75,16 @@ func setupWrapperTests(t *testing.T) (*sql.Context, *memory.Database, *MemoryHar
7575 return ctx , db , harness , e
7676}
7777
78+ // testQueryWithoutUnwrapping checks if a returned query result matches the expected result.
79+ // Unlike calling TestQueryWithContext, this doesn't normalize the results (which would result in unwrapping any wrapped values.)
80+ func testQueryWithoutUnwrapping (t * testing.T , ctx * sql.Context , e QueryEngine , query string , expectedRows []sql.Row ) {
81+ _ , rowIter , _ , err := e .Query (ctx , query )
82+ require .NoError (t , err )
83+ rows , err := sql .RowIterToRows (ctx , rowIter )
84+ require .NoError (t , err )
85+ require .Equal (t , expectedRows , rows , "Unexpected result for query %s" , query )
86+ }
87+
7888// TestWrapperCopyInKey tests that copying a wrapped value in the primary key doesn't require the value to be unwrapped.
7989// This is skipped because inserting into tables requires comparisons between primary keys, which currently requires
8090// unwrapping. But in the future, we may be able to skip fully unwrapping values for specific operations.
@@ -92,6 +102,7 @@ func TestWrapperCopyInKey(t *testing.T) {
92102 require .NoError (t , table .Insert (ctx , sql.Row {"!" }))
93103
94104 TestQueryWithContext (t , ctx , e , harness , "CREATE TABLE t2 AS SELECT 1, col1, 2 FROM test;" , nil , nil , nil , nil )
105+ TestQueryWithContext (t , ctx , e , harness , "SELECT * from t2;" , []sql.Row {{1 , "brave" , 2 }, {1 , longTextErrorWrapper , 2 }, {1 , "!" , 2 }}, nil , nil , nil )
95106}
96107
97108// TestWrapperCopyInKey tests that copying a wrapped value not in the primary key doesn't require the value to be unwrapped.
@@ -121,6 +132,7 @@ func TestWrapperCopyNotInKey(t *testing.T) {
121132 db .AddTable ("t2" , testTable2 )
122133
123134 TestQueryWithContext (t , ctx , e , harness , "INSERT INTO t2 SELECT 1, pk, col1, 2 FROM test;" , nil , nil , nil , nil )
135+ testQueryWithoutUnwrapping (t , ctx , e , "SELECT * from t2;" , []sql.Row {{int64 (1 ), int64 (1 ), "brave" , int64 (2 )}, {int64 (1 ), int64 (2 ), longTextErrorWrapper , int64 (2 )}, {int64 (1 ), int64 (3 ), "!" , int64 (2 )}})
124136}
125137
126138// TestWrapperCopyWhenWideningColumn tests that widening a column doesn't cause values to be unwrapped.
@@ -140,6 +152,7 @@ func TestWrapperCopyWhenWideningColumn(t *testing.T) {
140152 require .NoError (t , testTable .Insert (ctx , sql.Row {int64 (3 ), "!" }))
141153
142154 TestQueryWithContext (t , ctx , e , harness , "ALTER TABLE test MODIFY COLUMN col1 LONGTEXT;" , nil , nil , nil , nil )
155+ testQueryWithoutUnwrapping (t , ctx , e , "SELECT * from test;" , []sql.Row {{int64 (1 ), "brave" }, {int64 (2 ), textErrorWrapper }, {int64 (3 ), "!" }})
143156}
144157
145158// TestWrapperCopyWhenWideningColumn tests that widening a column doesn't cause values to be unwrapped.
@@ -172,9 +185,11 @@ func TestWrapperCopyWithExactLengthWhenNarrowingColumn(t *testing.T) {
172185 testTable := memory .NewTable (db .BaseDatabase , "test" , schema , nil )
173186 db .AddTable ("test" , testTable )
174187
188+ wrapper := exactLengthErrorWrapper (64 )
175189 require .NoError (t , testTable .Insert (ctx , sql.Row {int64 (1 ), "brave" }))
176- require .NoError (t , testTable .Insert (ctx , sql.Row {int64 (2 ), exactLengthErrorWrapper ( 64 ) }))
190+ require .NoError (t , testTable .Insert (ctx , sql.Row {int64 (2 ), wrapper }))
177191 require .NoError (t , testTable .Insert (ctx , sql.Row {int64 (3 ), "!" }))
178192
179193 TestQueryWithContext (t , ctx , e , harness , "ALTER TABLE test MODIFY COLUMN col1 TEXT;" , nil , nil , nil , nil )
194+ testQueryWithoutUnwrapping (t , ctx , e , "SELECT * from test;" , []sql.Row {{int64 (1 ), "brave" }, {int64 (2 ), wrapper }, {int64 (3 ), "!" }})
180195}
0 commit comments