A Go library for cleaning databases between tests with parallel execution support using file locking.
DbCleaner is a Go library that cleans database tables between test executions to ensure test isolation. It solves the problem of test pollution in database-dependent applications by providing reliable cleanup mechanisms. The library is specifically designed to work safely with parallel test execution using file locking.
Go developers writing database integration tests who need reliable test isolation and parallel test execution capabilities.
Developers choose DbCleaner because it provides thread-safe database cleaning specifically for Go test suites, with built-in support for major SQL databases and configurable locking behavior to prevent race conditions.
Clean database for testing, inspired by database_cleaner for Ruby
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses flock syscall to prevent race conditions, ensuring tests can run concurrently without data leakage between runs.
Works out of the box with PostgreSQL, MySQL, and SQLite3, covering common SQL databases for Go applications.
Configurable retry logic, timeouts, and lock file directories help mitigate deadlocks and adapt to different testing environments.
Designed to work seamlessly with testify's test suite structure, simplifying setup and teardown in database-dependent tests.
Supports any database driver via the Engine interface, allowing custom implementations for unsupported databases.
Only natively supports three SQL databases; NoSQL or other SQL databases require custom engine implementation, adding development overhead.
Relies on flock syscall, which may fail in environments without proper file locking support, such as some cloud or containerized systems.
Requires manual tuning of retries, timeouts, and lock directories to prevent deadlocks, which can be complex and error-prone for new users.
Best integrated with testify's suite, making it less straightforward for teams using other testing frameworks or Go's standard library alone.