Skip to content

Commit

Permalink
Add TestLogSinkEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpionknifes committed Oct 5, 2024
1 parent e9ba478 commit 2830a0a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bridges/otellogr/logsink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package otellogr

import (
"context"
"testing"
"time"

Expand Down Expand Up @@ -288,6 +289,33 @@ func TestLogSink(t *testing.T) {
}
}

func TestLogSinkEnabled(t *testing.T) {
enabledFunc := func(ctx context.Context, param log.EnabledParameters) bool {
lvl, ok := param.Severity()
if !ok {
return true
}
return lvl == log.SeverityInfo
}

rec := logtest.NewRecorder(logtest.WithEnabledFunc(enabledFunc))
ls := NewLogSink(
"name",
WithLoggerProvider(rec),
WithLevelSeverity(func(i int) log.Severity {
switch i {
case 0:
return log.SeverityDebug
default:
return log.SeverityInfo
}
}),
)

assert.False(t, ls.Enabled(0))
assert.True(t, ls.Enabled(1))
}

func buildRecord(body log.Value, timestamp time.Time, severity log.Severity, attrs []log.KeyValue) log.Record {
var record log.Record
record.SetBody(body)
Expand Down

0 comments on commit 2830a0a

Please sign in to comment.