Skip to content

Commit

Permalink
[exporter/instana] Simplify pushConvertedTraces tests (open-telemetry…
Browse files Browse the repository at this point in the history
…#13851)

Just removing some redundant code. `TestPushConvertedDefaultTraces` and `TestPushConvertedSimpleTraces` are equivalent except for that one passes a trace with attributes  to `pushConvertedTraces`, another passes a trace with SpanID/TraceID.  It doesn't seem there is a reason to make that distinction. This change combine the tests into one passing a trace with both attributes and SpanID/TraceID to `pushConvertedTraces`.
  • Loading branch information
dmitryax authored Sep 2, 2022
1 parent b2072de commit 7ab198f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 79 deletions.
41 changes: 5 additions & 36 deletions exporter/instanaexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,9 @@ import (
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/instanaexporter/internal/testutils"
)

func TestPushConvertedDefaultTraces(t *testing.T) {
traceServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusAccepted)
}))
defer traceServer.Close()

cfg := Config{
AgentKey: "key11",
HTTPClientSettings: confighttp.HTTPClientSettings{Endpoint: traceServer.URL},
Endpoint: traceServer.URL,
ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "valid")),
}

instanaExporter := newInstanaExporter(&cfg, componenttest.NewNopExporterCreateSettings())
ctx := context.Background()
err := instanaExporter.start(ctx, componenttest.NewNopHost())
assert.NoError(t, err)

err = instanaExporter.pushConvertedTraces(ctx, testutils.TestTraces.Clone())
assert.NoError(t, err)
}

func TestPushConvertedSimpleTraces(t *testing.T) {
func TestPushConvertedTraces(t *testing.T) {
traceServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusAccepted)
}))
Expand All @@ -70,23 +46,16 @@ func TestPushConvertedSimpleTraces(t *testing.T) {
err := instanaExporter.start(ctx, componenttest.NewNopHost())
assert.NoError(t, err)

err = instanaExporter.pushConvertedTraces(ctx, simpleTraces())
err = instanaExporter.pushConvertedTraces(ctx, newTestTraces())
assert.NoError(t, err)
}

func simpleTraces() ptrace.Traces {
return genTraces(pcommon.NewTraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}), nil)
}

func genTraces(traceID pcommon.TraceID, attrs map[string]interface{}) ptrace.Traces {
func newTestTraces() ptrace.Traces {
traces := ptrace.NewTraces()
rspans := traces.ResourceSpans().AppendEmpty()
rspans.Resource().Attributes().UpsertString("instana.agent", "agent1")
span := rspans.ScopeSpans().AppendEmpty().Spans().AppendEmpty()
span.SetTraceID(traceID)
span.SetTraceID(pcommon.NewTraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}))
span.SetSpanID(pcommon.NewSpanID([8]byte{0, 0, 0, 0, 1, 2, 3, 4}))
if attrs == nil {
return traces
}
pcommon.NewMapFromRaw(attrs).CopyTo(rspans.Resource().Attributes())
return traces
}
43 changes: 0 additions & 43 deletions exporter/instanaexporter/internal/testutils/test_utils.go

This file was deleted.

0 comments on commit 7ab198f

Please sign in to comment.