This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
110 lines (88 loc) · 2.72 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
100
101
102
103
104
105
106
107
108
109
110
// nolint: testpackage
package rec
import (
"os"
"testing"
)
func TestNewConfig(t *testing.T) {
t.Parallel()
t.Run("success(NewConfig)", func(t *testing.T) {
t.Parallel()
expect, actual := NewConfig(), newConfig(os.Hostname)
FailIfNotDeepEqual(t, expect, actual)
})
}
func Test_newConfig(t *testing.T) {
t.Parallel()
errFunc := func() (string, error) {
return "", errForTest
}
errConfig := newConfig(os.Hostname)
errConfig.HostnameFieldValue = "localhost"
type args struct {
osHostname func() (string, error)
}
tests := []struct {
name string
args args
expect *Config
}{
{"success(newConfig)", args{os.Hostname}, newConfig(os.Hostname)},
{"error(os.Hostname)", args{errFunc}, errConfig},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
expect, actual := tt.expect, newConfig(tt.args.osHostname)
FailIfNotDeepEqual(t, expect, actual)
})
}
}
func TestConfig_validate(t *testing.T) {
t.Parallel()
configOK := NewConfig()
configOKTimestampFieldKey := NewConfig()
configOKTimestampFieldKey.UseTimestampField = false
configOKTimestampFieldKey.TimestampFieldKey = ""
configNGTimestampFieldKey := NewConfig()
configNGTimestampFieldKey.TimestampFieldKey = ""
configOKSeverityFieldKey := NewConfig()
configOKSeverityFieldKey.UseSeverityField = false
configOKSeverityFieldKey.SeverityFieldKey = ""
configNGSeverityFieldKey := NewConfig()
configNGSeverityFieldKey.SeverityFieldKey = ""
configOKCallerFieldKey := NewConfig()
configOKCallerFieldKey.UseCallerField = false
configOKCallerFieldKey.CallerFieldKey = ""
configNGCallerFieldKey := NewConfig()
configNGCallerFieldKey.CallerFieldKey = ""
configOKMessageFieldKey := NewConfig()
configOKMessageFieldKey.UseMessageField = false
configOKMessageFieldKey.MessageFieldKey = ""
configNGMessageFieldKey := NewConfig()
configNGMessageFieldKey.MessageFieldKey = ""
tests := []struct {
name string
config *Config
expectErr error
}{
{"success(validate)", configOK, nil},
{"success(TimestampFieldKey)", configOKTimestampFieldKey, nil},
{"error(TimestampFieldKey)", configNGTimestampFieldKey, ErrIsEmpty},
{"success(SeverityFieldKey)", configOKSeverityFieldKey, nil},
{"error(SeverityFieldKey)", configNGSeverityFieldKey, ErrIsEmpty},
{"success(CallerFieldKey)", configOKCallerFieldKey, nil},
{"error(CallerFieldKey)", configNGCallerFieldKey, ErrIsEmpty},
{"success(MessageFieldKey)", configOKMessageFieldKey, nil},
{"error(MessageFieldKey)", configNGMessageFieldKey, ErrIsEmpty},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
expect, actual := tt.expectErr, tt.config.validate()
FailIfNotErrorIs(t, expect, actual)
})
}
}