summaryrefslogtreecommitdiff
path: root/logger
diff options
authorMichael Vogt <mvo@ubuntu.com>2016-04-14 15:47:58 +0200
committerMichael Vogt <mvo@ubuntu.com>2016-04-14 15:47:58 +0200
commita0f49a5512052c62099719b60f8b800d6cc26d9b (patch)
tree75fc83a5056aba52d97ca58aa86fe22b543de4db /logger
parent5d14472c9cd4d63361766561b9b63a4e756af448 (diff)
fix tests
Diffstat (limited to 'logger')
-rw-r--r--logger/logger.go4
-rw-r--r--logger/logger_test.go13
2 files changed, 15 insertions, 2 deletions
diff --git a/logger/logger.go b/logger/logger.go
index bb4588f1ed..cc2421ad06 100644
--- a/logger/logger.go
+++ b/logger/logger.go
@@ -106,12 +106,14 @@ type ConsoleLog struct {
sys *log.Logger
}
+var osStderr = os.Stderr
+
// Debug sends the msg to syslog
func (l *ConsoleLog) Debug(msg string) {
s := "DEBUG: " + msg
l.sys.Output(3, s)
// show debug log when run manually
- if osutil.Isatty(int(os.Stderr.Fd())) {
+ if osutil.Isatty(int(osStderr.Fd())) {
l.log.Output(3, s)
}
}
diff --git a/logger/logger_test.go b/logger/logger_test.go
index a3a98ff156..570fb26205 100644
--- a/logger/logger_test.go
+++ b/logger/logger_test.go
@@ -22,7 +22,9 @@ package logger
import (
"bytes"
"fmt"
+ "io/ioutil"
"log"
+ "os"
"testing"
. "gopkg.in/check.v1"
@@ -74,11 +76,20 @@ func (s *LogSuite) TestNew(c *C) {
c.Check(l.log, NotNil)
}
-func (s *LogSuite) TestDebugf(c *C) {
+func (s *LogSuite) TestDebugfForNonTTY(c *C) {
var logbuf bytes.Buffer
l, err := NewConsoleLog(&logbuf, DefaultFlags)
c.Assert(err, IsNil)
+ // stderr is not a tty for this test
+ tmpf, err := ioutil.TempFile("", "debugf")
+ c.Assert(err, IsNil)
+ osStderr = tmpf
+ defer func() {
+ os.Remove(tmpf.Name())
+ osStderr = os.Stderr
+ }()
+
SetLogger(l)
Debugf("xyzzy")