2023-02-17 10:38:45 +01:00
|
|
|
package cast
|
|
|
|
|
|
|
|
import (
|
2023-03-01 13:04:40 +01:00
|
|
|
"context"
|
2023-02-17 10:38:45 +01:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
if testing.Verbose() {
|
|
|
|
logger.SetLevel(slog.LevelDebug)
|
|
|
|
}
|
2023-02-17 10:38:45 +01:00
|
|
|
|
|
|
|
server := app.NewServer(
|
|
|
|
module.ConsoleModuleFactory(),
|
|
|
|
CastModuleFactory(),
|
|
|
|
)
|
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
script := "testdata/cast.js"
|
2023-02-17 10:38:45 +01:00
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
data, err := os.ReadFile(script)
|
|
|
|
if err != nil {
|
2023-02-17 10:38:45 +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-02-17 10:38:45 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
if testing.Verbose() {
|
|
|
|
logger.SetLevel(slog.LevelDebug)
|
|
|
|
}
|
2023-02-17 10:38:45 +01:00
|
|
|
|
|
|
|
server := app.NewServer(
|
|
|
|
module.ConsoleModuleFactory(),
|
|
|
|
CastModuleFactory(),
|
|
|
|
)
|
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
script := "testdata/refresh_devices.js"
|
2023-02-17 10:38:45 +01:00
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
data, err := os.ReadFile(script)
|
|
|
|
if err != nil {
|
2023-02-17 10:38:45 +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-02-17 10:38:45 +01:00
|
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
defer server.Stop()
|
|
|
|
|
2023-03-01 13:04:40 +01:00
|
|
|
result, err := server.ExecFuncByName(context.Background(), "refreshDevices")
|
2023-02-17 10:38:45 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
2023-11-28 16:35:49 +01:00
|
|
|
spew.Dump(result)
|
2023-02-17 10:38:45 +01:00
|
|
|
}
|