forked from netdata/go.d.plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter_test.go
34 lines (27 loc) · 996 Bytes
/
formatter_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
// SPDX-License-Identifier: GPL-3.0-or-later
package logger
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFormatter_Output_cli(t *testing.T) {
out := &bytes.Buffer{}
fmtter := newFormatter(out, true, "test")
fmtter.Output(INFO, "mod1", "job1", 1, "hello")
assert.NotRegexp(t, `\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}: `, out.String())
assert.Contains(t, out.String(), "INFO")
assert.Contains(t, out.String(), "mod1[job1]")
assert.Contains(t, out.String(), "formatter_test.go:")
assert.Contains(t, out.String(), "hello")
}
func TestFormatter_Output_file(t *testing.T) {
out := &bytes.Buffer{}
fmtter := newFormatter(out, false, "test")
fmtter.Output(INFO, "mod1", "job1", 1, "hello")
assert.Regexp(t, `\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}: `, out.String())
assert.Contains(t, out.String(), "INFO")
assert.Contains(t, out.String(), "mod1[job1]")
assert.NotContains(t, out.String(), "formatter_test.go:")
assert.Contains(t, out.String(), "hello")
}