@@ -157,11 +157,7 @@ INSERT INTO t.kv VALUES ('c', 'e'), ('a', 'c'), ('b', 'd');
157157 }
158158
159159 tableSpan := tbDesc .TableSpan ()
160- if kvs , err := kvDB .Scan (ctx , tableSpan .Key , tableSpan .EndKey , 0 ); err != nil {
161- t .Fatal (err )
162- } else if l := 6 ; len (kvs ) != l {
163- t .Fatalf ("expected %d key value pairs, but got %d" , l , len (kvs ))
164- }
160+ tests .CheckKeyCount (t , kvDB , tableSpan , 6 )
165161
166162 if _ , err := sqlDB .Exec (`DROP DATABASE t RESTRICT` ); ! testutils .IsError (err ,
167163 `database "t" is not empty` ) {
@@ -173,11 +169,7 @@ INSERT INTO t.kv VALUES ('c', 'e'), ('a', 'c'), ('b', 'd');
173169 }
174170
175171 // Data is not deleted.
176- if kvs , err := kvDB .Scan (ctx , tableSpan .Key , tableSpan .EndKey , 0 ); err != nil {
177- t .Fatal (err )
178- } else if l := 6 ; len (kvs ) != l {
179- t .Fatalf ("expected %d key value pairs, but got %d" , l , len (kvs ))
180- }
172+ tests .CheckKeyCount (t , kvDB , tableSpan , 6 )
181173
182174 if err := descExists (sqlDB , true , tbDesc .ID ); err != nil {
183175 t .Fatal (err )
@@ -259,40 +251,32 @@ INSERT INTO t.kv VALUES ('c', 'e'), ('a', 'c'), ('b', 'd');
259251 }
260252 tbDesc := desc .GetTable ()
261253
262- // Add a zone config for both the table and database.
263- cfg := config .DefaultZoneConfig ()
264- cfg .GC .TTLSeconds = 0 // Set TTL so the data is deleted immediately.
265- buf , err := protoutil .Marshal (& cfg )
266- if err != nil {
267- t .Fatal (err )
268- }
269- if _ , err := sqlDB .Exec (`INSERT INTO system.zones VALUES ($1, $2)` , tbDesc .ID , buf ); err != nil {
270- t .Fatal (err )
271- }
272- if _ , err := sqlDB .Exec (`INSERT INTO system.zones VALUES ($1, $2)` , dbDesc .ID , buf ); err != nil {
273- t .Fatal (err )
274- }
254+ tableSpan := tbDesc .TableSpan ()
255+ tests .CheckKeyCount (t , kvDB , tableSpan , 6 )
275256
276- if err := zoneExists (sqlDB , & cfg , tbDesc .ID ); err != nil {
257+ if _ , err := sqlDB .Exec (`DROP DATABASE t RESTRICT` ); ! testutils .IsError (err ,
258+ `database "t" is not empty` ) {
277259 t .Fatal (err )
278260 }
279- if err := zoneExists (sqlDB , & cfg , dbDesc .ID ); err != nil {
261+
262+ if _ , err := sqlDB .Exec (`DROP DATABASE t CASCADE` ); err != nil {
280263 t .Fatal (err )
281264 }
282265
283- tableSpan := tbDesc .TableSpan ()
284- if kvs , err := kvDB .Scan (ctx , tableSpan .Key , tableSpan .EndKey , 0 ); err != nil {
266+ tests .CheckKeyCount (t , kvDB , tableSpan , 6 )
267+
268+ // Push a new zone config for both the table and database with TTL=0
269+ // so the data is deleted immediately.
270+ cfg := config .DefaultZoneConfig ()
271+ cfg .GC .TTLSeconds = 0
272+ buf , err := protoutil .Marshal (& cfg )
273+ if err != nil {
285274 t .Fatal (err )
286- } else if l := 6 ; len (kvs ) != l {
287- t .Fatalf ("expected %d key value pairs, but got %d" , l , len (kvs ))
288275 }
289-
290- if _ , err := sqlDB .Exec (`DROP DATABASE t RESTRICT` ); ! testutils .IsError (err ,
291- `database "t" is not empty` ) {
276+ if _ , err := sqlDB .Exec (`INSERT INTO system.zones VALUES ($1, $2)` , tbDesc .ID , buf ); err != nil {
292277 t .Fatal (err )
293278 }
294-
295- if _ , err := sqlDB .Exec (`DROP DATABASE t CASCADE` ); err != nil {
279+ if _ , err := sqlDB .Exec (`INSERT INTO system.zones VALUES ($1, $2)` , dbDesc .ID , buf ); err != nil {
296280 t .Fatal (err )
297281 }
298282
@@ -305,11 +289,7 @@ INSERT INTO t.kv VALUES ('c', 'e'), ('a', 'c'), ('b', 'd');
305289 })
306290
307291 // Data is deleted.
308- if kvs , err := kvDB .Scan (ctx , tableSpan .Key , tableSpan .EndKey , 0 ); err != nil {
309- t .Fatal (err )
310- } else if l := 0 ; len (kvs ) != l {
311- t .Fatalf ("expected %d key value pairs, but got %d" , l , len (kvs ))
312- }
292+ tests .CheckKeyCount (t , kvDB , tableSpan , 0 )
313293}
314294
315295// Tests that SHOW TABLES works correctly when a database is recreated
@@ -618,24 +598,27 @@ func TestDropTableDeleteData(t *testing.T) {
618598 t .Fatalf ("Name entry %q does not exist" , nameKey )
619599 }
620600
621- // Add a zone config for the table.
622- cfg := config .DefaultZoneConfig ()
623- cfg .GC .TTLSeconds = 0 // Set TTL so the data is deleted immediately.
624- buf , err := protoutil .Marshal (& cfg )
625- if err != nil {
601+ tableSpan := tableDesc .TableSpan ()
602+ tests .CheckKeyCount (t , kvDB , tableSpan , 3 * numRows )
603+ if _ , err := sqlDB .Exec (`DROP TABLE t.kv` ); err != nil {
626604 t .Fatal (err )
627605 }
628- if _ , err := sqlDB .Exec (`INSERT INTO system.zones VALUES ($1, $2)` , tableDesc .ID , buf ); err != nil {
606+
607+ // Data still exists.
608+ if err := descExists (sqlDB , true , tableDesc .ID ); err != nil {
629609 t .Fatal (err )
630610 }
611+ tests .CheckKeyCount (t , kvDB , tableSpan , 3 * numRows )
631612
632- if err := zoneExists (sqlDB , & cfg , tableDesc .ID ); err != nil {
613+ // Push a new zone config for the table with TTL=0 so the data
614+ // is deleted immediately.
615+ cfg := config .DefaultZoneConfig ()
616+ cfg .GC .TTLSeconds = 0
617+ buf , err := protoutil .Marshal (& cfg )
618+ if err != nil {
633619 t .Fatal (err )
634620 }
635-
636- tableSpan := tableDesc .TableSpan ()
637- tests .CheckKeyCount (t , kvDB , tableSpan , 3 * numRows )
638- if _ , err := sqlDB .Exec (`DROP TABLE t.kv` ); err != nil {
621+ if _ , err := sqlDB .Exec (`INSERT INTO system.zones VALUES ($1, $2)` , tableDesc .ID , buf ); err != nil {
639622 t .Fatal (err )
640623 }
641624
0 commit comments