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"
|
|
|
|
|
2023-05-29 13:29:42 +08:00
|
|
|
// 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)
|
2023-09-26 17:16:58 +08:00
|
|
|
|
|
|
|
store := store.New(db.DBInstance, driver, profile)
|
2023-04-01 22:47:19 +08:00
|
|
|
return store
|
|
|
|
}
|