2023-04-03 04:53:36 +03:00
|
|
|
package teststore
|
2023-04-01 17:47:19 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2023-09-29 04:15:54 +03:00
|
|
|
// mysql driver.
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
// sqlite driver.
|
|
|
|
_ "modernc.org/sqlite"
|
|
|
|
|
2023-04-01 17:47:19 +03:00
|
|
|
"github.com/usememos/memos/store"
|
2023-10-05 18:11:29 +03:00
|
|
|
"github.com/usememos/memos/store/db"
|
2023-04-01 17:47:19 +03:00
|
|
|
"github.com/usememos/memos/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewTestingStore(ctx context.Context, t *testing.T) *store.Store {
|
|
|
|
profile := test.GetTestingProfile(t)
|
2023-10-05 18:11:29 +03:00
|
|
|
dbDriver, err := db.NewDBDriver(profile)
|
2023-09-27 06:56:20 +03:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("failed to create db driver, error: %+v\n", err)
|
2023-04-01 17:47:19 +03:00
|
|
|
}
|
2023-10-05 18:11:29 +03:00
|
|
|
if err := dbDriver.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
|
|
|
|
2023-10-05 18:11:29 +03:00
|
|
|
store := store.New(dbDriver, profile)
|
2023-04-01 17:47:19 +03:00
|
|
|
return store
|
|
|
|
}
|