github.com/observiq/bindplane-agent@v1.51.0/internal/throughputwrapper/metric_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/pmetric"
    24  	"go.uber.org/zap"
    25  )
    26  
    27  func Test_newMetricConsumer(t *testing.T) {
    28  	nopLogger := zap.NewNop()
    29  	componentID := "id"
    30  	baseConsumer := consumertest.NewNop()
    31  	mConsumer := newMetricConsumer(nopLogger, componentID, baseConsumer)
    32  
    33  	require.Equal(t, nopLogger, mConsumer.logger)
    34  	require.Equal(t, baseConsumer, mConsumer.baseConsumer)
    35  	require.Len(t, mConsumer.mutators, 1)
    36  	require.Equal(t, &pmetric.ProtoMarshaler{}, mConsumer.metricsSizer)
    37  }
    38  
    39  func Test_metricConsumer_ConsumeMetrics(t *testing.T) {
    40  	nopLogger := zap.NewNop()
    41  	componentID := "id"
    42  	baseConsumer := new(consumertest.MetricsSink)
    43  	mConsumer := newMetricConsumer(nopLogger, componentID, baseConsumer)
    44  
    45  	md := pmetric.NewMetrics()
    46  	metric := md.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics().AppendEmpty()
    47  	metric.SetEmptyGauge()
    48  	metric.Gauge().DataPoints().AppendEmpty()
    49  
    50  	err := mConsumer.ConsumeMetrics(context.Background(), md)
    51  	require.NoError(t, err)
    52  
    53  	require.Equal(t, 1, baseConsumer.DataPointCount())
    54  }
    55  
    56  func Test_metricConsumer_Capabilities(t *testing.T) {
    57  	nopLogger := zap.NewNop()
    58  	componentID := "id"
    59  	baseConsumer := consumertest.NewNop()
    60  	mConsumer := newMetricConsumer(nopLogger, componentID, baseConsumer)
    61  
    62  	require.Equal(t, baseConsumer.Capabilities(), mConsumer.Capabilities())
    63  }