Added TestErrorHandling which subsumes TestOpenClose.

This commit is contained in:
scruzin 2019-01-13 14:30:40 +10:30
parent 4c6c549f98
commit fb36a2dccf
1 changed files with 36 additions and 6 deletions

View File

@ -143,18 +143,48 @@ func TestSetupURL(t *testing.T) {
}
}
// TestOpenClose tests opening an closing an RTMP connection.
func TestOpenClose(t *testing.T) {
testLog(0, "TestOpenClose")
// TestErrorHandling tests error handling
func TestErorHandling(t *testing.T) {
testLog(0, "TestErrorHandling")
if testKey == "" {
t.Skip("Skipping TestOpenClose since no RTMP_TEST_KEY")
t.Skip("Skipping TestErrorHandling since no RTMP_TEST_KEY")
}
s := NewSession(testBaseURL+testKey, testTimeout, testLog)
err := s.Open()
// test errNotConnected
var buf [1024]byte
tag := buf[:0]
_, err := s.Write(tag)
if err == nil {
t.Errorf("Write did not return errNotConnected")
}
err = s.Open()
if err != nil {
t.Errorf("Open failed with error: %v", err)
return
}
// test errInvalidFlvTag
_, err = s.Write(tag)
if err == nil {
t.Errorf("Write did not return errInvalidFlvTag")
}
// test errUnimplemented
copy(tag, []byte("FLV"))
_, err = s.Write(tag)
if err == nil {
t.Errorf("Write did not return errUnimplemented")
}
// test errInvalidBody
tag = buf[:11]
_, err = s.Write(tag)
fmt.Printf("err = %v\n", err)
if err == nil {
t.Errorf("Write did not return errInvalidBody")
}
err = s.Close()
if err != nil {
t.Errorf("Close failed with error: %v", err)