-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole_test.go
66 lines (56 loc) · 1.54 KB
/
console_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// (c) 2022 Jacek Olszak
// This code is licensed under MIT license (see LICENSE for details)
package console_test
import (
"context"
"testing"
"github.com/elgopher/yala/adapter/console"
"github.com/elgopher/yala/adapter/internal/fake"
"github.com/elgopher/yala/logger"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWriterPrinter_Println(t *testing.T) {
t.Run("should not panic when Writer is nil", func(t *testing.T) {
p := console.WriterPrinter{Writer: nil}
assert.NotPanics(t, func() {
p.Println(0, "")
})
})
}
func TestStderrAdapter(t *testing.T) {
t.Run("should return adapter", func(t *testing.T) {
adapter := console.StderrAdapter()
require.NotNil(t, adapter)
})
t.Run("should log message", func(t *testing.T) {
stderr := fake.UseFakeStderr(t)
defer stderr.Release()
adapter := console.StderrAdapter()
// when
adapter.Log(context.Background(), logger.Entry{
Level: logger.InfoLevel,
Message: "message",
})
// then
assert.Equal(t, "INFO message\n", stderr.String(t))
})
}
func TestStdoutAdapter(t *testing.T) {
t.Run("should return adapter", func(t *testing.T) {
adapter := console.StdoutAdapter()
require.NotNil(t, adapter)
})
t.Run("should log message", func(t *testing.T) {
stdout := fake.UseFakeStdout(t)
defer stdout.Release()
adapter := console.StdoutAdapter()
// when
adapter.Log(context.Background(), logger.Entry{
Level: logger.InfoLevel,
Message: "message",
})
// then
assert.Equal(t, "INFO message\n", stdout.String(t))
})
}