forked from estafette/estafette-gke-preemptible-killer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes_client_test.go
45 lines (39 loc) · 929 Bytes
/
kubernetes_client_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
package main
import (
"testing"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestFilterOutPodByOwnerReferenceKind(t *testing.T) {
podList := []v1.Pod{
{
ObjectMeta: metav1.ObjectMeta{
Name: "node-1",
OwnerReferences: []metav1.OwnerReference{
{
Kind: "DaemonSet",
Name: "daemon-set",
},
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "node-2",
OwnerReferences: []metav1.OwnerReference{
{
Kind: "ReplicaSet",
Name: "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].ObjectMeta.Name != "node-2" {
t.Errorf("Expect first item name to be 'node-2', instead got %s", filteredPodList[0].ObjectMeta.Name)
}
}