Small utility functions for testing Gorm-related code. Such as sqlite database instantiation and wait groups with callbacks.
go get github.com/ing-bank/gormtestutil
package main
import (
"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())
// [...]
}
package main
import (
"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))
}
- Clone the repository
- Run
make tools
to install necessary tools - Run
make t
to run unit tests - Run
make fmt
to format code - Run
make lint
to lint your code
You can run make
to see a list of useful commands.
Nothing here yet!