From c20344d0ecbed9f41a4d2e29045ef8b10a249d21 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 14 Apr 2026 11:11:35 +0300 Subject: fix(t3): surface CreateSchema errors in integration import test Check CreateSchema in integration test runner so failures report 'create schema' instead of failing later on import. Extract testImportExportOnDB for the canceled-context regression test. Made-with: Cursor --- internal/goprecords/integration_test_runner.go | 12 ++++++++-- .../goprecords/integration_test_runner_test.go | 28 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 internal/goprecords/integration_test_runner_test.go diff --git a/internal/goprecords/integration_test_runner.go b/internal/goprecords/integration_test_runner.go index ee76a1d..0d07276 100644 --- a/internal/goprecords/integration_test_runner.go +++ b/internal/goprecords/integration_test_runner.go @@ -2,6 +2,7 @@ package goprecords import ( "context" + "database/sql" "fmt" "os" ) @@ -93,18 +94,25 @@ func testImportExport(ctx context.Context, aggregates *Aggregates, fixturesDir s _ = os.Remove(tmpDB) return 1 } - failed := 0 db, err := OpenDB(ctx, tmpDB) if err != nil { _ = os.Remove(tmpDB) fmt.Printf("FAIL: open tmp db: %v\n", err) return 1 } + return testImportExportOnDB(ctx, db, tmpDB, aggregates, fixturesDir) +} + +func testImportExportOnDB(ctx context.Context, db *sql.DB, tmpDB string, aggregates *Aggregates, fixturesDir string) int { defer func() { db.Close() _ = os.Remove(tmpDB) }() - CreateSchema(ctx, db) + if err := CreateSchema(ctx, db); err != nil { + fmt.Printf("FAIL: create schema: %v\n", err) + return 1 + } + failed := 0 if err := ImportFromDir(ctx, db, fixturesDir); err != nil { fmt.Printf("FAIL: import: %v\n", err) return 1 diff --git a/internal/goprecords/integration_test_runner_test.go b/internal/goprecords/integration_test_runner_test.go new file mode 100644 index 0000000..29de945 --- /dev/null +++ b/internal/goprecords/integration_test_runner_test.go @@ -0,0 +1,28 @@ +package goprecords + +import ( + "context" + "path/filepath" + "testing" +) + +func TestTestImportExportOnDB_createSchemaError(t *testing.T) { + ctx := context.Background() + fixturesDir := filepath.Join("..", "..", "fixtures") + aggr := NewAggregator(fixturesDir) + aggregates, err := aggr.Aggregate(ctx) + if err != nil { + t.Fatal(err) + } + tmpDir := t.TempDir() + dbPath := filepath.Join(tmpDir, "import.db") + db, err := OpenDB(ctx, dbPath) + if err != nil { + t.Fatal(err) + } + ctxCanceled, cancel := context.WithCancel(ctx) + cancel() + if n := testImportExportOnDB(ctxCanceled, db, dbPath, aggregates, fixturesDir); n != 1 { + t.Fatalf("testImportExportOnDB: got %d, want 1", n) + } +} -- cgit v1.2.3