From bec905ed9c3a4ec8c5e836bfd1a04b978bc472a3 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Fri, 7 May 2021 12:59:50 +0200 Subject: [PATCH] base: improve tests --- pkg/base/request_test.go | 21 ++++++++++++++++++--- pkg/base/response_test.go | 10 ++++++++++ track.go | 1 - 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pkg/base/request_test.go b/pkg/base/request_test.go index 4a007426..a6ac549c 100644 --- a/pkg/base/request_test.go +++ b/pkg/base/request_test.go @@ -168,20 +168,25 @@ func TestRequestReadErrors(t *testing.T) { "EOF", }, { - "missing url, protocol, eol", + "missing url, protocol, r, n", []byte("GET"), "EOF", }, { - "missing protocol, eol", + "missing protocol, r, n", []byte("GET rtsp://testing123/test"), "EOF", }, { - "missing eol", + "missing r, n", []byte("GET rtsp://testing123/test RTSP/1.0"), "EOF", }, + { + "missing n", + []byte("GET rtsp://testing123/test RTSP/1.0\r"), + "EOF", + }, { "empty method", []byte(" rtsp://testing123 RTSP/1.0\r\n"), @@ -207,6 +212,16 @@ func TestRequestReadErrors(t *testing.T) { []byte("GET rtsp://testing123 RTSP/2.0\r\n"), "expected 'RTSP/1.0', got 'RTSP/2.0'", }, + { + "invalid header", + []byte("GET rtsp://testing123 RTSP/1.0\r\nTesting: val\r"), + "EOF", + }, + { + "invalid body", + []byte("GET rtsp://testing123 RTSP/1.0\r\nContent-Length: 17\r\n\r\n123"), + "unexpected EOF", + }, } { t.Run(ca.name, func(t *testing.T) { var req Request diff --git a/pkg/base/response_test.go b/pkg/base/response_test.go index 873946fd..b040199b 100644 --- a/pkg/base/response_test.go +++ b/pkg/base/response_test.go @@ -169,6 +169,16 @@ func TestResponseReadErrors(t *testing.T) { []byte("RTSP/1.0 200 \r\n"), "empty status message", }, + { + "invalid header", + []byte("RTSP/1.0 200 OK\r\nTesting: val\r"), + "EOF", + }, + { + "invalid body", + []byte("RTSP/1.0 200 OK\r\nContent-Length: 17\r\n\r\n123"), + "unexpected EOF", + }, } { t.Run(ca.name, func(t *testing.T) { var res Response diff --git a/track.go b/track.go index 93012c6c..48499d10 100644 --- a/track.go +++ b/track.go @@ -217,7 +217,6 @@ func (t *Track) ExtractDataAAC() ([]byte, error) { if err != nil { return nil, fmt.Errorf("invalid config (%v)", v) } - break } }