base: add tests

This commit is contained in:
aler9
2021-04-12 14:25:22 +02:00
parent 2e5aef4c12
commit d050001b58
2 changed files with 32 additions and 18 deletions

View File

@@ -177,9 +177,17 @@ func TestRequestReadErrors(t *testing.T) {
"missing eol",
[]byte("GET rtsp://testing123/test RTSP/1.0"),
},
{
"empty method",
[]byte(" rtsp://testing123 RTSP/1.0\r\n"),
},
{
"empty URL",
[]byte("GET http://testing123 RTSP/1.0\r\n"),
[]byte("GET RTSP/1.0\r\n"),
},
{
"empty protocol",
[]byte("GET http://testing123 \r\n"),
},
{
"invalid URL",

View File

@@ -14,23 +14,7 @@ var casesResponse = []struct {
res Response
}{
{
"ok with single header",
[]byte("RTSP/1.0 200 OK\r\n" +
"CSeq: 1\r\n" +
"Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE\r\n" +
"\r\n",
),
Response{
StatusCode: StatusOK,
StatusMessage: "OK",
Header: Header{
"CSeq": HeaderValue{"1"},
"Public": HeaderValue{"DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE"},
},
},
},
{
"ok with multiple headers",
"ok",
[]byte("RTSP/1.0 200 OK\r\n" +
"CSeq: 2\r\n" +
"Date: Sat, Aug 16 2014 02:22:28 GMT\r\n" +
@@ -155,6 +139,10 @@ func TestResponseReadErrors(t *testing.T) {
"missing eol",
[]byte("RTSP/1.0 200 OK"),
},
{
"missing eol 2",
[]byte("RTSP/1.0 200 OK\r"),
},
{
"invalid protocol",
[]byte("RTSP/2.0 200 OK\r\n"),
@@ -163,6 +151,10 @@ func TestResponseReadErrors(t *testing.T) {
"invalid code",
[]byte("RTSP/2.0 string OK\r\n"),
},
{
"empty message",
[]byte("RTSP/2.0 string \r\n"),
},
} {
t.Run(ca.name, func(t *testing.T) {
var res Response
@@ -200,3 +192,17 @@ func TestResponseWriteAutoFillStatus(t *testing.T) {
require.NoError(t, err)
require.Equal(t, byts, buf.Bytes())
}
func TestReadIgnoreFrames(t *testing.T) {
byts := []byte{0x24, 0x6, 0x0, 0x4, 0x1, 0x2, 0x3, 0x4}
byts = append(byts, []byte("RTSP/1.0 200 OK\r\n"+
"CSeq: 1\r\n"+
"Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE\r\n"+
"\r\n")...)
rb := bufio.NewReader(bytes.NewBuffer(byts))
buf := make([]byte, 10)
var res Response
err := res.ReadIgnoreFrames(rb, buf)
require.NoError(t, err)
}