2023-02-21 15:05:01 +01:00
|
|
|
package store
|
2023-02-09 12:16:36 +01:00
|
|
|
|
|
|
|
import (
|
2023-03-01 13:04:40 +01:00
|
|
|
"context"
|
2023-09-13 06:03:25 +02:00
|
|
|
"os"
|
2023-02-09 12:16:36 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/app"
|
2023-02-21 15:05:01 +01:00
|
|
|
"forge.cadoles.com/arcad/edge/pkg/module"
|
2023-09-13 06:03:25 +02:00
|
|
|
"forge.cadoles.com/arcad/edge/pkg/storage/driver/sqlite"
|
2023-02-09 12:16:36 +01:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStoreModule(t *testing.T) {
|
|
|
|
logger.SetLevel(logger.LevelDebug)
|
|
|
|
|
2023-04-06 14:45:50 +02:00
|
|
|
store := sqlite.NewDocumentStore(":memory:?_pragma=foreign_keys(1)&_pragma=busy_timeout=60000")
|
2023-02-09 12:16:36 +01:00
|
|
|
server := app.NewServer(
|
2023-02-21 15:05:01 +01:00
|
|
|
module.ContextModuleFactory(),
|
|
|
|
module.ConsoleModuleFactory(),
|
|
|
|
ModuleFactory(store),
|
2023-02-09 12:16:36 +01:00
|
|
|
)
|
|
|
|
|
2023-09-13 06:03:25 +02:00
|
|
|
data, err := os.ReadFile("testdata/store.js")
|
2023-02-09 12:16:36 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := server.Load("testdata/store.js", string(data)); err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
2023-10-19 20:05:59 +02:00
|
|
|
ctx := context.Background()
|
|
|
|
if err := server.Start(ctx); err != nil {
|
2023-02-09 12:16:36 +01:00
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:04:40 +01:00
|
|
|
if _, err := server.ExecFuncByName(context.Background(), "testStore"); err != nil {
|
2023-02-09 12:16:36 +01:00
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
server.Stop()
|
|
|
|
}
|