From da07a5d63224db282c84aaafb4d22a7e962c4e2e Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Fri, 13 Oct 2023 16:56:49 +0000 Subject: [PATCH] test coverage --- bridge/opencensus/internal/ocmetric/metric.go | 6 +++--- .../opencensus/internal/ocmetric/metric_test.go | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/bridge/opencensus/internal/ocmetric/metric.go b/bridge/opencensus/internal/ocmetric/metric.go index b55874f3a669..aeb3479f40b4 100644 --- a/bridge/opencensus/internal/ocmetric/metric.go +++ b/bridge/opencensus/internal/ocmetric/metric.go @@ -17,6 +17,7 @@ package internal // import "go.opentelemetry.io/otel/bridge/opencensus/internal/ import ( "errors" "fmt" + "math" "reflect" "sort" "strconv" @@ -305,9 +306,8 @@ func intSliceKV[N int8 | int16 | int32](key string, val []N) attribute.KeyValue } func uintKV(key string, val uint) attribute.KeyValue { - const maxInt = ^uint(0) >> 1 - if val > maxInt { - return uint64KV(key, uint64(val)) + if val > uint(math.MaxInt) { + return attribute.String(key, strconv.FormatUint(uint64(val), 10)) } return attribute.Int(key, int(val)) } diff --git a/bridge/opencensus/internal/ocmetric/metric_test.go b/bridge/opencensus/internal/ocmetric/metric_test.go index 722c8ba7e015..92bd82f9ef3e 100644 --- a/bridge/opencensus/internal/ocmetric/metric_test.go +++ b/bridge/opencensus/internal/ocmetric/metric_test.go @@ -858,6 +858,10 @@ func TestConvertKV(t *testing.T) { value: uint(10), expected: attribute.IntValue(10), }, + { + value: uint(math.MaxUint), + expected: attribute.StringValue("18446744073709551615"), + }, { value: []uint{10, 20}, expected: attribute.StringSliceValue([]string{"10", "20"}), @@ -882,10 +886,6 @@ func TestConvertKV(t *testing.T) { value: uint32(10), expected: attribute.IntValue(10), }, - { - value: uint32(math.MaxUint32), - expected: attribute.Int64Value(math.MaxUint32), - }, { value: []uint32{10, 20}, expected: attribute.StringSliceValue([]string{"10", "20"}), @@ -910,6 +910,14 @@ func TestConvertKV(t *testing.T) { value: []uintptr{10, 20}, expected: attribute.StringSliceValue([]string{"10", "20"}), }, + { + value: float32(10), + expected: attribute.Float64Value(10), + }, + { + value: []float32{10, 20}, + expected: attribute.Float64SliceValue([]float64{10, 20}), + }, { value: float64(10), expected: attribute.Float64Value(10),