forked from mintel/gcp-quota-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
34 lines (29 loc) · 929 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"os"
"testing"
promlog "github.com/prometheus/common/promlog"
)
func TestScrape(t *testing.T) {
logger := promlog.New(&promlog.Config{})
// TestSuccessfulConnection
exporter, _ := NewExporter(os.Getenv("GOOGLE_PROJECT_ID"), logger)
projectUp, regionsUp := exporter.scrape()
if projectUp == nil {
t.Errorf("TestSuccessfulConnection: projectUp=0, expected=1")
}
if regionsUp == nil {
t.Errorf("TestSuccessfulConnection: regionsUp=0, expected=1")
}
// TestFailedConnection
// Set the project name to "503" since the Google Compute API will append this to the end of the BasePath
exporter, _ = NewExporter("503", logger)
exporter.service.BasePath = "http://httpstat.us/"
projectUp, regionsUp = exporter.scrape()
if projectUp != nil {
t.Errorf("TestFailedConnection: projectUp=1, expected=0")
}
if regionsUp != nil {
t.Errorf("TestFailedConnection: regionsUp=1, expected=0")
}
}