craban/server/services/store/testlib.go

41 lines
721 B
Go
Raw Normal View History

2021-09-11 22:50:53 +01:00
package store
import (
"testing"
2021-09-12 17:57:42 +01:00
"git.ctrlz.es/mgdelacroix/craban/model"
2021-09-11 22:50:53 +01:00
"github.com/icrowley/fake"
"github.com/stretchr/testify/require"
)
type TestHelper struct {
t *testing.T
store *Store
}
func NewTestHelper(t *testing.T) (*TestHelper, func()) {
s, err := NewStore(":memory:")
require.NoError(t, err)
teardown := func() {
require.NoError(t, s.Close())
}
return &TestHelper{t: t, store: s}, teardown
}
func (th *TestHelper) NewUser() *model.User {
user := &model.User{
Name: fake.FullName(),
Mail: fake.EmailAddress(),
Username: fake.UserName(),
Password: fake.SimplePassword(),
}
newUser, err := th.store.User().Create(user)
require.NoError(th.t, err)
return newUser
}