forked from hashicorp/raft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger_test.go
More file actions
38 lines (35 loc) · 1.23 KB
/
logger_test.go
File metadata and controls
38 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package raft
import (
"bytes"
"strings"
"testing"
)
// Keep this test up here, as it hard-codes the line number of the Debug() call.
func TestLogger_NewRaftLoggerForTesting(t *testing.T) {
dest := bytes.Buffer{}
logger := NewRaftLoggerForTesting(&dest, "tag")
logger.Debug("a debug msg")
if !strings.Contains(dest.String(), "(tag) logger_test.go:13") {
t.Errorf("Log message in wrong format: %q", dest.String())
}
}
func TestLogger_LogLevel(t *testing.T) {
dest := bytes.Buffer{}
logger := DefaultStdLogger(&dest)
logger.Debug("a debug msg")
if dest.Len() > 0 {
t.Errorf("Log message at DEBUG level not expected to appear in log when logging set to Info: %q", dest.String())
}
logger.Info("info")
if strings.Index(dest.String(), "[INFO ] info") == -1 {
t.Errorf("Log message at INFO level expected to be in log, but couldn't find it: %q", dest.String())
}
logger.Warn("warn")
if strings.Index(dest.String(), "[WARN ] warn") == -1 {
t.Errorf("Log message at WARN level expected to be in log, but couldn't find it: %q", dest.String())
}
logger.Error("error")
if strings.Index(dest.String(), "[ERROR] error") == -1 {
t.Errorf("Log message at ERROR level expected to be in log, but couldn't find it: %q", dest.String())
}
}