telegraf/plugins/mysql/mysql_test.go

65 lines
1023 B
Go
Raw Normal View History

2015-05-18 18:54:11 +00:00
package mysql
import (
"strings"
"testing"
"github.com/influxdb/telegraf/testutil"
2015-05-18 18:54:11 +00:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMysqlGeneratesMetrics(t *testing.T) {
m := &Mysql{
2015-05-27 05:14:55 +00:00
Servers: []string{""},
2015-05-18 18:54:11 +00:00
}
var acc testutil.Accumulator
err := m.Gather(&acc)
require.NoError(t, err)
prefixes := []struct {
prefix string
count int
}{
{"commands", 141},
{"handler", 18},
{"bytes", 2},
{"innodb", 51},
{"threads", 4},
2015-05-18 18:54:11 +00:00
}
intMetrics := []string{
"queries",
"slow_queries",
2015-05-18 18:54:11 +00:00
}
for _, prefix := range prefixes {
var count int
for _, p := range acc.Points {
if strings.HasPrefix(p.Measurement, prefix.prefix) {
2015-05-18 18:54:11 +00:00
count++
}
}
assert.Equal(t, prefix.count, count)
}
for _, metric := range intMetrics {
assert.True(t, acc.HasIntValue(metric))
}
}
func TestMysqlDefaultsToLocal(t *testing.T) {
m := &Mysql{}
var acc testutil.Accumulator
err := m.Gather(&acc)
require.NoError(t, err)
assert.True(t, len(acc.Points) > 0)
}