You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-17 01:12:45 +02:00
Make the AsType functions not panic (#3489)
* Make the AsType functions not panic * Adds changelog Signed-off-by: Aaron Clawson <3766680+MadVikingGod@users.noreply.github.com> Signed-off-by: Aaron Clawson <3766680+MadVikingGod@users.noreply.github.com> Co-authored-by: Chester Cheung <cheung.zhy.csu@gmail.com>
This commit is contained in:
@ -18,6 +18,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
)
|
||||
@ -132,3 +133,50 @@ func TestKeyValueValid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncorrectCast(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
val attribute.Value
|
||||
}{
|
||||
{
|
||||
name: "Float64",
|
||||
val: attribute.Float64Value(1.0),
|
||||
},
|
||||
{
|
||||
name: "Int64",
|
||||
val: attribute.Int64Value(2),
|
||||
},
|
||||
{
|
||||
name: "String",
|
||||
val: attribute.BoolValue(true),
|
||||
},
|
||||
{
|
||||
name: "Float64Slice",
|
||||
val: attribute.Float64SliceValue([]float64{1.0}),
|
||||
},
|
||||
{
|
||||
name: "Int64Slice",
|
||||
val: attribute.Int64SliceValue([]int64{2}),
|
||||
},
|
||||
{
|
||||
name: "StringSlice",
|
||||
val: attribute.BoolSliceValue([]bool{true}),
|
||||
},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.NotPanics(t, func() {
|
||||
tt.val.AsBool()
|
||||
tt.val.AsBoolSlice()
|
||||
tt.val.AsFloat64()
|
||||
tt.val.AsFloat64Slice()
|
||||
tt.val.AsInt64()
|
||||
tt.val.AsInt64Slice()
|
||||
tt.val.AsInterface()
|
||||
tt.val.AsString()
|
||||
tt.val.AsStringSlice()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user