|
4 | 4 | package taints |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "testing" |
| 8 | + |
7 | 9 | . "github.com/onsi/ginkgo/v2" |
8 | 10 | "github.com/onsi/gomega" |
| 11 | + "github.com/stretchr/testify/assert" |
| 12 | + v1 "k8s.io/api/core/v1" |
9 | 13 | apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" |
10 | 14 | runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" |
11 | 15 |
|
@@ -67,3 +71,48 @@ var _ = Describe("Generate taints patches for Worker", func() { |
67 | 71 | }) |
68 | 72 | } |
69 | 73 | }) |
| 74 | + |
| 75 | +func Test_toCoreTaints(t *testing.T) { |
| 76 | + t.Parallel() |
| 77 | + |
| 78 | + tests := []struct { |
| 79 | + name string |
| 80 | + existingTaints []v1.Taint |
| 81 | + newTaints []v1alpha1.Taint |
| 82 | + want []v1.Taint |
| 83 | + }{{ |
| 84 | + name: "nil new and existing taints", |
| 85 | + want: nil, |
| 86 | + }, { |
| 87 | + name: "nil new taints with existing taints", |
| 88 | + existingTaints: []v1.Taint{{Key: "key", Effect: v1.TaintEffectNoExecute, Value: "value"}}, |
| 89 | + want: []v1.Taint{{Key: "key", Effect: v1.TaintEffectNoExecute, Value: "value"}}, |
| 90 | + }, { |
| 91 | + name: "nil existing taints with new taints", |
| 92 | + newTaints: []v1alpha1.Taint{ |
| 93 | + {Key: "key", Effect: v1alpha1.TaintEffectNoExecute, Value: "value"}, |
| 94 | + }, |
| 95 | + want: []v1.Taint{{Key: "key", Effect: v1.TaintEffectNoExecute, Value: "value"}}, |
| 96 | + }, { |
| 97 | + name: "existing and new taints", |
| 98 | + existingTaints: []v1.Taint{{Key: "key", Effect: v1.TaintEffectNoExecute, Value: "value"}}, |
| 99 | + newTaints: []v1alpha1.Taint{ |
| 100 | + {Key: "key2", Effect: v1alpha1.TaintEffectNoExecute, Value: "value2"}, |
| 101 | + }, |
| 102 | + want: []v1.Taint{ |
| 103 | + {Key: "key", Effect: v1.TaintEffectNoExecute, Value: "value"}, |
| 104 | + {Key: "key2", Effect: v1.TaintEffectNoExecute, Value: "value2"}, |
| 105 | + }, |
| 106 | + }, { |
| 107 | + name: "nil existing taints and empty but non-nil new taints", |
| 108 | + newTaints: []v1alpha1.Taint{}, |
| 109 | + want: []v1.Taint{}, |
| 110 | + }} |
| 111 | + for _, tt := range tests { |
| 112 | + t.Run(tt.name, func(t *testing.T) { |
| 113 | + t.Parallel() |
| 114 | + |
| 115 | + assert.Equal(t, tt.want, toCoreTaints(tt.existingTaints, tt.newTaints)) |
| 116 | + }) |
| 117 | + } |
| 118 | +} |
0 commit comments