-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsnapshot_test.go
62 lines (53 loc) · 1.53 KB
/
snapshot_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 megos
import (
"fmt"
"net/http"
"strconv"
"strings"
"testing"
)
func TestGetMetricsSnapshot(t *testing.T) {
setup()
defer teardown()
mux1.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
c := getContentOfFile("tests/master1.metrics.snapshot.json")
fmt.Fprint(w, string(c))
})
role := "master"
host := "127.0.0.1"
port, _ := strconv.Atoi(strings.Split(server1.URL, ":")[2])
pid := fmt.Sprintf("%s@%s:%d", role, host, port)
parsedPid, _ := client.ParsePidInformation(pid)
snapshot, err := client.GetMetricsSnapshot(parsedPid)
if snapshot == nil {
t.Error("Snapshot is nil. Expected not nil")
}
if err != nil {
t.Errorf("Error is not nil. Expected nil, got %s", err)
}
if snapshot.SystemCpusTotal != 2 {
t.Errorf("SystemCpusTotal is not right value. Expected %v, got %v", 2, snapshot.SystemCpusTotal)
}
}
func TestGetMetricsSnapshotError(t *testing.T) {
setup()
defer teardown()
mux1.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
c := getContentOfFile("")
fmt.Fprint(w, string(c))
})
role := "master"
host := "127.0.0.1"
port, _ := strconv.Atoi(strings.Split(server1.URL, ":")[2])
pid := fmt.Sprintf("%s@%s:%d", role, host, port)
parsedPid, _ := client.ParsePidInformation(pid)
snapshot, err := client.GetMetricsSnapshot(parsedPid)
if snapshot != nil {
t.Errorf("Snapshot is not nil. Expected nil, get err is %v", err)
}
if err == nil {
t.Errorf("Error is nil. Expected not nil")
}
}