42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
|
package logging
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
"time"
|
||
|
|
||
|
"github.com/getsentry/sentry-go"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
var logEventJSON = []byte(`{"level":"error","requestId":"bee07485-2485-4f64-99e1-d10165884ca7","error":"dial timeout","time":"2020-06-25T17:19:00+03:00","message":"test message"}`)
|
||
|
|
||
|
// TestParseLogEvent asserts that the log event is forwarded from ZeroLog to Sentry.
|
||
|
func TestParseLogEvent(t *testing.T) {
|
||
|
ts := time.Now()
|
||
|
|
||
|
now = func() time.Time { return ts }
|
||
|
|
||
|
w := NewSentryWriter()
|
||
|
|
||
|
ev, ok := w.parseLogEvent(logEventJSON)
|
||
|
require.True(t, ok)
|
||
|
|
||
|
assert.Equal(t, ts, ev.Timestamp)
|
||
|
assert.Equal(t, sentry.LevelError, ev.Level)
|
||
|
assert.Equal(t, "zerolog", ev.Logger)
|
||
|
assert.Equal(t, "test message", ev.Message)
|
||
|
|
||
|
require.Len(t, ev.Exception, 1)
|
||
|
assert.Equal(t, "dial timeout", ev.Exception[0].Value)
|
||
|
}
|
||
|
|
||
|
// BenchmarkParseLogEvent checks the performance of the event log parser.
|
||
|
func BenchmarkParseLogEvent(b *testing.B) {
|
||
|
w := NewSentryWriter()
|
||
|
|
||
|
for i := 0; i < b.N; i++ {
|
||
|
w.parseLogEvent(logEventJSON)
|
||
|
}
|
||
|
}
|