| 288 | } |
| 289 | |
| 290 | func TestFieldKeyConversions(t *testing.T) { |
| 291 | tests := []struct { |
| 292 | name string |
| 293 | plugin *Strings |
| 294 | check func(t *testing.T, actual telegraf.Metric) |
| 295 | }{ |
| 296 | { |
| 297 | name: "Should change existing field key to lowercase", |
| 298 | plugin: &Strings{ |
| 299 | Lowercase: []converter{ |
| 300 | { |
| 301 | FieldKey: "Request", |
| 302 | }, |
| 303 | }, |
| 304 | }, |
| 305 | check: func(t *testing.T, actual telegraf.Metric) { |
| 306 | fv, ok := actual.GetField("request") |
| 307 | require.True(t, ok) |
| 308 | require.Equal(t, "/mixed/CASE/paTH/?from=-1D&to=now", fv) |
| 309 | }, |
| 310 | }, |
| 311 | { |
| 312 | name: "Should change existing field key to uppercase", |
| 313 | plugin: &Strings{ |
| 314 | Uppercase: []converter{ |
| 315 | { |
| 316 | FieldKey: "Request", |
| 317 | }, |
| 318 | }, |
| 319 | }, |
| 320 | check: func(t *testing.T, actual telegraf.Metric) { |
| 321 | fv, ok := actual.GetField("Request") |
| 322 | require.False(t, ok) |
| 323 | require.Nil(t, fv) |
| 324 | |
| 325 | fv, ok = actual.GetField("REQUEST") |
| 326 | require.True(t, ok) |
| 327 | require.Equal(t, "/mixed/CASE/paTH/?from=-1D&to=now", fv) |
| 328 | }, |
| 329 | }, |
| 330 | { |
| 331 | name: "Should trim from both sides", |
| 332 | plugin: &Strings{ |
| 333 | Trim: []converter{ |
| 334 | { |
| 335 | FieldKey: "Request", |
| 336 | Cutset: "eR", |
| 337 | }, |
| 338 | }, |
| 339 | }, |
| 340 | check: func(t *testing.T, actual telegraf.Metric) { |
| 341 | fv, ok := actual.GetField("quest") |
| 342 | require.True(t, ok) |
| 343 | require.Equal(t, "/mixed/CASE/paTH/?from=-1D&to=now", fv) |
| 344 | }, |
| 345 | }, |
| 346 | { |
| 347 | name: "Should trim from both sides but not make lowercase", |