-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathstruct_test.go
More file actions
45 lines (41 loc) · 843 Bytes
/
struct_test.go
File metadata and controls
45 lines (41 loc) · 843 Bytes
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
package monkit
import (
"reflect"
"testing"
)
func TestStatSourceFromStruct(t *testing.T) {
type SubStruct struct {
SubBool bool
SubFloat float64
SubInt int64
Ignored float64 `monkit:"ignore"`
}
result := Collect(StatSourceFromStruct(NewSeriesKey("struct"),
struct {
SomeBool bool
SomeFloat float64
SomeInt int64
Ignored float64 `monkit:"ignore"`
Sub SubStruct
Skip struct {
Nope int64
} `monkit:"whatever,ignore"`
}{
SomeInt: 5,
SomeBool: true,
Sub: SubStruct{
SubFloat: 3.2,
},
},
))
if !reflect.DeepEqual(result, map[string]float64{
"struct SomeBool": 1,
"struct SomeFloat": 0,
"struct SomeInt": 5,
"struct Sub.SubBool": 0,
"struct Sub.SubFloat": 3.2,
"struct Sub.SubInt": 0,
}) {
t.Fatal("unexpected result", result)
}
}