forked from xlab/suplog
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror_level_test.go
More file actions
38 lines (30 loc) · 833 Bytes
/
error_level_test.go
File metadata and controls
38 lines (30 loc) · 833 Bytes
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
package suplog
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestErrorLevel(t *testing.T) {
t.Run("raise level based on errors", func(t *testing.T) {
var recorder strings.Builder
l := NewLogger(&recorder, new(TextFormatter))
l.WithError(errors.New("fail")).
ErrLevel(ErrorLevel).
Debugf("deferred log level")
out := recorder.String()
require.Contains(t, out, "error=fail")
require.Contains(t, out, "level=error")
})
t.Run("keeps level based if no error", func(t *testing.T) {
var recorder strings.Builder
l := NewLogger(&recorder, new(TextFormatter))
var err error
l.WithError(err).
ErrLevel(ErrorLevel).
Debugf("deferred log level")
out := recorder.String()
require.NotContains(t, out, "error=")
require.Contains(t, out, "level=debug")
})
}