@@ -21,6 +21,7 @@ func tableUUIDSuffix() string {
2121
2222// nolint:revive
2323func (s * WriterTestSuite ) migrate (ctx context.Context , target * schema.Table , source * schema.Table , supportsSafeMigrate bool , writeOptionMigrateForce bool ) error {
24+ const rowsPerRecord = 10
2425 if err := s .plugin .writeOne (ctx , & message.WriteMigrateTable {
2526 Table : source ,
2627 MigrateForce : writeOptionMigrateForce ,
@@ -33,11 +34,11 @@ func (s *WriterTestSuite) migrate(ctx context.Context, target *schema.Table, sou
3334 opts := schema.GenTestDataOptions {
3435 SourceName : sourceName ,
3536 SyncTime : syncTime ,
36- MaxRows : 1 ,
37+ MaxRows : rowsPerRecord ,
3738 TimePrecision : s .genDatOptions .TimePrecision ,
3839 }
3940 tg := schema .NewTestDataGenerator ()
40- resource1 := tg .Generate (source , opts )[ 0 ]
41+ resource1 := tg .Generate (source , opts )
4142 if err := s .plugin .writeOne (ctx , & message.WriteInsert {
4243 Record : resource1 ,
4344 }); err != nil {
@@ -50,10 +51,10 @@ func (s *WriterTestSuite) migrate(ctx context.Context, target *schema.Table, sou
5051 return fmt .Errorf ("failed to sync: %w" , err )
5152 }
5253 totalItems := TotalRows (records )
53- if totalItems != 1 {
54- return fmt .Errorf ("expected 1 item , got %d" , totalItems )
54+ if totalItems != rowsPerRecord {
55+ return fmt .Errorf ("expected items: %d , got: %d" , rowsPerRecord , totalItems )
5556 }
56- if diff := RecordDiff ( records [ 0 ], resource1 ); diff != "" {
57+ if diff := RecordsDiff ( source . ToArrowSchema (), records , []arrow. Record { resource1 } ); diff != "" {
5758 return fmt .Errorf ("first record differs from expectation: %s" , diff )
5859 }
5960
@@ -64,7 +65,7 @@ func (s *WriterTestSuite) migrate(ctx context.Context, target *schema.Table, sou
6465 return fmt .Errorf ("failed to create table: %w" , err )
6566 }
6667
67- resource2 := tg .Generate (target , opts )[ 0 ]
68+ resource2 := tg .Generate (target , opts )
6869 if err := s .plugin .writeOne (ctx , & message.WriteInsert {
6970 Record : resource2 ,
7071 }); err != nil {
@@ -78,12 +79,13 @@ func (s *WriterTestSuite) migrate(ctx context.Context, target *schema.Table, sou
7879 }
7980 sortRecords (target , records , "id" )
8081
82+ lastRow := resource2 .NewSlice (resource2 .NumRows ()- 1 , resource2 .NumRows ())
8183 // if force migration is not required, we don't expect any items to be dropped (so there should be 2 items)
8284 if ! writeOptionMigrateForce || supportsSafeMigrate {
83- if err := expectRows (records , 2 , resource2 ); err != nil {
84- if writeOptionMigrateForce && TotalRows (records ) == 1 {
85+ if err := expectRows (target . ToArrowSchema (), records , 2 * rowsPerRecord , lastRow ); err != nil {
86+ if writeOptionMigrateForce && TotalRows (records ) == rowsPerRecord {
8587 // if force migration is required, we can also expect 1 item to be dropped
86- return expectRows (records , 1 , resource2 )
88+ return expectRows (target . ToArrowSchema (), records , rowsPerRecord , lastRow )
8789 }
8890
8991 return err
@@ -92,7 +94,7 @@ func (s *WriterTestSuite) migrate(ctx context.Context, target *schema.Table, sou
9294 return nil
9395 }
9496
95- return expectRows (records , 1 , resource2 )
97+ return expectRows (target . ToArrowSchema (), records , rowsPerRecord , lastRow )
9698}
9799
98100// nolint:revive
@@ -235,12 +237,14 @@ func (s *WriterTestSuite) testMigrate(
235237 })
236238}
237239
238- func expectRows (records []arrow.Record , expectTotal int64 , expectedLast arrow.Record ) error {
240+ func expectRows (sc * arrow. Schema , records []arrow.Record , expectTotal int64 , expectedLast arrow.Record ) error {
239241 totalItems := TotalRows (records )
240242 if totalItems != expectTotal {
241243 return fmt .Errorf ("expected %d items, got %d" , expectTotal , totalItems )
242244 }
243- if diff := RecordDiff (records [totalItems - 1 ], expectedLast ); diff != "" {
245+ lastRecord := records [len (records )- 1 ]
246+ lastRow := lastRecord .NewSlice (lastRecord .NumRows ()- 1 , lastRecord .NumRows ())
247+ if diff := RecordsDiff (sc , []arrow.Record {lastRow }, []arrow.Record {expectedLast }); diff != "" {
244248 return fmt .Errorf ("record #%d differs from expectation: %s" , totalItems , diff )
245249 }
246250 return nil
0 commit comments