diff --git a/test/e2e/yurt/iot.go b/test/e2e/yurt/iot.go index 6f7f800c98b..6b547a6a09e 100644 --- a/test/e2e/yurt/iot.go +++ b/test/e2e/yurt/iot.go @@ -25,6 +25,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" "sigs.k8s.io/controller-runtime/pkg/client" @@ -38,14 +39,20 @@ const ( prefix = "iot-e2e-test-" ) +func generateTestversions() []string { + return []string{"levski"} +} + var _ = Describe("OpenYurt IoT Test", func() { ctx := context.Background() k8sClient := ycfg.YurtE2eCfg.RuntimeClient timeout := 60 * time.Second - platformAdminName := "test-platform-admin" + platformadminTimeout := 10 * time.Minute + testVersions := generateTestversions() var ( - namespaceName string - nodePoolName string + namespaceName string + nodePoolName string + platformAdminName string ) createNamespace := func() { @@ -58,7 +65,7 @@ var _ = Describe("OpenYurt IoT Test", func() { func() error { return k8sClient.Delete(ctx, &ns, client.PropagationPolicy(metav1.DeletePropagationForeground)) }).WithTimeout(timeout).WithPolling(time.Millisecond * 500).Should(SatisfyAny(BeNil(), &util.NotFoundMatcher{})) - By("make sure all the resources are removed") + By("make sure the needed namespace are removed") res := &corev1.Namespace{} Eventually( @@ -82,6 +89,7 @@ var _ = Describe("OpenYurt IoT Test", func() { }, }) }).WithTimeout(timeout).WithPolling(500 * time.Millisecond).Should(SatisfyAny(BeNil(), &util.NotFoundMatcher{})) + By("make sure the needed nodepool are removed") nodePool := appsv1alpha1.NodePool{ ObjectMeta: metav1.ObjectMeta{ @@ -93,7 +101,6 @@ var _ = Describe("OpenYurt IoT Test", func() { func() error { return k8sClient.Create(ctx, &nodePool) }).WithTimeout(timeout).WithPolling(time.Millisecond * 500).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{})) - By("make sure all the resources are removed") } createPlatformAdmin := func(version string) { @@ -138,28 +145,59 @@ var _ = Describe("OpenYurt IoT Test", func() { Expect(k8sClient.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespaceName}}, client.PropagationPolicy(metav1.DeletePropagationBackground))).Should(BeNil()) }) - Describe("Test the levski version of PlatformAdmin", func() { - BeforeEach(func() { - createPlatformAdmin("levski") - }) + for _, testVersion := range testVersions { + version := testVersion + Describe(fmt.Sprintf("Test the %s version of PlatformAdmin", version), func() { + BeforeEach(func() { + platformAdminName = "test-platform-admin-" + version + createPlatformAdmin(version) + }) - AfterEach(func() { - By(fmt.Sprintf("Delete the platformAdmin %s", platformAdminName)) - Expect(k8sClient.Delete(ctx, &iotv1alpha2.PlatformAdmin{ObjectMeta: metav1.ObjectMeta{Name: platformAdminName, Namespace: namespaceName}}, client.PropagationPolicy(metav1.DeletePropagationBackground))).Should(BeNil()) - }) + AfterEach(func() { + By(fmt.Sprintf("Delete the platformAdmin %s", platformAdminName)) + Expect(k8sClient.Delete(ctx, &iotv1alpha2.PlatformAdmin{ObjectMeta: metav1.ObjectMeta{Name: platformAdminName, Namespace: namespaceName}}, client.PropagationPolicy(metav1.DeletePropagationBackground))).Should(BeNil()) + }) - It("The levski version of PlatformAdmin should be stable in ready state after it is created", func() { - By("verify the status of platformadmin") - Eventually(func() bool { - testPlatfromAdmin := &iotv1alpha2.PlatformAdmin{} - if err := k8sClient.Get(ctx, client.ObjectKey{Name: platformAdminName, Namespace: namespaceName}, testPlatfromAdmin); err != nil { - return false - } - if testPlatfromAdmin.Status.Ready == true { - return true - } - return false - }).WithTimeout(timeout).WithPolling(500*time.Millisecond).Should(BeTrue(), func() string { return "The levski version of PlatformAdmin is not ready" }) + It(fmt.Sprintf("The %s version of PlatformAdmin should be stable in ready state after it is created", version), func() { + By("verify the status of platformadmin") + Eventually(func() error { + testPlatfromAdmin := &iotv1alpha2.PlatformAdmin{} + if err := k8sClient.Get(ctx, types.NamespacedName{Name: platformAdminName, Namespace: namespaceName}, testPlatfromAdmin); err != nil { + return err + } + By(fmt.Sprintf("status of platformadmin %s: %v", platformAdminName, testPlatfromAdmin.Status)) + if testPlatfromAdmin.Status.Ready == true { + return nil + } else { + return fmt.Errorf("The %s version of PlatformAdmin is not ready", version) + } + }, platformadminTimeout, 10*time.Second).Should(Succeed()) + }) }) - }) + } + + // Describe("Test the levski version of PlatformAdmin", func() { + // BeforeEach(func() { + // createPlatformAdmin("levski") + // }) + + // AfterEach(func() { + // By(fmt.Sprintf("Delete the platformAdmin %s", platformAdminName)) + // Expect(k8sClient.Delete(ctx, &iotv1alpha2.PlatformAdmin{ObjectMeta: metav1.ObjectMeta{Name: platformAdminName, Namespace: namespaceName}}, client.PropagationPolicy(metav1.DeletePropagationBackground))).Should(BeNil()) + // }) + + // It("The levski version of PlatformAdmin should be stable in ready state after it is created", func() { + // By("verify the status of platformadmin") + // Eventually(func() bool { + // testPlatfromAdmin := &iotv1alpha2.PlatformAdmin{} + // if err := k8sClient.Get(ctx, client.ObjectKey{Name: platformAdminName, Namespace: namespaceName}, testPlatfromAdmin); err != nil { + // return false + // } + // if testPlatfromAdmin.Status.Ready == true { + // return true + // } + // return false + // }).WithTimeout(timeout).WithPolling(500*time.Millisecond).Should(BeTrue(), func() string { return "The levski version of PlatformAdmin is not ready" }) + // }) + // }) })