2023-09-13 06:03:25 +02:00
|
|
|
package share
|
2023-04-13 10:16:48 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-09-13 06:03:25 +02:00
|
|
|
"os"
|
2023-04-13 10:16:48 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/app"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/module"
|
2023-09-13 06:03:25 +02:00
|
|
|
"forge.cadoles.com/arcad/edge/pkg/storage/driver"
|
2023-04-13 10:16:48 +02:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gitlab.com/wpetit/goweb/logger"
|
2023-09-13 06:03:25 +02:00
|
|
|
|
|
|
|
_ "forge.cadoles.com/arcad/edge/pkg/storage/driver/sqlite"
|
2023-04-13 10:16:48 +02:00
|
|
|
)
|
|
|
|
|
2023-09-13 06:03:25 +02:00
|
|
|
func TestModule(t *testing.T) {
|
2023-04-13 10:16:48 +02:00
|
|
|
logger.SetLevel(logger.LevelDebug)
|
|
|
|
|
2023-09-13 06:03:25 +02:00
|
|
|
store, err := driver.NewShareStore("sqlite://testdata/test_share_module.sqlite")
|
2023-04-13 10:16:48 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
server := app.NewServer(
|
|
|
|
module.ContextModuleFactory(),
|
|
|
|
module.ConsoleModuleFactory(),
|
2023-09-13 06:03:25 +02:00
|
|
|
ModuleFactory("test.app.edge", store),
|
2023-04-13 10:16:48 +02:00
|
|
|
)
|
|
|
|
|
2023-09-13 06:03:25 +02:00
|
|
|
data, err := os.ReadFile("testdata/share.js")
|
2023-04-13 10:16:48 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
2023-10-19 20:05:59 +02:00
|
|
|
ctx := context.Background()
|
2023-11-28 16:35:49 +01:00
|
|
|
if err := server.Start(ctx, "testdata/share.js", string(data)); err != nil {
|
2023-04-13 10:16:48 +02:00
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
defer server.Stop()
|
|
|
|
|
2023-04-13 10:16:48 +02:00
|
|
|
if _, err := server.ExecFuncByName(context.Background(), "testModule"); err != nil {
|
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
}
|