2016-11-16 16:09:20 +00:00
|
|
|
// 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"
|
2016-11-17 15:26:33 +00:00
|
|
|
"fmt"
|
2016-11-16 16:09:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2016-11-17 15:26:33 +00:00
|
|
|
// TODO: it would be nice if this didn't mostly just recreate the scrape function
|
2016-11-16 16:09:20 +00:00
|
|
|
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()
|
|
|
|
|
2016-11-17 15:26:33 +00:00
|
|
|
// Do a version update
|
|
|
|
err = s.e.checkMapVersions(ch, db)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
2016-11-16 16:09:20 +00:00
|
|
|
// Check the show variables work
|
|
|
|
nonFatalErrors := queryShowVariables(ch, db, s.e.variableMap)
|
2016-11-17 15:26:33 +00:00
|
|
|
if !c.Check(len(nonFatalErrors), Equals, 0) {
|
|
|
|
fmt.Println("## NONFATAL ERRORS FOUND")
|
|
|
|
for _, err := range nonFatalErrors {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 16:09:20 +00:00
|
|
|
|
|
|
|
// This should never happen in our test cases.
|
2016-11-17 15:26:33 +00:00
|
|
|
errMap := queryNamespaceMappings(ch, db, s.e.metricMap, s.e.queryOverrides)
|
|
|
|
if !c.Check(len(errMap), Equals, 0) {
|
|
|
|
fmt.Println("## NAMESPACE ERRORS FOUND")
|
|
|
|
for namespace, err := range errMap {
|
|
|
|
fmt.Println(namespace, ":", err)
|
|
|
|
}
|
|
|
|
}
|
2016-11-16 16:09:20 +00:00
|
|
|
}
|