47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
|
|
package agent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
corev1 "k8s.io/api/core/v1"
|
||
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||
|
|
)
|
||
|
|
|
||
|
|
func readyPod(deletionTimestamp *metav1.Time) *corev1.Pod {
|
||
|
|
return &corev1.Pod{
|
||
|
|
ObjectMeta: metav1.ObjectMeta{DeletionTimestamp: deletionTimestamp},
|
||
|
|
Status: corev1.PodStatus{
|
||
|
|
Conditions: []corev1.PodCondition{
|
||
|
|
{Type: corev1.PodReady, Status: corev1.ConditionTrue},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestPodAnycastEligible(t *testing.T) {
|
||
|
|
now := metav1.Now()
|
||
|
|
cases := []struct {
|
||
|
|
name string
|
||
|
|
pod *corev1.Pod
|
||
|
|
want bool
|
||
|
|
}{
|
||
|
|
{"ready, not deleting", readyPod(nil), true},
|
||
|
|
{"ready, but deleting", readyPod(&now), false},
|
||
|
|
{
|
||
|
|
"not ready, not deleting",
|
||
|
|
&corev1.Pod{Status: corev1.PodStatus{Conditions: []corev1.PodCondition{
|
||
|
|
{Type: corev1.PodReady, Status: corev1.ConditionFalse},
|
||
|
|
}}},
|
||
|
|
false,
|
||
|
|
},
|
||
|
|
{"no conditions, not deleting", &corev1.Pod{}, false},
|
||
|
|
}
|
||
|
|
for _, c := range cases {
|
||
|
|
t.Run(c.name, func(t *testing.T) {
|
||
|
|
if got := podAnycastEligible(c.pod); got != c.want {
|
||
|
|
t.Fatalf("got %v want %v", got, c.want)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|