memos/test/store/store.go

32 lines
692 B
Go
Raw Normal View History

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