From cffaee955767f16fc242f431f51a0ac1cc4bbe11 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Sat, 12 Apr 2025 20:42:41 +0200 Subject: [PATCH] fixup! refactor(container): restart handling --- internal/app/integration_test.go | 89 +++++++++++++++++++++++++++- internal/container/container_test.go | 2 +- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/internal/app/integration_test.go b/internal/app/integration_test.go index ddca547..eb0ae57 100644 --- a/internal/app/integration_test.go +++ b/internal/app/integration_test.go @@ -266,7 +266,6 @@ func testIntegration(t *testing.T, streamKey string) { // TODO: // - Source error - // - Destination error // - Additional features (copy URL, etc.) cancel() @@ -274,6 +273,94 @@ func testIntegration(t *testing.T, streamKey string) { <-done } +func TestIntegrationStartDestinationFailed(t *testing.T) { + ctx, cancel := context.WithTimeout(t.Context(), 10*time.Minute) + defer cancel() + + logger := testhelpers.NewTestLogger(t).With("component", "integration") + dockerClient, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv, dockerclient.WithAPIVersionNegotiation()) + require.NoError(t, err) + + screen, screenCaptureC, getContents := setupSimulationScreen(t) + + configService := setupConfigService(t, config.Config{ + Sources: config.Sources{RTMP: config.RTMPSource{Enabled: true}}, + Destinations: []config.Destination{{Name: "Example server", URL: "rtmp://rtmp.example.com/live"}}, + }) + + done := make(chan struct{}) + go func() { + defer func() { + done <- struct{}{} + }() + + err := app.Run(ctx, app.RunParams{ + ConfigService: configService, + DockerClient: dockerClient, + Screen: &terminal.Screen{ + Screen: screen, + Width: 160, + Height: 25, + CaptureC: screenCaptureC, + }, + ClipboardAvailable: false, + BuildInfo: domain.BuildInfo{Version: "0.0.1", GoVersion: "go1.16.3"}, + Logger: logger, + }) + require.NoError(t, err) + }() + + require.EventuallyWithT( + t, + func(t *assert.CollectT) { + contents := getContents() + require.True(t, len(contents) > 2, "expected at least 3 lines of output") + + assert.Contains(t, contents[2], "Status waiting for stream", "expected mediaserver status to be waiting") + }, + 2*time.Minute, + time.Second, + "expected the mediaserver to start", + ) + printScreen(getContents, "After starting the mediaserver") + + // Start streaming a test video to the app: + testhelpers.StreamFLV(t, "rtmp://localhost:1935/live") + + require.EventuallyWithT( + t, + func(t *assert.CollectT) { + contents := getContents() + require.True(t, len(contents) > 3, "expected at least 3 lines of output") + + assert.Contains(t, contents[2], "Status receiving", "expected mediaserver status to be receiving") + }, + time.Minute, + time.Second, + "expected to receive an ingress stream", + ) + printScreen(getContents, "After receiving the ingress stream") + + // Start destination: + sendKey(screen, tcell.KeyRune, ' ') + + require.EventuallyWithT( + t, + func(t *assert.CollectT) { + contents := getContents() + assert.True(t, contentsIncludes(contents, "Streaming to Example server failed:"), "expected to see destination error") + assert.True(t, contentsIncludes(contents, "container failed to start"), "expected to see destination error") + }, + time.Minute, + time.Second, + "expected to see the destination start error modal", + ) + printScreen(getContents, "After starting the destination stream fails") + + cancel() + + <-done +} func TestIntegrationDestinationValidations(t *testing.T) { ctx, cancel := context.WithTimeout(t.Context(), 10*time.Minute) defer cancel() diff --git a/internal/container/container_test.go b/internal/container/container_test.go index eb8fca3..7248b2a 100644 --- a/internal/container/container_test.go +++ b/internal/container/container_test.go @@ -44,7 +44,7 @@ func TestClientRunContainer(t *testing.T) { dockerClient. EXPECT(). ImagePull(mock.Anything, "alpine", image.PullOptions{}). - Return(io.NopCloser(bytes.NewReader(nil)), errors.New("error pulling image should not be fatal")) + Return(nil, errors.New("error pulling image should not be fatal")) dockerClient. EXPECT(). ContainerCreate(mock.Anything, mock.Anything, mock.Anything, mock.Anything, (*ocispec.Platform)(nil), mock.Anything).