package cast import ( "context" "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 } if testing.Verbose() { logger.SetLevel(slog.LevelDebug) } server := app.NewServer( module.ConsoleModuleFactory(), CastModuleFactory(), ) script := "testdata/cast.js" data, err := os.ReadFile(script) if err != nil { t.Fatal(err) } ctx := context.Background() if err := server.Start(ctx, script, string(data)); 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 } if testing.Verbose() { logger.SetLevel(slog.LevelDebug) } server := app.NewServer( module.ConsoleModuleFactory(), CastModuleFactory(), ) script := "testdata/refresh_devices.js" data, err := os.ReadFile(script) if err != nil { t.Fatal(err) } ctx := context.Background() if err := server.Start(ctx, script, string(data)); 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)) } spew.Dump(result) }