mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
base: improve coverage
This commit is contained in:
@@ -117,6 +117,40 @@ func TestReadInterleavedFrameOrRequest(t *testing.T) {
|
|||||||
require.Equal(t, &f, out)
|
require.Equal(t, &f, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadInterleavedFrameOrRequestError(t *testing.T) {
|
||||||
|
for _, ca := range []struct {
|
||||||
|
name string
|
||||||
|
byts []byte
|
||||||
|
err string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"empty",
|
||||||
|
[]byte{},
|
||||||
|
"EOF",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"invalid frame",
|
||||||
|
[]byte{0x24, 0x00},
|
||||||
|
"unexpected EOF",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"invalid request",
|
||||||
|
[]byte("DESCRIBE"),
|
||||||
|
"EOF",
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
|
var f InterleavedFrame
|
||||||
|
f.Payload = make([]byte, 10)
|
||||||
|
var req Request
|
||||||
|
br := bufio.NewReader(bytes.NewBuffer(ca.byts))
|
||||||
|
|
||||||
|
_, err := ReadInterleavedFrameOrRequest(&f, &req, br)
|
||||||
|
require.Equal(t, ca.err, err.Error())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadInterleavedFrameOrResponse(t *testing.T) {
|
func TestReadInterleavedFrameOrResponse(t *testing.T) {
|
||||||
byts := []byte("RTSP/1.0 200 OK\r\n" +
|
byts := []byte("RTSP/1.0 200 OK\r\n" +
|
||||||
"CSeq: 1\r\n" +
|
"CSeq: 1\r\n" +
|
||||||
@@ -137,3 +171,37 @@ func TestReadInterleavedFrameOrResponse(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, &f, out)
|
require.Equal(t, &f, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadInterleavedFrameOrResponseError(t *testing.T) {
|
||||||
|
for _, ca := range []struct {
|
||||||
|
name string
|
||||||
|
byts []byte
|
||||||
|
err string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"empty",
|
||||||
|
[]byte{},
|
||||||
|
"EOF",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"invalid frame",
|
||||||
|
[]byte{0x24, 0x00},
|
||||||
|
"unexpected EOF",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"invalid response",
|
||||||
|
[]byte("RTSP/1.0"),
|
||||||
|
"EOF",
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
|
var f InterleavedFrame
|
||||||
|
f.Payload = make([]byte, 10)
|
||||||
|
var res Response
|
||||||
|
br := bufio.NewReader(bytes.NewBuffer(ca.byts))
|
||||||
|
|
||||||
|
_, err := ReadInterleavedFrameOrResponse(&f, &res, br)
|
||||||
|
require.Equal(t, ca.err, err.Error())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -6,11 +6,15 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestURLInvalid(t *testing.T) {
|
func TestURLError(t *testing.T) {
|
||||||
for _, ca := range []struct {
|
for _, ca := range []struct {
|
||||||
name string
|
name string
|
||||||
enc string
|
enc string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
"invalid",
|
||||||
|
"testing",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"with opaque data",
|
"with opaque data",
|
||||||
"rtsp:opaque?query",
|
"rtsp:opaque?query",
|
||||||
@@ -63,6 +67,30 @@ func TestURLRTSPPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestURLClone(t *testing.T) {
|
||||||
|
u := MustParseURL("rtsp://localhost:8554/test/stream")
|
||||||
|
u2 := u.Clone()
|
||||||
|
u.Host = "otherhost"
|
||||||
|
|
||||||
|
require.Equal(t, &URL{
|
||||||
|
Scheme: "rtsp",
|
||||||
|
Host: "otherhost",
|
||||||
|
Path: "/test/stream",
|
||||||
|
}, u)
|
||||||
|
|
||||||
|
require.Equal(t, &URL{
|
||||||
|
Scheme: "rtsp",
|
||||||
|
Host: "localhost:8554",
|
||||||
|
Path: "/test/stream",
|
||||||
|
}, u2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestURLErrorRTSPPath(t *testing.T) {
|
||||||
|
u := MustParseURL("rtsp://localhost:8554")
|
||||||
|
_, ok := u.RTSPPath()
|
||||||
|
require.Equal(t, false, ok)
|
||||||
|
}
|
||||||
|
|
||||||
func TestURLRTSPPathAndQuery(t *testing.T) {
|
func TestURLRTSPPathAndQuery(t *testing.T) {
|
||||||
for _, ca := range []struct {
|
for _, ca := range []struct {
|
||||||
u *URL
|
u *URL
|
||||||
|
Reference in New Issue
Block a user