Skip to content

Commit

Permalink
Merge pull request #4159 from chandankumar4/e2e-gomega-handles-fix
Browse files Browse the repository at this point in the history
Ensure Gomega handles are created in subtests
  • Loading branch information
k8s-ci-robot authored Oct 23, 2023
2 parents f736841 + 03d6235 commit 6e074c7
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 139 deletions.
98 changes: 33 additions & 65 deletions api/v1beta1/azurecluster_validation_test.go

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions api/v1beta1/azurecluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
)

func TestAzureCluster_ValidateCreate(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
cluster *AzureCluster
Expand Down Expand Up @@ -109,6 +107,7 @@ func TestAzureCluster_ValidateCreate(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
_, err := tc.cluster.ValidateCreate()
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
Expand All @@ -120,8 +119,6 @@ func TestAzureCluster_ValidateCreate(t *testing.T) {
}

func TestAzureCluster_ValidateUpdate(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
oldCluster *AzureCluster
Expand Down Expand Up @@ -347,6 +344,7 @@ func TestAzureCluster_ValidateUpdate(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
_, err := tc.cluster.ValidateUpdate(tc.oldCluster)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
Expand Down
6 changes: 2 additions & 4 deletions api/v1beta1/azureclusteridentity_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const fakeTenantID = "fake-tenant-id"
const fakeResourceID = "fake-resource-id"

func TestAzureClusterIdentity_ValidateCreate(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
clusterIdentity *AzureClusterIdentity
Expand Down Expand Up @@ -84,6 +82,7 @@ func TestAzureClusterIdentity_ValidateCreate(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
_, err := tc.clusterIdentity.ValidateCreate()
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
Expand All @@ -95,8 +94,6 @@ func TestAzureClusterIdentity_ValidateCreate(t *testing.T) {
}

func TestAzureClusterIdentity_ValidateUpdate(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
oldClusterIdentity *AzureClusterIdentity
Expand Down Expand Up @@ -165,6 +162,7 @@ func TestAzureClusterIdentity_ValidateUpdate(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
_, err := tc.clusterIdentity.ValidateUpdate(tc.oldClusterIdentity)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
Expand Down
12 changes: 4 additions & 8 deletions api/v1beta1/azureimage_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ func TestImageTooManyDetails(t *testing.T) {
}

func TestComputeImageGalleryValid(t *testing.T) {
g := NewWithT(t)

testCases := map[string]struct {
image *Image
expectedErrors int
Expand All @@ -87,13 +85,12 @@ func TestComputeImageGalleryValid(t *testing.T) {
}

for _, tc := range testCases {
g := NewWithT(t)
g.Expect(ValidateImage(tc.image, field.NewPath("image"))).To(HaveLen(tc.expectedErrors))
}
}

func TestSharedImageGalleryValid(t *testing.T) {
g := NewWithT(t)

testCases := map[string]struct {
image *Image
expectedErrors int
Expand Down Expand Up @@ -125,13 +122,12 @@ func TestSharedImageGalleryValid(t *testing.T) {
}

for _, tc := range testCases {
g := NewWithT(t)
g.Expect(ValidateImage(tc.image, field.NewPath("image"))).To(HaveLen(tc.expectedErrors))
}
}

func TestMarketPlaceImageValid(t *testing.T) {
g := NewWithT(t)

testCases := map[string]struct {
image *Image
expectedErrors int
Expand Down Expand Up @@ -159,13 +155,12 @@ func TestMarketPlaceImageValid(t *testing.T) {
}

for _, tc := range testCases {
g := NewWithT(t)
g.Expect(ValidateImage(tc.image, field.NewPath("image"))).To(HaveLen(tc.expectedErrors))
}
}

func TestImageByIDValid(t *testing.T) {
g := NewWithT(t)

testCases := map[string]struct {
image *Image
expectedErrors int
Expand All @@ -181,6 +176,7 @@ func TestImageByIDValid(t *testing.T) {
}

for _, tc := range testCases {
g := NewWithT(t)
g.Expect(ValidateImage(tc.image, field.NewPath("image"))).To(HaveLen(tc.expectedErrors))
}
}
Expand Down
6 changes: 2 additions & 4 deletions api/v1beta1/azuremachine_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,6 @@ func TestAzureMachineSpec_SetDataDisksDefaults(t *testing.T) {
}

func TestAzureMachineSpec_SetNetworkInterfacesDefaults(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
machine *AzureMachine
Expand Down Expand Up @@ -442,6 +440,7 @@ func TestAzureMachineSpec_SetNetworkInterfacesDefaults(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
tc.machine.Spec.SetNetworkInterfacesDefaults()
g.Expect(tc.machine).To(Equal(tc.want))
})
Expand Down Expand Up @@ -496,8 +495,6 @@ func TestAzureMachineSpec_GetOwnerCluster(t *testing.T) {
}

func TestAzureMachineSpec_GetSubscriptionID(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
maxAttempts int
Expand Down Expand Up @@ -541,6 +538,7 @@ func TestAzureMachineSpec_GetSubscriptionID(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
client := mockClient{ReturnError: tc.wantErr}
result, err := GetSubscriptionID(client, tc.ownerAzureClusterName, tc.ownerAzureClusterNamespace, tc.maxAttempts)
if tc.wantErr {
Expand Down
27 changes: 9 additions & 18 deletions api/v1beta1/azuremachine_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
)

func TestAzureMachine_ValidateSSHKey(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
sshKey string
Expand All @@ -58,6 +56,7 @@ func TestAzureMachine_ValidateSSHKey(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
err := ValidateSSHKey(tc.sshKey, field.NewPath("sshPublicKey"))
if tc.wantErr {
g.Expect(err).NotTo(BeEmpty())
Expand All @@ -84,8 +83,6 @@ type osDiskTestInput struct {
}

func TestAzureMachine_ValidateOSDisk(t *testing.T) {
g := NewWithT(t)

testcases := []osDiskTestInput{
{
name: "valid os disk spec",
Expand Down Expand Up @@ -135,6 +132,7 @@ func TestAzureMachine_ValidateOSDisk(t *testing.T) {

for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
g := NewWithT(t)
err := ValidateOSDisk(test.osDisk, field.NewPath("osDisk"))
if test.wantErr {
g.Expect(err).NotTo(BeEmpty())
Expand Down Expand Up @@ -227,8 +225,6 @@ func createOSDiskWithCacheType(cacheType string) OSDisk {
}

func TestAzureMachine_ValidateDataDisks(t *testing.T) {
g := NewWithT(t)

testcases := []struct {
name string
disks []DataDisk
Expand Down Expand Up @@ -434,6 +430,7 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) {

for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
g := NewWithT(t)
err := ValidateDataDisks(test.disks, field.NewPath("dataDisks"))
if test.wantErr {
g.Expect(err).NotTo(BeEmpty())
Expand All @@ -445,8 +442,6 @@ func TestAzureMachine_ValidateDataDisks(t *testing.T) {
}

func TestAzureMachine_ValidateSystemAssignedIdentity(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
roleAssignmentName string
Expand Down Expand Up @@ -489,6 +484,7 @@ func TestAzureMachine_ValidateSystemAssignedIdentity(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
err := ValidateSystemAssignedIdentity(tc.Identity, tc.old, tc.roleAssignmentName, field.NewPath("sshPublicKey"))
if tc.wantErr {
g.Expect(err).NotTo(BeEmpty())
Expand All @@ -500,8 +496,6 @@ func TestAzureMachine_ValidateSystemAssignedIdentity(t *testing.T) {
}

func TestAzureMachine_ValidateSystemAssignedIdentityRole(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
Identity VMIdentity
Expand Down Expand Up @@ -570,6 +564,7 @@ func TestAzureMachine_ValidateSystemAssignedIdentityRole(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
err := ValidateSystemAssignedIdentityRole(tc.Identity, tc.roleAssignmentName, tc.role, field.NewPath("systemAssignedIdentityRole"))
if tc.wantErr {
g.Expect(err).NotTo(BeEmpty())
Expand All @@ -581,8 +576,6 @@ func TestAzureMachine_ValidateSystemAssignedIdentityRole(t *testing.T) {
}

func TestAzureMachine_ValidateUserAssignedIdentity(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
idType VMIdentity
Expand Down Expand Up @@ -639,6 +632,7 @@ func TestAzureMachine_ValidateUserAssignedIdentity(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
errs := ValidateUserAssignedIdentity(tc.idType, tc.identities, field.NewPath("userAssignedIdentities"))
if tc.wantErr {
g.Expect(errs).NotTo(BeEmpty())
Expand All @@ -650,8 +644,6 @@ func TestAzureMachine_ValidateUserAssignedIdentity(t *testing.T) {
}

func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
disks []DataDisk
Expand Down Expand Up @@ -835,6 +827,7 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
g := NewWithT(t)
err := ValidateDataDisksUpdate(test.oldDisks, test.disks, field.NewPath("dataDisks"))
if test.wantErr {
g.Expect(err).NotTo(BeEmpty())
Expand All @@ -846,8 +839,6 @@ func TestAzureMachine_ValidateDataDisksUpdate(t *testing.T) {
}

func TestAzureMachine_ValidateNetwork(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
subnetName string
Expand Down Expand Up @@ -928,6 +919,7 @@ func TestAzureMachine_ValidateNetwork(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
g := NewWithT(t)
err := ValidateNetwork(test.subnetName, test.acceleratedNetworking, test.networkInterfaces, field.NewPath("networkInterfaces"))
if test.wantErr {
g.Expect(err).ToNot(BeEmpty())
Expand All @@ -939,8 +931,6 @@ func TestAzureMachine_ValidateNetwork(t *testing.T) {
}

func TestAzureMachine_ValidateConfidentialCompute(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
managedDisk *ManagedDiskParameters
Expand Down Expand Up @@ -1111,6 +1101,7 @@ func TestAzureMachine_ValidateConfidentialCompute(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
err := ValidateConfidentialCompute(tc.managedDisk, tc.securityProfile, field.NewPath("securityProfile"))
if tc.wantErr {
g.Expect(err).NotTo(BeEmpty())
Expand Down
6 changes: 2 additions & 4 deletions api/v1beta1/azuremachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ var (
)

func TestAzureMachine_ValidateCreate(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
machine *AzureMachine
Expand Down Expand Up @@ -220,6 +218,7 @@ func TestAzureMachine_ValidateCreate(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
mw := &azureMachineWebhook{}
_, err := mw.ValidateCreate(context.Background(), tc.machine)
if tc.wantErr {
Expand All @@ -232,8 +231,6 @@ func TestAzureMachine_ValidateCreate(t *testing.T) {
}

func TestAzureMachine_ValidateUpdate(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
oldMachine *AzureMachine
Expand Down Expand Up @@ -812,6 +809,7 @@ func TestAzureMachine_ValidateUpdate(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
mw := &azureMachineWebhook{}
_, err := mw.ValidateUpdate(context.Background(), tc.oldMachine, tc.newMachine)
if tc.wantErr {
Expand Down
6 changes: 3 additions & 3 deletions api/v1beta1/azuremachinetemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
)

func TestAzureMachineTemplate_ValidateCreate(t *testing.T) {
g := NewWithT(t)

tests := []struct {
name string
machineTemplate *AzureMachineTemplate
Expand Down Expand Up @@ -240,6 +238,7 @@ func TestAzureMachineTemplate_ValidateCreate(t *testing.T) {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
ctx := context.Background()
_, err := test.machineTemplate.ValidateCreate(ctx, test.machineTemplate)
if test.wantErr {
Expand All @@ -252,7 +251,6 @@ func TestAzureMachineTemplate_ValidateCreate(t *testing.T) {
}

func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) {
g := NewWithT(t)
failureDomain := "domaintest"

tests := []struct {
Expand Down Expand Up @@ -587,6 +585,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) {
for _, amt := range tests {
amt := amt
t.Run(amt.name, func(t *testing.T) {
g := NewWithT(t)
ctx := admission.NewContextWithRequest(context.Background(), admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: ptr.To(true)}})
_, err := amt.template.ValidateUpdate(ctx, amt.oldTemplate, amt.template)
if amt.wantErr {
Expand All @@ -601,6 +600,7 @@ func TestAzureMachineTemplate_ValidateUpdate(t *testing.T) {
amt := amt
t.Run(amt.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
ctx := admission.NewContextWithRequest(context.Background(), admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{DryRun: ptr.To(false)}})
_, err := amt.template.ValidateUpdate(ctx, amt.oldTemplate, amt.template)
if amt.wantErr {
Expand Down
Loading

0 comments on commit 6e074c7

Please sign in to comment.