forked from estafette/estafette-gke-preemptible-killer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes_test.go
46 lines (40 loc) · 1.03 KB
/
kubernetes_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
package main
import (
"testing"
"github.com/ericchiang/k8s"
apiv1 "github.com/ericchiang/k8s/api/v1"
metav1 "github.com/ericchiang/k8s/apis/meta/v1"
)
func TestFilterOutPodByOwnerReferenceKind(t *testing.T) {
podList := []*apiv1.Pod{
{
Metadata: &metav1.ObjectMeta{
Name: k8s.String("node-1"),
OwnerReferences: []*metav1.OwnerReference{
{
Kind: k8s.String("DaemonSet"),
Name: k8s.String("daemon-set"),
},
},
},
},
{
Metadata: &metav1.ObjectMeta{
Name: k8s.String("node-2"),
OwnerReferences: []*metav1.OwnerReference{
{
Kind: k8s.String("ReplicaSet"),
Name: k8s.String("replica-set"),
},
},
},
},
}
filteredPodList := filterOutPodByOwnerReferenceKind(podList, "DaemonSet")
if len(filteredPodList) != 1 {
t.Errorf("Expect pod list to have 1 item, instead got %d", len(filteredPodList))
}
if *filteredPodList[0].Metadata.Name != "node-2" {
t.Errorf("Expect first item name to be 'node-2', instead got %s", *filteredPodList[0].Metadata.Name)
}
}