memos/test/store/store.go

29 lines
607 B
Go
Raw Normal View History

2023-04-03 04:53:36 +03:00
package teststore
2023-04-01 17:47:19 +03:00
import (
"context"
"fmt"
"testing"
"github.com/usememos/memos/store"
2023-09-26 14:15:18 +03:00
"github.com/usememos/memos/store/sqlite"
2023-04-01 17:47:19 +03:00
"github.com/usememos/memos/test"
// sqlite driver.
_ "modernc.org/sqlite"
2023-04-01 17:47:19 +03:00
)
func NewTestingStore(ctx context.Context, t *testing.T) *store.Store {
profile := test.GetTestingProfile(t)
driver, err := sqlite.NewDriver(profile)
if err != nil {
fmt.Printf("failed to create db driver, error: %+v\n", err)
2023-04-01 17:47:19 +03:00
}
if err := driver.Migrate(ctx); err != nil {
2023-08-26 02:33:45 +03:00
fmt.Printf("failed to migrate db, error: %+v\n", err)
}
2023-04-01 17:47:19 +03:00
store := store.New(driver, profile)
2023-04-01 17:47:19 +03:00
return store
}