A simple, go-based DNS resolver/caching server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

60 lines
1011 B

package main
import (
"bufio"
"os"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestConsole(t *testing.T) {
logger := NewLogger()
logger.SetLogger("console", nil)
logger.SetLevel(LevelInfo)
logger.Debug("debug")
logger.Info("info")
logger.Notice("notiece")
logger.Warn("warn")
logger.Error("error")
}
func TestFile(t *testing.T) {
logger := NewLogger()
logger.SetLogger("file", map[string]interface{}{"file": "test.log"})
logger.SetLevel(LevelInfo)
logger.Debug("debug")
logger.Info("info")
logger.Notice("notiece")
logger.Warn("warn")
logger.Error("error")
time.Sleep(time.Second)
f, err := os.Open("test.log")
if err != nil {
t.Fatal(err)
}
b := bufio.NewReader(f)
linenum := 0
for {
line, _, err := b.ReadLine()
if err != nil {
break
}
if len(line) > 0 {
linenum++
}
}
Convey("Test Log File Handler", t, func() {
Convey("file line nums should be 4", func() {
So(linenum, ShouldEqual, 4)
})
})
os.Remove("test.log")
}