Skip to content

Commit

Permalink
Add v2 VNet CRUD test
Browse files Browse the repository at this point in the history
  • Loading branch information
Porges committed May 30, 2021
1 parent 7098553 commit 9095628
Show file tree
Hide file tree
Showing 4 changed files with 653 additions and 1 deletion.
58 changes: 58 additions & 0 deletions hack/generated/controllers/crd_virtualnetwork_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
*/

package controllers_test

import (
"context"
"testing"

. "github.com/onsi/gomega"

network "github.com/Azure/azure-service-operator/hack/generated/_apis/microsoft.network/v1alpha1api20171001"
"github.com/Azure/azure-service-operator/hack/generated/pkg/testcommon"
)

func Test_VirtualNetwork_CRUD(t *testing.T) {
t.Parallel()

g := NewGomegaWithT(t)
ctx := context.Background()
testContext, err := testContext.ForTest(t)
g.Expect(err).ToNot(HaveOccurred())

rg, err := testContext.CreateNewTestResourceGroup(testcommon.WaitForCreation)
g.Expect(err).ToNot(HaveOccurred())

vn := &network.VirtualNetwork{
ObjectMeta: testContext.MakeObjectMetaWithName(testContext.Namer.GenerateName("vn")),
Spec: network.VirtualNetworks_Spec{
Owner: testcommon.AsOwner(rg.ObjectMeta),
Location: &testcommon.DefaultTestRegion,
Properties: network.VirtualNetworkPropertiesFormat{
AddressSpace: &network.AddressSpace{
AddressPrefixes: []string{"10.0.0.0/8"},
},
},
},
}

// Create
g.Expect(testContext.KubeClient.Create(ctx, vn)).To(Succeed())
g.Eventually(vn, remainingTime(t)).Should(testContext.Match.BeProvisioned(ctx))

g.Expect(vn.Status.Id).ToNot(BeNil())
armId := *vn.Status.Id

// Delete
g.Expect(testContext.KubeClient.Delete(ctx, vn)).To(Succeed())
g.Eventually(vn, remainingTime(t)).Should(testContext.Match.BeDeleted(ctx))

// Ensure that the resource was really deleted in Azure
exists, retryAfter, err := testContext.AzureClient.HeadResource(ctx, armId, "2017-10-01")
g.Expect(err).ToNot(HaveOccurred())
g.Expect(retryAfter).To(BeZero())
g.Expect(exists).To(BeFalse())
}
Loading

0 comments on commit 9095628

Please sign in to comment.