2023-03-23 19:01:20 +01:00
|
|
|
package blob
|
|
|
|
|
|
|
|
import (
|
2023-10-19 20:05:59 +02:00
|
|
|
"context"
|
2023-09-13 06:03:25 +02:00
|
|
|
"os"
|
2023-03-23 19:01:20 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"cdr.dev/slog"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/app"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/bus/memory"
|
|
|
|
"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-03-23 19:01:20 +01:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBlobModule(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
if testing.Verbose() {
|
|
|
|
logger.SetLevel(slog.LevelDebug)
|
|
|
|
}
|
2023-03-23 19:01:20 +01:00
|
|
|
|
|
|
|
bus := memory.NewBus()
|
2023-04-06 14:45:50 +02:00
|
|
|
store := sqlite.NewBlobStore(":memory:?_pragma=foreign_keys(1)&_pragma=busy_timeout=60000")
|
2023-03-23 19:01:20 +01:00
|
|
|
|
|
|
|
server := app.NewServer(
|
|
|
|
module.ContextModuleFactory(),
|
|
|
|
module.ConsoleModuleFactory(),
|
|
|
|
ModuleFactory(bus, store),
|
|
|
|
)
|
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
script := "testdata/blob.js"
|
2023-03-23 19:01:20 +01:00
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
data, err := os.ReadFile(script)
|
|
|
|
if err != nil {
|
2023-03-23 19:01:20 +01:00
|
|
|
t.Fatal(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, script, string(data)); err != nil {
|
2023-03-23 19:01:20 +01:00
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
2023-11-28 16:35:49 +01:00
|
|
|
|
|
|
|
defer server.Stop()
|
2023-03-23 19:01:20 +01:00
|
|
|
}
|