Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test to check replicas is vaild #95

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/reconciler/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ var _ = Describe("Deloyment reconciler", func() {
Expect(result.Error).Should(BeNil())
Expect(result.RequeueOrNot()).Should(BeTrue())

By("Checking the deployment spec.replicas is valid")
deployment := &appv1.Deployment{}
Expect(k8sClient.Get(ctx, ctrlclient.ObjectKey{Namespace: namespace, Name: name}, deployment)).Should(Succeed())
Expect(deployment.Spec.Replicas).Should(Equal(&replcias))

By("check the deployment is ready or not")
result = deploymentReconciler.Ready(ctx)
Expect(result).ShouldNot(BeNil())
Expand All @@ -104,7 +109,7 @@ var _ = Describe("Deloyment reconciler", func() {
// Because the envtest does not handle the pod, we need to mock that the statefulset is ready
// Mock that the deployment is ready by updating the ready replicas to 3
By("mock the deployment is ready")
deployment := &appv1.Deployment{}
deployment = &appv1.Deployment{}
Expect(k8sClient.Get(ctx, ctrlclient.ObjectKey{Namespace: namespace, Name: name}, deployment)).Should(Succeed())
deployment.Status.Replicas = replcias
deployment.Status.ReadyReplicas = replcias
Expand Down
12 changes: 11 additions & 1 deletion pkg/reconciler/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,37 @@ var _ = Describe("Statefulset reconciler", func() {
})

It("Should successfully reconcile a whoami statefulset", func() {
By("Create a statefulset reconciler")
statusfulSetReconciler := reconciler.NewStatefulSet(resourceClient, name, statefulSetBuilder)
Expect(statusfulSetReconciler).ShouldNot(BeNil())

By("Reconcile the statefulset")
result := statusfulSetReconciler.Reconcile(ctx)
Expect(result).ShouldNot(BeNil())
Expect(result.Error).Should(BeNil())
Expect(result.RequeueOrNot()).Should(BeTrue())

By("Checking the statefulset spec.replicas is valid")
statefulSet := &appv1.StatefulSet{}
Expect(k8sClient.Get(ctx, ctrlclient.ObjectKey{Namespace: namespace, Name: name}, statefulSet)).Should(Succeed())
Expect(*statefulSet.Spec.Replicas).Should(Equal(replcias))

By("Check the statefulset is ready or not")
result = statusfulSetReconciler.Ready(ctx)
Expect(result).ShouldNot(BeNil())
Expect(result.Error).Should(BeNil())
Expect(result.RequeueOrNot()).Should(BeTrue())

// Because of the envtest do not handle the pod, we need to mock the statefulset is ready
// mock the statefulset is ready, update the ready replicas to 3
statefulSet := &appv1.StatefulSet{}
By("Mock the statefulset is ready")
statefulSet = &appv1.StatefulSet{}
Expect(k8sClient.Get(ctx, ctrlclient.ObjectKey{Namespace: namespace, Name: name}, statefulSet)).Should(Succeed())
statefulSet.Status.Replicas = replcias
statefulSet.Status.ReadyReplicas = replcias
Expect(k8sClient.Status().Update(ctx, statefulSet)).Should(Succeed())

By("Check the statefulset is ready or not")
result = statusfulSetReconciler.Ready(ctx)
Expect(result).ShouldNot(BeNil())
Expect(result.Error).Should(BeNil())
Expand Down
Loading