-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add microsoft.compute/20200930/Disk to generated resources
With a CRUD test.
- Loading branch information
1 parent
6bc381c
commit 5a0de5b
Showing
3 changed files
with
984 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright (c) Microsoft Corporation. | ||
Licensed under the MIT license. | ||
*/ | ||
|
||
package controllers_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
compute "github.com/Azure/azure-service-operator/hack/generated/_apis/microsoft.compute/v1alpha1api20200930" | ||
"github.com/Azure/azure-service-operator/hack/generated/pkg/testcommon" | ||
) | ||
|
||
func Test_Disk_CRUD(t *testing.T) { | ||
t.Parallel() | ||
|
||
tc := globalTestContext.ForTest(t) | ||
|
||
rg := tc.CreateNewTestResourceGroupAndWait() | ||
|
||
// Create a disk. | ||
standardSkuName := compute.DiskSkuNameStandardLRS | ||
size := 500 | ||
disk := &compute.Disk{ | ||
ObjectMeta: tc.MakeObjectMeta("disk"), | ||
Spec: compute.Disks_Spec{ | ||
Location: tc.AzureRegion, | ||
Owner: testcommon.AsOwner(rg.ObjectMeta), | ||
Sku: &compute.DiskSku{ | ||
Name: &standardSkuName, | ||
}, | ||
Properties: compute.DiskProperties{ | ||
CreationData: compute.CreationData{ | ||
CreateOption: "Empty", | ||
}, | ||
DiskSizeGB: &size, | ||
}, | ||
}, | ||
} | ||
tc.CreateResourceAndWait(disk) | ||
|
||
tc.Expect(disk.Status.Location).To(Equal(tc.AzureRegion)) | ||
tc.Expect(disk.Status.Sku.Name).To(BeEquivalentTo(&standardSkuName)) | ||
tc.Expect(*disk.Status.Properties.DiskSizeGB).To(BeNumerically(">=", 500)) | ||
tc.Expect(disk.Status.Id).ToNot(BeNil()) | ||
armId := *disk.Status.Id | ||
|
||
// Perform a simple patch. | ||
patcher := tc.NewResourcePatcher(disk) | ||
networkAccessPolicy := compute.DiskPropertiesNetworkAccessPolicyDenyAll | ||
disk.Spec.Properties.NetworkAccessPolicy = &networkAccessPolicy | ||
patcher.Patch(disk) | ||
|
||
objectKey, err := client.ObjectKeyFromObject(disk) | ||
tc.Expect(err).ToNot(HaveOccurred()) | ||
|
||
// Ensure state eventually gets updated in k8s from change in Azure. | ||
tc.Eventually(func() *compute.NetworkAccessPolicy_Status { | ||
var updatedDisk compute.Disk | ||
tc.GetResource(objectKey, &updatedDisk) | ||
return updatedDisk.Status.Properties.NetworkAccessPolicy | ||
}).Should(BeEquivalentTo(&networkAccessPolicy)) | ||
|
||
tc.DeleteResourceAndWait(disk) | ||
|
||
// Ensure that the resource group was really deleted in Azure | ||
exists, _, err := tc.AzureClient.HeadResource( | ||
tc.Ctx, | ||
armId, | ||
string(compute.DisksSpecAPIVersion20200930)) | ||
tc.Expect(err).ToNot(HaveOccurred()) | ||
tc.Expect(exists).To(BeFalse()) | ||
} |
Oops, something went wrong.