-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub_test.go
92 lines (80 loc) · 2.58 KB
/
sub_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package xop
import (
"errors"
"github.com/stretchr/testify/assert"
"github.com/xoplog/xop-go/xopnum"
"testing"
"time"
)
func TestLog_Settings(t *testing.T) {
defaultLog := Default
logSettings := defaultLog.Settings()
assert.Equal(t, noFilenameFunc(DefaultSettings), noFilenameFunc(logSettings))
}
func TestSub_StackFrames(t *testing.T) {
sub := Default.Sub()
sub.StackFrames(xopnum.TraceLevel, 100)
sub.StackFrames(xopnum.ErrorLevel, 100)
sub.StackFrames(xopnum.DebugLevel, 2)
assert.Equal(t, 100, sub.settings.stackFramesWanted[xopnum.ErrorLevel])
assert.Equal(t, 100, sub.settings.stackFramesWanted[xopnum.AlertLevel])
assert.Equal(t, 2, sub.settings.stackFramesWanted[xopnum.TraceLevel])
assert.Equal(t, 2, sub.settings.stackFramesWanted[xopnum.DebugLevel])
}
func TestSub_SynchronousFlush(t *testing.T) {
sub := Default.Sub()
sub.SynchronousFlush(true)
assert.True(t, sub.settings.synchronousFlushWhenDone)
sub.SynchronousFlush(false)
assert.False(t, sub.settings.synchronousFlushWhenDone)
}
func TestSub_MinLevel(t *testing.T) {
sub := Default.Sub()
sub.MinLevel(xopnum.ErrorLevel)
assert.Equal(t, xopnum.ErrorLevel, sub.settings.minimumLogLevel)
}
func TestSub_TagLinesWithSpanSequence(t *testing.T) {
sub := Default.Sub()
sub.TagLinesWithSpanSequence(true)
assert.True(t, sub.settings.tagLinesWithSpanSequence)
sub.TagLinesWithSpanSequence(false)
assert.False(t, sub.settings.tagLinesWithSpanSequence)
}
func TestSub_PrefillText(t *testing.T) {
sub := Default.Sub()
assert.Empty(t, sub.settings.prefillMsg)
sub.PrefillText("text")
assert.Equal(t, "text", sub.settings.prefillMsg)
}
func TestSub_NoPrefill(t *testing.T) {
sub := Default.Sub()
assert.Nil(t, sub.settings.prefillData)
assert.Empty(t, sub.settings.prefillMsg)
sub.PrefillAny(Key("foo"), "bar")
sub.PrefillText("text")
assert.NotNil(t, sub.settings.prefillData)
assert.NotEmpty(t, sub.settings.prefillMsg)
sub.NoPrefill()
assert.Nil(t, sub.settings.prefillData)
assert.Empty(t, sub.settings.prefillMsg)
}
func TestSub_PrefillBool(t *testing.T) {
sub := Default.Sub()
sub.PrefillBool(Key("key"), true)
assert.Len(t, sub.settings.prefillData, 1)
}
func TestSub_PrefillDuration(t *testing.T) {
sub := Default.Sub()
sub.PrefillDuration(Key("key"), 1*time.Second)
assert.Len(t, sub.settings.prefillData, 1)
}
func TestSub_PrefillError(t *testing.T) {
sub := Default.Sub()
sub.PrefillError(Key("key"), errors.New("error"))
assert.Len(t, sub.settings.prefillData, 1)
}
func TestSub_PrefillFloat64(t *testing.T) {
sub := Default.Sub()
sub.PrefillFloat64(Key("key"), 64)
assert.Len(t, sub.settings.prefillData, 1)
}