1
+ // These are specialized integration tests. We only build them when we're doing
2
+ // a lot of additional work to keep the external docker environment they require
3
+ // working.
4
+ // +build integration
5
+
6
+ package main
7
+
8
+ import (
9
+ "os"
10
+ "testing"
11
+
12
+ . "gopkg.in/check.v1"
13
+
14
+ "github.com/prometheus/client_golang/prometheus"
15
+ "database/sql"
16
+ _ "github.com/lib/pq"
17
+ "fmt"
18
+ )
19
+
20
+ // Hook up gocheck into the "go test" runner.
21
+ func Test (t * testing.T ) { TestingT (t ) }
22
+
23
+ type IntegrationSuite struct {
24
+ e * Exporter
25
+ }
26
+
27
+ var _ = Suite (& IntegrationSuite {})
28
+
29
+ func (s * IntegrationSuite ) SetUpSuite (c * C ) {
30
+ dsn := os .Getenv ("DATA_SOURCE_NAME" )
31
+ c .Assert (dsn , Not (Equals ), "" )
32
+
33
+ exporter := NewExporter (dsn , "" )
34
+ c .Assert (exporter , NotNil )
35
+ // Assign the exporter to the suite
36
+ s .e = exporter
37
+
38
+ prometheus .MustRegister (exporter )
39
+ }
40
+
41
+ // TODO: it would be nice if this didn't mostly just recreate the scrape function
42
+ func (s * IntegrationSuite ) TestAllNamespacesReturnResults (c * C ) {
43
+ // Setup a dummy channel to consume metrics
44
+ ch := make (chan prometheus.Metric , 100 )
45
+ go func () {
46
+ for _ = range ch {}
47
+ }()
48
+
49
+ // Open a database connection
50
+ db , err := sql .Open ("postgres" , s .e .dsn )
51
+ c .Assert (db , NotNil )
52
+ c .Assert (err , IsNil )
53
+ defer db .Close ()
54
+
55
+ // Do a version update
56
+ err = s .e .checkMapVersions (ch , db )
57
+ c .Assert (err , IsNil )
58
+
59
+ // Check the show variables work
60
+ nonFatalErrors := queryShowVariables (ch , db , s .e .variableMap )
61
+ if ! c .Check (len (nonFatalErrors ), Equals , 0 ) {
62
+ fmt .Println ("## NONFATAL ERRORS FOUND" )
63
+ for _ , err := range nonFatalErrors {
64
+ fmt .Println (err )
65
+ }
66
+ }
67
+
68
+
69
+ // This should never happen in our test cases.
70
+ errMap := queryNamespaceMappings (ch , db , s .e .metricMap , s .e .queryOverrides )
71
+ if ! c .Check (len (errMap ), Equals , 0 ) {
72
+ fmt .Println ("## NAMESPACE ERRORS FOUND" )
73
+ for namespace , err := range errMap {
74
+ fmt .Println (namespace , ":" , err )
75
+ }
76
+ }
77
+ }
0 commit comments