github.com/observiq/bindplane-agent@v1.51.0/internal/throughputwrapper/trace_consumer_test.go (about) 1 // Copyright observIQ, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package throughputwrapper 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/stretchr/testify/require" 22 "go.opentelemetry.io/collector/consumer/consumertest" 23 "go.opentelemetry.io/collector/pdata/ptrace" 24 "go.uber.org/zap" 25 ) 26 27 func Test_newTraceConsumer(t *testing.T) { 28 nopLogger := zap.NewNop() 29 componentID := "id" 30 baseConsumer := consumertest.NewNop() 31 tConsumer := newTraceConsumer(nopLogger, componentID, baseConsumer) 32 33 require.Equal(t, nopLogger, tConsumer.logger) 34 require.Equal(t, baseConsumer, tConsumer.baseConsumer) 35 require.Len(t, tConsumer.mutators, 1) 36 require.Equal(t, &ptrace.ProtoMarshaler{}, tConsumer.tracesSizer) 37 } 38 39 func Test_traceConsumer_ConsumeTraces(t *testing.T) { 40 nopLogger := zap.NewNop() 41 componentID := "id" 42 baseConsumer := new(consumertest.TracesSink) 43 tConsumer := newTraceConsumer(nopLogger, componentID, baseConsumer) 44 45 td := ptrace.NewTraces() 46 td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty() 47 48 err := tConsumer.ConsumeTraces(context.Background(), td) 49 require.NoError(t, err) 50 51 require.Equal(t, 1, baseConsumer.SpanCount()) 52 } 53 54 func Test_traceConsumer_Capabilities(t *testing.T) { 55 nopLogger := zap.NewNop() 56 componentID := "id" 57 baseConsumer := consumertest.NewNop() 58 tConsumer := newTraceConsumer(nopLogger, componentID, baseConsumer) 59 60 require.Equal(t, baseConsumer.Capabilities(), tConsumer.Capabilities()) 61 }