https://github.com/trueifnotfalse/dbassert
Go database assert package
https://github.com/trueifnotfalse/dbassert
database golang testing
Last synced: 2 months ago
JSON representation
Go database assert package
- Host: GitHub
- URL: https://github.com/trueifnotfalse/dbassert
- Owner: trueifnotfalse
- License: mit
- Created: 2024-08-19T06:19:29.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-03T09:31:08.000Z (over 1 year ago)
- Last Synced: 2025-06-24T05:39:15.399Z (about 1 year ago)
- Topics: database, golang, testing
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dbassert
The `dbassert` package provides several useful functions to help you write integration tests.
# Example exists usage:
```go
import (
"database/sql"
_ "github.com/lib/pq"
"github.com/trueifnotfalse/dbassert"
)
func TestSomeDb(t *testing.T) {
conn, err := sql.Open("postgres", "postgres://postgres:secret@localhost:%s?sslmode=disable")
if err != nil {
t.Fatal(err)
}
defer conn.Close()
_, err = conn.Exec(`INSERT INTO your_table(name) VALUES('John')`)
dbassert := dbassert.New(conn)
// check row exists in table
dbassert.ExistsInDatabase(t, "your_table", map[string]any{
"name": "John",
}))
// check row not exists in table
dbassert.NotExistsInDatabase(t, "your_table", map[string]any{
"name": "Boris",
}))
}
```