William Petit
90020d6ea6
Some checks failed
arcad/edge/pipeline/head There was a failure building this commit
77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
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
|
|
}
|
|
|
|
logger.SetLevel(slog.LevelDebug)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
devices, err := ListDevices(ctx, true)
|
|
if err != nil {
|
|
t.Error(errors.WithStack(err))
|
|
}
|
|
|
|
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))
|
|
|
|
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()
|
|
|
|
if err := LoadURL(ctx, dev.UUID, "https://go.dev"); err != nil {
|
|
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))
|
|
}
|
|
|
|
t.Logf("DEVICE STATUS: %s", spew.Sdump(status))
|
|
|
|
ctx, cancel4 := context.WithTimeout(context.Background(), 15*time.Second)
|
|
defer cancel4()
|
|
|
|
if err := StopCast(ctx, dev.UUID); err != nil {
|
|
t.Error(errors.WithStack(err))
|
|
}
|
|
}
|