Skip to content

Commit

Permalink
Merge pull request #3312 from shivi28/webhook_1
Browse files Browse the repository at this point in the history
Added AWSMachinepool webhook create and update test
  • Loading branch information
k8s-ci-robot authored Mar 16, 2022
2 parents cb9c395 + a9d6a90 commit 3da422c
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions exp/api/v1beta1/awsmachinepool_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"

infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
utildefaulting "sigs.k8s.io/cluster-api/util/defaulting"
Expand Down Expand Up @@ -70,6 +71,41 @@ func TestAWSMachinePool_ValidateCreate(t *testing.T) {
},
wantErr: true,
},
{
name: "Should fail if both subnet ID and filters passed in AWSMachinePool spec",
pool: &AWSMachinePool{
Spec: AWSMachinePoolSpec{
AdditionalTags: infrav1.Tags{
"key-1": "value-1",
"key-2": "value-2",
},
Subnets: []infrav1.AWSResourceReference{
{
ID: pointer.StringPtr("subnet-id"),
Filters: []infrav1.Filter{{Name: "filter_name", Values: []string{"filter_value"}}},
},
},
},
},
wantErr: true,
},
{
name: "Should pass if either subnet ID or filters passed in AWSMachinePool spec",
pool: &AWSMachinePool{
Spec: AWSMachinePoolSpec{
AdditionalTags: infrav1.Tags{
"key-1": "value-1",
"key-2": "value-2",
},
Subnets: []infrav1.AWSResourceReference{
{
ID: pointer.StringPtr("subnet-id"),
},
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -132,6 +168,55 @@ func TestAWSMachinePool_ValidateUpdate(t *testing.T) {
},
wantErr: true,
},
{
name: "Should fail update if both subnetID and filters passed in AWSMachinePool spec",
old: &AWSMachinePool{
Spec: AWSMachinePoolSpec{
AdditionalTags: infrav1.Tags{
"key-1": "value-1",
},
},
},
new: &AWSMachinePool{
Spec: AWSMachinePoolSpec{
AdditionalTags: infrav1.Tags{
"key-1": "value-1",
"key-2": "value-2",
},
Subnets: []infrav1.AWSResourceReference{
{
ID: pointer.StringPtr("subnet-id"),
Filters: []infrav1.Filter{{Name: "filter_name", Values: []string{"filter_value"}}},
},
},
},
},
wantErr: true,
},
{
name: "Should pass update if either subnetID or filters passed in AWSMachinePool spec",
old: &AWSMachinePool{
Spec: AWSMachinePoolSpec{
AdditionalTags: infrav1.Tags{
"key-1": "value-1",
},
},
},
new: &AWSMachinePool{
Spec: AWSMachinePoolSpec{
AdditionalTags: infrav1.Tags{
"key-1": "value-1",
"key-2": "value-2",
},
Subnets: []infrav1.AWSResourceReference{
{
ID: pointer.StringPtr("subnet-id"),
},
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 3da422c

Please sign in to comment.