1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2025-06-17 15:42:05 +03:00
Files
postgres_exporter/postgres_exporter_integration_test.go
Will Rouesnel 045ae96430 Implement the compileable source code of the basic integration test suite.
This is the first step in moving the integration test suite to a more
reliable Golang based one.
2016-11-17 03:09:20 +11:00

60 lines
1.4 KiB
Go

// These are specialized integration tests. We only build them when we're doing
// a lot of additional work to keep the external docker environment they require
// working.
// +build integration
package main
import (
"os"
"testing"
. "gopkg.in/check.v1"
"github.com/prometheus/client_golang/prometheus"
"database/sql"
_ "github.com/lib/pq"
)
// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) }
type IntegrationSuite struct{
e *Exporter
}
var _ = Suite(&IntegrationSuite{})
func (s *IntegrationSuite) SetUpSuite(c *C) {
dsn := os.Getenv("DATA_SOURCE_NAME")
c.Assert(dsn, Not(Equals), "")
exporter := NewExporter(dsn)
c.Assert(exporter, NotNil)
// Assign the exporter to the suite
s.e = exporter
prometheus.MustRegister(exporter)
}
func (s *IntegrationSuite) TestAllNamespacesReturnResults(c *C) {
// Setup a dummy channel to consume metrics
ch := make(chan prometheus.Metric, 100)
go func() {
for _ = range ch {}
}()
// Open a database connection
db, err := sql.Open("postgres", s.e.dsn)
c.Assert(db, NotNil)
c.Assert(err, IsNil)
defer db.Close()
// Check the show variables work
nonFatalErrors := queryShowVariables(ch, db, s.e.variableMap)
c.Check(len(nonFatalErrors), Equals, 0)
// This should never happen in our test cases.
errMap := queryNamespaceMappings(ch, db, s.e.metricMap)
c.Check(len(errMap), Equals, 0)
}