Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Boten committed Mar 1, 2022
1 parent 53371f1 commit b297782
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions model/otlp/pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ func TestProtobufMetricsSizer_withNil(t *testing.T) {
assert.Equal(t, 0, sizer.MetricsSize(pdata.NewMetrics()))
}

func TestProtobufMetricsSizerWithOptional(t *testing.T) {
sizer := NewProtobufMetricsMarshaler().(pdata.MetricsSizer)
marshaler := NewProtobufMetricsMarshaler()
md := pdata.NewMetrics()
metric := md.ResourceMetrics().AppendEmpty().InstrumentationLibraryMetrics().AppendEmpty().Metrics().AppendEmpty()
metric.SetDataType(pdata.MetricDataTypeHistogram)
datapoint := metric.Histogram().DataPoints().AppendEmpty()
datapoint.SetMin(0.1)
datapoint.SetMax(100)

size := sizer.MetricsSize(md)

bytes, err := marshaler.MarshalMetrics(md)
require.NoError(t, err)
assert.Equal(t, len(bytes), size)

p := NewProtobufMetricsUnmarshaler()
unmarshalled, err := p.UnmarshalMetrics(bytes)
assert.NoError(t, err)
assert.Equal(t, metric, unmarshalled.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0))

}

func TestProtobufLogsSizer(t *testing.T) {
sizer := NewProtobufLogsMarshaler().(pdata.LogsSizer)
marshaler := NewProtobufLogsMarshaler()
Expand Down
4 changes: 4 additions & 0 deletions model/pdata/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ func TestOtlpToFromInternalHistogramMutating(t *testing.T) {
histogramDataPoints.At(0).SetExplicitBounds([]float64{1})
assert.EqualValues(t, []float64{1}, histogramDataPoints.At(0).ExplicitBounds())
histogramDataPoints.At(0).SetBucketCounts([]uint64{21, 32})
histogramDataPoints.At(0).SetMin(10.1)
histogramDataPoints.At(0).SetMax(27)
// Test that everything is updated.
assert.EqualValues(t, &otlpmetrics.MetricsData{
ResourceMetrics: []*otlpmetrics.ResourceMetrics{
Expand Down Expand Up @@ -549,6 +551,8 @@ func TestOtlpToFromInternalHistogramMutating(t *testing.T) {
TimeUnixNano: endTime + 1,
BucketCounts: []uint64{21, 32},
ExplicitBounds: []float64{1},
Min_: histogramDataPoints.At(0).orig.Min_,
Max_: histogramDataPoints.At(0).orig.Max_,
},
},
},
Expand Down

0 comments on commit b297782

Please sign in to comment.