-
Notifications
You must be signed in to change notification settings - Fork 7
/
top_test.go
70 lines (61 loc) · 1.56 KB
/
top_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
63
64
65
66
67
68
69
70
package main
import (
"io/ioutil"
"log"
"testing"
)
func TestBuildManyPodTop(t *testing.T) {
b, err := ioutil.ReadFile("test-data/top-many-pods.txt")
if err != nil {
log.Fatal(err)
}
data := string(b)
tops := buildTopList(data, "")
ex := 69
if l := len(tops); l != ex {
t.Fatalf("Test failed! found %d expected %d", l, ex)
}
for _, pod := range tops {
if &pod.Pod == nil || pod.Pod == "" {
t.Fatalf("Test failed! Pod Name should not be empty")
}
if &pod.Containers == nil || len(pod.Containers) == 0 {
t.Fatalf("Test failed! Pod must have containers")
}
for _, c := range pod.Containers {
if &c.Name == nil || c.Name == "" ||
&c.CPU == nil || c.CPU == "" ||
&c.Memory == nil || c.Memory == "" {
t.Fatalf("Test failed! Containaer data must be set")
}
}
}
}
func TestBuildPodTopDefaultNamespace(t *testing.T) {
b, err := ioutil.ReadFile("test-data/top-many-pods.txt")
if err != nil {
log.Fatal(err)
}
data := string(b)
tops := buildTopList(data, "default")
ex := 23
if l := len(tops); l != ex {
t.Fatalf("Test failed! found %d expected %d", l, ex)
}
}
func TestBuildOnePodTop(t *testing.T) {
b, err := ioutil.ReadFile("test-data/top-one-pod.txt")
if err != nil {
log.Fatal(err)
}
data := string(b)
top := buildTopList(data, "")[0]
expectedCPU := 32
if cpu := top.GetMilliCPU(); cpu != expectedCPU {
t.Fatalf("Test failed! %d but expected %d", cpu, expectedCPU)
}
expectedMemory := 25
if mem := top.GetMiMemory(); mem != expectedMemory {
t.Fatalf("Test failed! %d but expected %d", mem, expectedMemory)
}
}