aboutsummaryrefslogtreecommitdiff
path: root/outputs/keyvalue/keyvalue_test.go
blob: 4ce6d904d4600d1fc6f01ad548b96efca497c54f (plain)
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
package keyvalue

import (
	"bytes"
	"github.com/felix/logger"
	"strings"
	"testing"
)

func TestKeyValueWriter(t *testing.T) {
	var tests = []struct {
		in  []interface{}
		out string
	}{
		{
			in:  []interface{}{"test message"},
			out: "[INFO ] test: message=\"test message\"",
		},
		{
			in:  []interface{}{"test message", "name", "me"},
			out: "[INFO ] test: message=\"test message\" name=me",
		},
		{
			in:  []interface{}{"test message", "name", "me", "number", 2},
			out: "[INFO ] test: message=\"test message\" name=me number=2",
		},
	}

	for _, tt := range tests {
		var buf bytes.Buffer
		logger := logger.New(&logger.Options{
			Name:      "test",
			Output:    &buf,
			Formatter: New(),
		})

		logger.Info(tt.in...)

		str := buf.String()

		// Chop timestamp
		dataIdx := strings.IndexByte(str, ' ')
		rest := str[dataIdx+1:]

		if rest != tt.out {
			t.Errorf("Info(%q) => %q, expected %q\n", tt.in, rest, tt.out)
		}
	}
}