Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AWSMachinepool webhook create and update test #3312

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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