edge/pkg/module/store/module_test.go

41 lines
961 B
Go
Raw Permalink Normal View History

package store
2023-02-09 12:16:36 +01:00
import (
"context"
"os"
2023-02-09 12:16:36 +01:00
"testing"
"forge.cadoles.com/arcad/edge/pkg/app"
"forge.cadoles.com/arcad/edge/pkg/module"
"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)
store := sqlite.NewDocumentStore(":memory:?_pragma=foreign_keys(1)&_pragma=busy_timeout=60000")
2023-02-09 12:16:36 +01:00
server := app.NewServer(
module.ContextModuleFactory(),
module.ConsoleModuleFactory(),
ModuleFactory(store),
2023-02-09 12:16:36 +01: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))
}
ctx := context.Background()
2023-11-28 16:35:49 +01:00
if err := server.Start(ctx, "testdata/store.js", string(data)); err != nil {
2023-02-09 12:16:36 +01:00
t.Fatalf("%+v", errors.WithStack(err))
}
2023-11-28 16:35:49 +01:00
defer server.Stop()
if _, err := server.ExecFuncByName(context.Background(), "testStore"); err != nil {
2023-02-09 12:16:36 +01:00
t.Fatalf("%+v", errors.WithStack(err))
}
}