Skip to content

Commit f3eda02

Browse files
committed
Update provider and logger tests
1 parent f47c058 commit f3eda02

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

sdk/log/logger_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ func TestLoggerEmit(t *testing.T) {
215215
}
216216

217217
func TestLoggerEnabled(t *testing.T) {
218-
p0, p1, p2WithDisabled := newProcessor("0"), newProcessor("1"), newProcessor("2")
219-
p2WithDisabled.enabled = false
218+
p0 := newFilterProcessor("0", true)
219+
p1 := newFilterProcessor("1", true)
220+
p2WithDisabled := newFilterProcessor("2", false)
220221

221222
testCases := []struct {
222223
name string

sdk/log/provider_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ type processor struct {
3131
forceFlushCalls int
3232

3333
records []Record
34-
enabled bool
3534
}
3635

3736
func newProcessor(name string) *processor {
38-
return &processor{Name: name, enabled: true}
37+
return &processor{Name: name}
3938
}
4039

4140
func (p *processor) OnEmit(ctx context.Context, r *Record) error {
@@ -47,10 +46,6 @@ func (p *processor) OnEmit(ctx context.Context, r *Record) error {
4746
return nil
4847
}
4948

50-
func (p *processor) Enabled(context.Context, Record) bool {
51-
return p.enabled
52-
}
53-
5449
func (p *processor) Shutdown(context.Context) error {
5550
p.shutdownCalls++
5651
return p.Err
@@ -61,6 +56,23 @@ func (p *processor) ForceFlush(context.Context) error {
6156
return p.Err
6257
}
6358

59+
type filterProcessor struct {
60+
*processor
61+
62+
enabled bool
63+
}
64+
65+
func newFilterProcessor(name string, enabled bool) *filterProcessor {
66+
return &filterProcessor{
67+
processor: newProcessor(name),
68+
enabled: enabled,
69+
}
70+
}
71+
72+
func (p *filterProcessor) Enabled(context.Context, Record) bool {
73+
return p.enabled
74+
}
75+
6476
func TestNewLoggerProviderConfiguration(t *testing.T) {
6577
t.Cleanup(func(orig otel.ErrorHandler) func() {
6678
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {

0 commit comments

Comments
 (0)