-
Notifications
You must be signed in to change notification settings - Fork 0
/
aurora_test.go
50 lines (43 loc) · 1.09 KB
/
aurora_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
"testing"
"time"
)
func TestObservability(t *testing.T) {
initObservability()
tr := &http.Transport{
MaxIdleConns: 10,
IdleConnTimeout: 10 * time.Second,
}
httpClient := &http.Client{
Transport: tr,
Timeout: 10 * time.Second,
}
apiEndpoint := "/metrics"
url := fmt.Sprintf("http://0.0.0.0:2112/%s", apiEndpoint)
time.Sleep(time.Second * 1) // Allow it to boot up
req, _ := http.NewRequest("GET", url, nil)
resp, err := httpClient.Do(req)
if err != nil {
t.Errorf("expected to be able to reach the metrics endpoint")
return
} else if resp.StatusCode != 200 {
t.Errorf("connected but received non-200 status code %d", resp.StatusCode)
return
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Errorf("unexpected error reading the response body")
return
}
bodyString := string(bodyBytes)
r := regexp.MustCompile(`.*_version_info (\d.*?)`)
if len(r.FindStringSubmatch(bodyString)) == 0 {
t.Errorf("expecting to find the version_info in the metrics endpoint")
}
defer resp.Body.Close()
}