From 69dc78288c9edf5fa886dffa3c8df39b98137d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=B0=8F=E9=BE=99?= Date: Tue, 13 Nov 2018 11:40:13 +0800 Subject: [PATCH] test log level and add some unit test case --- log/level_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/log/level_test.go b/log/level_test.go index d7d42bce..e82a4bdb 100644 --- a/log/level_test.go +++ b/log/level_test.go @@ -1,6 +1,8 @@ package log import ( + "encoding/json" + "os" "testing" ) @@ -16,4 +18,33 @@ func TestGetLevel(t *testing.T) { if num != 7 { t.Errorf("defaultLogLevel set failed: %d\n", num) } + + initLogLevel("error") + Debug("my book is bought in the year of ", 2016) + Info("this %s cat is %v years old", "yellow", 3) + Notice("Notice log") + Warn("json is a type of kv like", map[string]int{"key": 2016}) + Error("error log") + Critical("critical log") + Alert("alert log") + Emergency("emergency log") +} + +func initLogLevel(level string) { + fileName := "/tmp/test.log" + + logConf := struct { + FileName string `json:"filename"` + Level int `json:"level"` + }{ + FileName: fileName, + Level: GetLevel(level), + } + + configuration, err := json.Marshal(logConf) + if err != nil { + panic(err) + } + Init(string(configuration)) + os.Remove(fileName) }