fixup! wip: refactor: API

This commit is contained in:
Rob Watson 2025-05-10 21:47:10 +02:00
parent 59b0a060ba
commit c706a41acd
2 changed files with 33 additions and 31 deletions

View File

@ -3,6 +3,7 @@
package app_test package app_test
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
@ -21,6 +22,7 @@ import (
"git.netflux.io/rob/octoplex/internal/domain" "git.netflux.io/rob/octoplex/internal/domain"
"git.netflux.io/rob/octoplex/internal/terminal" "git.netflux.io/rob/octoplex/internal/terminal"
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go"
) )
@ -75,6 +77,28 @@ func buildClientServer(
return clientApp, srvApp return clientApp, srvApp
} }
func runClientServer(
ctx context.Context,
t *testing.T,
wg *sync.WaitGroup,
clientApp *client.App,
serverApp *app.App,
) {
wg.Add(1)
go func() {
defer wg.Done()
assert.ErrorIs(t, serverApp.Run(ctx), context.Canceled)
}()
wg.Add(1)
go func() {
defer wg.Done()
// May be a gRPC error, not context.Canceled:
assert.ErrorContains(t, clientApp.Run(ctx), "context canceled")
}()
}
func setupSimulationScreen(t *testing.T) (tcell.SimulationScreen, chan<- terminal.ScreenCapture, func() []string) { func setupSimulationScreen(t *testing.T) (tcell.SimulationScreen, chan<- terminal.ScreenCapture, func() []string) {
t.Helper() t.Helper()

View File

@ -128,19 +128,7 @@ func testIntegration(t *testing.T, mediaServerConfig config.MediaServerSource) {
client, server := buildClientServer(configService, dockerClient, screen, screenCaptureC, logger) client, server := buildClientServer(configService, dockerClient, screen, screenCaptureC, logger)
var wg sync.WaitGroup var wg sync.WaitGroup
runClientServer(ctx, t, &wg, client, server)
wg.Add(1)
go func() {
defer wg.Done()
assert.ErrorIs(t, server.Run(ctx), context.Canceled)
}()
wg.Add(1)
go func() {
defer wg.Done()
// May be a gRPC error, not context.Canceled:
assert.ErrorContains(t, client.Run(ctx), "context canceled")
}()
require.EventuallyWithT( require.EventuallyWithT(
t, t,
@ -304,14 +292,9 @@ func TestIntegrationCustomHost(t *testing.T) {
}) })
screen, screenCaptureC, getContents := setupSimulationScreen(t) screen, screenCaptureC, getContents := setupSimulationScreen(t)
done := make(chan struct{}) client, server := buildClientServer(configService, dockerClient, screen, screenCaptureC, logger)
go func() { var wg sync.WaitGroup
defer func() { runClientServer(ctx, t, &wg, client, server)
done <- struct{}{}
}()
require.Equal(t, context.Canceled, app.New(buildAppParams(t, configService, dockerClient, screen, screenCaptureC, logger)).Run(ctx))
}()
time.Sleep(time.Second) time.Sleep(time.Second)
sendKey(t, screen, tcell.KeyF1, ' ') sendKey(t, screen, tcell.KeyF1, ' ')
@ -351,7 +334,7 @@ func TestIntegrationCustomHost(t *testing.T) {
cancel() cancel()
<-done wg.Wait()
} }
func TestIntegrationCustomTLSCerts(t *testing.T) { func TestIntegrationCustomTLSCerts(t *testing.T) {
@ -375,14 +358,9 @@ func TestIntegrationCustomTLSCerts(t *testing.T) {
}) })
screen, screenCaptureC, getContents := setupSimulationScreen(t) screen, screenCaptureC, getContents := setupSimulationScreen(t)
done := make(chan struct{}) client, server := buildClientServer(configService, dockerClient, screen, screenCaptureC, logger)
go func() { var wg sync.WaitGroup
defer func() { runClientServer(ctx, t, &wg, client, server)
done <- struct{}{}
}()
require.Equal(t, context.Canceled, app.New(buildAppParams(t, configService, dockerClient, screen, screenCaptureC, logger)).Run(ctx))
}()
require.EventuallyWithT( require.EventuallyWithT(
t, t,
@ -417,7 +395,7 @@ func TestIntegrationCustomTLSCerts(t *testing.T) {
cancel() cancel()
<-done wg.Wait()
} }
func TestIntegrationRestartDestination(t *testing.T) { func TestIntegrationRestartDestination(t *testing.T) {