Skip to content

Commit

Permalink
Update provider and logger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Aug 7, 2024
1 parent 970fa42 commit 5d7f710
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
5 changes: 3 additions & 2 deletions sdk/log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ func TestLoggerEmit(t *testing.T) {
}

func TestLoggerEnabled(t *testing.T) {
p0, p1, p2WithDisabled := newProcessor("0"), newProcessor("1"), newProcessor("2")
p2WithDisabled.enabled = false
p0 := newFilterProcessor("0", true)
p1 := newFilterProcessor("1", true)
p2WithDisabled := newFilterProcessor("2", false)

testCases := []struct {
name string
Expand Down
24 changes: 18 additions & 6 deletions sdk/log/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ type processor struct {
forceFlushCalls int

records []Record
enabled bool
}

func newProcessor(name string) *processor {
return &processor{Name: name, enabled: true}
return &processor{Name: name}
}

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

func (p *processor) Enabled(context.Context, Record) bool {
return p.enabled
}

func (p *processor) Shutdown(context.Context) error {
p.shutdownCalls++
return p.Err
Expand All @@ -61,6 +56,23 @@ func (p *processor) ForceFlush(context.Context) error {
return p.Err
}

type filterProcessor struct {
*processor

enabled bool
}

func newFilterProcessor(name string, enabled bool) *filterProcessor {
return &filterProcessor{
processor: newProcessor(name),
enabled: enabled,
}
}

func (p *filterProcessor) Enabled(context.Context, Record) bool {
return p.enabled
}

func TestNewLoggerProviderConfiguration(t *testing.T) {
t.Cleanup(func(orig otel.ErrorHandler) func() {
otel.SetErrorHandler(otel.ErrorHandlerFunc(func(err error) {
Expand Down

0 comments on commit 5d7f710

Please sign in to comment.