Created
November 21, 2022 21:48
-
-
Save MadVikingGod/841174e217a53eda6c6d5c8da814598c to your computer and use it in GitHub Desktop.
Attribute test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
}) | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- FAIL: TestIncorrectCast (0.00s) | |
--- FAIL: TestIncorrectCast/Float64 (0.00s) | |
kv_test.go:169: | |
Error Trace: /home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 | |
Error: func (assert.PanicTestFunc)(0x6c0e40) should not panic | |
Panic value: reflect: call of reflect.Value.Type on zero Value | |
Panic stack: goroutine 48 [running]: | |
runtime/debug.Stack() | |
/usr/local/go/src/runtime/debug/stack.go:24 +0x65 | |
github.com/stretchr/testify/assert.didPanic.func1() | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1050 +0x6c | |
panic({0x6f9820, 0xc000196b40}) | |
/usr/local/go/src/runtime/panic.go:884 +0x212 | |
reflect.Value.typeSlow({0x0?, 0x0?, 0x96bf40?}) | |
/usr/local/go/src/reflect/value.go:2534 +0x12e | |
reflect.Value.Type(...) | |
/usr/local/go/src/reflect/value.go:2529 | |
go.opentelemetry.io/otel/internal/attribute.AsSlice[...]({0x0, 0x0?}) | |
/home/aaron/projects/opentelemetry-go/internal/attribute/attribute.go:36 +0xec | |
go.opentelemetry.io/otel/attribute.Value.AsBoolSlice(...) | |
/home/aaron/projects/opentelemetry-go/attribute/value.go:145 | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1.1() | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:171 +0x6f | |
github.com/stretchr/testify/assert.didPanic(0xc0002561a0?) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1055 +0x8c | |
github.com/stretchr/testify/assert.NotPanics({0x7ce2e0, 0xc0002561a0}, 0xc000181980, {0x0, 0x0, 0x0}) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1126 +0x7b | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1(0xc00024bd40?) | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 +0x76 | |
testing.tRunner(0xc0002561a0, 0xc000181970) | |
/usr/local/go/src/testing/testing.go:1446 +0x10b | |
created by testing.(*T).Run | |
/usr/local/go/src/testing/testing.go:1493 +0x35f | |
Test: TestIncorrectCast/Float64 | |
--- FAIL: TestIncorrectCast/Int64 (0.00s) | |
kv_test.go:169: | |
Error Trace: /home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 | |
Error: func (assert.PanicTestFunc)(0x6c0e40) should not panic | |
Panic value: reflect: call of reflect.Value.Type on zero Value | |
Panic stack: goroutine 49 [running]: | |
runtime/debug.Stack() | |
/usr/local/go/src/runtime/debug/stack.go:24 +0x65 | |
github.com/stretchr/testify/assert.didPanic.func1() | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1050 +0x6c | |
panic({0x6f9820, 0xc000196bb8}) | |
/usr/local/go/src/runtime/panic.go:884 +0x212 | |
reflect.Value.typeSlow({0x0?, 0x0?, 0x96bf40?}) | |
/usr/local/go/src/reflect/value.go:2534 +0x12e | |
reflect.Value.Type(...) | |
/usr/local/go/src/reflect/value.go:2529 | |
go.opentelemetry.io/otel/internal/attribute.AsSlice[...]({0x0, 0x0?}) | |
/home/aaron/projects/opentelemetry-go/internal/attribute/attribute.go:36 +0xec | |
go.opentelemetry.io/otel/attribute.Value.AsBoolSlice(...) | |
/home/aaron/projects/opentelemetry-go/attribute/value.go:145 | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1.1() | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:171 +0x6f | |
github.com/stretchr/testify/assert.didPanic(0xc000256340?) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1055 +0x8c | |
github.com/stretchr/testify/assert.NotPanics({0x7ce2e0, 0xc000256340}, 0xc000181a20, {0x0, 0x0, 0x0}) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1126 +0x7b | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1(0xc00024bd40?) | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 +0x76 | |
testing.tRunner(0xc000256340, 0xc000181a10) | |
/usr/local/go/src/testing/testing.go:1446 +0x10b | |
created by testing.(*T).Run | |
/usr/local/go/src/testing/testing.go:1493 +0x35f | |
Test: TestIncorrectCast/Int64 | |
--- FAIL: TestIncorrectCast/String (0.00s) | |
kv_test.go:169: | |
Error Trace: /home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 | |
Error: func (assert.PanicTestFunc)(0x6c0e40) should not panic | |
Panic value: reflect: call of reflect.Value.Type on zero Value | |
Panic stack: goroutine 50 [running]: | |
runtime/debug.Stack() | |
/usr/local/go/src/runtime/debug/stack.go:24 +0x65 | |
github.com/stretchr/testify/assert.didPanic.func1() | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1050 +0x6c | |
panic({0x6f9820, 0xc000196c30}) | |
/usr/local/go/src/runtime/panic.go:884 +0x212 | |
reflect.Value.typeSlow({0x0?, 0x0?, 0x96bf40?}) | |
/usr/local/go/src/reflect/value.go:2534 +0x12e | |
reflect.Value.Type(...) | |
/usr/local/go/src/reflect/value.go:2529 | |
go.opentelemetry.io/otel/internal/attribute.AsSlice[...]({0x0, 0x0?}) | |
/home/aaron/projects/opentelemetry-go/internal/attribute/attribute.go:36 +0xec | |
go.opentelemetry.io/otel/attribute.Value.AsBoolSlice(...) | |
/home/aaron/projects/opentelemetry-go/attribute/value.go:145 | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1.1() | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:171 +0x6f | |
github.com/stretchr/testify/assert.didPanic(0xc0002564e0?) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1055 +0x8c | |
github.com/stretchr/testify/assert.NotPanics({0x7ce2e0, 0xc0002564e0}, 0xc000181ac0, {0x0, 0x0, 0x0}) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1126 +0x7b | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1(0xc00024bd40?) | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 +0x76 | |
testing.tRunner(0xc0002564e0, 0xc000181ab0) | |
/usr/local/go/src/testing/testing.go:1446 +0x10b | |
created by testing.(*T).Run | |
/usr/local/go/src/testing/testing.go:1493 +0x35f | |
Test: TestIncorrectCast/String | |
--- FAIL: TestIncorrectCast/Float64Slice (0.00s) | |
kv_test.go:169: | |
Error Trace: /home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 | |
Error: func (assert.PanicTestFunc)(0x6c0e40) should not panic | |
Panic value: reflect.Copy: bool != float64 | |
Panic stack: goroutine 51 [running]: | |
runtime/debug.Stack() | |
/usr/local/go/src/runtime/debug/stack.go:24 +0x65 | |
github.com/stretchr/testify/assert.didPanic.func1() | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1050 +0x6c | |
panic({0x6ebca0, 0xc000181b70}) | |
/usr/local/go/src/runtime/panic.go:884 +0x212 | |
reflect.typesMustMatch({0x747aaa, 0xc}, {0x7d2960?, 0x6e89a0}, {0x7d2960?, 0x6e93a0}) | |
/usr/local/go/src/reflect/value.go:2689 +0x105 | |
reflect.Copy({0xc0001a6550?, 0xc00019dc98?, 0x6e89a0?}, {0xc0001a64b0?, 0xc00019d548?, 0x0?}) | |
/usr/local/go/src/reflect/value.go:2785 +0x236 | |
go.opentelemetry.io/otel/internal/attribute.AsSlice[...]({0xc0001a64b0, 0xc00019d548?}) | |
/home/aaron/projects/opentelemetry-go/internal/attribute/attribute.go:43 +0x1b9 | |
go.opentelemetry.io/otel/attribute.Value.AsBoolSlice(...) | |
/home/aaron/projects/opentelemetry-go/attribute/value.go:145 | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1.1() | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:171 +0x6f | |
github.com/stretchr/testify/assert.didPanic(0xc000256680?) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1055 +0x8c | |
github.com/stretchr/testify/assert.NotPanics({0x7ce2e0, 0xc000256680}, 0xc000181b60, {0x0, 0x0, 0x0}) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1126 +0x7b | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1(0xc00024bd40?) | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 +0x76 | |
testing.tRunner(0xc000256680, 0xc000181b50) | |
/usr/local/go/src/testing/testing.go:1446 +0x10b | |
created by testing.(*T).Run | |
/usr/local/go/src/testing/testing.go:1493 +0x35f | |
Test: TestIncorrectCast/Float64Slice | |
--- FAIL: TestIncorrectCast/Int64Slice (0.00s) | |
kv_test.go:169: | |
Error Trace: /home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 | |
Error: func (assert.PanicTestFunc)(0x6c0e40) should not panic | |
Panic value: reflect.Copy: bool != int64 | |
Panic stack: goroutine 52 [running]: | |
runtime/debug.Stack() | |
/usr/local/go/src/runtime/debug/stack.go:24 +0x65 | |
github.com/stretchr/testify/assert.didPanic.func1() | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1050 +0x6c | |
panic({0x6ebca0, 0xc000181c20}) | |
/usr/local/go/src/runtime/panic.go:884 +0x212 | |
reflect.typesMustMatch({0x747aaa, 0xc}, {0x7d2960?, 0x6e89a0}, {0x7d2960?, 0x6eb3e0}) | |
/usr/local/go/src/reflect/value.go:2689 +0x105 | |
reflect.Copy({0xc0001a6550?, 0xc00019def8?, 0x6e89a0?}, {0xc0001a6500?, 0xc00019d578?, 0x0?}) | |
/usr/local/go/src/reflect/value.go:2785 +0x236 | |
go.opentelemetry.io/otel/internal/attribute.AsSlice[...]({0xc0001a6500, 0xc00019d578?}) | |
/home/aaron/projects/opentelemetry-go/internal/attribute/attribute.go:43 +0x1b9 | |
go.opentelemetry.io/otel/attribute.Value.AsBoolSlice(...) | |
/home/aaron/projects/opentelemetry-go/attribute/value.go:145 | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1.1() | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:171 +0x6f | |
github.com/stretchr/testify/assert.didPanic(0xc000256820?) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1055 +0x8c | |
github.com/stretchr/testify/assert.NotPanics({0x7ce2e0, 0xc000256820}, 0xc000181c10, {0x0, 0x0, 0x0}) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1126 +0x7b | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1(0xc00024bd40?) | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 +0x76 | |
testing.tRunner(0xc000256820, 0xc000181c00) | |
/usr/local/go/src/testing/testing.go:1446 +0x10b | |
created by testing.(*T).Run | |
/usr/local/go/src/testing/testing.go:1493 +0x35f | |
Test: TestIncorrectCast/Int64Slice | |
--- FAIL: TestIncorrectCast/StringSlice (0.00s) | |
kv_test.go:169: | |
Error Trace: /home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 | |
Error: func (assert.PanicTestFunc)(0x6c0e40) should not panic | |
Panic value: reflect.Copy: float64 != bool | |
Panic stack: goroutine 53 [running]: | |
runtime/debug.Stack() | |
/usr/local/go/src/runtime/debug/stack.go:24 +0x65 | |
github.com/stretchr/testify/assert.didPanic.func1() | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1050 +0x6c | |
panic({0x6ebca0, 0xc000181ce0}) | |
/usr/local/go/src/runtime/panic.go:884 +0x212 | |
reflect.typesMustMatch({0x747aaa, 0xc}, {0x7d2960?, 0x6e93a0}, {0x7d2960?, 0x6e89a0}) | |
/usr/local/go/src/reflect/value.go:2689 +0x105 | |
reflect.Copy({0xc0001a64b0?, 0xc0002b2160?, 0x6e93a0?}, {0xc0001a6550?, 0xc00019d58a?, 0x0?}) | |
/usr/local/go/src/reflect/value.go:2785 +0x236 | |
go.opentelemetry.io/otel/internal/attribute.AsSlice[...]({0xc0001a6550, 0xc00019d58a?}) | |
/home/aaron/projects/opentelemetry-go/internal/attribute/attribute.go:43 +0x1b2 | |
go.opentelemetry.io/otel/attribute.Value.AsFloat64Slice(...) | |
/home/aaron/projects/opentelemetry-go/attribute/value.go:169 | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1.1() | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:173 +0xb4 | |
github.com/stretchr/testify/assert.didPanic(0xc0002569c0?) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1055 +0x8c | |
github.com/stretchr/testify/assert.NotPanics({0x7ce2e0, 0xc0002569c0}, 0xc000181cc0, {0x0, 0x0, 0x0}) | |
/home/aaron/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1126 +0x7b | |
go.opentelemetry.io/otel/attribute_test.TestIncorrectCast.func1(0xc00024bd40?) | |
/home/aaron/projects/opentelemetry-go/attribute/kv_test.go:169 +0x76 | |
testing.tRunner(0xc0002569c0, 0xc000181cb0) | |
/usr/local/go/src/testing/testing.go:1446 +0x10b | |
created by testing.(*T).Run | |
/usr/local/go/src/testing/testing.go:1493 +0x35f | |
Test: TestIncorrectCast/StringSlice | |
FAIL | |
FAIL go.opentelemetry.io/otel/attribute 0.008s | |
FAIL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment