Skip to content

Commit

Permalink
dynamic: add one more test case
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Dec 19, 2024
1 parent 75f1e72 commit 005bf23
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions pkg/dynamic/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,30 @@ func TestInitializeConfigMetrics(t *testing.T) {
ignoredFieldInt int
}

metricNames, err := initializeConfigMetricsWithFieldPrefix("test", "test-01", "", &Foo{
MinMarginLevel: Number(1.4),
Bar: &Bar{
Enabled: true,
},
t.Run("general", func(t *testing.T) {
metricNames, err := initializeConfigMetricsWithFieldPrefix("test", "test-01", "", &Foo{
MinMarginLevel: Number(1.4),
Bar: &Bar{
Enabled: true,
},
})

if assert.NoError(t, err) {
assert.Len(t, metricNames, 2)
assert.Equal(t, "test_config_min_margin_level", metricNames[0])
assert.Equal(t, "test_config_bar_enabled", metricNames[1], "nested struct field as a metric")
}
})

t.Run("nil struct field", func(t *testing.T) {
metricNames, err := initializeConfigMetricsWithFieldPrefix("test", "test-01", "", &Foo{
MinMarginLevel: Number(1.4),
})

if assert.NoError(t, err) {
assert.Len(t, metricNames, 1)
assert.Equal(t, "test_config_min_margin_level", metricNames[0])
}
})

if assert.NoError(t, err) {
assert.Len(t, metricNames, 2)
assert.Equal(t, "test_config_min_margin_level", metricNames[0])
assert.Equal(t, "test_config_bar_enabled", metricNames[1], "nested struct field as a metric")
}
}

0 comments on commit 005bf23

Please sign in to comment.