improve ut for taint

Signed-off-by: AllenZMC <zhongming.chang@daocloud.io>
This commit is contained in:
AllenZMC 2022-08-14 23:49:15 +08:00
parent 66af6ef502
commit 53550a825c
1 changed files with 93 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package helper
import (
"context"
"reflect"
"testing"
corev1 "k8s.io/api/core/v1"
@ -264,3 +265,95 @@ func TestTolerationExists(t *testing.T) {
})
}
}
func TestHasNoExecuteTaints(t *testing.T) {
tests := []struct {
name string
taints []corev1.Taint
want bool
}{
{
name: "has NoExecute taints",
taints: []corev1.Taint{
{
Key: clusterv1alpha1.TaintClusterUnreachable,
Effect: corev1.TaintEffectNoExecute,
},
{
Key: clusterv1alpha1.TaintClusterNotReady,
Effect: corev1.TaintEffectNoSchedule,
},
},
want: true,
},
{
name: "no NoExecute taints",
taints: []corev1.Taint{
{
Key: clusterv1alpha1.TaintClusterUnreachable,
Effect: corev1.TaintEffectPreferNoSchedule,
},
{
Key: clusterv1alpha1.TaintClusterNotReady,
Effect: corev1.TaintEffectNoSchedule,
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := HasNoExecuteTaints(tt.taints); got != tt.want {
t.Errorf("HasNoExecuteTaints() = %v, want %v", got, tt.want)
}
})
}
}
func TestGetNoExecuteTaints(t *testing.T) {
tests := []struct {
name string
taints []corev1.Taint
want []corev1.Taint
}{
{
name: "has NoExecute taints",
taints: []corev1.Taint{
{
Key: clusterv1alpha1.TaintClusterUnreachable,
Effect: corev1.TaintEffectNoExecute,
},
{
Key: clusterv1alpha1.TaintClusterNotReady,
Effect: corev1.TaintEffectNoSchedule,
},
},
want: []corev1.Taint{
{
Key: clusterv1alpha1.TaintClusterUnreachable,
Effect: corev1.TaintEffectNoExecute,
},
},
},
{
name: "no NoExecute taints",
taints: []corev1.Taint{
{
Key: clusterv1alpha1.TaintClusterUnreachable,
Effect: corev1.TaintEffectPreferNoSchedule,
},
{
Key: clusterv1alpha1.TaintClusterNotReady,
Effect: corev1.TaintEffectNoSchedule,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetNoExecuteTaints(tt.taints); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetNoExecuteTaints() = %v, want %v", got, tt.want)
}
})
}
}