test(integration): use require.EventuallyWithT

This commit is contained in:
Rob Watson 2025-03-22 09:56:58 +01:00
parent 797ef57417
commit 2468111369

View File

@ -4,6 +4,7 @@ package app_test
import ( import (
"context" "context"
"fmt"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -121,14 +122,16 @@ func TestIntegration(t *testing.T) {
screen.PostEvent(tcell.NewEventKey(tcell.KeyDown, ' ', tcell.ModNone)) screen.PostEvent(tcell.NewEventKey(tcell.KeyDown, ' ', tcell.ModNone))
screen.PostEvent(tcell.NewEventKey(tcell.KeyRune, ' ', tcell.ModNone)) screen.PostEvent(tcell.NewEventKey(tcell.KeyRune, ' ', tcell.ModNone))
time.Sleep(15 * time.Second) require.EventuallyWithT(
t,
func(t *assert.CollectT) {
contents := getContents() contents := getContents()
fmt.Println("test")
require.True(t, len(contents) > 2, "expected at least 3 lines of output") require.True(t, len(contents) > 2, "expected at least 3 lines of output")
require.Contains(t, contents[2], "Status receiving", "expected mediaserver status to be receiving") assert.Contains(t, contents[2], "Status receiving", "expected mediaserver status to be receiving")
require.Contains(t, contents[3], "Tracks H264", "expected mediaserver tracks to be H264") assert.Contains(t, contents[3], "Tracks H264", "expected mediaserver tracks to be H264")
require.Contains(t, contents[4], "Health healthy", "expected mediaserver to be healthy") assert.Contains(t, contents[4], "Health healthy", "expected mediaserver to be healthy")
require.Contains(t, contents[2], "Local server 1", "expected local server 1 to be present") require.Contains(t, contents[2], "Local server 1", "expected local server 1 to be present")
assert.Contains(t, contents[2], "sending", "expected local server 1 to be sending") assert.Contains(t, contents[2], "sending", "expected local server 1 to be sending")
@ -138,6 +141,11 @@ func TestIntegration(t *testing.T) {
assert.Contains(t, contents[3], "sending", "expected local server 2 to be sending") assert.Contains(t, contents[3], "sending", "expected local server 2 to be sending")
assert.Contains(t, contents[3], "healthy", "expected local server 2 to be healthy") assert.Contains(t, contents[3], "healthy", "expected local server 2 to be healthy")
},
time.Minute,
time.Second,
)
// Stop destinations: // Stop destinations:
screen.PostEvent(tcell.NewEventKey(tcell.KeyRune, ' ', tcell.ModNone)) screen.PostEvent(tcell.NewEventKey(tcell.KeyRune, ' ', tcell.ModNone))
screen.PostEvent(tcell.NewEventKey(tcell.KeyUp, ' ', tcell.ModNone)) screen.PostEvent(tcell.NewEventKey(tcell.KeyUp, ' ', tcell.ModNone))
@ -145,7 +153,10 @@ func TestIntegration(t *testing.T) {
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
contents = getContents() require.EventuallyWithT(
t,
func(t *assert.CollectT) {
contents := getContents()
require.True(t, len(contents) > 2, "expected at least 3 lines of output") require.True(t, len(contents) > 2, "expected at least 3 lines of output")
require.Contains(t, contents[2], "Local server 1", "expected local server 1 to be present") require.Contains(t, contents[2], "Local server 1", "expected local server 1 to be present")
@ -153,6 +164,10 @@ func TestIntegration(t *testing.T) {
require.Contains(t, contents[3], "Local server 2", "expected local server 2 to be present") require.Contains(t, contents[3], "Local server 2", "expected local server 2 to be present")
assert.Contains(t, contents[3], "exited", "expected local server 2 to have exited") assert.Contains(t, contents[3], "exited", "expected local server 2 to have exited")
},
time.Minute,
time.Second,
)
// TODO: // TODO:
// - Source error // - Source error