| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package logrus_test |
| 8 |
|
| 9 |
import ( |
| 10 |
"io" |
| 11 |
"testing" |
| 12 |
|
| 13 |
"github.com/google/go-cmp/cmp" |
| 14 |
"github.com/sirupsen/logrus" |
| 15 |
"golang.org/x/exp/event" |
| 16 |
elogrus "golang.org/x/exp/event/adapter/logrus" |
| 17 |
"golang.org/x/exp/event/eventtest" |
| 18 |
"golang.org/x/exp/event/severity" |
| 19 |
) |
| 20 |
|
| 21 |
func Test(t *testing.T) { |
| 22 |
ctx, th := eventtest.NewCapture() |
| 23 |
log := logrus.New() |
| 24 |
log.SetFormatter(elogrus.NewFormatter()) |
| 25 |
log.SetOutput(io.Discard) |
| 26 |
|
| 27 |
log.WithContext(ctx).WithField("traceID", 17).WithField("resource", "R").Info("mess") |
| 28 |
|
| 29 |
want := []event.Event{{ |
| 30 |
ID: 1, |
| 31 |
Kind: event.LogKind, |
| 32 |
Labels: []event.Label{ |
| 33 |
severity.Info.Label(), |
| 34 |
event.Value("traceID", 17), |
| 35 |
event.Value("resource", "R"), |
| 36 |
event.String("msg", "mess"), |
| 37 |
}, |
| 38 |
}} |
| 39 |
|
| 40 |
|
| 41 |
if diff := cmp.Diff(want, th.Got, eventtest.CmpOptions()...); diff != "" { |
| 42 |
t.Errorf("mismatch (-want, +got):\n%s", diff) |
| 43 |
} |
| 44 |
} |