Skip to content

Commit c3d795f

Browse files
authored
Merge pull request #1400 Fix drop table in tests helper
2 parents 6260e4d + 853c5df commit c3d795f

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tests/integration/helpers_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ func (scope *scopeT) TableName(opts ...func(t *tableNameParams)) string {
327327
}
328328

329329
f := func() (*fixenv.GenericResult[string], error) {
330+
tablePath := path.Join(scope.Folder(), params.tableName)
331+
332+
// drop previous table if exists
333+
err := scope.Driver().Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error {
334+
return s.DropTable(ctx, tablePath)
335+
})
336+
if err != nil && !ydb.IsOperationErrorSchemeError(err) {
337+
return nil, fmt.Errorf("failed to drop previous table: %w", err)
338+
}
339+
330340
createTableErr := scope.Driver().Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) (err error) {
331341
if len(params.createTableOptions) == 0 {
332342
tmpl, err := template.New("").Parse(params.createTableQueryTemplate)
@@ -350,19 +360,23 @@ func (scope *scopeT) TableName(opts ...func(t *tableNameParams)) string {
350360
return s.ExecuteSchemeQuery(ctx, query.String())
351361
}
352362

353-
return s.CreateTable(ctx, path.Join(scope.Folder(), params.tableName), params.createTableOptions...)
363+
return s.CreateTable(ctx, tablePath, params.createTableOptions...)
354364
})
355365

366+
if createTableErr != nil {
367+
return nil, err
368+
}
369+
356370
cleanup := func() {
357371
// doesn't drop table after fail test - for debugging
358-
if createTableErr == nil && !scope.t.Failed() {
372+
if !scope.t.Failed() {
359373
_ = scope.Driver().Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error {
360-
return s.DropTable(ctx, params.tableName)
374+
return s.DropTable(ctx, tablePath)
361375
})
362376
}
363377
}
364378

365-
return fixenv.NewGenericResultWithCleanup(params.tableName, cleanup), createTableErr
379+
return fixenv.NewGenericResultWithCleanup(params.tableName, cleanup), nil
366380
}
367381

368382
return fixenv.CacheResult(scope.Env, f, fixenv.CacheOptions{CacheKey: params.tableName})

0 commit comments

Comments
 (0)