Skip to content

Commit

Permalink
fix lint in exemplar
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Sep 11, 2024
1 parent d310561 commit 5880fee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion sdk/metric/internal/exemplar/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type Value struct {
func NewValue[N int64 | float64](value N) Value {
switch v := any(value).(type) {
case int64:
return Value{t: Int64ValueType, val: uint64(v)}
// This can be later converted back to int64 (overflow not checked).
return Value{t: Int64ValueType, val: uint64(v)} // nolint:gosec
case float64:
return Value{t: Float64ValueType, val: math.Float64bits(v)}
}
Expand Down
8 changes: 6 additions & 2 deletions sdk/metric/internal/exemplar/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

func TestValue(t *testing.T) {
const iVal, fVal = int64(43), float64(0.3)
i, f, bad := NewValue[int64](iVal), NewValue[float64](fVal), Value{}
const iVal, fVal, nVal = int64(43), float64(0.3), int64(-42)
i, f, n, bad := NewValue[int64](iVal), NewValue[float64](fVal), NewValue[int64](nVal), Value{}

assert.Equal(t, Int64ValueType, i.Type())
assert.Equal(t, iVal, i.Int64())
Expand All @@ -21,6 +21,10 @@ func TestValue(t *testing.T) {
assert.Equal(t, fVal, f.Float64())
assert.Equal(t, int64(0), f.Int64())

assert.Equal(t, Int64ValueType, n.Type())
assert.Equal(t, nVal, n.Int64())
assert.Equal(t, float64(0), i.Float64())

assert.Equal(t, UnknownValueType, bad.Type())
assert.Equal(t, float64(0), bad.Float64())
assert.Equal(t, int64(0), bad.Int64())
Expand Down

0 comments on commit 5880fee

Please sign in to comment.