From 773d9477c6f3b046bc5d10da4e78b97b5f733058 Mon Sep 17 00:00:00 2001 From: DangPeng Liu Date: Thu, 30 Jul 2020 10:07:58 +0800 Subject: [PATCH] fix e2e when managed cluster do not on hub (#188) --- test/README.md | 1 + test/e2e/common/common.go | 5 +- test/e2e/tests/actions/actions_test.go | 77 +++++++++++++++----------- 3 files changed, 49 insertions(+), 34 deletions(-) diff --git a/test/README.md b/test/README.md index eb2abf946..996fe0880 100644 --- a/test/README.md +++ b/test/README.md @@ -6,6 +6,7 @@ The tests contained in this repository will test the core functionality of Multi * A Kubernetes cluster with Multicloud Management installed * Before running testing, kubeconfig file for cluster admin should be in place. Test suites try to load the configuration file from either `$HOME/.kube/config` or the path set by environment variable `KUBECONFIG`. +* If you want to run e2e locally, when managedcluster do not deployed on hub, please set env `export SINGLE_MANAGED_CLUSTER_ON_HUB=FALSE`. ## How to run diff --git a/test/e2e/common/common.go b/test/e2e/common/common.go index d5f2df04c..bf36d3186 100644 --- a/test/e2e/common/common.go +++ b/test/e2e/common/common.go @@ -24,8 +24,9 @@ import ( ) const ( - kubeConfigFileEnv = "KUBECONFIG" - SingleManagedOnHub = true + kubeConfigFileEnv = "KUBECONFIG" + //Managedcluster deployed on hub + SingleManagedOnHub = "SINGLE_MANAGED_CLUSTER_ON_HUB" ) var ManagedClusterGVR schema.GroupVersionResource = schema.GroupVersionResource{ diff --git a/test/e2e/tests/actions/actions_test.go b/test/e2e/tests/actions/actions_test.go index 3faded5b8..efd94cd19 100644 --- a/test/e2e/tests/actions/actions_test.go +++ b/test/e2e/tests/actions/actions_test.go @@ -3,6 +3,9 @@ package actions_test import ( + "os" + "strings" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/open-cluster-management/multicloud-operators-foundation/test/e2e/common" @@ -19,6 +22,8 @@ const ( actionDeploymentNameSpace = "default" ) +var singleManagedOnHub = true + var actionGVR = schema.GroupVersionResource{ Group: "action.open-cluster-management.io", Version: "v1beta1", @@ -38,6 +43,10 @@ var ( var _ = BeforeSuite(func() { var err error + managedOnHub := os.Getenv(common.SingleManagedOnHub) + if strings.ToLower(managedOnHub) == "false" { + singleManagedOnHub = false + } dynamicClient, err = common.NewDynamicClient() Ω(err).ShouldNot(HaveOccurred()) @@ -63,11 +72,10 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() { obj *unstructured.Unstructured err error ) - - Context("Creating a CreateManagedClusterAction", func() { - It("should create successfully", func() { + Context("Creating a UpdateManagedClusterAction when resource do not exist", func() { + It("Should create update managedclusteraction successfully", func() { // load object from json template - obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionCreateTemplate) + obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionUpdateTemplate) Ω(err).ShouldNot(HaveOccurred()) err = unstructured.SetNestedField(obj.Object, realCluster.GetName(), "metadata", "namespace") @@ -100,15 +108,8 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() { } return condition["status"], nil - }, eventuallyTimeout, eventuallyInterval).Should(Equal("True")) + }, eventuallyTimeout, eventuallyInterval).Should(Equal("False")) }) - if common.SingleManagedOnHub { - It("deployment should be created successfully in managedcluster", func() { - Eventually(func() (interface{}, error) { - return common.HasResource(dynamicClient, depGVR, actionDeploymentNameSpace, actionDeploymentName) - }, eventuallyTimeout, eventuallyInterval).Should(BeTrue()) - }) - } It("should delete successfully", func() { err := common.DeleteResource(dynamicClient, actionGVR, realCluster.GetName(), obj.GetName()) @@ -116,10 +117,10 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() { }) }) - Context("Creating a UpdateManagedClusterAction", func() { + Context("Creating a DeleteManagedClusterAction when resource do not exist", func() { It("Should create update managedclusteraction successfully", func() { // load object from json template - obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionUpdateTemplate) + obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionDeleteTemplate) Ω(err).ShouldNot(HaveOccurred()) err = unstructured.SetNestedField(obj.Object, realCluster.GetName(), "metadata", "namespace") @@ -152,7 +153,15 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() { } return condition["status"], nil - }, eventuallyTimeout, eventuallyInterval).Should(Equal("True")) + }, eventuallyTimeout, eventuallyInterval).Should(Equal("False")) + }) + + It("deployment should be deleted successfully in managedcluster", func() { + if singleManagedOnHub { + Eventually(func() (interface{}, error) { + return common.HasResource(dynamicClient, depGVR, actionDeploymentNameSpace, actionDeploymentName) + }, eventuallyTimeout, eventuallyInterval).ShouldNot(BeTrue()) + } }) It("should delete successfully", func() { @@ -160,11 +169,10 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() { Ω(err).ShouldNot(HaveOccurred()) }) }) - - Context("Creating a DeleteManagedClusterAction", func() { - It("Should create update managedclusteraction successfully", func() { + Context("Creating a CreateManagedClusterAction", func() { + It("should create successfully", func() { // load object from json template - obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionDeleteTemplate) + obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionCreateTemplate) Ω(err).ShouldNot(HaveOccurred()) err = unstructured.SetNestedField(obj.Object, realCluster.GetName(), "metadata", "namespace") @@ -199,20 +207,22 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() { return condition["status"], nil }, eventuallyTimeout, eventuallyInterval).Should(Equal("True")) }) - if common.SingleManagedOnHub { - It("deployment should be deleted successfully in managedcluster", func() { + It("deployment should be created successfully in managedcluster", func() { + if singleManagedOnHub { Eventually(func() (interface{}, error) { return common.HasResource(dynamicClient, depGVR, actionDeploymentNameSpace, actionDeploymentName) - }, eventuallyTimeout, eventuallyInterval).ShouldNot(BeTrue()) - }) - } + }, eventuallyTimeout, eventuallyInterval).Should(BeTrue()) + + } + }) It("should delete successfully", func() { err := common.DeleteResource(dynamicClient, actionGVR, realCluster.GetName(), obj.GetName()) Ω(err).ShouldNot(HaveOccurred()) }) }) - Context("Creating a UpdateManagedClusterAction when resource do not exist", func() { + + Context("Creating a UpdateManagedClusterAction", func() { It("Should create update managedclusteraction successfully", func() { // load object from json template obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionUpdateTemplate) @@ -248,7 +258,7 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() { } return condition["status"], nil - }, eventuallyTimeout, eventuallyInterval).Should(Equal("False")) + }, eventuallyTimeout, eventuallyInterval).Should(Equal("True")) }) It("should delete successfully", func() { @@ -257,7 +267,7 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() { }) }) - Context("Creating a DeleteManagedClusterAction when resource do not exist", func() { + Context("Creating a DeleteManagedClusterAction", func() { It("Should create update managedclusteraction successfully", func() { // load object from json template obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionDeleteTemplate) @@ -293,21 +303,24 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() { } return condition["status"], nil - }, eventuallyTimeout, eventuallyInterval).Should(Equal("False")) + }, eventuallyTimeout, eventuallyInterval).Should(Equal("True")) }) - if common.SingleManagedOnHub { - It("deployment should be deleted successfully in managedcluster", func() { + + It("deployment should be deleted successfully in managedcluster", func() { + + if singleManagedOnHub { Eventually(func() (interface{}, error) { return common.HasResource(dynamicClient, depGVR, actionDeploymentNameSpace, actionDeploymentName) }, eventuallyTimeout, eventuallyInterval).ShouldNot(BeTrue()) - }) - } + } + }) It("should delete successfully", func() { err := common.DeleteResource(dynamicClient, actionGVR, realCluster.GetName(), obj.GetName()) Ω(err).ShouldNot(HaveOccurred()) }) }) + }) var _ = Describe("Testing ManagedClusterAction when agent is lost", func() {