Skip to content

Commit

Permalink
refactor: add test cases (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Sep 19, 2022
1 parent 87f53bf commit 9621795
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
39 changes: 39 additions & 0 deletions controllers/applicationhealthcomment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,43 @@ var _ = Describe("Application health comment controller", func() {
}, 100*time.Millisecond).Should(Equal(1))
})
})

Context("When an application is degraded and then healthy", func() {
It("Should notify a comment for degraded and healthy", func() {
By("By updating the health status to progressing")
patch := client.MergeFrom(app.DeepCopy())
app.Status = argocdv1alpha1.ApplicationStatus{
Health: argocdv1alpha1.HealthStatus{
Status: health.HealthStatusProgressing,
},
OperationState: &argocdv1alpha1.OperationState{
StartedAt: metav1.Now(),
Operation: argocdv1alpha1.Operation{
Sync: &argocdv1alpha1.SyncOperation{
Revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
},
},
},
}
Expect(k8sClient.Patch(ctx, &app, patch)).Should(Succeed())

By("By updating the health status to degraded")
patch = client.MergeFrom(app.DeepCopy())
app.Status.Health.Status = health.HealthStatusDegraded
Expect(k8sClient.Patch(ctx, &app, patch)).Should(Succeed())

Eventually(func() int {
return notificationMock.Comments.CountBy(appKey)
}, timeout, interval).Should(Equal(1))

By("By updating the health status to healthy")
patch = client.MergeFrom(app.DeepCopy())
app.Status.Health.Status = health.HealthStatusHealthy
Expect(k8sClient.Patch(ctx, &app, patch)).Should(Succeed())

Eventually(func() int {
return notificationMock.Comments.CountBy(appKey)
}, timeout, interval).Should(Equal(2))
})
})
})
39 changes: 39 additions & 0 deletions controllers/applicationhealthdeployment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,43 @@ var _ = Describe("Application health deployment controller", func() {
}, 100*time.Millisecond).Should(Equal(1))
})
})

Context("When an application is degraded and then healthy", func() {
It("Should notify a deployment status for degraded and healthy", func() {
By("By updating the health status to progressing")
patch := client.MergeFrom(app.DeepCopy())
app.Status = argocdv1alpha1.ApplicationStatus{
Health: argocdv1alpha1.HealthStatus{
Status: health.HealthStatusProgressing,
},
OperationState: &argocdv1alpha1.OperationState{
StartedAt: metav1.Now(),
Operation: argocdv1alpha1.Operation{
Sync: &argocdv1alpha1.SyncOperation{
Revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
},
},
},
}
Expect(k8sClient.Patch(ctx, &app, patch)).Should(Succeed())

By("By updating the health status to degraded")
patch = client.MergeFrom(app.DeepCopy())
app.Status.Health.Status = health.HealthStatusDegraded
Expect(k8sClient.Patch(ctx, &app, patch)).Should(Succeed())

Eventually(func() int {
return notificationMock.DeploymentStatuses.CountBy(appKey)
}, timeout, interval).Should(Equal(1))

By("By updating the health status to healthy")
patch = client.MergeFrom(app.DeepCopy())
app.Status.Health.Status = health.HealthStatusHealthy
Expect(k8sClient.Patch(ctx, &app, patch)).Should(Succeed())

Eventually(func() int {
return notificationMock.DeploymentStatuses.CountBy(appKey)
}, timeout, interval).Should(Equal(2))
})
})
})
39 changes: 39 additions & 0 deletions controllers/applicationphase_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ = Describe("Application phase controller", func() {
var appKey types.NamespacedName

BeforeEach(func() {
By("By creating an application")
app = argocdv1alpha1.Application{
TypeMeta: metav1.TypeMeta{
APIVersion: "argoproj.io/v1alpha1",
Expand Down Expand Up @@ -82,4 +83,42 @@ var _ = Describe("Application phase controller", func() {
}, timeout, interval).Should(Equal(2))
})
})

Context("When an application sync operation is failed", func() {
It("Should notify a comment and deployment status", func() {
By("By updating the operation state to running")
patch := client.MergeFrom(app.DeepCopy())
app.Status = argocdv1alpha1.ApplicationStatus{
OperationState: &argocdv1alpha1.OperationState{
Phase: synccommon.OperationRunning,
StartedAt: metav1.Now(),
Operation: argocdv1alpha1.Operation{
Sync: &argocdv1alpha1.SyncOperation{
Revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
},
},
},
}
Expect(k8sClient.Patch(ctx, &app, patch)).Should(Succeed())

Eventually(func() int {
return notificationMock.Comments.CountBy(appKey)
}, timeout, interval).Should(Equal(1))
Eventually(func() int {
return notificationMock.DeploymentStatuses.CountBy(appKey)
}, timeout, interval).Should(Equal(1))

By("By updating the operation state to failed")
patch = client.MergeFrom(app.DeepCopy())
app.Status.OperationState.Phase = synccommon.OperationFailed
Expect(k8sClient.Patch(ctx, &app, patch)).Should(Succeed())

Eventually(func() int {
return notificationMock.Comments.CountBy(appKey)
}, timeout, interval).Should(Equal(2))
Eventually(func() int {
return notificationMock.DeploymentStatuses.CountBy(appKey)
}, timeout, interval).Should(Equal(2))
})
})
})

0 comments on commit 9621795

Please sign in to comment.