Skip to content

Commit 3da422c

Browse files
authored
Merge pull request #3312 from shivi28/webhook_1
Added AWSMachinepool webhook create and update test
2 parents cb9c395 + a9d6a90 commit 3da422c

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

exp/api/v1beta1/awsmachinepool_webhook_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
. "github.com/onsi/gomega"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/utils/pointer"
2526

2627
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
2728
utildefaulting "sigs.k8s.io/cluster-api/util/defaulting"
@@ -70,6 +71,41 @@ func TestAWSMachinePool_ValidateCreate(t *testing.T) {
7071
},
7172
wantErr: true,
7273
},
74+
{
75+
name: "Should fail if both subnet ID and filters passed in AWSMachinePool spec",
76+
pool: &AWSMachinePool{
77+
Spec: AWSMachinePoolSpec{
78+
AdditionalTags: infrav1.Tags{
79+
"key-1": "value-1",
80+
"key-2": "value-2",
81+
},
82+
Subnets: []infrav1.AWSResourceReference{
83+
{
84+
ID: pointer.StringPtr("subnet-id"),
85+
Filters: []infrav1.Filter{{Name: "filter_name", Values: []string{"filter_value"}}},
86+
},
87+
},
88+
},
89+
},
90+
wantErr: true,
91+
},
92+
{
93+
name: "Should pass if either subnet ID or filters passed in AWSMachinePool spec",
94+
pool: &AWSMachinePool{
95+
Spec: AWSMachinePoolSpec{
96+
AdditionalTags: infrav1.Tags{
97+
"key-1": "value-1",
98+
"key-2": "value-2",
99+
},
100+
Subnets: []infrav1.AWSResourceReference{
101+
{
102+
ID: pointer.StringPtr("subnet-id"),
103+
},
104+
},
105+
},
106+
},
107+
wantErr: false,
108+
},
73109
}
74110
for _, tt := range tests {
75111
t.Run(tt.name, func(t *testing.T) {
@@ -132,6 +168,55 @@ func TestAWSMachinePool_ValidateUpdate(t *testing.T) {
132168
},
133169
wantErr: true,
134170
},
171+
{
172+
name: "Should fail update if both subnetID and filters passed in AWSMachinePool spec",
173+
old: &AWSMachinePool{
174+
Spec: AWSMachinePoolSpec{
175+
AdditionalTags: infrav1.Tags{
176+
"key-1": "value-1",
177+
},
178+
},
179+
},
180+
new: &AWSMachinePool{
181+
Spec: AWSMachinePoolSpec{
182+
AdditionalTags: infrav1.Tags{
183+
"key-1": "value-1",
184+
"key-2": "value-2",
185+
},
186+
Subnets: []infrav1.AWSResourceReference{
187+
{
188+
ID: pointer.StringPtr("subnet-id"),
189+
Filters: []infrav1.Filter{{Name: "filter_name", Values: []string{"filter_value"}}},
190+
},
191+
},
192+
},
193+
},
194+
wantErr: true,
195+
},
196+
{
197+
name: "Should pass update if either subnetID or filters passed in AWSMachinePool spec",
198+
old: &AWSMachinePool{
199+
Spec: AWSMachinePoolSpec{
200+
AdditionalTags: infrav1.Tags{
201+
"key-1": "value-1",
202+
},
203+
},
204+
},
205+
new: &AWSMachinePool{
206+
Spec: AWSMachinePoolSpec{
207+
AdditionalTags: infrav1.Tags{
208+
"key-1": "value-1",
209+
"key-2": "value-2",
210+
},
211+
Subnets: []infrav1.AWSResourceReference{
212+
{
213+
ID: pointer.StringPtr("subnet-id"),
214+
},
215+
},
216+
},
217+
},
218+
wantErr: false,
219+
},
135220
}
136221
for _, tt := range tests {
137222
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)