cleanup and improve tests of utils package

This commit is contained in:
Lucas Clemente
2016-05-13 14:55:42 +02:00
parent d1272650c3
commit 9abda1c91f
6 changed files with 188 additions and 107 deletions

57
utils/log_test.go Normal file
View File

@@ -0,0 +1,57 @@
package utils
import (
"bytes"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Log", func() {
var (
b *bytes.Buffer
)
BeforeEach(func() {
b = bytes.NewBuffer([]byte{})
out = b
})
AfterEach(func() {
out = os.Stdout
SetLogLevel(LogLevelNothing)
})
It("log level nothing", func() {
SetLogLevel(LogLevelNothing)
Debugf("debug")
Infof("info")
Errorf("err")
Expect(b.Bytes()).To(Equal([]byte("")))
})
It("log level err", func() {
SetLogLevel(LogLevelError)
Debugf("debug")
Infof("info")
Errorf("err")
Expect(b.Bytes()).To(Equal([]byte("err\n")))
})
It("log level info", func() {
SetLogLevel(LogLevelInfo)
Debugf("debug")
Infof("info")
Errorf("err")
Expect(b.Bytes()).To(Equal([]byte("info\nerr\n")))
})
It("log level debug", func() {
SetLogLevel(LogLevelDebug)
Debugf("debug")
Infof("info")
Errorf("err")
Expect(b.Bytes()).To(Equal([]byte("debug\ninfo\nerr\n")))
})
})