Skip to content

Commit a60ff1a

Browse files
committed
test: add TestWriterFromPrinter in log_test.go
Signed-off-by: aoright <102943475+aoright@users.noreply.github.com>
1 parent d5da5b0 commit a60ff1a

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

log_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package fx
2222

2323
import (
24+
"fmt"
2425
"testing"
2526

2627
"github.com/stretchr/testify/assert"
@@ -76,3 +77,24 @@ func TestWithLoggerDecorate(t *testing.T) {
7677
assert.NotZero(t, logs.Len(),
7778
"should post to replacement logger")
7879
}
80+
81+
type testPrinter struct {
82+
messages []string
83+
}
84+
85+
func (p *testPrinter) Printf(format string, args ...interface{}) {
86+
p.messages = append(p.messages, fmt.Sprintf(format, args...))
87+
}
88+
89+
func TestWriterFromPrinter(t *testing.T) {
90+
t.Parallel()
91+
92+
p := &testPrinter{}
93+
w := writerFromPrinter(p)
94+
95+
n, err := w.Write([]byte("hello world"))
96+
assert.NoError(t, err)
97+
assert.Equal(t, 11, n)
98+
assert.Equal(t, []string{"hello world"}, p.messages)
99+
}
100+

0 commit comments

Comments
 (0)