forked from zhevron/gqlgen-opentelemetry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
value_test.go
50 lines (44 loc) · 1.22 KB
/
value_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package gqlgen_opentelemetry
import (
"testing"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/attribute"
)
type valueTestStruct struct {
Value string
}
type valueTestTable []struct {
input interface{}
expectedType attribute.Type
}
func TestMakeAttributeValue(t *testing.T) {
values := valueTestTable{
{true, attribute.BOOL},
{float32(1.5), attribute.FLOAT64},
{float64(1.5), attribute.FLOAT64},
{int(1), attribute.INT64},
{int32(1), attribute.INT64},
{int64(1), attribute.INT64},
{"test", attribute.STRING},
{valueTestStruct{Value: "test"}, attribute.STRING},
}
for _, v := range values {
assert.Equal(t, v.expectedType, makeAttributeValue(v.input).Type())
}
}
func TestMakeAttributeSliceValue(t *testing.T) {
values := valueTestTable{
{true, attribute.BOOLSLICE},
{float32(1.5), attribute.FLOAT64SLICE},
{float64(1.5), attribute.FLOAT64SLICE},
{int(1), attribute.INT64SLICE},
{int32(1), attribute.INT64SLICE},
{int64(1), attribute.INT64SLICE},
{"test", attribute.STRINGSLICE},
{valueTestStruct{Value: "test"}, attribute.STRINGSLICE},
}
for _, v := range values {
a := []interface{}{v.input}
assert.Equal(t, v.expectedType, makeAttributeSliceValue(a).Type())
}
}