diff --git a/test/e2e/create/create-ingress.go b/test/e2e/create/create-ingress.go index 006f25b..fd812b4 100644 --- a/test/e2e/create/create-ingress.go +++ b/test/e2e/create/create-ingress.go @@ -69,10 +69,28 @@ func CreateIngressMsbDeployment(ctx *framework.TestContext, f *framework.Framewo }) Context("Delete msbdeployment mod ingress", func() { - It("Should be delete mod ingress success", func() {}) - It("Should not be exist msbdeployment", func() {}) - It("Should not be exist deployment", func() {}) - It("Should not be exist service", func() {}) - It("Should not be exist ingress", func() {}) + It("Should be delete mod ingress success", func() { + err = dc.Resource(msbGVR).Namespace("default").Delete(context.TODO(), obj.GetName(), metav1.DeleteOptions{}) + Expect(err).Should(BeNil()) + + By("Sleep 1 second wait deleting done") + time.Sleep(time.Second) + }) + It("Should not be exist msbdeployment", func() { + _, err = dc.Resource(msbGVR).Namespace("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist deployment", func() { + _, err = cs.AppsV1().Deployments("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist service", func() { + _, err = cs.CoreV1().Services("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist ingress", func() { + _, err = cs.NetworkingV1().Ingresses("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) }) } diff --git a/test/e2e/create/create-nodeport.go b/test/e2e/create/create-nodeport.go index dfb2781..9acd149 100644 --- a/test/e2e/create/create-nodeport.go +++ b/test/e2e/create/create-nodeport.go @@ -1,7 +1,16 @@ package create import ( + "context" + "time" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/dynamic" + "k8s.io/client-go/kubernetes" "mashibing.com/pkg/mashibing-deployment/test/framework" ) @@ -10,19 +19,79 @@ import ( // 测试创建Nodeport模式 func CreateNodeportMsbDeployment(ctx *framework.TestContext, f *framework.Framework) { + var ( + // 1. 准备测试数据 + ctFilePath = "create/testdata/create-nodeport.yaml" + obj = &unstructured.Unstructured{Object: make(map[string]interface{})} + dc dynamic.Interface + cs *kubernetes.Clientset + + // 3. 准备测试用到的全局变量 + msbGVR = schema.GroupVersionResource{ + Group: "apps.mashibing.com", + Version: "v1", + Resource: "msbdeployments", + } + err error + ) + BeforeEach(func() { + // 2. 加载测试数据 + err = f.LoadYamlToUnstructured(ctFilePath, obj) + Expect(err).Should(BeNil()) + + // 4. 初始化测试用到的全局变量 + dc = ctx.CreateDynamicClient() + cs = ctx.CreateClientSet() + }) Context("Create msbdeployment mod nodeport", func() { - It("Should be create mode nodeport success", func() {}) - It("Should be exist msbdeployment", func() {}) - It("Should be exist deployment", func() {}) - It("Should be exist service", func() {}) - It("Should not be exist ingress", func() {}) + It("Should be create mod nodeport success", func() { + _, err = dc.Resource(msbGVR).Namespace("default").Create(context.TODO(), obj, metav1.CreateOptions{}) + Expect(err).Should(BeNil()) + + By("Sleep 1 second wait creating done") + time.Sleep(time.Second) + }) + It("Should be exist msbdeployment", func() { + _, err = dc.Resource(msbGVR).Namespace("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) + It("Should be exist deployment", func() { + _, err = cs.AppsV1().Deployments("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) + It("Should be exist service", func() { + _, err = cs.CoreV1().Services("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) + It("Should not be exist ingress", func() { + _, err = cs.NetworkingV1().Ingresses("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) }) Context("Delete msbdeployment mod nodeport", func() { - It("Should be delete mod nodeport success", func() {}) - It("Should not be exist msbdeployment", func() {}) - It("Should not be exist deployment", func() {}) - It("Should not be exist service", func() {}) - It("Should not be exist ingress", func() {}) + It("Should be delete mod nodeport success", func() { + err = dc.Resource(msbGVR).Namespace("default").Delete(context.TODO(), obj.GetName(), metav1.DeleteOptions{}) + Expect(err).Should(BeNil()) + + By("Sleep 1 second wait deleting done") + time.Sleep(time.Second) + }) + It("Should not be exist msbdeployment", func() { + _, err = dc.Resource(msbGVR).Namespace("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist deployment", func() { + _, err = cs.AppsV1().Deployments("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist service", func() { + _, err = cs.CoreV1().Services("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist ingress", func() { + _, err = cs.NetworkingV1().Ingresses("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) }) } diff --git a/test/e2e/e2e.xml b/test/e2e/e2e.xml index 74a809a..44b7b0c 100644 --- a/test/e2e/e2e.xml +++ b/test/e2e/e2e.xml @@ -1,47 +1,47 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/e2e/update/update-i2n.go b/test/e2e/update/update-i2n.go index 2fad3ad..3f0299c 100644 --- a/test/e2e/update/update-i2n.go +++ b/test/e2e/update/update-i2n.go @@ -1,7 +1,16 @@ package update import ( + "context" + "time" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/dynamic" + "k8s.io/client-go/kubernetes" "mashibing.com/pkg/mashibing-deployment/test/framework" ) @@ -10,22 +19,101 @@ import ( // 测试从Ingress模式更新为Nodeport模式 func UpdateI2NMsbDeployment(ctx *framework.TestContext, f *framework.Framework) { + var ( + // 1. 准备测试数据 + ctFilePath = "update/testdata/update-ingress.yaml" + ctUpdateFilePath = "update/testdata/update-i2n.yaml" + obj = &unstructured.Unstructured{Object: make(map[string]interface{})} + objUpdate = &unstructured.Unstructured{Object: make(map[string]interface{})} + dc dynamic.Interface + cs *kubernetes.Clientset + + // 3. 准备测试用到的全局变量 + msbGVR = schema.GroupVersionResource{ + Group: "apps.mashibing.com", + Version: "v1", + Resource: "msbdeployments", + } + err error + ) + BeforeEach(func() { + // 2. 加载测试数据 + err = f.LoadYamlToUnstructured(ctFilePath, obj) + Expect(err).Should(BeNil()) + + err = f.LoadYamlToUnstructured(ctUpdateFilePath, objUpdate) + Expect(err).Should(BeNil()) + + // 4. 初始化测试用到的全局变量 + dc = ctx.CreateDynamicClient() + cs = ctx.CreateClientSet() + }) Context("Update msbdeployment mod ingress to nodeport", func() { - It("Should be create mod ingress success", func() {}) - It("Should be exist msbdeployment", func() {}) - It("Should be exist deployment", func() {}) - It("Should be exist service", func() {}) - It("Should be exist ingress", func() {}) - - It("Should be update to nodeport success", func() {}) - It("Should not be exist ingress", func() {}) + It("Should be create mod ingress success", func() { + _, err = dc.Resource(msbGVR).Namespace("default").Create(context.TODO(), obj, metav1.CreateOptions{}) + Expect(err).Should(BeNil()) + + By("Sleep 1 second wait creating done") + time.Sleep(time.Second) + }) + It("Should be exist msbdeployment", func() { + _, err = dc.Resource(msbGVR).Namespace("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) + It("Should be exist deployment", func() { + _, err = cs.AppsV1().Deployments("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) + It("Should be exist service", func() { + _, err = cs.CoreV1().Services("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) + It("Should be exist ingress", func() { + _, err = cs.NetworkingV1().Ingresses("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) + + It("Should be update to nodeport success", func() { + var md *unstructured.Unstructured + md, err = dc.Resource(msbGVR).Namespace("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + + objUpdate.SetResourceVersion(md.GetResourceVersion()) + _, err = dc.Resource(msbGVR).Namespace("default").Update(context.TODO(), objUpdate, metav1.UpdateOptions{}) + Expect(err).Should(BeNil()) + + By("Sleep 1 second wait creating done") + time.Sleep(time.Second) + }) + It("Should not be exist ingress", func() { + _, err = cs.NetworkingV1().Ingresses("default").Get(context.TODO(), objUpdate.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) }) Context("Delete msbdeployment i2n", func() { - It("Should be delete success", func() {}) - It("Should not be exist msbdeployment", func() {}) - It("Should not be exist deployment", func() {}) - It("Should not be exist service", func() {}) - It("Should not be exist ingress", func() {}) + It("Should be delete mod ingress success", func() { + err = dc.Resource(msbGVR).Namespace("default").Delete(context.TODO(), objUpdate.GetName(), metav1.DeleteOptions{}) + Expect(err).Should(BeNil()) + + By("Sleep 1 second wait deleting done") + time.Sleep(time.Second) + }) + It("Should not be exist msbdeployment", func() { + _, err = dc.Resource(msbGVR).Namespace("default").Get(context.TODO(), objUpdate.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist deployment", func() { + _, err = cs.AppsV1().Deployments("default").Get(context.TODO(), objUpdate.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist service", func() { + _, err = cs.CoreV1().Services("default").Get(context.TODO(), objUpdate.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist ingress", func() { + _, err = cs.NetworkingV1().Ingresses("default").Get(context.TODO(), objUpdate.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) }) } diff --git a/test/e2e/update/update-n2i.go b/test/e2e/update/update-n2i.go index 010a2cc..39befaf 100644 --- a/test/e2e/update/update-n2i.go +++ b/test/e2e/update/update-n2i.go @@ -1,7 +1,16 @@ package update import ( + "context" + "time" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/dynamic" + "k8s.io/client-go/kubernetes" "mashibing.com/pkg/mashibing-deployment/test/framework" ) @@ -10,22 +19,101 @@ import ( // 测试从Nodeport模式更新为Ingress模式 func UpdateN2IMsbDeployment(ctx *framework.TestContext, f *framework.Framework) { + var ( + // 1. 准备测试数据 + ctFilePath = "update/testdata/update-nodeport.yaml" + ctUpdateFilePath = "update/testdata/update-n2i.yaml" + obj = &unstructured.Unstructured{Object: make(map[string]interface{})} + objUpdate = &unstructured.Unstructured{Object: make(map[string]interface{})} + dc dynamic.Interface + cs *kubernetes.Clientset + + // 3. 准备测试用到的全局变量 + msbGVR = schema.GroupVersionResource{ + Group: "apps.mashibing.com", + Version: "v1", + Resource: "msbdeployments", + } + err error + ) + BeforeEach(func() { + // 2. 加载测试数据 + err = f.LoadYamlToUnstructured(ctFilePath, obj) + Expect(err).Should(BeNil()) + + err = f.LoadYamlToUnstructured(ctUpdateFilePath, objUpdate) + Expect(err).Should(BeNil()) + + // 4. 初始化测试用到的全局变量 + dc = ctx.CreateDynamicClient() + cs = ctx.CreateClientSet() + }) Context("Update msbdeployment mod nodeport to ingress", func() { - It("Should be create mod nodeport success", func() {}) - It("Should be exist msbdeployment", func() {}) - It("Should be exist deployment", func() {}) - It("Should be exist service", func() {}) - It("Should not be exist ingress", func() {}) - - It("Should be update to ingress success", func() {}) - It("Should be exist ingress", func() {}) + It("Should be create mod nodeport success", func() { + _, err = dc.Resource(msbGVR).Namespace("default").Create(context.TODO(), obj, metav1.CreateOptions{}) + Expect(err).Should(BeNil()) + + By("Sleep 1 second wait creating done") + time.Sleep(time.Second) + }) + It("Should be exist msbdeployment", func() { + _, err = dc.Resource(msbGVR).Namespace("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) + It("Should be exist deployment", func() { + _, err = cs.AppsV1().Deployments("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) + It("Should be exist service", func() { + _, err = cs.CoreV1().Services("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) + It("Should not be exist ingress", func() { + _, err = cs.NetworkingV1().Ingresses("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + + It("Should be update to ingress success", func() { + var md *unstructured.Unstructured + md, err = dc.Resource(msbGVR).Namespace("default").Get(context.TODO(), obj.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + + objUpdate.SetResourceVersion(md.GetResourceVersion()) + _, err = dc.Resource(msbGVR).Namespace("default").Update(context.TODO(), objUpdate, metav1.UpdateOptions{}) + Expect(err).Should(BeNil()) + + By("Sleep 1 second wait creating done") + time.Sleep(time.Second) + }) + It("Should be exist ingress", func() { + _, err = cs.NetworkingV1().Ingresses("default").Get(context.TODO(), objUpdate.GetName(), metav1.GetOptions{}) + Expect(err).Should(BeNil()) + }) }) Context("Delete msbdeployment n2i", func() { - It("Should be delete success", func() {}) - It("Should not be exist msbdeployment", func() {}) - It("Should not be exist deployment", func() {}) - It("Should not be exist service", func() {}) - It("Should not be exist ingress", func() {}) + It("Should be delete mod nodeport success", func() { + err = dc.Resource(msbGVR).Namespace("default").Delete(context.TODO(), objUpdate.GetName(), metav1.DeleteOptions{}) + Expect(err).Should(BeNil()) + + By("Sleep 1 second wait deleting done") + time.Sleep(time.Second) + }) + It("Should not be exist msbdeployment", func() { + _, err = dc.Resource(msbGVR).Namespace("default").Get(context.TODO(), objUpdate.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist deployment", func() { + _, err = cs.AppsV1().Deployments("default").Get(context.TODO(), objUpdate.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist service", func() { + _, err = cs.CoreV1().Services("default").Get(context.TODO(), objUpdate.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) + It("Should not be exist ingress", func() { + _, err = cs.NetworkingV1().Ingresses("default").Get(context.TODO(), objUpdate.GetName(), metav1.GetOptions{}) + Expect(err).ShouldNot(BeNil()) + }) }) }