From f5fd2cbbf6b19df933aeaea002811303dfd2b857 Mon Sep 17 00:00:00 2001 From: priyakumarank <51063856+priyakumarank@users.noreply.github.com> Date: Wed, 21 Aug 2019 10:23:34 +1000 Subject: [PATCH] refactor tests (#90) * improve tests with parallel execution and rm sleep * fix the tests to run on kindcluster --- Makefile | 4 +- api/v1/suite_test.go | 1 + controllers/eventhub_controller_test.go | 118 ++++------------ .../eventhubnamespace_controller_test.go | 131 +++++++----------- controllers/resourcegroup_controller_test.go | 8 +- controllers/suite_test.go | 34 ++++- pkg/resourcemanager/eventhubs/hub_test.go | 32 ++--- .../eventhubs/namespace_test.go | 16 +-- pkg/resourcemanager/eventhubs/suite_test.go | 26 +++- .../resourcegroups/resourcegroup_test.go | 5 - .../resourcegroups/suite_test.go | 4 + 11 files changed, 159 insertions(+), 220 deletions(-) diff --git a/Makefile b/Makefile index 85ef2b161ec..a7425b076e5 100644 --- a/Makefile +++ b/Makefile @@ -8,12 +8,12 @@ all: manager # Run tests test: generate fmt vet manifests - TEST_USE_EXISTING_CLUSTER=false go test -v -coverprofile=coverage.txt -covermode count ./api/... ./controllers/... ./resourcemanager/eventhubs/... ./resourcemanager/resourcegroups/... 2>&1 | tee testlogs.txt + TEST_USE_EXISTING_CLUSTER=false go test -v -coverprofile=coverage.txt -covermode count ./api/... ./controllers/... ./pkg/resourcemanager/eventhubs/... ./pkg/resourcemanager/resourcegroups/... 2>&1 | tee testlogs.txt go-junit-report < testlogs.txt > report.xml go tool cover -html=coverage.txt -o cover.html # Run tests with existing cluster test-existing: generate fmt vet manifests - TEST_USE_EXISTING_CLUSTER=true go test -v -coverprofile=coverage-existing.txt -covermode count ./api/... ./controllers/... ./resourcemanager/eventhubs/... ./resourcemanager/resourcegroups/... 2>&1 | tee testlogs-existing.txt + TEST_USE_EXISTING_CLUSTER=true go test -v -coverprofile=coverage-existing.txt -covermode count ./api/... ./controllers/... ./pkg/resourcemanager/eventhubs/... ./pkg/resourcemanager/resourcegroups/... 2>&1 | tee testlogs-existing.txt go-junit-report < testlogs-existing.txt > report-existing.xml go tool cover -html=coverage-existing.txt -o cover-existing.html diff --git a/api/v1/suite_test.go b/api/v1/suite_test.go index b3d69f9de67..e4d5357f792 100644 --- a/api/v1/suite_test.go +++ b/api/v1/suite_test.go @@ -38,6 +38,7 @@ var k8sClient client.Client var testEnv *envtest.Environment func TestAPIs(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecsWithDefaultAndCustomReporters(t, diff --git a/controllers/eventhub_controller_test.go b/controllers/eventhub_controller_test.go index d4ac4b6149b..216f03c4df4 100644 --- a/controllers/eventhub_controller_test.go +++ b/controllers/eventhub_controller_test.go @@ -17,14 +17,15 @@ package controllers import ( "context" + azurev1 "github.com/Azure/azure-service-operator/api/v1" helpers "github.com/Azure/azure-service-operator/pkg/helpers" - resoucegroupsresourcemanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/resourcegroups" + + "time" + . "github.com/onsi/ginkgo" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "os" - "time" . "github.com/onsi/gomega" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -48,87 +49,45 @@ var _ = Describe("EventHub Controller", func() { // Avoid adding tests for vanilla CRUD operations because they would // test Kubernetes API server, which isn't the goal here. Context("Create and Delete", func() { - if os.Getenv("TEST_USE_EXISTING_CLUSTER") == "true" { - It("should validate eventhubnamespaces exist before creating eventhubs", func() { - - resourceGroupName := "t-rg-dev-eh-" + helpers.RandomString(10) - eventhubNamespaceName := "t-ns-dev-eh-" + helpers.RandomString(10) - eventhubName := "t-eh-" + helpers.RandomString(10) - - // Create the EventHub object and expect the Reconcile to be created - eventhubInstance := &azurev1.Eventhub{ - ObjectMeta: metav1.ObjectMeta{ - Name: eventhubName, - Namespace: "default", - }, - Spec: azurev1.EventhubSpec{ - Location: "westus", - Namespace: eventhubNamespaceName, - ResourceGroup: resourceGroupName, - Properties: azurev1.EventhubProperties{ - MessageRetentionInDays: 7, - PartitionCount: 1, - }, - }, - } - - k8sClient.Create(context.Background(), eventhubInstance) - - time.Sleep(60 * time.Second) - - eventhubNamespacedName := types.NamespacedName{Name: eventhubName, Namespace: "default"} - - Eventually(func() bool { - _ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance) - return eventhubInstance.IsSubmitted() - }, timeout, - ).Should(BeFalse()) - - }) - } - - It("should create and delete eventhubs", func() { + It("should validate eventhubnamespaces exist before creating eventhubs", func() { - resourceGroupName := "t-rg-dev-eh-" + helpers.RandomString(10) - eventhubNamespaceName := "t-ns-dev-eh-" + helpers.RandomString(10) eventhubName := "t-eh-" + helpers.RandomString(10) - var err error - - // Create the Resourcegroup object and expect the Reconcile to be created - resourceGroupInstance := &azurev1.ResourceGroup{ + // Create the EventHub object and expect the Reconcile to be created + eventhubInstance := &azurev1.Eventhub{ ObjectMeta: metav1.ObjectMeta{ - Name: resourceGroupName, + Name: eventhubName, Namespace: "default", }, - Spec: azurev1.ResourceGroupSpec{ - Location: "westus", + Spec: azurev1.EventhubSpec{ + Location: "westus", + Namespace: "t-ns-dev-eh-" + helpers.RandomString(10), + ResourceGroup: "t-rg-dev-eh-" + helpers.RandomString(10), + Properties: azurev1.EventhubProperties{ + MessageRetentionInDays: 7, + PartitionCount: 1, + }, }, } - err = k8sClient.Create(context.Background(), resourceGroupInstance) - Expect(apierrors.IsInvalid(err)).To(Equal(false)) - Expect(err).NotTo(HaveOccurred()) + k8sClient.Create(context.Background(), eventhubInstance) - time.Sleep(30 * time.Second) + eventhubNamespacedName := types.NamespacedName{Name: eventhubName, Namespace: "default"} - // Create the Eventhub namespace object and expect the Reconcile to be created - eventhubNamespaceInstance := &azurev1.EventhubNamespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: eventhubNamespaceName, - Namespace: "default", - }, - Spec: azurev1.EventhubNamespaceSpec{ - Location: "westus", - ResourceGroup: resourceGroupName, - }, - } + Eventually(func() bool { + _ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance) + return eventhubInstance.IsSubmitted() + }, timeout, + ).Should(BeFalse()) + }) - err = k8sClient.Create(context.Background(), eventhubNamespaceInstance) - Expect(apierrors.IsInvalid(err)).To(Equal(false)) - Expect(err).NotTo(HaveOccurred()) + It("should create and delete eventhubs", func() { + + resourceGroupName = "t-rg-dev-controller" + eventhubNamespaceName = "t-ns-dev-eh-ns" + eventhubName := "t-eh-" + helpers.RandomString(10) - time.Sleep(30 * time.Second) + var err error // Create the EventHub object and expect the Reconcile to be created eventhubInstance := &azurev1.Eventhub{ @@ -151,12 +110,6 @@ var _ = Describe("EventHub Controller", func() { Expect(apierrors.IsInvalid(err)).To(Equal(false)) Expect(err).NotTo(HaveOccurred()) - time.Sleep(30 * time.Second) - // The instance object may not be a valid object because it might be missing some required fields. - // Please modify the instance object by adding required fields and then remove the following if statement. - Expect(apierrors.IsInvalid(err)).To(Equal(false)) - Expect(err).NotTo(HaveOccurred()) - eventhubNamespacedName := types.NamespacedName{Name: eventhubName, Namespace: "default"} Eventually(func() bool { @@ -171,8 +124,6 @@ var _ = Describe("EventHub Controller", func() { }, timeout, ).Should(BeTrue()) - time.Sleep(2 * time.Second) - //create secret in k8s csecret := &v1.Secret{ TypeMeta: metav1.TypeMeta{ @@ -197,8 +148,6 @@ var _ = Describe("EventHub Controller", func() { err = k8sClient.Create(context.Background(), csecret) Expect(err).NotTo(HaveOccurred()) - time.Sleep(2 * time.Second) - //get secret from k8s secret := &v1.Secret{} err = k8sClient.Get(context.Background(), types.NamespacedName{Name: eventhubName, Namespace: eventhubInstance.Namespace}, secret) @@ -206,8 +155,6 @@ var _ = Describe("EventHub Controller", func() { Expect(secret.Data).To(Equal(csecret.Data)) Expect(secret.ObjectMeta).To(Equal(csecret.ObjectMeta)) - time.Sleep(2 * time.Second) - k8sClient.Delete(context.Background(), eventhubInstance) Eventually(func() bool { _ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance) @@ -215,11 +162,6 @@ var _ = Describe("EventHub Controller", func() { }, timeout, ).Should(BeTrue()) - time.Sleep(2 * time.Second) - - _, err = resoucegroupsresourcemanager.DeleteGroup(context.Background(), resourceGroupName) - Expect(err).NotTo(HaveOccurred()) - }) }) }) diff --git a/controllers/eventhubnamespace_controller_test.go b/controllers/eventhubnamespace_controller_test.go index 4ffb1c690c8..4735a5bbb96 100644 --- a/controllers/eventhubnamespace_controller_test.go +++ b/controllers/eventhubnamespace_controller_test.go @@ -17,13 +17,14 @@ package controllers import ( "context" + azurev1 "github.com/Azure/azure-service-operator/api/v1" helpers "github.com/Azure/azure-service-operator/pkg/helpers" - resoucegroupsresourcemanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/resourcegroups" - . "github.com/onsi/ginkgo" - "os" + "time" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -36,6 +37,7 @@ var _ = Describe("EventHubNamespace Controller", func() { BeforeEach(func() { // Add any setup steps that needs to be executed before each test + }) AfterEach(func() { @@ -47,94 +49,72 @@ var _ = Describe("EventHubNamespace Controller", func() { // Avoid adding tests for vanilla CRUD operations because they would // test Kubernetes API server, which isn't the goal here. Context("Create and Delete", func() { - if os.Getenv("TEST_USE_EXISTING_CLUSTER") == "true" { - It("should validate eventhubnamespace name is valid", func() { - resourceGroupName := "t-rg-dev-eh-" + helpers.RandomString(10) - eventhubNamespaceName := "t-ns" + It("should validate eventhubnamespace name is valid", func() { - // Create the EventHubNamespace object and expect the Reconcile to be created - eventhubNamespaceInstance := &azurev1.EventhubNamespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: eventhubNamespaceName, - Namespace: "default", - }, - Spec: azurev1.EventhubNamespaceSpec{ - Location: "westus", - ResourceGroup: resourceGroupName, - }, - } - - k8sClient.Create(context.Background(), eventhubNamespaceInstance) + resourceGroupName := "t-rg-dev-eh-" + helpers.RandomString(10) + eventhubNamespaceName := "t-ns" - time.Sleep(60 * time.Second) + // Create the EventHubNamespace object and expect the Reconcile to be created + eventhubNamespaceInstance := &azurev1.EventhubNamespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: eventhubNamespaceName, + Namespace: "default", + }, + Spec: azurev1.EventhubNamespaceSpec{ + Location: "westus", + ResourceGroup: resourceGroupName, + }, + } - eventhubNamespacedName := types.NamespacedName{Name: eventhubNamespaceName, Namespace: "default"} + k8sClient.Create(context.Background(), eventhubNamespaceInstance) - Eventually(func() bool { - _ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubNamespaceInstance) - return eventhubNamespaceInstance.IsSubmitted() - }, timeout, - ).Should(BeFalse()) + eventhubNamespacedName := types.NamespacedName{Name: eventhubNamespaceName, Namespace: "default"} - }) + Eventually(func() bool { + _ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubNamespaceInstance) + return eventhubNamespaceInstance.IsSubmitted() + }, timeout, + ).Should(BeFalse()) - It("should validate resourcegroup exist before creating eventhubnamespaces", func() { + }) - resourceGroupName := "t-rg-dev-eh-" + helpers.RandomString(10) - eventhubNamespaceName := "t-ns-dev-eh-" + helpers.RandomString(10) + It("should validate resourcegroup exist before creating eventhubnamespaces", func() { - // Create the EventHubNamespace object and expect the Reconcile to be created - eventhubNamespaceInstance := &azurev1.EventhubNamespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: eventhubNamespaceName, - Namespace: "default", - }, - Spec: azurev1.EventhubNamespaceSpec{ - Location: "westus", - ResourceGroup: resourceGroupName, - }, - } + resourceGroupName := "t-rg-dev-eh-" + helpers.RandomString(10) + eventhubNamespaceName := "t-ns-dev-eh-" + helpers.RandomString(10) - k8sClient.Create(context.Background(), eventhubNamespaceInstance) + // Create the EventHubNamespace object and expect the Reconcile to be created + eventhubNamespaceInstance := &azurev1.EventhubNamespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: eventhubNamespaceName, + Namespace: "default", + }, + Spec: azurev1.EventhubNamespaceSpec{ + Location: "westus", + ResourceGroup: resourceGroupName, + }, + } - time.Sleep(60 * time.Second) + k8sClient.Create(context.Background(), eventhubNamespaceInstance) - eventhubNamespacedName := types.NamespacedName{Name: eventhubNamespaceName, Namespace: "default"} + eventhubNamespacedName := types.NamespacedName{Name: eventhubNamespaceName, Namespace: "default"} - Eventually(func() bool { - _ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubNamespaceInstance) - return eventhubNamespaceInstance.IsSubmitted() - }, timeout, - ).Should(BeFalse()) + Eventually(func() bool { + _ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubNamespaceInstance) + return eventhubNamespaceInstance.IsSubmitted() + }, timeout, + ).Should(BeFalse()) - }) - } + }) It("should create and delete namespace in k8s", func() { - resourceGroupName := "t-rg-dev-eh-" + helpers.RandomString(10) + resourceGroupName := "t-rg-dev-controller" eventhubNamespaceName := "t-ns-dev-eh-" + helpers.RandomString(10) var err error - // Create the Resourcegroup object and expect the Reconcile to be created - resourceGroupInstance := &azurev1.ResourceGroup{ - ObjectMeta: metav1.ObjectMeta{ - Name: resourceGroupName, - Namespace: "default", - }, - Spec: azurev1.ResourceGroupSpec{ - Location: "westus", - }, - } - - err = k8sClient.Create(context.Background(), resourceGroupInstance) - Expect(apierrors.IsInvalid(err)).To(Equal(false)) - Expect(err).NotTo(HaveOccurred()) - - time.Sleep(60 * time.Second) - // Create the Eventhub namespace object and expect the Reconcile to be created eventhubNamespaceInstance := &azurev1.EventhubNamespace{ ObjectMeta: metav1.ObjectMeta{ @@ -151,8 +131,6 @@ var _ = Describe("EventHubNamespace Controller", func() { Expect(apierrors.IsInvalid(err)).To(Equal(false)) Expect(err).NotTo(HaveOccurred()) - time.Sleep(30 * time.Second) - eventhubNamespacedName := types.NamespacedName{Name: eventhubNamespaceName, Namespace: "default"} Eventually(func() bool { @@ -161,16 +139,12 @@ var _ = Describe("EventHubNamespace Controller", func() { }, timeout, ).Should(BeTrue()) - time.Sleep(30 * time.Second) - Eventually(func() bool { _ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubNamespaceInstance) return eventhubNamespaceInstance.IsSubmitted() }, timeout, ).Should(BeTrue()) - time.Sleep(30 * time.Second) - k8sClient.Delete(context.Background(), eventhubNamespaceInstance) Eventually(func() bool { _ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubNamespaceInstance) @@ -178,11 +152,6 @@ var _ = Describe("EventHubNamespace Controller", func() { }, timeout, ).Should(BeTrue()) - time.Sleep(2 * time.Second) - - _, err = resoucegroupsresourcemanager.DeleteGroup(context.Background(), resourceGroupName) - Expect(err).NotTo(HaveOccurred()) - }) }) }) diff --git a/controllers/resourcegroup_controller_test.go b/controllers/resourcegroup_controller_test.go index a9ec25a2eb0..9a7f519c484 100644 --- a/controllers/resourcegroup_controller_test.go +++ b/controllers/resourcegroup_controller_test.go @@ -23,7 +23,6 @@ import ( azurev1 "github.com/Azure/azure-service-operator/api/v1" helpers "github.com/Azure/azure-service-operator/pkg/helpers" - //resoucegroupsresourcemanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/resourcegroups" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -70,8 +69,11 @@ var _ = Describe("ResourceGroup Controller", func() { Expect(err).NotTo(HaveOccurred()) resourceGroupNamespacedName := types.NamespacedName{Name: resourceGroupName, Namespace: "default"} - - time.Sleep(2 * time.Second) + Eventually(func() bool { + _ = k8sClient.Get(context.Background(), resourceGroupNamespacedName, resourceGroupInstance) + return resourceGroupInstance.IsSubmitted() + }, timeout, + ).Should(BeTrue()) k8sClient.Delete(context.Background(), resourceGroupInstance) Eventually(func() bool { diff --git a/controllers/suite_test.go b/controllers/suite_test.go index c79e25b2b4d..64a49c50a89 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -16,14 +16,19 @@ limitations under the License. package controllers import ( + "context" "os" "path/filepath" "testing" azurev1 "github.com/Azure/azure-service-operator/api/v1" resourcemanagerconfig "github.com/Azure/azure-service-operator/pkg/resourcemanager/config" + + eventhubs "github.com/Azure/azure-service-operator/pkg/resourcemanager/eventhubs" + resoucegroupsresourcemanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/resourcegroups" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" ctrl "sigs.k8s.io/controller-runtime" @@ -41,10 +46,19 @@ var cfg *rest.Config var k8sClient client.Client var k8sManager ctrl.Manager var testEnv *envtest.Environment +var resourceGroupName string +var resourcegroupLocation string +var eventhubNamespaceName string +var namespaceLocation string func TestAPIs(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) + resourceGroupName = "t-rg-dev-controller" + resourcegroupLocation = "westus" + eventhubNamespaceName = "t-ns-dev-eh-ns" + namespaceLocation = "westus" RunSpecsWithDefaultAndCustomReporters(t, "Controller Suite", []Reporter{envtest.NewlineReporter{}}) @@ -119,13 +133,27 @@ var _ = BeforeSuite(func(done Done) { k8sClient = k8sManager.GetClient() Expect(k8sClient).ToNot(BeNil()) + // Create the Resourcegroup resource + result, _ := resoucegroupsresourcemanager.CheckExistence(context.Background(), resourceGroupName) + if result.Response.StatusCode != 204 { + _, _ = resoucegroupsresourcemanager.CreateGroup(context.Background(), resourceGroupName, resourcegroupLocation) + } + + // Create the Eventhub namespace resource + _, err = eventhubs.CreateNamespaceAndWait(context.Background(), resourceGroupName, eventhubNamespaceName, namespaceLocation) + close(done) -}, 60) +}, 120) -var _ = AfterSuite(func() { +var _ = AfterSuite(func(done Done) { //clean up the resources created for test By("tearing down the test environment") + + _, _ = resoucegroupsresourcemanager.DeleteGroup(context.Background(), resourceGroupName) + err := testEnv.Stop() Expect(err).ToNot(HaveOccurred()) -}) + close(done) + +}, 60) diff --git a/pkg/resourcemanager/eventhubs/hub_test.go b/pkg/resourcemanager/eventhubs/hub_test.go index d76c3497826..55be9925906 100644 --- a/pkg/resourcemanager/eventhubs/hub_test.go +++ b/pkg/resourcemanager/eventhubs/hub_test.go @@ -22,17 +22,25 @@ import ( model "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" helpers "github.com/Azure/azure-service-operator/pkg/helpers" - resoucegroupsresourcemanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/resourcegroups" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) -var _ = Describe("Namespace", func() { +var _ = Describe("Eventhub", func() { const timeout = time.Second * 240 + var resourceGroupName string + var eventhubNamespaceName string + var namespaceLocation string BeforeEach(func() { // Add any setup steps that needs to be executed before each test + resourceGroupName = "t-rg-dev-rm-eh" + eventhubNamespaceName = "t-ns-dev-eh-" + helpers.RandomString(10) + namespaceLocation = "westus" + + _, _ = CreateNamespaceAndWait(context.Background(), resourceGroupName, eventhubNamespaceName, namespaceLocation) + }) AfterEach(func() { @@ -47,26 +55,12 @@ var _ = Describe("Namespace", func() { Context("Create and Delete", func() { It("should create and delete hubs in azure", func() { - resourceGroupName := "t-rg-dev-eh-" + helpers.RandomString(10) - resourcegroupLocation := "westus" - eventhubNamespaceName := "t-ns-dev-eh-" + helpers.RandomString(10) - namespaceLocation := "westus" eventhubName := "t-eh-" + helpers.RandomString(10) messageRetentionInDays := int32(7) partitionCount := int32(1) var err error - _, err = resoucegroupsresourcemanager.CreateGroup(context.Background(), resourceGroupName, resourcegroupLocation) - Expect(err).NotTo(HaveOccurred()) - - time.Sleep(30 * time.Second) - - _, err = CreateNamespaceAndWait(context.Background(), resourceGroupName, eventhubNamespaceName, namespaceLocation) - Expect(err).NotTo(HaveOccurred()) - - time.Sleep(30 * time.Second) - _, err = CreateHub(context.Background(), resourceGroupName, eventhubNamespaceName, eventhubName, messageRetentionInDays, partitionCount) Expect(err).NotTo(HaveOccurred()) @@ -83,6 +77,7 @@ var _ = Describe("Namespace", func() { Rights: &accessRights, }, } + _, err = CreateOrUpdateAuthorizationRule(context.Background(), resourceGroupName, eventhubNamespaceName, eventhubName, authorizationRuleName, parameters) Expect(err).NotTo(HaveOccurred()) @@ -101,11 +96,6 @@ var _ = Describe("Namespace", func() { }, timeout, ).Should(BeTrue()) - time.Sleep(30 * time.Second) - - _, err = resoucegroupsresourcemanager.DeleteGroup(context.Background(), resourceGroupName) - Expect(err).NotTo(HaveOccurred()) - }) }) diff --git a/pkg/resourcemanager/eventhubs/namespace_test.go b/pkg/resourcemanager/eventhubs/namespace_test.go index 1c24274135f..35449a3d4ed 100644 --- a/pkg/resourcemanager/eventhubs/namespace_test.go +++ b/pkg/resourcemanager/eventhubs/namespace_test.go @@ -20,8 +20,6 @@ import ( "context" "time" - resoucegroupsresourcemanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/resourcegroups" - helpers "github.com/Azure/azure-service-operator/pkg/helpers" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -47,16 +45,11 @@ var _ = Describe("Namespace", func() { Context("Create and Delete", func() { It("should create and delete namespace in azure", func() { - resourceGroupName := "t-rg-dev-eh-" + helpers.RandomString(10) - resourcegroupLocation := "westus" + resourceGroupName := "t-rg-dev-rm-eh" eventhubNamespaceName := "t-ns-dev-eh-" + helpers.RandomString(10) namespaceLocation := "westus" - var err error - - _, err = resoucegroupsresourcemanager.CreateGroup(context.Background(), resourceGroupName, resourcegroupLocation) - Expect(err).NotTo(HaveOccurred()) - time.Sleep(30 * time.Second) + var err error _, err = CreateNamespaceAndWait(context.Background(), resourceGroupName, eventhubNamespaceName, namespaceLocation) Expect(err).NotTo(HaveOccurred()) @@ -76,11 +69,6 @@ var _ = Describe("Namespace", func() { }, timeout, ).Should(BeTrue()) - time.Sleep(30 * time.Second) - - _, err = resoucegroupsresourcemanager.DeleteGroup(context.Background(), resourceGroupName) - Expect(err).NotTo(HaveOccurred()) - }) }) diff --git a/pkg/resourcemanager/eventhubs/suite_test.go b/pkg/resourcemanager/eventhubs/suite_test.go index bd812b6d291..c30e6878f1a 100644 --- a/pkg/resourcemanager/eventhubs/suite_test.go +++ b/pkg/resourcemanager/eventhubs/suite_test.go @@ -19,9 +19,13 @@ import ( "testing" resourcemanagerconfig "github.com/Azure/azure-service-operator/pkg/resourcemanager/config" + + resoucegroupsresourcemanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/resourcegroups" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "context" + "k8s.io/client-go/rest" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" @@ -32,9 +36,17 @@ import ( // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. var cfg *rest.Config +var resourceGroupName string +var resourcegroupLocation string func TestAPIs(t *testing.T) { + t.Parallel() + if testing.Short() { + t.Skip("skipping Resource Manager Eventhubs Suite") + } RegisterFailHandler(Fail) + resourceGroupName = "t-rg-dev-rm-eh" + resourcegroupLocation = "westus" RunSpecs(t, "Eventhubs Suite") } @@ -46,12 +58,20 @@ var _ = BeforeSuite(func(done Done) { resourcemanagerconfig.LoadSettings() + //create resourcegroup for this suite + result, _ := resoucegroupsresourcemanager.CheckExistence(context.Background(), resourceGroupName) + if result.Response.StatusCode != 204 { + _, _ = resoucegroupsresourcemanager.CreateGroup(context.Background(), resourceGroupName, resourcegroupLocation) + } + close(done) }, 60) -var _ = AfterSuite(func() { +var _ = AfterSuite(func(done Done) { //clean up the resources created for test - By("tearing down the test environment") -}) + _, _ = resoucegroupsresourcemanager.DeleteGroup(context.Background(), resourceGroupName) + + close(done) +}, 60) diff --git a/pkg/resourcemanager/resourcegroups/resourcegroup_test.go b/pkg/resourcemanager/resourcegroups/resourcegroup_test.go index 1a87ef8f621..099ecde64c2 100644 --- a/pkg/resourcemanager/resourcegroups/resourcegroup_test.go +++ b/pkg/resourcemanager/resourcegroups/resourcegroup_test.go @@ -54,8 +54,6 @@ var _ = Describe("ResourceGroups", func() { _, err = CreateGroup(context.Background(), resourcegroupName, resourcegroupLocation) Expect(err).NotTo(HaveOccurred()) - time.Sleep(40 * time.Second) - Eventually(func() bool { result, _ := CheckExistence(context.Background(), resourcegroupName) @@ -66,8 +64,6 @@ var _ = Describe("ResourceGroups", func() { _, err = DeleteGroup(context.Background(), resourcegroupName) Expect(err).NotTo(HaveOccurred()) - time.Sleep(30 * time.Second) - Eventually(func() bool { result, _ := CheckExistence(context.Background(), resourcegroupName) @@ -75,7 +71,6 @@ var _ = Describe("ResourceGroups", func() { }, timeout, ).Should(BeTrue()) - //DeleteAllGroupsWithPrefix(context.Background(), "t-rg-") }) }) diff --git a/pkg/resourcemanager/resourcegroups/suite_test.go b/pkg/resourcemanager/resourcegroups/suite_test.go index c5d2ed330ce..5a7a91bbfe2 100644 --- a/pkg/resourcemanager/resourcegroups/suite_test.go +++ b/pkg/resourcemanager/resourcegroups/suite_test.go @@ -32,6 +32,10 @@ import ( var cfg *rest.Config func TestAPIs(t *testing.T) { + t.Parallel() + if testing.Short() { + t.Skip("skipping Resource Manager Resource Group Suite") + } RegisterFailHandler(Fail) RunSpecs(t, "Resource Manager Suite")