Skip to content

Commit

Permalink
update stackdriver test to use pdata
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencl1013 committed Jul 21, 2020
1 parent efe20d3 commit 619c749
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions exporter/stackdriverexporter/stackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ import (
"testing"
"time"

resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/empty"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer/consumerdata"
cloudtracepb "google.golang.org/genproto/googleapis/devtools/cloudtrace/v2"
"google.golang.org/grpc"

"go.opentelemetry.io/collector/consumer/pdata"
)

func mustTS(t time.Time) *timestamp.Timestamp {
Expand Down Expand Up @@ -83,27 +82,28 @@ func TestStackdriverExport(t *testing.T) {

testTime := time.Now()

td := consumerdata.TraceData{
Resource: &resourcepb.Resource{},
Spans: []*tracepb.Span{
{
Name: &tracepb.TruncatableString{
Value: "foobar",
},
StartTime: mustTS(testTime),
},
},
}

err = sde.ConsumeTraceData(ctx, td)
resource := pdata.NewResource()
resource.InitEmpty()
traces := pdata.NewTraces()
traces.ResourceSpans().Resize(1)
rspans := traces.ResourceSpans().At(0)
resource.CopyTo(rspans.Resource())
rspans.InstrumentationLibrarySpans().Resize(1)
ispans := rspans.InstrumentationLibrarySpans().At(0)
ispans.Spans().Resize(1)
span := pdata.NewSpan()
span.InitEmpty()
span.SetName("foobar")
span.SetStartTime(pdata.TimestampUnixNano(testTime.UnixNano()))
err = sde.ConsumeTraces(ctx, traces)
assert.NoError(t, err)

select {
case <-time.After(10 * time.Second):
t.Errorf("test timed out")
case r := <-reqCh:
assert.Len(t, r.Spans, 1)
assert.Equal(t, "foobar", r.Spans[0].GetDisplayName().GetValue())
assert.Equal(t, "foobar", r.Spans[0].GetName())
assert.Equal(t, mustTS(testTime), r.Spans[0].StartTime)
}
}

0 comments on commit 619c749

Please sign in to comment.