From 9be0a1e53a5d26d0457fec2b2e790aff25b04635 Mon Sep 17 00:00:00 2001 From: Rangel Reale Date: Wed, 12 Apr 2023 11:01:36 -0300 Subject: [PATCH] tests --- provider_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 provider_test.go diff --git a/provider_test.go b/provider_test.go new file mode 100644 index 0000000..6caa91e --- /dev/null +++ b/provider_test.go @@ -0,0 +1,32 @@ +package ddspanname + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/sdk/trace/tracetest" +) + +func TestProvider(t *testing.T) { + sr := tracetest.NewSpanRecorder() + tracerProvider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + + ddprovider := NewTracerProvider("ddspanname.operation", + WithTracerProvider(tracerProvider)) + ddtracer := ddprovider.Tracer("ddspanname.instrument") + + require.IsType(t, &tracer{}, ddtracer) + + _, span := ddtracer.Start(context.Background(), "ddspanname.span") + span.End() + + spans := sr.Ended() + require.Len(t, spans, 1) + + require.Equal(t, "ddspanname.span", spans[0].Name()) + require.Contains(t, spans[0].Attributes(), DDOperationNameKey.String("ddspanname.operation")) + require.Contains(t, spans[0].Attributes(), DDResourceNameKey.String("ddspanname.span")) + +}