edge/pkg/module/cast/cast_test.go

92 lines
2.1 KiB
Go
Raw Normal View History

package cast_test
2023-02-17 10:38:45 +01:00
import (
"context"
2024-01-12 14:02:53 +01:00
"fmt"
2023-02-17 10:38:45 +01:00
"os"
"testing"
"time"
"cdr.dev/slog"
"forge.cadoles.com/arcad/edge/pkg/module/cast"
2023-02-17 10:38:45 +01:00
"github.com/davecgh/go-spew/spew"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger"
// Register casting device supported types
2024-01-12 14:02:53 +01:00
_ "forge.cadoles.com/arcad/edge/pkg/module/cast/arcast"
_ "forge.cadoles.com/arcad/edge/pkg/module/cast/chromecast"
2023-02-17 10:38:45 +01:00
)
func TestCastLoadURL(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
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
devices, err := cast.ListDevices(ctx, true)
2023-02-17 10:38:45 +01:00
if err != nil {
t.Error(errors.WithStack(err))
}
t.Logf("DEVICES: %s", spew.Sdump(devices))
2024-01-12 14:02:53 +01:00
if e, g := 1, len(devices); e > g {
t.Fatalf("len(devices): expected 'value >= %v', got '%v'", e, g)
}
devices, err = cast.ListDevices(ctx, false)
if err != nil {
t.Error(errors.WithStack(err))
}
t.Logf("CACHED DEVICES: %s", spew.Sdump(devices))
2024-01-12 14:02:53 +01:00
if e, g := 1, len(devices); e > g {
t.Fatalf("len(devices): expected 'value >= %v', got '%v'", e, g)
2023-02-17 10:38:45 +01:00
}
2024-01-12 14:02:53 +01:00
for _, device := range devices {
testName := fmt.Sprintf("%s(%s)", device.DeviceType(), device.DeviceID())
func(device cast.Device) {
t.Run(testName, func(t *testing.T) {
t.Parallel()
2023-02-17 10:38:45 +01:00
2024-01-12 14:02:53 +01:00
ctx, cancel2 := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel2()
2023-02-17 10:38:45 +01:00
2024-01-12 14:02:53 +01:00
if err := cast.LoadURL(ctx, device.DeviceID(), "https://go.dev"); err != nil {
t.Error(errors.WithStack(err))
}
2023-02-17 10:38:45 +01:00
2024-01-12 14:02:53 +01:00
ctx, cancel3 := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel3()
2023-02-17 10:38:45 +01:00
2024-01-12 14:02:53 +01:00
status, err := cast.GetStatus(ctx, device.DeviceID())
if err != nil {
t.Error(errors.WithStack(err))
}
2023-02-17 10:38:45 +01:00
2024-01-12 14:02:53 +01:00
t.Logf("DEVICE STATUS: %s", spew.Sdump(status))
2023-02-17 10:38:45 +01:00
2024-01-12 14:02:53 +01:00
ctx, cancel4 := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel4()
2023-02-17 10:38:45 +01:00
2024-01-12 14:02:53 +01:00
if err := cast.StopCast(ctx, device.DeviceID()); err != nil {
t.Error(errors.WithStack(err))
}
})
}(device)
2023-02-17 10:38:45 +01:00
}
}