Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Oct 17, 2023
1 parent 29aaba1 commit f495b5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions bridge/opencensus/internal/ocmetric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package internal // import "go.opentelemetry.io/otel/bridge/opencensus/internal/
import (
"errors"
"fmt"
"math"
"reflect"
"sort"
"strconv"
Expand Down Expand Up @@ -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))
}
Expand Down
16 changes: 12 additions & 4 deletions bridge/opencensus/internal/ocmetric/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ func TestConvertKV(t *testing.T) {
value: uint(10),
expected: attribute.IntValue(10),
},
{
value: uint(math.MaxUint),
expected: attribute.StringValue(fmt.Sprintf("%v", uint(math.MaxUint))),
},
{
value: []uint{10, 20},
expected: attribute.StringSliceValue([]string{"10", "20"}),
Expand All @@ -891,10 +895,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"}),
Expand All @@ -919,6 +919,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),
Expand Down

0 comments on commit f495b5d

Please sign in to comment.