-
-
Notifications
You must be signed in to change notification settings - Fork 319
/
Copy pathlog_test.go
38 lines (28 loc) · 838 Bytes
/
log_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
package mercure
import (
"bytes"
"net/url"
"testing"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
// MemorySink implements zap.Sink by writing all messages to a buffer.
type MemorySink struct {
*bytes.Buffer
}
// Implement Close and Sync as no-ops to satisfy the interface. The Write
// method is provided by the embedded buffer.
func (s *MemorySink) Close() error { return nil }
func (s *MemorySink) Sync() error { return nil }
func newTestLogger(t *testing.T) (*MemorySink, *zap.Logger) {
t.Helper()
sink := &MemorySink{new(bytes.Buffer)}
require.NoError(t, zap.RegisterSink(t.Name(), func(*url.URL) (zap.Sink, error) {
return sink, nil
}))
conf := zap.NewProductionConfig()
conf.OutputPaths = []string{t.Name() + "://"}
logger, err := conf.Build()
require.NoError(t, err)
return sink, logger
}