go-sqlmock
Sql mock driver for golang to test database interactions
What is go-sqlmock?
Sql mock driver for golang to test database interactions
Overview of go-sqlmock
What it is
go-sqlmock is a mock library that implements the database/sql/driver interface in Go. Its sole purpose is to simulate the behavior of any SQL driver during tests, eliminating the need for a real database connection. It is designed to support a correct Test-Driven Development (TDD) workflow. The library is complete and stable, supports concurrency and multiple connections, and has no third-party dependencies. It also supports Go 1.8 Context-related features and named SQL parameters. The driver allows mocking of any SQL driver method behavior and has strict, by-default, expectation order matching.
Key features
- Simulates any SQL driver behavior in tests without a real database connection.
- Supports concurrency and multiple connections.
- Supports Go 1.8 Context-related features and named SQL parameters.
- Does not require modifications to source code.
- Has strict, by-default, expectation order matching.
- Has no third-party dependencies.
Use cases
- Unit testing database interactions without a real database.
- Testing SQL query execution, prepared statements, transactions, and error handling.
- Validating SQL query strings with customizable
QueryMatcheroptions (regexp or equality). - Matching complex argument types, such as
time.Time, using theArgumentinterface.
Getting started
Install the library:go get github.com/DATA-DOG/go-sqlmockFor detailed usage examples, including how to create a mock database connection, set expectations, and verify them, see the repository README.
License and pricing
The license is not stated in the provided metadata or README. The project is categorized as open source.
Based on the project's public README and repository metadata.