From 2830a0a6aaa06f2eab34cbb5f6befb6f2a53026f Mon Sep 17 00:00:00 2001 From: Cheng-Zhen Yang Date: Sun, 6 Oct 2024 01:46:20 +1300 Subject: [PATCH] Add TestLogSinkEnabled --- bridges/otellogr/logsink_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bridges/otellogr/logsink_test.go b/bridges/otellogr/logsink_test.go index df6a2c18fc6..2b2e71a541c 100644 --- a/bridges/otellogr/logsink_test.go +++ b/bridges/otellogr/logsink_test.go @@ -3,6 +3,7 @@ package otellogr import ( + "context" "testing" "time" @@ -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)