diff --git a/rtmp/rtmp_test.go b/rtmp/rtmp_test.go index 2ce90e63..618f2b95 100644 --- a/rtmp/rtmp_test.go +++ b/rtmp/rtmp_test.go @@ -116,75 +116,54 @@ func TestKey(t *testing.T) { testLog(0, "Testing against URL "+testBaseURL+testKey) } -// TestInit tests session construction and link initialization. -func TestInit(t *testing.T) { - testLog(0, "TestInit") - // test with just the base URL - s := NewSession(testBaseURL, testTimeout, testLog) - if s.url != testBaseURL && s.link.timeout != testTimeout { - t.Errorf("NewSession failed") - } - err := s.init() - if err != nil { - t.Errorf("setupURL: failed with error: %v", err) - } - // test the parts are as expected - if s.link.protocol&featureWrite == 0 { - t.Errorf("setupURL: link not writable") - } - if rtmpProtocolStrings[s.link.protocol&^featureWrite] != rtmpProtocol { - t.Errorf("setupURL: wrong protocol: %v", s.link.protocol) - } - if s.link.host != testHost { - t.Errorf("setupURL: wrong host: %v", s.link.host) - } - if s.link.app != testApp { - t.Errorf("setupURL: wrong app: %v", s.link.app) - } -} - // TestErrorHandling tests error handling func TestErorHandling(t *testing.T) { testLog(0, "TestErrorHandling") if testKey == "" { t.Skip("Skipping TestErrorHandling since no RTMP_TEST_KEY") } - s := NewSession(testBaseURL+testKey, testTimeout, testLog) - - // test errNotConnected - var buf [1024]byte - tag := buf[:0] - _, err := s.Write(tag) - if err == nil { - t.Errorf("Write did not return errNotConnected") + c, err := Dial(testBaseURL+testKey, testTimeout, testLog) + if err != nil { + t.Errorf("Dial failed with error: %v", err) } - err = s.Open() - if err != nil { - t.Errorf("Open failed with error: %v", err) + // test the link parts are as expected + if c.link.protocol&featureWrite == 0 { + t.Errorf("link not writable") + } + if rtmpProtocolStrings[c.link.protocol&^featureWrite] != rtmpProtocol { + t.Errorf("wrong protocol: %v", c.link.protocol) + } + if c.link.host != testHost { + t.Errorf("wrong host: %v", c.link.host) + } + if c.link.app != testApp { + t.Errorf("wrong app: %v", c.link.app) } // test errInvalidFlvTag - _, err = s.Write(tag) + var buf [1024]byte + tag := buf[:0] + _, err = c.Write(tag) if err == nil { t.Errorf("Write did not return errInvalidFlvTag") } // test errUnimplemented copy(tag, []byte("FLV")) - _, err = s.Write(tag) + _, err = c.Write(tag) if err == nil { t.Errorf("Write did not return errUnimplemented") } // test errInvalidBody tag = buf[:11] - _, err = s.Write(tag) + _, err = c.Write(tag) if err == nil { t.Errorf("Write did not return errInvalidBody") } - err = s.Close() + err = c.Close() if err != nil { t.Errorf("Close failed with error: %v", err) return @@ -197,10 +176,9 @@ func TestFromFrame(t *testing.T) { if testKey == "" { t.Skip("Skipping TestFromFrame since no RTMP_TEST_KEY") } - s := NewSession(testBaseURL+testKey, testTimeout, testLog) - err := s.Open() + c, err := Dial(testBaseURL+testKey, testTimeout, testLog) if err != nil { - t.Errorf("Session.Open failed with error: %v", err) + t.Errorf("Dial failed with error: %v", err) } testFrame := os.Getenv("RTMP_TEST_FRAME") @@ -216,7 +194,7 @@ func TestFromFrame(t *testing.T) { } const frameRate = 25 - rs := &rtmpSender{s: s} + rs := &rtmpSender{conn: c} flvEncoder, err := flv.NewEncoder(rs, true, true, frameRate) if err != nil { t.Errorf("Failed to create flv encoder with error: %v", err) @@ -226,18 +204,18 @@ func TestFromFrame(t *testing.T) { t.Errorf("Lexing failed with error: %v", err) } - err = s.Close() + err = c.Close() if err != nil { t.Errorf("Session.Close failed with error: %v", err) } } type rtmpSender struct { - s *Session + conn *Conn } func (rs *rtmpSender) Write(p []byte) (int, error) { - n, err := rs.s.Write(p) + n, err := rs.conn.Write(p) if err != errInvalidFlvTag && err != nil { return 0, err } @@ -255,12 +233,10 @@ func TestFromFile(t *testing.T) { if testKey == "" { t.Skip("Skipping TestFromFile since no RTMP_TEST_KEY") } - s := NewSession(testBaseURL+testKey, testTimeout, testLog) - err := s.Open() + c, err := Dial(testBaseURL+testKey, testTimeout, testLog) if err != nil { - t.Errorf("Session.Open failed with error: %v", err) + t.Errorf("Dial failed with error: %v", err) } - f, err := os.Open(testFile) if err != nil { t.Errorf("Open failed with error: %v", err) @@ -268,7 +244,7 @@ func TestFromFile(t *testing.T) { defer f.Close() // Pass RTMP session, true for audio, true for video, and 25 FPS - flvEncoder, err := flv.NewEncoder(s, true, true, 25) + flvEncoder, err := flv.NewEncoder(c, true, true, 25) if err != nil { t.Fatalf("failed to create encoder: %v", err) } @@ -277,7 +253,7 @@ func TestFromFile(t *testing.T) { t.Errorf("Lexing and encoding failed with error: %v", err) } - err = s.Close() + err = c.Close() if err != nil { t.Errorf("Session.Close failed with error: %v", err) }