setupURL() now a method on Session and renamed init().

This commit is contained in:
scruzin 2019-01-13 09:18:52 +10:30
parent f1e46461c3
commit 8898ee3add
3 changed files with 12 additions and 9 deletions

View File

@ -163,7 +163,7 @@ var (
)
// init initialises the Session link
func setupURL(s *Session) (err error) {
func (s *Session) init() (err error) {
s.link.protocol, s.link.host, s.link.port, s.link.app, s.link.playpath, err = parseURL(s.url)
if err != nil {
return err

View File

@ -116,7 +116,7 @@ func TestKey(t *testing.T) {
testLog(0, "Testing against URL "+testBaseURL+testKey)
}
// TestSetupURL tests URL parsing.
// TestSetupURL tests URL parsing and link initialization.
func TestSetupURL(t *testing.T) {
testLog(0, "TestSetupURL")
// test with just the base URL
@ -124,19 +124,22 @@ func TestSetupURL(t *testing.T) {
if s.url != testBaseURL && s.link.timeout != testTimeout {
t.Errorf("NewSession failed")
}
err := setupURL(s)
err := s.init()
if err != nil {
t.Errorf("setupURL(testBaseURL) failed with error: %v", err)
t.Errorf("setupURL: failed with error: %v", err)
}
// test the parts are as expected
if rtmpProtocolStrings[s.link.protocol] != rtmpProtocol {
t.Errorf("setupURL returned wrong protocol: %v", s.link.protocol)
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 returned wrong host: %v", s.link.host)
t.Errorf("setupURL: wrong host: %v", s.link.host)
}
if s.link.app != testApp {
t.Errorf("setupURL returned wrong app: %v", s.link.app)
t.Errorf("setupURL: wrong app: %v", s.link.app)
}
}

View File

@ -129,7 +129,7 @@ func (s *Session) Open() error {
if s.isConnected() {
return errConnected
}
err := setupURL(s)
err := s.init()
if err != nil {
return err
}