Skip to content

Commit 182aa1d

Browse files
internal/sqltest: add documentation
1 parent 0fe78c5 commit 182aa1d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

internal/sqltest/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# sqltest
2+
3+
The `sqltest` package provides utilities for writing database integration tests that work consistently across multiple database engines (PostgreSQL and SQLite).
4+
5+
## Basic Usage
6+
7+
The primary entry point is `RunDatabaseTest`, which runs your test function against both PostgreSQL and SQLite databases:
8+
9+
```go
10+
func TestMyDatabaseCode(t *testing.T) {
11+
sqltest.RunDatabaseTest(t, func(t *testing.T, dbFactory sqltest.DBFactory) {
12+
// Get a fresh database connection
13+
db := dbFactory(t)
14+
15+
// Use `db` to perform your database operations
16+
})
17+
}
18+
```
19+
20+
See `db_test.go` for complete examples, including:
21+
- `TestDatabaseIsolation`: Demonstrates parallel test isolation
22+
- `TestDatabaseMultipleRecordsOps`: Shows CRUD operations
23+
24+
## Test Isolation
25+
26+
Each test gets its own isolated database:
27+
- **PostgreSQL**: A new database is created in the shared container
28+
- **SQLite**: A new file-based database is created in a temp directory
29+
30+
Databases are automatically cleaned up when tests complete.
31+
32+
33+
## Performance Considerations
34+
35+
- PostgreSQL container is shared across all tests in a package
36+
- Database names are deterministic based on test names for proper Go test caching
37+
- Tests can run in parallel safely

0 commit comments

Comments
 (0)