test(processors.enum): Add unit-test for tracking metrics (#14736)

This commit is contained in:
Dane Strandboge 2024-02-09 13:08:09 -06:00 committed by GitHub
parent 5732270330
commit 0338bd03a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 21 additions and 0 deletions

View File

@ -196,3 +196,24 @@ func TestTagGlobMatching(t *testing.T) {
assertTagValue(t, "glob", "tag", tags)
}
func TestTracking(t *testing.T) {
m := createTestMetric()
var delivered bool
notify := func(di telegraf.DeliveryInfo) {
delivered = true
}
m, _ = metric.WithTracking(m, notify)
mapper := EnumMapper{Mappings: []Mapping{{Tag: "*", ValueMappings: map[string]interface{}{"tag_value": "glob"}}}}
err := mapper.Init()
require.NoError(t, err)
actual := mapper.Apply(m)[0]
assertTagValue(t, "glob", "tag", actual.Tags())
actual.Accept()
require.Eventually(t, func() bool {
return delivered
}, time.Second, 100*time.Millisecond, "no metrics delivered")
}