forked from dunglas/mercure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_test.go
45 lines (34 loc) · 874 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
39
40
41
42
43
44
45
package mercure
import (
"bytes"
"net/url"
"testing"
"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 }
var sink *MemorySink
func newTestLogger(t *testing.T) (*MemorySink, *zap.Logger) {
t.Helper()
if sink == nil {
sink = &MemorySink{new(bytes.Buffer)}
if err := zap.RegisterSink("memory", func(*url.URL) (zap.Sink, error) {
return sink, nil
}); err != nil {
t.Fatal(err)
}
}
conf := zap.NewProductionConfig()
conf.OutputPaths = []string{"memory://"}
logger, err := conf.Build()
if err != nil {
t.Fatal(err)
}
return sink, logger
}