diff --git a/main_rtmp_test.go b/main_clientrtmp_test.go similarity index 96% rename from main_rtmp_test.go rename to main_clientrtmp_test.go index 551a9067..e9f1c491 100644 --- a/main_rtmp_test.go +++ b/main_clientrtmp_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestRTMPPublish(t *testing.T) { +func TestClientRTMPPublish(t *testing.T) { p, ok := testProgram("") require.Equal(t, true, ok) defer p.close() @@ -37,7 +37,7 @@ func TestRTMPPublish(t *testing.T) { require.Equal(t, 0, cnt2.wait()) } -func TestRTMPRead(t *testing.T) { +func TestClientRTMPRead(t *testing.T) { p, ok := testProgram("") require.Equal(t, true, ok) defer p.close() @@ -66,7 +66,7 @@ func TestRTMPRead(t *testing.T) { require.Equal(t, 0, cnt2.wait()) } -func TestRTMPAuth(t *testing.T) { +func TestClientRTMPAuth(t *testing.T) { t.Run("publish", func(t *testing.T) { p, ok := testProgram("rtspDisable: yes\n" + "paths:\n" + @@ -134,7 +134,7 @@ func TestRTMPAuth(t *testing.T) { }) } -func TestRTMPAuthFail(t *testing.T) { +func TestClientRTMPAuthFail(t *testing.T) { t.Run("publish", func(t *testing.T) { p, ok := testProgram("rtspDisable: yes\n" + "paths:\n" + diff --git a/main_rtsp_test.go b/main_clientrtsp_test.go similarity index 97% rename from main_rtsp_test.go rename to main_clientrtsp_test.go index 69aec16f..f336fc08 100644 --- a/main_rtsp_test.go +++ b/main_clientrtsp_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestRTSPPublishRead(t *testing.T) { +func TestClientRTSPPublishRead(t *testing.T) { for _, ca := range []struct { encrypted bool publisherSoft string @@ -149,7 +149,7 @@ func TestRTSPPublishRead(t *testing.T) { } } -func TestRTSPAuth(t *testing.T) { +func TestClientRTSPAuth(t *testing.T) { t.Run("publish", func(t *testing.T) { p, ok := testProgram("rtmpDisable: yes\n" + "paths:\n" + @@ -271,7 +271,7 @@ func TestRTSPAuth(t *testing.T) { }) } -func TestRTSPAuthFail(t *testing.T) { +func TestClientRTSPAuthFail(t *testing.T) { for _, ca := range []struct { name string user string @@ -389,7 +389,7 @@ func TestRTSPAuthFail(t *testing.T) { } } -func TestRTSPAuthIpFail(t *testing.T) { +func TestClientRTSPAuthIpFail(t *testing.T) { p, ok := testProgram("rtmpDisable: yes\n" + "paths:\n" + " all:\n" + @@ -411,7 +411,7 @@ func TestRTSPAuthIpFail(t *testing.T) { require.NotEqual(t, 0, cnt1.wait()) } -func TestRTSPAutomaticProtocol(t *testing.T) { +func TestClientRTSPAutomaticProtocol(t *testing.T) { for _, source := range []string{ "ffmpeg", } { @@ -448,7 +448,7 @@ func TestRTSPAutomaticProtocol(t *testing.T) { } } -func TestRTSPPublisherOverride(t *testing.T) { +func TestClientRTSPPublisherOverride(t *testing.T) { p, ok := testProgram("rtmpDisable: yes\n") require.Equal(t, true, ok) defer p.close() @@ -490,7 +490,7 @@ func TestRTSPPublisherOverride(t *testing.T) { require.Equal(t, 0, dest.wait()) } -func TestRTSPNonCompliantFrameSize(t *testing.T) { +func TestClientRTSPNonCompliantFrameSize(t *testing.T) { t.Run("publish", func(t *testing.T) { p, ok := testProgram("rtmpDisable: yes\n" + "readBufferSize: 4500\n") @@ -580,7 +580,7 @@ func TestRTSPNonCompliantFrameSize(t *testing.T) { }) } -func TestRTSPRTPInfo(t *testing.T) { +func TestClientRTSPRTPInfo(t *testing.T) { p, ok := testProgram("rtmpDisable: yes\n") require.Equal(t, true, ok) defer p.close() @@ -683,7 +683,7 @@ func TestRTSPRTPInfo(t *testing.T) { }() } -func TestRTSPRedirect(t *testing.T) { +func TestClientRTSPRedirect(t *testing.T) { p1, ok := testProgram("rtmpDisable: yes\n" + "paths:\n" + " path1:\n" + @@ -719,7 +719,7 @@ func TestRTSPRedirect(t *testing.T) { require.Equal(t, 0, cnt2.wait()) } -func TestRTSPFallback(t *testing.T) { +func TestClientRTSPFallback(t *testing.T) { for _, ca := range []string{ "absolute", "relative", @@ -768,7 +768,7 @@ func TestRTSPFallback(t *testing.T) { } } -func TestRTSPRunOnDemand(t *testing.T) { +func TestClientRTSPRunOnDemand(t *testing.T) { doneFile := filepath.Join(os.TempDir(), "ondemand_done") onDemandFile, err := writeTempFile([]byte(fmt.Sprintf(`#!/bin/sh trap 'touch %s; [ -z "$(jobs -p)" ] || kill $(jobs -p)' INT diff --git a/main_sourcertmp_test.go b/main_sourcertmp_test.go new file mode 100644 index 00000000..5f05ce62 --- /dev/null +++ b/main_sourcertmp_test.go @@ -0,0 +1,62 @@ +package main + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +func TestSourceRTMP(t *testing.T) { + for _, source := range []string{ + "videoaudio", + "video", + } { + t.Run(source, func(t *testing.T) { + switch source { + case "videoaudio", "video": + cnt1, err := newContainer("nginx-rtmp", "rtmpserver", []string{}) + require.NoError(t, err) + defer cnt1.close() + + input := "emptyvideoaudio.ts" + if source == "video" { + input = "emptyvideo.ts" + } + + cnt2, err := newContainer("ffmpeg", "source", []string{ + "-re", + "-stream_loop", "-1", + "-i", input, + "-c", "copy", + "-f", "flv", + "rtmp://" + cnt1.ip() + "/stream/test", + }) + require.NoError(t, err) + defer cnt2.close() + + time.Sleep(1 * time.Second) + + p, ok := testProgram("paths:\n" + + " proxied:\n" + + " source: rtmp://" + cnt1.ip() + "/stream/test\n" + + " sourceOnDemand: yes\n") + require.Equal(t, true, ok) + defer p.close() + } + + time.Sleep(1 * time.Second) + + cnt3, err := newContainer("ffmpeg", "dest", []string{ + "-rtsp_transport", "udp", + "-i", "rtsp://" + ownDockerIP + ":8554/proxied", + "-vframes", "1", + "-f", "image2", + "-y", "/dev/null", + }) + require.NoError(t, err) + defer cnt3.close() + require.Equal(t, 0, cnt3.wait()) + }) + } +} diff --git a/main_source_test.go b/main_sourcertsp_test.go similarity index 72% rename from main_source_test.go rename to main_sourcertsp_test.go index bcde386c..8077e7b8 100644 --- a/main_source_test.go +++ b/main_sourcertsp_test.go @@ -8,17 +8,15 @@ import ( "github.com/stretchr/testify/require" ) -func TestSource(t *testing.T) { +func TestSourceRTSP(t *testing.T) { for _, source := range []string{ - "rtsp_udp", - "rtsp_tcp", - "rtsps", - "rtmp_videoaudio", - "rtmp_video", + "udp", + "tcp", + "tls", } { t.Run(source, func(t *testing.T) { switch source { - case "rtsp_udp", "rtsp_tcp": + case "udp", "tcp": p1, ok := testProgram("rtmpDisable: yes\n" + "rtspPort: 8555\n" + "rtpPort: 8100\n" + @@ -46,12 +44,12 @@ func TestSource(t *testing.T) { "paths:\n" + " proxied:\n" + " source: rtsp://testuser:testpass@localhost:8555/teststream\n" + - " sourceProtocol: " + source[len("rtsp_"):] + "\n" + + " sourceProtocol: " + source[len(""):] + "\n" + " sourceOnDemand: yes\n") require.Equal(t, true, ok) defer p2.close() - case "rtsps": + case "tls": serverCertFpath, err := writeTempFile(serverCert) require.NoError(t, err) defer os.Remove(serverCertFpath) @@ -96,36 +94,6 @@ func TestSource(t *testing.T) { " sourceOnDemand: yes\n") require.Equal(t, true, ok) defer p2.close() - - case "rtmp_videoaudio", "rtmp_video": - cnt1, err := newContainer("nginx-rtmp", "rtmpserver", []string{}) - require.NoError(t, err) - defer cnt1.close() - - input := "emptyvideoaudio.ts" - if source == "rtmp_video" { - input = "emptyvideo.ts" - } - - cnt2, err := newContainer("ffmpeg", "source", []string{ - "-re", - "-stream_loop", "-1", - "-i", input, - "-c", "copy", - "-f", "flv", - "rtmp://" + cnt1.ip() + "/stream/test", - }) - require.NoError(t, err) - defer cnt2.close() - - time.Sleep(1 * time.Second) - - p, ok := testProgram("paths:\n" + - " proxied:\n" + - " source: rtmp://" + cnt1.ip() + "/stream/test\n" + - " sourceOnDemand: yes\n") - require.Equal(t, true, ok) - defer p.close() } time.Sleep(1 * time.Second)