mirror of
https://github.com/caddyserver/caddy.git
synced 2026-07-11 03:14:19 +00:00
add test for buldOpts error path
This commit is contained in:
parent
2926062009
commit
5754acae57
1 changed files with 26 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package tracing
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
|
|
@ -74,3 +75,28 @@ func Test_tracersProvider_buildOptsOnlyOnCreate(t *testing.T) {
|
|||
t.Errorf("Tracer providers counter should equal to 6, got %d", tp.tracerProvidersCounter)
|
||||
}
|
||||
}
|
||||
|
||||
// Test_tracersProvider_buildOptsError verifies that an error from buildOpts is
|
||||
// propagated and that no provider is created nor the counter incremented, so a
|
||||
// failed build leaves the tracerProvider in its initial state.
|
||||
func Test_tracersProvider_buildOptsError(t *testing.T) {
|
||||
tp := tracerProvider{}
|
||||
|
||||
wantErr := errors.New("build failed")
|
||||
build := func() ([]sdktrace.TracerProviderOption, error) {
|
||||
return nil, wantErr
|
||||
}
|
||||
|
||||
_, err := tp.getTracerProvider(build)
|
||||
if !errors.Is(err, wantErr) {
|
||||
t.Errorf("Expected error %v, got %v", wantErr, err)
|
||||
}
|
||||
|
||||
if tp.tracerProvider != nil {
|
||||
t.Errorf("There should be no tracer provider when buildOpts fails")
|
||||
}
|
||||
|
||||
if tp.tracerProvidersCounter != 0 {
|
||||
t.Errorf("Tracer providers counter should equal to 0, got %d", tp.tracerProvidersCounter)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue