2019-08-21 23:49:07 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/influxdata/telegraf/selfstat"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestErrorCounting(t *testing.T) {
|
2020-02-25 18:40:29 +00:00
|
|
|
reg := selfstat.Register(
|
2019-08-21 23:49:07 +00:00
|
|
|
"gather",
|
|
|
|
"errors",
|
|
|
|
map[string]string{"input": "test"},
|
2020-02-25 18:40:29 +00:00
|
|
|
)
|
|
|
|
iLog := Logger{Name: "inputs.test"}
|
|
|
|
iLog.OnErr(func() {
|
|
|
|
reg.Incr(1)
|
|
|
|
})
|
2019-08-21 23:49:07 +00:00
|
|
|
iLog.Error("something went wrong")
|
|
|
|
iLog.Errorf("something went wrong")
|
|
|
|
|
2020-02-25 18:40:29 +00:00
|
|
|
require.Equal(t, int64(2), reg.Get())
|
2019-08-21 23:49:07 +00:00
|
|
|
}
|