Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ing-bank/gormtestutil
Utilities for writing unit-tests with Gorm
https://github.com/ing-bank/gormtestutil
gorm sqlite test testing unit
Last synced: 3 months ago
JSON representation
Utilities for writing unit-tests with Gorm
- Host: GitHub
- URL: https://github.com/ing-bank/gormtestutil
- Owner: ing-bank
- License: mit
- Created: 2023-03-23T10:50:03.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-01T12:37:38.000Z (over 1 year ago)
- Last Synced: 2024-03-25T20:55:34.114Z (11 months ago)
- Topics: gorm, sqlite, test, testing, unit
- Language: Go
- Homepage: https://pkg.go.dev/github.com/ing-bank/gormtestutil
- Size: 16.6 KB
- Stars: 3
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🦁 Gorm Test Utils
[![Go package](https://github.com/ing-bank/gormtestutil/actions/workflows/test.yaml/badge.svg)](https://github.com/ing-bank/gormtestutil/actions/workflows/test.yaml)
![GitHub](https://img.shields.io/github/license/ing-bank/gormtestutil)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/ing-bank/gormtestutil)Small utility functions for testing Gorm-related code.
Such as sqlite database instantiation and wait groups with callbacks.## ⬇️ Installation
`go get github.com/ing-bank/gormtestutil`
## 📋 Usage
### Database Instantiation
```go
package mainimport (
"testing"
"github.com/ing-bank/gormtestutil"
)func TestProductService_FetchAll_ReturnsAllProducts(t *testing.T) {
// Arrange
db := gormtestutil.NewMemoryDatabase(t,
gormtestutil.WithName(t.Name()),
gormtestutil.WithoutForeignKeys(),
gormtestutil.WithSingularConnection())
// [...]
}
```### Hooks
```go
package mainimport (
"github.com/ing-bank/gormtestutil"
"time"
"testing"
)func TestProductService_Create_CreatesProduct(t *testing.T) {
// Arrange
db := gormtestutil.NewMemoryDatabase(t)expectation := gormtestutil.ExpectCreated(t, db, Product{}, gormtestutil.WithCalls(1))
// Act
go Create(db, Product{Name: "Test"})// Assert
gormtestutil.EnsureCompletion(t, expectation, gormtestutil.WithTimeout(30*time.Second))
}
```## 🚀 Development
1. Clone the repository
2. Run `make tools` to install necessary tools
3. Run `make t` to run unit tests
4. Run `make fmt` to format code
4. Run `make lint` to lint your codeYou can run `make` to see a list of useful commands.
## 🔭 Future Plans
Nothing here yet!