forked from trpc-group/trpc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
99 lines (93 loc) · 2.29 KB
/
config_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
93
94
95
96
97
98
99
// Tencent is pleased to support the open source community by making tRPC available.
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
// If you have downloaded a copy of the tRPC source code from Tencent,
// please note that tRPC source code is licensed under the Apache 2.0 License that can be found in the LICENSE file.
package log_test
import (
"testing"
"time"
"trpc.group/trpc-go/trpc-go/log"
)
var defaultConfig = []log.OutputConfig{
{
Writer: "console",
Level: "debug",
Formatter: "console",
FormatConfig: log.FormatConfig{
TimeFmt: "2006.01.02 15:04:05",
},
},
{
Writer: "file",
Level: "info",
Formatter: "json",
WriteConfig: log.WriteConfig{
Filename: "trpc_size.log",
RollType: "size",
MaxAge: 7,
MaxBackups: 10,
MaxSize: 100,
},
FormatConfig: log.FormatConfig{
TimeFmt: "2006.01.02 15:04:05",
},
},
{
Writer: "file",
Level: "info",
Formatter: "json",
WriteConfig: log.WriteConfig{
Filename: "trpc_time.log",
RollType: "time",
MaxAge: 7,
MaxBackups: 10,
MaxSize: 100,
TimeUnit: log.Day,
},
FormatConfig: log.FormatConfig{
TimeFmt: "2006-01-02 15:04:05",
},
},
}
func TestTimeUnit_Format(t *testing.T) {
tests := []struct {
name string
tr log.TimeUnit
want string
}{
{"Minute", log.Minute, ".%Y%m%d%H%M"},
{"Hour", log.Hour, ".%Y%m%d%H"},
{"Day", log.Day, ".%Y%m%d"},
{"Month", log.Month, ".%Y%m"},
{"Year", log.Year, ".%Y"},
{"default", log.TimeUnit("xxx"), ".%Y%m%d"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.tr.Format(); got != tt.want {
t.Errorf("TimeUnit.Format() = %v, want %v", got, tt.want)
}
})
}
}
func TestTimeUnit_RotationGap(t *testing.T) {
tests := []struct {
name string
tr log.TimeUnit
want time.Duration
}{
{"Minute", log.Minute, time.Minute},
{"Hour", log.Hour, time.Hour},
{"Day", log.Day, time.Hour * 24},
{"Month", log.Month, time.Hour * 24 * 30},
{"Year", log.Year, time.Hour * 24 * 365},
{"default", log.TimeUnit("xxx"), time.Hour * 24},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.tr.RotationGap(); got != tt.want {
t.Errorf("TimeUnit.RotationGap() = %v, want %v", got, tt.want)
}
})
}
}