WIP: refactor/api #1
@ -3,6 +3,7 @@
|
||||
package app_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -21,6 +22,7 @@ import (
|
||||
"git.netflux.io/rob/octoplex/internal/domain"
|
||||
"git.netflux.io/rob/octoplex/internal/terminal"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
)
|
||||
@ -75,6 +77,28 @@ func buildClientServer(
|
||||
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) {
|
||||
t.Helper()
|
||||
|
||||
|
@ -128,19 +128,7 @@ func testIntegration(t *testing.T, mediaServerConfig config.MediaServerSource) {
|
||||
|
||||
client, server := buildClientServer(configService, dockerClient, screen, screenCaptureC, logger)
|
||||
var wg sync.WaitGroup
|
||||
|
||||
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")
|
||||
}()
|
||||
runClientServer(ctx, t, &wg, client, server)
|
||||
|
||||
require.EventuallyWithT(
|
||||
t,
|
||||
@ -304,14 +292,9 @@ func TestIntegrationCustomHost(t *testing.T) {
|
||||
})
|
||||
screen, screenCaptureC, getContents := setupSimulationScreen(t)
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer func() {
|
||||
done <- struct{}{}
|
||||
}()
|
||||
|
||||
require.Equal(t, context.Canceled, app.New(buildAppParams(t, configService, dockerClient, screen, screenCaptureC, logger)).Run(ctx))
|
||||
}()
|
||||
client, server := buildClientServer(configService, dockerClient, screen, screenCaptureC, logger)
|
||||
var wg sync.WaitGroup
|
||||
runClientServer(ctx, t, &wg, client, server)
|
||||
|
||||
time.Sleep(time.Second)
|
||||
sendKey(t, screen, tcell.KeyF1, ' ')
|
||||
@ -351,7 +334,7 @@ func TestIntegrationCustomHost(t *testing.T) {
|
||||
|
||||
cancel()
|
||||
|
||||
<-done
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestIntegrationCustomTLSCerts(t *testing.T) {
|
||||
@ -375,14 +358,9 @@ func TestIntegrationCustomTLSCerts(t *testing.T) {
|
||||
})
|
||||
screen, screenCaptureC, getContents := setupSimulationScreen(t)
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer func() {
|
||||
done <- struct{}{}
|
||||
}()
|
||||
|
||||
require.Equal(t, context.Canceled, app.New(buildAppParams(t, configService, dockerClient, screen, screenCaptureC, logger)).Run(ctx))
|
||||
}()
|
||||
client, server := buildClientServer(configService, dockerClient, screen, screenCaptureC, logger)
|
||||
var wg sync.WaitGroup
|
||||
runClientServer(ctx, t, &wg, client, server)
|
||||
|
||||
require.EventuallyWithT(
|
||||
t,
|
||||
@ -417,7 +395,7 @@ func TestIntegrationCustomTLSCerts(t *testing.T) {
|
||||
|
||||
cancel()
|
||||
|
||||
<-done
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestIntegrationRestartDestination(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user