Add left function to string processor (#6189)

This commit is contained in:
Russ Savage
2019-07-31 16:55:25 -07:00
committed by Daniel Nelson
parent 28f1bdb696
commit ef4f4eed3a
3 changed files with 56 additions and 0 deletions

View File

@@ -479,6 +479,38 @@ func TestFieldKeyConversions(t *testing.T) {
require.Equal(t, "/mixed/CASE/paTH/?from=-1D&to=now", fv)
},
},
{
name: "Should trim the existing field to 6 characters",
plugin: &Strings{
Left: []converter{
{
Field: "Request",
Width: 6,
},
},
},
check: func(t *testing.T, actual telegraf.Metric) {
fv, ok := actual.GetField("Request")
require.True(t, ok)
require.Equal(t, "/mixed", fv)
},
},
{
name: "Should do nothing to the string",
plugin: &Strings{
Left: []converter{
{
Field: "Request",
Width: 600,
},
},
},
check: func(t *testing.T, actual telegraf.Metric) {
fv, ok := actual.GetField("Request")
require.True(t, ok)
require.Equal(t, "/mixed/CASE/paTH/?from=-1D&to=now", fv)
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {