-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_entry_test.go
52 lines (40 loc) · 1.1 KB
/
log_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
package clogger
import (
"context"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_exampleLog(t *testing.T) {
l := NewDefaultLogger()
SetGlobal(l)
ctx := context.Background()
assert.NotPanics(t, func() {
Debug(ctx, "A debug statement happened.")
Info(nil, "An informational message.")
})
}
func Test_exampleLogWithFields(t *testing.T) {
l := NewDefaultLogger()
SetGlobal(l)
ctx := context.Background()
assert.NotPanics(t, func() {
With("key1", "value1").
With("key2", "value2").
Debug(ctx, "A debug statement happened.")
With("key3", "value3").
Info(nil, "An informational message.")
})
}
func TestLogEntryOptions(t *testing.T) {
l := NewDefaultLogger()
l.SetLogEntryOptions(WithExampleEntryOption(), WithOpenTelemetrySpan(), WithOpenTelemetrySpan())
SetGlobal(l)
assert.Equal(t, 3, len(l.LogEntryOptions()))
assert.Equal(t, 3, len(l.LogEntryOptions()))
for _, opt := range l.LogEntryOptions() {
typ := reflect.TypeOf(opt)
assert.Equal(t, "func", typ.Kind().String(), "Expecting a func (callable)")
assert.Equal(t, "LogEntryOption", typ.Name())
}
}