-
Notifications
You must be signed in to change notification settings - Fork 20
/
output_test.go
82 lines (63 loc) · 1.67 KB
/
output_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
package funnel
import (
"log/syslog"
"testing"
"github.com/spf13/viper"
)
// get nil outputwriter with file
func TestNilOutputWriter(t *testing.T) {
v := viper.New()
v.Set(Target, "file")
logger, _ := syslog.New(syslog.LOG_ERR, "test")
ow, err := GetOutputWriter(v, logger)
if ow != nil {
t.Errorf("Expected nil outputwriter, Got %s", ow)
}
if err != nil {
t.Errorf("Expected nil error, Got %s", err)
}
}
// get unregistered
func TestUnregisteredOutputWriter(t *testing.T) {
v := viper.New()
v.Set(Target, "somethingnotthere")
logger, _ := syslog.New(syslog.LOG_ERR, "test")
ow, err := GetOutputWriter(v, logger)
if ow != nil {
t.Errorf("Expected nil outputwriter, Got %s", ow)
}
if _, ok := err.(*UnregisteredOutputError); !ok {
t.Errorf("Expected error to be UnregisteredOutputError, Got %s", err)
}
}
// get registered
func TestRegisteredOutputWriter(t *testing.T) {
target := "test"
v := viper.New()
v.Set(Target, target)
RegisterNewWriter(target, newTestOutput)
logger, _ := syslog.New(syslog.LOG_ERR, "test")
ow, err := GetOutputWriter(v, logger)
if err != nil {
t.Errorf("Expected nil error, Got %s", err)
}
if _, ok := ow.(*testOutput); !ok {
t.Errorf("Expected outputwriter to be testOutput, Got %s", ow)
}
}
// Dummy function and struct types to test out the output registration
func newTestOutput(v *viper.Viper, logger *syslog.Writer) (OutputWriter, error) {
return &testOutput{}, nil
}
type testOutput struct {
}
// Implementing the OutputWriter interface
func (k *testOutput) Write(p []byte) (n int, err error) {
return len(p), nil
}
func (k *testOutput) Flush() error {
return nil
}
func (k *testOutput) Close() error {
return nil
}