Skip to content

Commit

Permalink
many cases
Browse files Browse the repository at this point in the history
Signed-off-by: LavenderQAQ <[email protected]>
  • Loading branch information
LavenderQAQ committed Oct 28, 2023
1 parent 5a4e86f commit 618afde
Showing 1 changed file with 64 additions and 26 deletions.
90 changes: 64 additions & 26 deletions test/e2e/yurt/iot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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() {
Expand All @@ -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(
Expand All @@ -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{
Expand All @@ -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) {
Expand Down Expand Up @@ -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, resource version: %v", platformAdminName, testPlatfromAdmin.Status, testPlatfromAdmin.ObjectMeta.ResourceVersion))
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" })
// })
// })
})

0 comments on commit 618afde

Please sign in to comment.