sigs.k8s.io/cluster-api@v1.6.3/internal/util/taints/taints_test.go (about) 1 /* 2 Copyright 2023 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package taints 18 19 import ( 20 "testing" 21 22 . "github.com/onsi/gomega" 23 corev1 "k8s.io/api/core/v1" 24 ) 25 26 func TestRemoveNodeTaint(t *testing.T) { 27 taint1 := corev1.Taint{Key: "taint1", Effect: corev1.TaintEffectNoSchedule} 28 taint2 := corev1.Taint{Key: "taint2", Effect: corev1.TaintEffectNoSchedule} 29 30 tests := []struct { 31 name string 32 node *corev1.Node 33 dropTaint corev1.Taint 34 wantTaints []corev1.Taint 35 wantModified bool 36 }{ 37 { 38 name: "dropping taint from node should return true", 39 node: &corev1.Node{Spec: corev1.NodeSpec{ 40 Taints: []corev1.Taint{ 41 taint1, 42 taint2, 43 }}}, 44 dropTaint: taint1, 45 wantTaints: []corev1.Taint{taint2}, 46 wantModified: true, 47 }, 48 { 49 name: "drop non-existing taint should return false", 50 node: &corev1.Node{Spec: corev1.NodeSpec{ 51 Taints: []corev1.Taint{ 52 taint2, 53 }}}, 54 dropTaint: taint1, 55 wantTaints: []corev1.Taint{taint2}, 56 wantModified: false, 57 }, 58 { 59 name: "drop last taint should return true", 60 node: &corev1.Node{Spec: corev1.NodeSpec{ 61 Taints: []corev1.Taint{ 62 taint1, 63 }}}, 64 dropTaint: taint1, 65 wantTaints: []corev1.Taint{}, 66 wantModified: true, 67 }, 68 } 69 70 for _, tt := range tests { 71 t.Run(tt.name, func(t *testing.T) { 72 g := NewWithT(t) 73 got := RemoveNodeTaint(tt.node, tt.dropTaint) 74 g.Expect(got).To(Equal(tt.wantModified)) 75 g.Expect(tt.node.Spec.Taints).To(BeComparableTo(tt.wantTaints)) 76 }) 77 } 78 }