41 lines
719 B
Go
41 lines
719 B
Go
|
package store
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"git.ctrlz.es/mgdelacroix/rmsn/model"
|
||
|
|
||
|
"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
|
||
|
}
|