https://github.com/rubenv/pgtest
PostgreSQL test helper for Go
https://github.com/rubenv/pgtest
Last synced: about 1 year ago
JSON representation
PostgreSQL test helper for Go
- Host: GitHub
- URL: https://github.com/rubenv/pgtest
- Owner: rubenv
- License: mit
- Created: 2019-12-16T15:49:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T11:47:36.000Z (over 2 years ago)
- Last Synced: 2025-04-02T06:43:12.045Z (over 1 year ago)
- Language: Go
- Size: 36.1 KB
- Stars: 56
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pgtest
> Go library to spawn single-use PostgreSQL servers for unit testing
[](https://github.com/rubenv/pgtest/actions) [](https://godoc.org/github.com/rubenv/pgtest)
Spawns a PostgreSQL server with a single database configured. Ideal for unit
tests where you want a clean instance each time. Then clean up afterwards.
Features:
* Starts a clean isolated PostgreSQL database
* Tested on Fedora, Ubuntu and Alpine
* Optimized for in-memory execution, to speed up unit tests
* Less than 1 second startup / initialization time
* Automatically drops permissions when testing as root
## Usage
In your unit test:
```go
pg, err := pgtest.Start()
defer pg.Stop()
// Do something with pg.DB (which is a *sql.DB)
```
## License
This library is distributed under the [MIT](LICENSE) license.