memos/test/store/store.go

29 lines
598 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"
"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
store := store.New(db.DBInstance, profile)
return store
}