1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-10-31 00:07:40 +02:00
Files
opentelemetry-go/sdk/trace/tracetest/exporter_test.go
Mikhail Mazurskiy 5e1c62a2d5 Modernize (#7089)
Use
https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize
to update code to new style.

---------

Co-authored-by: Flc゛ <four_leaf_clover@foxmail.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-07-29 10:19:11 +02:00

50 lines
1.4 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package tracetest
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestNoop tests only that the no-op does not crash in different scenarios.
func TestNoop(t *testing.T) {
nsb := NewNoopExporter()
require.NoError(t, nsb.ExportSpans(context.Background(), nil))
require.NoError(t, nsb.ExportSpans(context.Background(), make(SpanStubs, 10).Snapshots()))
require.NoError(t, nsb.ExportSpans(context.Background(), make(SpanStubs, 0, 10).Snapshots()))
}
func TestNewInMemoryExporter(t *testing.T) {
imsb := NewInMemoryExporter()
require.NoError(t, imsb.ExportSpans(context.Background(), nil))
assert.Empty(t, imsb.GetSpans())
input := make(SpanStubs, 10)
for i := range 10 {
input[i] = SpanStub{Name: fmt.Sprintf("span %d", i)}
}
require.NoError(t, imsb.ExportSpans(context.Background(), input.Snapshots()))
sds := imsb.GetSpans()
assert.Len(t, sds, 10)
for i, sd := range sds {
assert.Equal(t, input[i], sd)
}
imsb.Reset()
// Ensure that operations on the internal storage does not change the previously returned value.
assert.Len(t, sds, 10)
assert.Empty(t, imsb.GetSpans())
require.NoError(t, imsb.ExportSpans(context.Background(), input.Snapshots()[0:1]))
sds = imsb.GetSpans()
assert.Len(t, sds, 1)
assert.Equal(t, input[0], sds[0])
}