From 0f4e030b84e9bb08697277cafb1116fcf499af72 Mon Sep 17 00:00:00 2001 From: Qiaozp Date: Sun, 30 Oct 2022 19:44:32 +0800 Subject: [PATCH] fix e2e test and unit test Signed-off-by: Qiaozp --- pkg/apiserver/domain/service/cloudshell_test.go | 3 ++- pkg/apiserver/domain/service/helm_test.go | 4 ++-- pkg/apiserver/domain/service/pipeline_test.go | 7 ++++--- pkg/apiserver/domain/service/workflow_test.go | 2 +- test/e2e-apiserver-test/pipeline_test.go | 15 +++++++++++++-- test/e2e-apiserver-test/testdata/request.yaml | 2 +- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pkg/apiserver/domain/service/cloudshell_test.go b/pkg/apiserver/domain/service/cloudshell_test.go index 5fd90527f..c5daf7e8b 100644 --- a/pkg/apiserver/domain/service/cloudshell_test.go +++ b/pkg/apiserver/domain/service/cloudshell_test.go @@ -66,7 +66,8 @@ var _ = Describe("Test cloudshell service function", func() { ProjectService: projectService, } projectService = &projectServiceImpl{ - Store: ds, + Store: ds, + K8sClient: k8sClient, RbacService: &rbacServiceImpl{ Store: ds, }, diff --git a/pkg/apiserver/domain/service/helm_test.go b/pkg/apiserver/domain/service/helm_test.go index c5076cf13..762d27413 100644 --- a/pkg/apiserver/domain/service/helm_test.go +++ b/pkg/apiserver/domain/service/helm_test.go @@ -83,7 +83,7 @@ var _ = Describe("Test helm repo list", func() { pSec = v1.Secret{} gSec = v1.Secret{} Expect(k8sClient.Create(ctx, &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "vela-system"}})).Should(SatisfyAny(BeNil(), util.AlreadyExistMatcher{})) - Expect(k8sClient.Create(ctx, &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "project-my-project"}})).Should(SatisfyAny(BeNil(), util.AlreadyExistMatcher{})) + Expect(k8sClient.Create(ctx, &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "my-project"}})).Should(SatisfyAny(BeNil(), util.AlreadyExistMatcher{})) Expect(yaml.Unmarshal([]byte(projectSecret), &pSec)).Should(BeNil()) Expect(yaml.Unmarshal([]byte(globalSecret), &gSec)).Should(BeNil()) Expect(k8sClient.Create(ctx, &pSec)).Should(BeNil()) @@ -390,7 +390,7 @@ apiVersion: v1 kind: Secret metadata: name: project-helm-repo - namespace: project-my-project + namespace: my-project labels: config.oam.dev/type: helm-repository config.oam.dev/catalog: velacore-config diff --git a/pkg/apiserver/domain/service/pipeline_test.go b/pkg/apiserver/domain/service/pipeline_test.go index 58d2c8d79..b946315a9 100644 --- a/pkg/apiserver/domain/service/pipeline_test.go +++ b/pkg/apiserver/domain/service/pipeline_test.go @@ -17,14 +17,15 @@ limitations under the License. package service import ( - "github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore" - "github.com/oam-dev/kubevela/pkg/oam/util" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + + "github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore" + "github.com/oam-dev/kubevela/pkg/oam/util" ) var ( - defaultNamespace = "project-default-ns1-test" + // defaultNamespace = "project-default-ns1-test" pipelineService *pipelineServiceImpl pipelineRunService *pipelineRunServiceImpl contextService *contextServiceImpl diff --git a/pkg/apiserver/domain/service/workflow_test.go b/pkg/apiserver/domain/service/workflow_test.go index 7b3f5f265..cee26d258 100644 --- a/pkg/apiserver/domain/service/workflow_test.go +++ b/pkg/apiserver/domain/service/workflow_test.go @@ -58,7 +58,7 @@ var _ = Describe("Test workflow service functions", func() { Expect(ds).ToNot(BeNil()) Expect(err).Should(BeNil()) rbacService := &rbacServiceImpl{Store: ds} - projectService = &projectServiceImpl{Store: ds, RbacService: rbacService} + projectService = &projectServiceImpl{Store: ds, RbacService: rbacService, K8sClient: k8sClient} envService = &envServiceImpl{Store: ds, KubeClient: k8sClient, ProjectService: projectService} envBinding = &envBindingServiceImpl{ Store: ds, diff --git a/test/e2e-apiserver-test/pipeline_test.go b/test/e2e-apiserver-test/pipeline_test.go index 55ee80116..7b6298dd4 100644 --- a/test/e2e-apiserver-test/pipeline_test.go +++ b/test/e2e-apiserver-test/pipeline_test.go @@ -47,7 +47,7 @@ func init() { Type: "request", Outputs: v1alpha1.StepOutputs{ { - ValueFrom: "import \"strconv\"\\n\"Current star count: \" + strconv.FormatInt(response[\"stargazers_count\"], 10)\n", + ValueFrom: "import \"strconv\"\n\"Current star count: \" + strconv.FormatInt(response[\"stargazers_count\"], 10)\n", Name: "stars", }, }, @@ -59,7 +59,7 @@ func init() { } } -var _ = FDescribe("Test the rest api about the pipeline", func() { +var _ = Describe("Test the rest api about the pipeline", func() { var ( projectName1 = testNSprefix + strconv.FormatInt(time.Now().UnixNano(), 10) pipelineName = "test-pipeline" @@ -173,6 +173,17 @@ var _ = FDescribe("Test the rest api about the pipeline", func() { Expect(run.PipelineRunName).Should(Equal(pipelineRunName)) }) + It("get pipeline run status", func() { + Eventually(func(g Gomega) { + res := get("/projects/" + projectName1 + "/pipelines/" + pipelineName + "/runs/" + pipelineRunName + "/status") + var status v1alpha1.WorkflowRunStatus + g.Expect(decodeResponseBody(res, &status)).Should(Succeed()) + g.Expect(status.Finished).Should(Equal(true)) + g.Expect(status.Phase).Should(Equal(v1alpha1.WorkflowStateSucceeded)) + g.Expect(status.Message).Should(BeEmpty()) + }, 100*time.Second, 1*time.Second).Should(Succeed()) + }) + It("get pipeline run output", func() { outputStep := "request" res := get("/projects/" + projectName1 + "/pipelines/" + pipelineName + "/runs/" + pipelineRunName + "/output?step=" + outputStep) diff --git a/test/e2e-apiserver-test/testdata/request.yaml b/test/e2e-apiserver-test/testdata/request.yaml index 30a9a9ee8..2aa294d28 100644 --- a/test/e2e-apiserver-test/testdata/request.yaml +++ b/test/e2e-apiserver-test/testdata/request.yaml @@ -15,7 +15,7 @@ spec: "encoding/json" ) - http: op.#HTTPDo & { + http: op.http.#Do & { method: parameter.method url: parameter.url request: {