diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-14 11:11:35 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-14 11:11:35 +0300 |
| commit | c20344d0ecbed9f41a4d2e29045ef8b10a249d21 (patch) | |
| tree | 51a1d96f01ba23e69fbdae0ed7dec87f919f1c17 | |
| parent | 75cc707dd049c52b82ff4e4d9ee4639cbabed9d1 (diff) | |
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
| -rw-r--r-- | internal/goprecords/integration_test_runner.go | 12 | ||||
| -rw-r--r-- | internal/goprecords/integration_test_runner_test.go | 28 |
2 files changed, 38 insertions, 2 deletions
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) + } +} |
