From 8a23609f6ebb71c1c02f2e64671bc70b59e0f2ec Mon Sep 17 00:00:00 2001 From: scruzin Date: Fri, 11 Jan 2019 07:24:31 +1030 Subject: [PATCH] Exit test for errors and fatals errors regardless of testVerbosity. --- rtmp/rtmp_test.go | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/rtmp/rtmp_test.go b/rtmp/rtmp_test.go index 6e07535a..be4cf276 100644 --- a/rtmp/rtmp_test.go +++ b/rtmp/rtmp_test.go @@ -6,6 +6,8 @@ DESCRIPTION RTMP tests AUTHORS + Saxon Nelson-Milton + Dan Kortschak Alan Noble LICENSE @@ -49,20 +51,22 @@ const ( testDataDir = "../../test/test-data/av/input" ) -// testVerbosity controls the amount of output +// testVerbosity controls the amount of output. // NB: This is not the log level, which is DebugLevel. // 0: suppress logging completely // 1: log messages only // 2: log messages with errors, if any var testVerbosity = 1 -// testKey is the RTMP key required for YouTube streaming (RTMP_TEST_KEY env var) +// testKey is the YouTube RTMP key required for YouTube streaming (RTMP_TEST_KEY env var). +// NB: don't share your key with others. var testKey string -// testFile is the test video file (RTMP_TEST_FILE env var) +// testFile is the test video file (RTMP_TEST_FILE env var). +// betterInput.h264 is a good one to use. var testFile string -// testLog is a bare bones logger that logs to stdout. +// testLog is a bare bones logger that logs to stdout, and exits upon either an error or fatal error. func testLog(level int8, msg string, params ...interface{}) { logLevels := [...]string{"Debug", "Info", "Warn", "Error", "", "", "Fatal"} if testVerbosity == 0 { @@ -71,21 +75,28 @@ func testLog(level int8, msg string, params ...interface{}) { if level < -1 || level > 5 { panic("Invalid log level") } - if testVerbosity == 2 && len(params) >= 2 { - // extract the params we know about, otherwise just print the message - switch params[0].(string) { - case "error": - fmt.Printf("%s: %s, error=%v\n", logLevels[level+1], msg, params[1].(string)) - case "size": - fmt.Printf("%s: %s, size=%d\n", logLevels[level+1], msg, params[1].(int)) - default: + switch testVerbosity { + case 0: + // silence is golden + case 1: + fmt.Printf("%s: %s\n", logLevels[level+1], msg) + case 2: + // extract the first param if it is one we care about, otherwise just print the message + if len(params) >= 2 { + switch params[0].(string) { + case "error": + fmt.Printf("%s: %s, error=%v\n", logLevels[level+1], msg, params[1].(string)) + case "size": + fmt.Printf("%s: %s, size=%d\n", logLevels[level+1], msg, params[1].(int)) + default: + fmt.Printf("%s: %s\n", logLevels[level+1], msg) + } + } else { fmt.Printf("%s: %s\n", logLevels[level+1], msg) } - } else { - fmt.Printf("%s: %s\n", logLevels[level+1], msg) } - if level == 5 { - // Fatal + if level >= 4 { + // Error or Fatal buf := make([]byte, 1<<16) size := runtime.Stack(buf, true) fmt.Printf("%s\n", string(buf[:size]))