From 42797c723883dccc5272ca27eae2b86a03a7b640 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:45:33 +0100 Subject: [PATCH] add tests --- server_test.go | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/server_test.go b/server_test.go index e8445f3c..4f0a4234 100644 --- a/server_test.go +++ b/server_test.go @@ -311,7 +311,40 @@ func TestServerErrorCSeqMissing(t *testing.T) { res, err := writeReqReadRes(conn, base.Request{ Method: base.Options, URL: mustParseURL("rtsp://localhost:8554/"), - Header: base.Header{}, + }) + require.NoError(t, err) + require.Equal(t, base.StatusBadRequest, res.StatusCode) + + <-nconnClosed +} + +func TestServerErrorNilURL(t *testing.T) { + nconnClosed := make(chan struct{}) + + s := &Server{ + Handler: &testServerHandler{ + onConnClose: func(ctx *ServerHandlerOnConnCloseCtx) { + require.EqualError(t, ctx.Error, "invalid path") + close(nconnClosed) + }, + }, + RTSPAddress: "localhost:8554", + } + err := s.Start() + require.NoError(t, err) + defer s.Close() + + nconn, err := net.Dial("tcp", "localhost:8554") + require.NoError(t, err) + defer nconn.Close() + conn := conn.NewConn(nconn) + + res, err := writeReqReadRes(conn, base.Request{ + Method: base.Describe, + URL: nil, + Header: base.Header{ + "CSeq": base.HeaderValue{"1"}, + }, }) require.NoError(t, err) require.Equal(t, base.StatusBadRequest, res.StatusCode)