A mock driver for pgx (PostgreSQL driver for Go) to test database interactions without a real database connection.
pgxmock is a mock driver for the pgx PostgreSQL driver in Go that allows developers to test database interactions without requiring a real database connection. It simulates pgx's behavior in memory, enabling comprehensive unit testing of database-related code. The library helps maintain proper test-driven development workflows by isolating database logic from infrastructure dependencies.
Go developers who use the pgx driver for PostgreSQL and need to write unit tests for database interaction code. Particularly valuable for teams practicing test-driven development or requiring reliable database layer testing.
Developers choose pgxmock because it provides a faithful pgx interface implementation specifically designed for testing, with no external dependencies beyond pgx itself. Its expectation-based API and flexible query matching make it easy to write precise, reliable tests without modifying production code.
pgx mock driver for golang to test database interactions
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Simulates pgx behavior entirely in-memory, allowing fast unit tests without setting up PostgreSQL, as shown in the examples where tests run without real connections.
Supports regex, exact, or custom matchers via QueryMatcher interface, enabling precise validation of SQL queries, including complex patterns like time.Time arguments.
Accurately mocks BEGIN, COMMIT, and ROLLBACK, facilitating reliable testing of transactional code, as demonstrated in the rollback test example.
Implements the pgx interface without modifying production code, making it easy to drop into existing Go projects for test-driven development workflows.
Requires manual expectation definitions for each query, which can become tedious and error-prone in tests with many database interactions or complex SQL.
Only simulates behavior without executing SQL against PostgreSQL, so it cannot catch database-specific errors, performance issues, or schema mismatches.
Advanced query matching, such as SQL AST validation, requires implementing custom QueryMatcher interfaces, adding development effort beyond basic use.