@@ -23,16 +23,30 @@ func TestInitializeConfigMetrics(t *testing.T) {
23
23
ignoredFieldInt int
24
24
}
25
25
26
- metricNames , err := initializeConfigMetricsWithFieldPrefix ("test" , "test-01" , "" , & Foo {
27
- MinMarginLevel : Number (1.4 ),
28
- Bar : & Bar {
29
- Enabled : true ,
30
- },
26
+ t .Run ("general" , func (t * testing.T ) {
27
+ metricNames , err := initializeConfigMetricsWithFieldPrefix ("test" , "test-01" , "" , & Foo {
28
+ MinMarginLevel : Number (1.4 ),
29
+ Bar : & Bar {
30
+ Enabled : true ,
31
+ },
32
+ })
33
+
34
+ if assert .NoError (t , err ) {
35
+ assert .Len (t , metricNames , 2 )
36
+ assert .Equal (t , "test_config_min_margin_level" , metricNames [0 ])
37
+ assert .Equal (t , "test_config_bar_enabled" , metricNames [1 ], "nested struct field as a metric" )
38
+ }
39
+ })
40
+
41
+ t .Run ("nil struct field" , func (t * testing.T ) {
42
+ metricNames , err := initializeConfigMetricsWithFieldPrefix ("test" , "test-01" , "" , & Foo {
43
+ MinMarginLevel : Number (1.4 ),
44
+ })
45
+
46
+ if assert .NoError (t , err ) {
47
+ assert .Len (t , metricNames , 1 )
48
+ assert .Equal (t , "test_config_min_margin_level" , metricNames [0 ])
49
+ }
31
50
})
32
51
33
- if assert .NoError (t , err ) {
34
- assert .Len (t , metricNames , 2 )
35
- assert .Equal (t , "test_config_min_margin_level" , metricNames [0 ])
36
- assert .Equal (t , "test_config_bar_enabled" , metricNames [1 ], "nested struct field as a metric" )
37
- }
38
52
}
0 commit comments