-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_test.go
61 lines (53 loc) · 1.43 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package log
import (
"context"
"errors"
"fmt"
"os"
"testing"
"time"
)
var (
TestField ContextField = "test_field1"
)
func TestMain(m *testing.M) {
loggable = []fmt.Stringer{TestField, UserID}
os.Exit(m.Run())
}
func TestParse(t *testing.T) {
ctx := context.WithValue(context.Background(), TestField, "test")
ctx = context.WithValue(ctx, UserID, "test_user")
result := Parse(ctx, "info", "test_message", nil)
t.Log(result)
}
func TestError(t *testing.T) {
ctx := context.WithValue(context.Background(), TestField, "test")
ctx = context.WithValue(ctx, UserID, "test_user")
Error(ctx, errors.New("test_error"), "")
}
func TestTrace(t *testing.T) {
ctx := context.WithValue(context.Background(), TestField, "test")
ctx = context.WithValue(ctx, UserID, "test_user")
ctx = context.WithValue(ctx, TracingTime, time.Now())
Trace(ctx, "prepare query")
time.Sleep(300 * time.Millisecond)
Trace(ctx, "database query")
}
func BenchmarkParse(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
p = blank{}
ctx := context.WithValue(context.Background(), TestField, "test")
ctx = context.WithValue(ctx, UserID, "test_user")
Parse(ctx, "info", "test_message", nil)
}
}
func BenchmarkError(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
p = blank{}
ctx := context.WithValue(context.Background(), TestField, "test")
ctx = context.WithValue(ctx, UserID, "test_user")
Error(ctx, errors.New("test_error"), "")
}
}