Exit if RTMP_TEST_KEY not defined.

This commit is contained in:
scruzin 2019-01-10 12:51:18 +10:30
parent 3dbaa810fc
commit 9796465018
1 changed files with 20 additions and 9 deletions

View File

@ -29,10 +29,10 @@ package rtmp
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"io/ioutil"
) )
const ( const (
@ -81,9 +81,9 @@ func testLog(level int8, msg string, params ...interface{}) {
func TestKey(t *testing.T) { func TestKey(t *testing.T) {
testLog(0, "TestKey") testLog(0, "TestKey")
testKey := os.Getenv("RTMP_TEST_KEY") testKey = os.Getenv("RTMP_TEST_KEY")
if testKey == "" { if testKey == "" {
t.Errorf("RTMP_TEST_KEY environment variable not defined") fmt.Printf("RTMP_TEST_KEY environment variable not defined\n")
os.Exit(1) os.Exit(1)
} }
testLog(0, "Testing against URL "+testBaseURL+testKey) testLog(0, "Testing against URL "+testBaseURL+testKey)
@ -118,25 +118,35 @@ func TestSetupURL(t *testing.T) {
} }
} }
func TestOpen(t *testing.T) {
testLog(0, "TestOpen")
s := NewSession(testBaseURL+testKey, testTimeout, testLog)
err := setupURL(s, s.url)
if err != nil {
t.Errorf("setupURL failed with error: %v", err)
}
s.enableWrite()
err = s.Open()
if err != nil {
t.Errorf("connect failed with error: %v", err)
}
}
func TestOpenClose(t *testing.T) { func TestOpenClose(t *testing.T) {
testLog(0, "TestOpenClose") testLog(0, "TestOpenClose")
s := NewSession(testBaseURL+testKey, testTimeout, testLog) s := NewSession(testBaseURL+testKey, testTimeout, testLog)
err := s.Open() err := s.Open()
if err != nil { if err != nil {
t.Errorf("Session.Open failed with error: %v", err) t.Errorf("Open failed with error: %v", err)
return return
} }
err = s.Close()
if err != nil {
t.Errorf("Session.Close failed with error: %v", err)
}
} }
func TestFromFile(t *testing.T) { func TestFromFile(t *testing.T) {
testLog(0, "TestFromFile") testLog(0, "TestFromFile")
testFile := os.Getenv("RTMP_TEST_FILE") testFile := os.Getenv("RTMP_TEST_FILE")
if testKey == "" { if testKey == "" {
t.Errorf("RTMP_TEST_FILE environment variable not defined") fmt.Printf("RTMP_TEST_FILE environment variable not defined\n")
os.Exit(1) os.Exit(1)
} }
s := NewSession(testBaseURL+testKey, testTimeout, testLog) s := NewSession(testBaseURL+testKey, testTimeout, testLog)
@ -150,6 +160,7 @@ func TestFromFile(t *testing.T) {
} }
// ToDo: rate limit writing // ToDo: rate limit writing
n, err := s.Write(video) n, err := s.Write(video)
if err != nil { if err != nil {
t.Errorf("Session.Write failed with error: %v", err) t.Errorf("Session.Write failed with error: %v", err)
} }