-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhpa_test.go
60 lines (54 loc) · 1.61 KB
/
hpa_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
package main
import (
"io/ioutil"
"log"
"testing"
)
func TestBuildHpaList(t *testing.T) {
b, err := ioutil.ReadFile("test-data/hpa.txt")
if err != nil {
log.Fatal(err)
}
data := string(b)
hpas := buildHpaList(data, "", []Pod{})
ex := 18
if l := len(hpas); l != ex {
t.Fatalf("Test failed! found %d expected %d", l, ex)
}
for _, hpa := range hpas {
if hpa.Namespace == "" || hpa.Name == "" || hpa.ReferenceKind == "" || hpa.ReferenceName == "" || hpa.Age == "" {
t.Fatalf("Test failed! hpa must have all info")
}
}
}
func TestBuildHpaMap(t *testing.T) {
data := `default nginx-1-hpa Deployment/nginx-1 <unknown>/80% 1 5 3 33d
default paymentservice Deployment/paymentservice 4%/80% 2 20 2 87d`
hpas := buildHpaList(data, "", []Pod{})
hpa := hpas[0]
if hpa.Namespace != "default" ||
hpa.Name != "nginx-1-hpa" ||
hpa.ReferenceKind != "Deployment" ||
hpa.ReferenceName != "nginx-1" ||
hpa.UsageCPU != -1 ||
hpa.Target != 80 ||
hpa.MinPods != 1 ||
hpa.MaxPods != 5 ||
hpa.Replicas != 3 ||
hpa.Age != "33d" {
t.Fatalf("Test failed! hpa does not match data")
}
hpa = hpas[1]
if hpa.Namespace != "default" ||
hpa.Name != "paymentservice" ||
hpa.ReferenceKind != "Deployment" ||
hpa.ReferenceName != "paymentservice" ||
hpa.UsageCPU != 4 ||
hpa.Target != 80 ||
hpa.MinPods != 2 ||
hpa.MaxPods != 20 ||
hpa.Replicas != 2 ||
hpa.Age != "87d" {
t.Fatalf("Test failed! hpa does not match data")
}
}