Update README with the new library API

This commit is contained in:
Miguel de la Cruz 2022-08-12 16:55:21 +02:00
parent 0bfc18f735
commit 29ac8f6f33

View file

@ -21,6 +21,7 @@ type Migrator interface {
DriverName() string DriverName() string
Setup() error Setup() error
MigrateToStep(step int) error MigrateToStep(step int) error
Interceptors() map[int]Interceptor
TearDown() error TearDown() error
} }
@ -39,7 +40,6 @@ your assertions:
```go ```go
t.Run("migration should link book 1 with its author", func(t *testing.T) { t.Run("migration should link book 1 with its author", func(t *testing.T) {
f := foundation.New(t, migrator). f := foundation.New(t, migrator).
RegisterInterceptors(interceptors).
// runs migrations up to and including 5 // runs migrations up to and including 5
MigrateToStep(5). MigrateToStep(5).
// loads the SQL of the file // loads the SQL of the file
@ -48,14 +48,21 @@ t.Run("migration should link book 1 with its author", func(t *testing.T) {
MigrateToStep(6) MigrateToStep(6)
defer f.TearDown() defer f.TearDown()
book := struct{ book := struct{ID int; AuthorID int}{}
ID int
AuthorID int
}{}
err = f.DB().Get(&book, "SELECT id, authorID FROM books") err := f.DB().Get(&book, "SELECT id, authorID FROM books")
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, book.ID) require.Equal(t, 1, book.ID)
require.Equal(t, 3, book.AuthorID) require.Equal(t, 3, book.AuthorID)
}) })
t.Run("test specifically the interceptor 6", func(t *testing.T) {
f := foundation.New(t, migrator).
MigrateToStepSkippingLastInterceptor(6).
ExecFile("./myfixtures.sql").
RunInterceptor(6)
defer f.TearDown()
// ...
})
``` ```