1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2025-11-26 22:23:31 +03:00

Add test cases for unknown metric parsing.

This commit is contained in:
Will Rouesnel
2017-11-29 12:58:54 +11:00
parent df3a71eb79
commit 6802f4bbe3
2 changed files with 36 additions and 3 deletions

View File

@@ -95,3 +95,30 @@ func (s *IntegrationSuite) TestInvalidDsnDoesntCrash(c *C) {
c.Assert(exporter, NotNil)
exporter.scrape(ch)
}
// TestUnknownMetricParsingDoesntCrash deliberately deletes all the column maps out
// of an exporter to test that the default metric handling code can cope with unknown columns.
func (s *IntegrationSuite) TestUnknownMetricParsingDoesntCrash(c *C) {
// Setup a dummy channel to consume metrics
ch := make(chan prometheus.Metric, 100)
go func() {
for range ch {
}
}()
dsn := os.Getenv("DATA_SOURCE_NAME")
c.Assert(dsn, Not(Equals), "")
exporter := NewExporter(dsn, "")
c.Assert(exporter, NotNil)
// Convert the default maps into a list of empty maps.
emptyMaps := make(map[string]map[string]ColumnMapping, 0)
for k := range exporter.builtinMetricMaps {
emptyMaps[k] = map[string]ColumnMapping{}
}
exporter.builtinMetricMaps = emptyMaps
// scrape the exporter and make sure it works
exporter.scrape(ch)
}