Merge pull request #2376 from AllenZMC/improve_taint
improve ut for taint
This commit is contained in:
commit
6662906cb7
|
@ -2,6 +2,7 @@ package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue