-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_test.go
42 lines (32 loc) · 1.03 KB
/
log_test.go
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
39
40
41
42
package ripcord
import (
"os"
"strings"
"testing"
"time"
"github.com/Sirupsen/logrus"
"github.com/codingconcepts/ripcord/test"
)
func TestNewLogger(t *testing.T) {
logger := NewLogger(os.Stdout, logrus.WarnLevel)
test.Equals(t, logrus.WarnLevel, logger.Level)
test.Equals(t, os.Stdout, logger.Out)
utcFormatter, ok := logger.Formatter.(UTCFormatter)
test.Assert(t, ok)
innerFormatter, ok := utcFormatter.Formatter.(*logrus.TextFormatter)
test.Assert(t, ok)
test.Assert(t, innerFormatter.FullTimestamp)
test.Assert(t, innerFormatter.DisableColors)
}
func TestFormatProvidesUTCTime(t *testing.T) {
formatter := UTCFormatter{
Formatter: &logrus.TextFormatter{},
}
london, err := time.LoadLocation("Europe/London")
test.ErrorNil(t, err)
bstTime, err := time.ParseInLocation(time.RFC1123, "Tue, 28 Apr 2017 07:33:01 BST", london)
test.ErrorNil(t, err)
logBytes, err := formatter.Format(&logrus.Entry{Time: bstTime})
test.ErrorNil(t, err)
test.Assert(t, strings.Contains(string(logBytes), `time="2017-04-28T06:33:01Z"`))
}