Browse Source

rewrite TestSource

pull/235/head
aler9 5 years ago
parent
commit
ac04b7afb4
  1. 90
      main_test.go

90
main_test.go

@ -685,21 +685,26 @@ func TestAuthIpFail(t *testing.T) { @@ -685,21 +685,26 @@ func TestAuthIpFail(t *testing.T) {
require.NotEqual(t, 0, cnt1.wait())
}
func TestSourceRtsp(t *testing.T) {
for _, proto := range []string{
"udp",
"tcp",
func TestSource(t *testing.T) {
for _, source := range []string{
"rtsp_udp",
"rtsp_tcp",
"rtsps",
"rtmp",
} {
t.Run(proto, func(t *testing.T) {
p1, ok := testProgram("paths:\n" +
t.Run(source, func(t *testing.T) {
switch source {
case "rtsp_udp", "rtsp_tcp":
p1, ok := testProgram("rtspPort: 8555\n" +
"rtpPort: 8100\n" +
"rtcpPort: 8101\n" +
"paths:\n" +
" all:\n" +
" readUser: testuser\n" +
" readPass: testpass\n")
require.Equal(t, true, ok)
defer p1.close()
time.Sleep(1 * time.Second)
cnt1, err := newContainer("ffmpeg", "source", []string{
"-re",
"-stream_loop", "-1",
@ -707,43 +712,20 @@ func TestSourceRtsp(t *testing.T) { @@ -707,43 +712,20 @@ func TestSourceRtsp(t *testing.T) {
"-c", "copy",
"-f", "rtsp",
"-rtsp_transport", "udp",
"rtsp://" + ownDockerIP + ":8554/teststream",
"rtsp://" + ownDockerIP + ":8555/teststream",
})
require.NoError(t, err)
defer cnt1.close()
time.Sleep(1 * time.Second)
p2, ok := testProgram("rtspPort: 8555\n" +
"rtpPort: 8100\n" +
"rtcpPort: 8101\n" +
"\n" +
"paths:\n" +
p2, ok := testProgram("paths:\n" +
" proxied:\n" +
" source: rtsp://testuser:testpass@localhost:8554/teststream\n" +
" sourceProtocol: " + proto + "\n" +
" source: rtsp://testuser:testpass@localhost:8555/teststream\n" +
" sourceProtocol: " + source[len("rtsp_"):] + "\n" +
" sourceOnDemand: yes\n")
require.Equal(t, true, ok)
defer p2.close()
time.Sleep(1 * time.Second)
cnt2, err := newContainer("ffmpeg", "dest", []string{
"-rtsp_transport", "udp",
"-i", "rtsp://" + ownDockerIP + ":8555/proxied",
"-vframes", "1",
"-f", "image2",
"-y", "/dev/null",
})
require.NoError(t, err)
defer cnt2.close()
require.Equal(t, 0, cnt2.wait())
})
}
}
func TestSourceRtsps(t *testing.T) {
case "rtsps":
serverCertFpath, err := writeTempFile(serverCert)
require.NoError(t, err)
defer os.Remove(serverCertFpath)
@ -752,7 +734,10 @@ func TestSourceRtsps(t *testing.T) { @@ -752,7 +734,10 @@ func TestSourceRtsps(t *testing.T) {
require.NoError(t, err)
defer os.Remove(serverKeyFpath)
p, ok := testProgram("readTimeout: 20s\n" +
p, ok := testProgram("rtspPort: 8555\n" +
"rtpPort: 8100\n" +
"rtcpPort: 8101\n" +
"readTimeout: 20s\n" +
"protocols: [tcp]\n" +
"encryption: yes\n" +
"serverCert: " + serverCertFpath + "\n" +
@ -764,8 +749,6 @@ func TestSourceRtsps(t *testing.T) { @@ -764,8 +749,6 @@ func TestSourceRtsps(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
time.Sleep(1 * time.Second)
cnt1, err := newContainer("ffmpeg", "source", []string{
"-re",
"-stream_loop", "-1",
@ -779,39 +762,18 @@ func TestSourceRtsps(t *testing.T) { @@ -779,39 +762,18 @@ func TestSourceRtsps(t *testing.T) {
time.Sleep(1 * time.Second)
p2, ok := testProgram("rtspPort: 8556\n" +
"rtpPort: 8100\n" +
"rtcpPort: 8101\n" +
"\n" +
"paths:\n" +
p2, ok := testProgram("paths:\n" +
" proxied:\n" +
" source: rtsps://testuser:testpass@localhost:8555/teststream\n" +
" sourceOnDemand: yes\n")
require.Equal(t, true, ok)
defer p2.close()
time.Sleep(1 * time.Second)
cnt2, err := newContainer("ffmpeg", "dest", []string{
"-rtsp_transport", "udp",
"-i", "rtsp://" + ownDockerIP + ":8556/proxied",
"-vframes", "1",
"-f", "image2",
"-y", "/dev/null",
})
require.NoError(t, err)
defer cnt2.close()
require.Equal(t, 0, cnt2.wait())
}
func TestSourceRtmp(t *testing.T) {
case "rtmp":
cnt1, err := newContainer("nginx-rtmp", "rtmpserver", []string{})
require.NoError(t, err)
defer cnt1.close()
time.Sleep(1 * time.Second)
cnt2, err := newContainer("ffmpeg", "source", []string{
"-re",
"-stream_loop", "-1",
@ -831,6 +793,7 @@ func TestSourceRtmp(t *testing.T) { @@ -831,6 +793,7 @@ func TestSourceRtmp(t *testing.T) {
" sourceOnDemand: yes\n")
require.Equal(t, true, ok)
defer p.close()
}
time.Sleep(1 * time.Second)
@ -843,8 +806,9 @@ func TestSourceRtmp(t *testing.T) { @@ -843,8 +806,9 @@ func TestSourceRtmp(t *testing.T) {
})
require.NoError(t, err)
defer cnt3.close()
require.Equal(t, 0, cnt3.wait())
})
}
}
func TestRedirect(t *testing.T) {

Loading…
Cancel
Save