2023-02-17 10:38:45 +01:00
|
|
|
package cast
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"cdr.dev/slog"
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2023-04-20 19:20:52 +02:00
|
|
|
devices, err := ListDevices(ctx, true)
|
2023-02-17 10:38:45 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Error(errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
2023-04-20 19:20:52 +02:00
|
|
|
t.Logf("DEVICES: %s", spew.Sdump(devices))
|
|
|
|
|
|
|
|
if e, g := 1, len(devices); e != g {
|
|
|
|
t.Fatalf("len(devices): expected '%v', got '%v'", e, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
devices, err = ListDevices(ctx, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("CACHED DEVICES: %s", spew.Sdump(devices))
|
|
|
|
|
2023-02-17 10:38:45 +01:00
|
|
|
if e, g := 1, len(devices); e != g {
|
|
|
|
t.Fatalf("len(devices): expected '%v', got '%v'", e, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
dev := devices[0]
|
|
|
|
|
|
|
|
ctx, cancel2 := context.WithTimeout(context.Background(), 15*time.Second)
|
|
|
|
defer cancel2()
|
|
|
|
|
2023-04-05 15:12:51 +02:00
|
|
|
if err := LoadURL(ctx, dev.UUID, "https://go.dev"); err != nil {
|
2023-02-17 10:38:45 +01:00
|
|
|
t.Error(errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel3 := context.WithTimeout(context.Background(), 15*time.Second)
|
|
|
|
defer cancel3()
|
|
|
|
|
|
|
|
status, err := getStatus(ctx, dev.UUID)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
2023-04-20 19:20:52 +02:00
|
|
|
t.Logf("DEVICE STATUS: %s", spew.Sdump(status))
|
2023-02-17 10:38:45 +01:00
|
|
|
|
|
|
|
ctx, cancel4 := context.WithTimeout(context.Background(), 15*time.Second)
|
|
|
|
defer cancel4()
|
|
|
|
|
2023-04-05 15:12:51 +02:00
|
|
|
if err := StopCast(ctx, dev.UUID); err != nil {
|
2023-02-17 10:38:45 +01:00
|
|
|
t.Error(errors.WithStack(err))
|
|
|
|
}
|
|
|
|
}
|