edge/pkg/module/blob/module_test.go

47 lines
938 B
Go
Raw Normal View History

2023-03-23 19:01:20 +01:00
package blob
import (
"context"
"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"
"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()
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)
}
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
}