File: log_test.go

package info (click to toggle)
golang-github-kisom-goutils 0.0~git20161101.0.858c9cb-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 384 kB
  • ctags: 331
  • sloc: makefile: 6
file content (55 lines) | stat: -rw-r--r-- 1,193 bytes parent folder | download | duplicates (3)
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
package logging

import (
	"bytes"
	"fmt"
	"os"
	"testing"
)

// A list of implementations that should be tested.
var implementations []Logger

func init() {
	lw := NewLogWriter(&bytes.Buffer{}, nil)
	cw := NewConsole()

	implementations = append(implementations, lw)
	implementations = append(implementations, cw)
}

func TestFileSetup(t *testing.T) {
	fw1, err := NewFile("fw1.log", true)
	if err != nil {
		t.Fatalf("failed to create new file logger: %v", err)
	}

	fw2, err := NewSplitFile("fw2.log", "fw2.err", true)
	if err != nil {
		t.Fatalf("failed to create new split file logger: %v", err)
	}

	implementations = append(implementations, fw1)
	implementations = append(implementations, fw2)
}

func TestImplementations(t *testing.T) {
	for _, l := range implementations {
		l.Info("TestImplementations", "Info message",
			map[string]string{"type": fmt.Sprintf("%T", l)})
		l.Warn("TestImplementations", "Warning message",
			map[string]string{"type": fmt.Sprintf("%T", l)})
	}
}

func TestCloseLoggers(t *testing.T) {
	for _, l := range implementations {
		l.Close()
	}
}

func TestDestroyLogFiles(t *testing.T) {
	os.Remove("fw1.log")
	os.Remove("fw2.log")
	os.Remove("fw2.err")
}