-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry_test.go
53 lines (43 loc) · 1.47 KB
/
entry_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
43
44
45
46
47
48
49
50
51
52
53
package log
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEntry_WithFields(t *testing.T) {
a := NewEntry(nil)
assert.Nil(t, a.Fields)
b := a.WithFields(Fields{"foo": "bar"})
assert.Equal(t, Fields{}, a.mergedFields())
assert.Equal(t, Fields{"foo": "bar"}, b.mergedFields())
c := a.WithFields(Fields{"foo": "hello", "bar": "world"})
e := c.finalize(InfoLevel, "upload")
assert.Equal(t, e.Message, "upload")
assert.Equal(t, e.Fields, Fields{"foo": "hello", "bar": "world"})
assert.Equal(t, e.Level, InfoLevel)
assert.NotEmpty(t, e.Timestamp)
}
func TestEntry_WithField(t *testing.T) {
a := NewEntry(nil)
b := a.WithField("foo", "bar")
assert.Equal(t, Fields{}, a.mergedFields())
assert.Equal(t, Fields{"foo": "bar"}, b.mergedFields())
}
func TestEntry_WithError(t *testing.T) {
a := NewEntry(nil)
b := a.WithError(fmt.Errorf("boom"))
assert.Equal(t, Fields{}, a.mergedFields())
assert.Equal(t, Fields{"error": "boom"}, b.mergedFields())
c := a.WithError(nil)
assert.Equal(t, Fields{"error": nil}, c.mergedFields())
}
func TestEntry_WithMem(t *testing.T) {
a := NewEntry(nil).WithError(fmt.Errorf("boom")).WithMemStats()
x := a.mergedFields()
assert.NotEqual(t, x["error"], nil)
assert.NotEqual(t, x["memstats"], nil)
assert.NotEqual(t, x["memstats"].(logMemStats).Alloc, nil)
assert.NotEqual(t, x["memstats"].(logMemStats).HeapAlloc, nil)
assert.NotEqual(t, x["memstats"].(logMemStats).StackSys, nil)
assert.Equal(t, x["notset"], nil)
}