You've already forked mysqld_exporter
mirror of
https://github.com/prometheus/mysqld_exporter.git
synced 2025-07-30 06:43:05 +03:00
Added the last binlog file number metric.
This commit is contained in:
52
collector/binlog_test.go
Normal file
52
collector/binlog_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
package collector
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
"gopkg.in/DATA-DOG/go-sqlmock.v1"
|
||||
)
|
||||
|
||||
func TestScrapeBinlogSize(t *testing.T) {
|
||||
db, mock, err := sqlmock.New()
|
||||
if err != nil {
|
||||
t.Fatalf("error opening a stub database connection: %s", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
mock.ExpectQuery(logbinQuery).WillReturnRows(sqlmock.NewRows([]string{""}).AddRow(1))
|
||||
|
||||
columns := []string{"Log_name", "File_size"}
|
||||
rows := sqlmock.NewRows(columns).
|
||||
AddRow("centos6-bin.000001", "1813").
|
||||
AddRow("centos6-bin.000002", "120").
|
||||
AddRow("centos6-bin.000444", "573009")
|
||||
mock.ExpectQuery(sanitizeQuery(binlogQuery)).WillReturnRows(rows)
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = ScrapeBinlogSize(db, ch); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
}()
|
||||
|
||||
counterExpected := []MetricResult{
|
||||
{labels: labelMap{}, value: 574942, metricType: dto.MetricType_GAUGE},
|
||||
{labels: labelMap{}, value: 3, metricType: dto.MetricType_GAUGE},
|
||||
{labels: labelMap{}, value: 444, metricType: dto.MetricType_GAUGE},
|
||||
}
|
||||
convey.Convey("Metrics comparison", t, func() {
|
||||
for _, expect := range counterExpected {
|
||||
got := readMetric(<-ch)
|
||||
convey.So(got, convey.ShouldResemble, expect)
|
||||
}
|
||||
})
|
||||
|
||||
// Ensure all SQL queries were executed
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("there were unfulfilled expections: %s", err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user