rewrite TestAuth and TestPath

This commit is contained in:
aler9 2021-01-30 19:10:41 +01:00
parent ac04b7afb4
commit 4920a1d6a1

View File

@ -348,68 +348,49 @@ func TestTCPOnly(t *testing.T) {
require.Equal(t, 0, cnt2.wait()) require.Equal(t, 0, cnt2.wait())
} }
func TestPathWithSlash(t *testing.T) { func TestPath(t *testing.T) {
p, ok := testProgram("") for _, ca := range []struct {
require.Equal(t, true, ok) name string
defer p.close() path string
}{
{
"with slash",
"test/stream",
},
{
"with query",
"test?param1=val&param2=val",
},
} {
t.Run(ca.name, func(t *testing.T) {
p, ok := testProgram("")
require.Equal(t, true, ok)
defer p.close()
time.Sleep(1 * time.Second) cnt1, err := newContainer("ffmpeg", "source", []string{
"-re",
"-stream_loop", "-1",
"-i", "emptyvideo.ts",
"-c", "copy",
"-f", "rtsp",
"-rtsp_transport", "udp",
"rtsp://" + ownDockerIP + ":8554/" + ca.path,
})
require.NoError(t, err)
defer cnt1.close()
cnt1, err := newContainer("ffmpeg", "source", []string{ cnt2, err := newContainer("ffmpeg", "dest", []string{
"-re", "-rtsp_transport", "udp",
"-stream_loop", "-1", "-i", "rtsp://" + ownDockerIP + ":8554/" + ca.path,
"-i", "emptyvideo.ts", "-vframes", "1",
"-c", "copy", "-f", "image2",
"-f", "rtsp", "-y", "/dev/null",
"-rtsp_transport", "udp", })
"rtsp://" + ownDockerIP + ":8554/test/stream", require.NoError(t, err)
}) defer cnt2.close()
require.NoError(t, err) require.Equal(t, 0, cnt2.wait())
defer cnt1.close() })
}
cnt2, err := newContainer("ffmpeg", "dest", []string{
"-rtsp_transport", "udp",
"-i", "rtsp://" + ownDockerIP + ":8554/test/stream",
"-vframes", "1",
"-f", "image2",
"-y", "/dev/null",
})
require.NoError(t, err)
defer cnt2.close()
require.Equal(t, 0, cnt2.wait())
}
func TestPathWithQuery(t *testing.T) {
p, ok := testProgram("")
require.Equal(t, true, ok)
defer p.close()
time.Sleep(1 * time.Second)
cnt1, err := newContainer("ffmpeg", "source", []string{
"-re",
"-stream_loop", "-1",
"-i", "emptyvideo.ts",
"-c", "copy",
"-f", "rtsp",
"-rtsp_transport", "udp",
"rtsp://" + ownDockerIP + ":8554/test?param1=val&param2=val",
})
require.NoError(t, err)
defer cnt1.close()
cnt2, err := newContainer("ffmpeg", "dest", []string{
"-rtsp_transport", "udp",
"-i", "rtsp://" + ownDockerIP + ":8554/test?param3=otherval",
"-vframes", "1",
"-f", "image2",
"-y", "/dev/null",
})
require.NoError(t, err)
defer cnt2.close()
require.Equal(t, 0, cnt2.wait())
} }
func TestAuth(t *testing.T) { func TestAuth(t *testing.T) {
@ -422,8 +403,6 @@ func TestAuth(t *testing.T) {
require.Equal(t, true, ok) require.Equal(t, true, ok)
defer p.close() defer p.close()
time.Sleep(1 * time.Second)
cnt1, err := newContainer("ffmpeg", "source", []string{ cnt1, err := newContainer("ffmpeg", "source", []string{
"-re", "-re",
"-stream_loop", "-1", "-stream_loop", "-1",
@ -447,7 +426,6 @@ func TestAuth(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
defer cnt2.close() defer cnt2.close()
require.Equal(t, 0, cnt2.wait()) require.Equal(t, 0, cnt2.wait())
}) })
@ -464,8 +442,6 @@ func TestAuth(t *testing.T) {
require.Equal(t, true, ok) require.Equal(t, true, ok)
defer p.close() defer p.close()
time.Sleep(1 * time.Second)
cnt1, err := newContainer("ffmpeg", "source", []string{ cnt1, err := newContainer("ffmpeg", "source", []string{
"-re", "-re",
"-stream_loop", "-1", "-stream_loop", "-1",
@ -490,7 +466,6 @@ func TestAuth(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
defer cnt2.close() defer cnt2.close()
require.Equal(t, 0, cnt2.wait()) require.Equal(t, 0, cnt2.wait())
} else { } else {
@ -499,46 +474,42 @@ func TestAuth(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
defer cnt2.close() defer cnt2.close()
require.Equal(t, 0, cnt2.wait()) require.Equal(t, 0, cnt2.wait())
} }
}) })
} }
}
func TestAuthHashed(t *testing.T) { t.Run("hashed", func(t *testing.T) {
p, ok := testProgram("paths:\n" + p, ok := testProgram("paths:\n" +
" all:\n" + " all:\n" +
" readUser: sha256:rl3rgi4NcZkpAEcacZnQ2VuOfJ0FxAqCRaKB/SwdZoQ=\n" + " readUser: sha256:rl3rgi4NcZkpAEcacZnQ2VuOfJ0FxAqCRaKB/SwdZoQ=\n" +
" readPass: sha256:E9JJ8stBJ7QM+nV4ZoUCeHk/gU3tPFh/5YieiJp6n2w=\n") " readPass: sha256:E9JJ8stBJ7QM+nV4ZoUCeHk/gU3tPFh/5YieiJp6n2w=\n")
require.Equal(t, true, ok) require.Equal(t, true, ok)
defer p.close() defer p.close()
time.Sleep(1 * time.Second) cnt1, err := newContainer("ffmpeg", "source", []string{
"-re",
"-stream_loop", "-1",
"-i", "emptyvideo.ts",
"-c", "copy",
"-f", "rtsp",
"-rtsp_transport", "udp",
"rtsp://" + ownDockerIP + ":8554/test/stream",
})
require.NoError(t, err)
defer cnt1.close()
cnt1, err := newContainer("ffmpeg", "source", []string{ cnt2, err := newContainer("ffmpeg", "dest", []string{
"-re", "-rtsp_transport", "udp",
"-stream_loop", "-1", "-i", "rtsp://testuser:testpass@" + ownDockerIP + ":8554/test/stream",
"-i", "emptyvideo.ts", "-vframes", "1",
"-c", "copy", "-f", "image2",
"-f", "rtsp", "-y", "/dev/null",
"-rtsp_transport", "udp", })
"rtsp://" + ownDockerIP + ":8554/test/stream", require.NoError(t, err)
defer cnt2.close()
require.Equal(t, 0, cnt2.wait())
}) })
require.NoError(t, err)
defer cnt1.close()
cnt2, err := newContainer("ffmpeg", "dest", []string{
"-rtsp_transport", "udp",
"-i", "rtsp://testuser:testpass@" + ownDockerIP + ":8554/test/stream",
"-vframes", "1",
"-f", "image2",
"-y", "/dev/null",
})
require.NoError(t, err)
defer cnt2.close()
require.Equal(t, 0, cnt2.wait())
} }
func TestAuthFail(t *testing.T) { func TestAuthFail(t *testing.T) {