Skip to content

Commit 477ab2d

Browse files
committed
test coverage
1 parent df68b86 commit 477ab2d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

bridge/opencensus/internal/ocmetric/metric.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package internal // import "go.opentelemetry.io/otel/bridge/opencensus/internal/
1717
import (
1818
"errors"
1919
"fmt"
20+
"math"
2021
"reflect"
2122
"sort"
2223
"strconv"
@@ -305,9 +306,8 @@ func intSliceKV[N int8 | int16 | int32](key string, val []N) attribute.KeyValue
305306
}
306307

307308
func uintKV(key string, val uint) attribute.KeyValue {
308-
const maxInt = ^uint(0) >> 1
309-
if val > maxInt {
310-
return uint64KV(key, uint64(val))
309+
if val > uint(math.MaxInt) {
310+
return attribute.String(key, strconv.FormatUint(uint64(val), 10))
311311
}
312312
return attribute.Int(key, int(val))
313313
}

bridge/opencensus/internal/ocmetric/metric_test.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,10 @@ func TestConvertKV(t *testing.T) {
858858
value: uint(10),
859859
expected: attribute.IntValue(10),
860860
},
861+
{
862+
value: uint(math.MaxUint),
863+
expected: attribute.StringValue(fmt.Sprintf("%v", uint(math.MaxUint))),
864+
},
861865
{
862866
value: []uint{10, 20},
863867
expected: attribute.StringSliceValue([]string{"10", "20"}),
@@ -882,10 +886,6 @@ func TestConvertKV(t *testing.T) {
882886
value: uint32(10),
883887
expected: attribute.IntValue(10),
884888
},
885-
{
886-
value: uint32(math.MaxUint32),
887-
expected: attribute.Int64Value(math.MaxUint32),
888-
},
889889
{
890890
value: []uint32{10, 20},
891891
expected: attribute.StringSliceValue([]string{"10", "20"}),
@@ -910,6 +910,14 @@ func TestConvertKV(t *testing.T) {
910910
value: []uintptr{10, 20},
911911
expected: attribute.StringSliceValue([]string{"10", "20"}),
912912
},
913+
{
914+
value: float32(10),
915+
expected: attribute.Float64Value(10),
916+
},
917+
{
918+
value: []float32{10, 20},
919+
expected: attribute.Float64SliceValue([]float64{10, 20}),
920+
},
913921
{
914922
value: float64(10),
915923
expected: attribute.Float64Value(10),

0 commit comments

Comments
 (0)