-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmflow_integration_test.go
62 lines (53 loc) · 1.33 KB
/
mflow_integration_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
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"bufio"
"fmt"
"net/http"
"strings"
"testing"
"time"
)
const testPort = 9889
const testFile = "misc/test_data.txt"
func TestAllComponentsWorkTogether(t *testing.T) {
go runTheDaemon(testFile, "file", testPort)
expectedMetrics := buildExpectedMetricsMap()
url := fmt.Sprintf("http://localhost:%d/metrics", testPort)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Logf("Faield to construct request for %v", url)
t.Fail()
}
// give the daemon some time to start up
time.Sleep(1 * time.Second)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
t.Logf("Faield to GET metrics from %s", url)
t.Fail()
}
scanner := bufio.NewScanner(resp.Body)
for scanner.Scan() {
l := strings.Trim(scanner.Text(), " \n")
_, exists := expectedMetrics[l]
if exists {
expectedMetrics[l] = true
}
}
for k, v := range expectedMetrics {
if !v {
t.Logf("Expected metric [%s] not found in the registry", k)
t.Fail()
}
}
}
func buildExpectedMetricsMap() map[string]bool {
// expected metrics values after aggregating
// data from `testFile`
m := make(map[string]bool)
m["numApiCalls{userId=\"user1\"} 114"] = false
m["avgNumEvents{userId=\"user1\"} 1"] = false
m["avgNumEvents{userId=\"user2\"} 2.875"] = false
m["avgLatency{userId=\"user1\"} 666638"] = false
return m
}