Skip to content

Commit

Permalink
Fix: enhance the test cases
Browse files Browse the repository at this point in the history
Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
  • Loading branch information
barnettZQG committed Jan 5, 2023
1 parent ebe8c1b commit 6af6dc8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
4 changes: 3 additions & 1 deletion pkg/apiserver/domain/service/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func (c *applicationServiceImpl) Deploy(ctx context.Context, app *model.Applicat
status = revision.Status
}
if status != model.RevisionStatusComplete && status != model.RevisionStatusTerminated && status != model.RevisionStatusFail {
klog.Warningf("last app revision can not complete %s/%s", list[0].(*model.ApplicationRevision).AppPrimaryKey, list[0].(*model.ApplicationRevision).Version)
klog.Warningf("last app revision can not complete %s/%s,the current status is %s", list[0].(*model.ApplicationRevision).AppPrimaryKey, list[0].(*model.ApplicationRevision).Version, status)
return nil, bcode.ErrDeployConflict
}
}
Expand Down Expand Up @@ -1696,6 +1696,8 @@ func (c *applicationServiceImpl) RollbackWithRevision(ctx context.Context, appli
oam.SetPublishVersion(rollBackApp, publishVersion)
if appCR != nil {
rollBackApp.ResourceVersion = appCR.ResourceVersion
} else {
rollBackApp.ResourceVersion = ""
}
err = c.Apply.Apply(ctx, rollBackApp)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions pkg/apiserver/domain/service/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,10 @@ var _ = Describe("Test application service function", func() {
})
Expect(err).Should(BeNil())
Expect(cmp.Diff(compareResponse.IsDiff, true)).Should(BeEmpty())
Expect(cmp.Diff(compareResponse.TargetAppYAML, "")).Should(BeEmpty())
Expect(cmp.Diff(compareResponse.BaseAppYAML, "")).ShouldNot(BeEmpty())
// The target represents the latest config
Expect(cmp.Diff(compareResponse.TargetAppYAML, "")).ShouldNot(BeEmpty())
// The base represents the running config
Expect(cmp.Diff(compareResponse.BaseAppYAML, "")).Should(BeEmpty())

By("compare when app's env add target, should return false")
_, err = targetService.CreateTarget(context.TODO(), v1.CreateTargetRequest{Name: "dev-target1", Project: appModel.Project, Cluster: &v1.ClusterTarget{ClusterName: "local", Namespace: "dev-target1"}})
Expand Down
1 change: 1 addition & 0 deletions pkg/apiserver/domain/service/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ var _ = Describe("Test workflow service functions", func() {
app.Status.Workflow.Finished = true
err = workflowService.KubeClient.Create(ctx, app.DeepCopy())
Expect(err).Should(BeNil())
app.Status.ObservedGeneration = 1
err = workflowService.KubeClient.Status().Patch(ctx, app, client.Merge)
Expect(err).Should(BeNil())
err = workflowService.SyncWorkflowRecord(ctx)
Expand Down
26 changes: 20 additions & 6 deletions test/e2e-apiserver-test/application_rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("Test the rest api that rollback the application", func() {
var appName = "test-rollback"
var envName = "rollback"
var revision = ""
var waitAppReady = func() apisv1.ApplicationStatusResponse {
var waitAppReady = func(v string) apisv1.ApplicationStatusResponse {
var sr apisv1.ApplicationStatusResponse
Eventually(func() error {
res := get("/applications/" + appName + "/envs/" + envName + "/status")
Expand All @@ -49,6 +49,17 @@ var _ = Describe("Test the rest api that rollback the application", func() {
}
return nil
}).WithTimeout(time.Minute * 1).WithPolling(3 * time.Second).Should(BeNil())
Eventually(func() error {
res := get("/applications/" + appName + "/revisions/" + v)
var version apisv1.DetailRevisionResponse
if err := decodeResponseBody(res, &version); err != nil {
return err
}
if version.Status == model.RevisionStatusComplete {
return nil
}
return fmt.Errorf("the application revision status is %s, not complete", version.Status)
}).WithTimeout(time.Minute * 1).WithPolling(3 * time.Second).Should(BeNil())
return sr
}

Expand Down Expand Up @@ -110,7 +121,7 @@ var _ = Describe("Test the rest api that rollback the application", func() {
It("Test rollback by the cluster revision", func() {
// first deploy
firstRevision := deployApp()
status := waitAppReady()
status := waitAppReady(firstRevision)
Expect(len(status.Status.Services)).Should(Equal(1))
var createComponent = apisv1.CreateComponentRequest{
Name: "component2",
Expand All @@ -123,22 +134,23 @@ var _ = Describe("Test the rest api that rollback the application", func() {
Expect(cmp.Diff(cb.Name, "component2")).Should(BeEmpty())
// second deploy
revision = deployApp()
status = waitAppReady()
status = waitAppReady(revision)
Expect(len(status.Status.Services)).Should(Equal(2))

// rollback to first revision
res = post("/applications/"+appName+"/revisions/"+firstRevision+"/rollback", nil)
var rollback apisv1.ApplicationRollbackResponse
Expect(decodeResponseBody(res, &rollback)).Should(Succeed())
Expect(rollback.WorkflowRecord.Name).ShouldNot(BeEmpty())
status = waitAppReady()
status = waitAppReady(firstRevision)
Expect(len(status.Status.Services)).Should(Equal(1))
})
It("Test rollback by the local revision", func() {
res := post("/applications/"+appName+"/envs/"+envName+"/recycle", nil)
Expect(decodeResponseBody(res, nil)).Should(Succeed())
var sr apisv1.ApplicationStatusResponse

Eventually(func() error {
var sr apisv1.ApplicationStatusResponse
res := get("/applications/" + appName + "/envs/" + envName + "/status")
if err := decodeResponseBody(res, &sr); err != nil {
return err
Expand All @@ -149,11 +161,13 @@ var _ = Describe("Test the rest api that rollback the application", func() {
return fmt.Errorf("the application status is %s", sr.Status.Phase)
}).WithTimeout(time.Minute * 1).WithPolling(3 * time.Second).Should(BeNil())

Expect(revision).ShouldNot(BeEmpty())

res = post("/applications/"+appName+"/revisions/"+revision+"/rollback", nil)
var rollback apisv1.ApplicationRollbackResponse
Expect(decodeResponseBody(res, &rollback)).Should(Succeed())
Expect(rollback.WorkflowRecord.Name).ShouldNot(BeEmpty())
status := waitAppReady()
status := waitAppReady(revision)
Expect(len(status.Status.Services)).Should(Equal(2))
})
})

0 comments on commit 6af6dc8

Please sign in to comment.