Debian Codegraph @

logging/log_test.go

raw
1 package logging
2
3 import (
4 "bytes"
5 "fmt"
6 "os"
7 "testing"
8 )
9
10 // A list of implementations that should be tested.
11 var implementations []Logger
12
13 func init() {
14 lw := NewLogWriter(&bytes.Buffer{}, nil)
15 cw := NewConsole()
16
17 implementations = append(implementations, lw)
18 implementations = append(implementations, cw)
19 }
20
21 func TestFileSetup(t *testing.T) {
22 fw1, err := NewFile("fw1.log", true)
23 if err != nil {
24 t.Fatalf("failed to create new file logger: %v", err)
25 }
26
27 fw2, err := NewSplitFile("fw2.log", "fw2.err", true)
28 if err != nil {
29 t.Fatalf("failed to create new split file logger: %v", err)
30 }
31
32 implementations = append(implementations, fw1)
33 implementations = append(implementations, fw2)
34 }
35
36 func TestImplementations(t *testing.T) {
37 for _, l := range implementations {
38 l.Info("TestImplementations", "Info message",
39 map[string]string{"type": fmt.Sprintf("%T", l)})
40 l.Warn("TestImplementations", "Warning message",
41 map[string]string{"type": fmt.Sprintf("%T", l)})
42 }
43 }
44
45 func TestCloseLoggers(t *testing.T) {
46 for _, l := range implementations {
47 l.Close()
48 }
49 }
50
51 func TestDestroyLogFiles(t *testing.T) {
52 os.Remove("fw1.log")
53 os.Remove("fw2.log")
54 os.Remove("fw2.err")
55 }