99 lines
1.8 KiB
Go
99 lines
1.8 KiB
Go
package cast
|
|
|
|
import (
|
|
"context"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"cdr.dev/slog"
|
|
"forge.cadoles.com/arcad/edge/pkg/app"
|
|
"forge.cadoles.com/arcad/edge/pkg/module"
|
|
"github.com/davecgh/go-spew/spew"
|
|
"github.com/pkg/errors"
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
)
|
|
|
|
func TestCastModule(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if os.Getenv("TEST_CAST_MODULE") != "yes" {
|
|
t.Skip("Test skipped. Set environment variable TEST_CAST_MODULE=yes to run.")
|
|
|
|
return
|
|
}
|
|
|
|
logger.SetLevel(slog.LevelDebug)
|
|
|
|
server := app.NewServer(
|
|
module.ConsoleModuleFactory(),
|
|
CastModuleFactory(),
|
|
)
|
|
|
|
data, err := ioutil.ReadFile("testdata/cast.js")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := server.Load("testdata/cast.js", string(data)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
if err := server.Start(ctx); err != nil {
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
}
|
|
|
|
defer server.Stop()
|
|
|
|
time.Sleep(20 * time.Second)
|
|
}
|
|
|
|
func TestCastModuleRefreshDevices(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if os.Getenv("TEST_CAST_MODULE") != "yes" {
|
|
t.Skip("Test skipped. Set environment variable TEST_CAST_MODULE=yes to run.")
|
|
|
|
return
|
|
}
|
|
|
|
logger.SetLevel(slog.LevelDebug)
|
|
|
|
server := app.NewServer(
|
|
module.ConsoleModuleFactory(),
|
|
CastModuleFactory(),
|
|
)
|
|
|
|
data, err := ioutil.ReadFile("testdata/refresh_devices.js")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := server.Load("testdata/refresh_devices.js", string(data)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
if err := server.Start(ctx); err != nil {
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
}
|
|
|
|
defer server.Stop()
|
|
|
|
result, err := server.ExecFuncByName(context.Background(), "refreshDevices")
|
|
if err != nil {
|
|
t.Error(errors.WithStack(err))
|
|
}
|
|
|
|
promise, ok := app.IsPromise(result)
|
|
if !ok {
|
|
t.Fatal("expected promise")
|
|
}
|
|
|
|
value := server.WaitForPromise(promise)
|
|
|
|
spew.Dump(value.Export())
|
|
}
|