From 891ed746cca369b1c558ad01d5982305548e2aa2 Mon Sep 17 00:00:00 2001 From: samir-tahir Date: Mon, 1 Apr 2024 20:50:26 +0100 Subject: [PATCH] up tests --- internal/controller/githubapp_controller.go | 42 ------------------- .../controller/githubapp_controller_test.go | 42 +++++++++++++++++++ 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/internal/controller/githubapp_controller.go b/internal/controller/githubapp_controller.go index d79300d..41c3fd8 100644 --- a/internal/controller/githubapp_controller.go +++ b/internal/controller/githubapp_controller.go @@ -637,46 +637,4 @@ func (r *GithubAppReconciler) SetupWithManager(mgr ctrl.Manager) error { // Watch access token secrets owned by GithubApps. Owns(&corev1.Secret{}, builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}, accessTokenSecretPredicate())). Complete(r) - - Context("When encountering errors while restarting pods", func() { - It("Should return an error when listing pods fails", func() { - ctx := context.Background() - - // Create a GithubApp instance with the RestartPods field initialized - githubApp := &githubappv1.GithubApp{ - ObjectMeta: metav1.ObjectMeta{ - Name: githubAppName, - Namespace: sourceNamespace, - }, - Spec: githubappv1.GithubAppSpec{ - AppId: appId, - InstallId: installId, - PrivateKeySecret: privateKeySecret, - RestartPods: &githubappv1.RestartPodsSpec{ - Labels: map[string]string{ - "foo": "bar", - }, - }, - }, - } - - // Mock the List method of the client to return an error - mockErr := fmt.Errorf("mock error: failed to list pods") - r := &GithubAppReconciler{ - Client: &fakeClient{ - ListFunc: func(ctx context.Context, list runtime.Object, opts ...client.ListOption) error { - return mockErr - }, - }, - } - - // Call the restartPods function - err := r.restartPods(ctx, githubApp) - - // Check if the error is as expected - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(fmt.Sprintf("failed to list pods with label foo=bar: %v", mockErr))) - }) - }) - } diff --git a/internal/controller/githubapp_controller_test.go b/internal/controller/githubapp_controller_test.go index a753df6..93ebe57 100644 --- a/internal/controller/githubapp_controller_test.go +++ b/internal/controller/githubapp_controller_test.go @@ -395,4 +395,46 @@ var _ = Describe("GithubApp controller", func() { }, "60s", "5s").Should(BeTrue(), "Failed to delete GitHubApp within timeout") }) }) + + Context("When encountering errors while restarting pods", func() { + It("Should return an error when listing pods fails", func() { + ctx := context.Background() + + // Create a GithubApp instance with the RestartPods field initialized + githubApp := &githubappv1.GithubApp{ + ObjectMeta: metav1.ObjectMeta{ + Name: githubAppName2, + Namespace: sourceNamespace, + }, + Spec: githubappv1.GithubAppSpec{ + AppId: appId, + InstallId: installId, + PrivateKeySecret: privateKeySecret, + RestartPods: &githubappv1.RestartPodsSpec{ + Labels: map[string]string{ + "foo": "bar", + }, + }, + }, + } + + // Mock the List method of the client to return an error + mockErr := fmt.Errorf("mock error: failed to list pods") + r := &GithubAppReconciler{ + Client: &fakeClient{ + ListFunc: func(ctx context.Context, list runtime.Object, opts ...client.ListOption) error { + return mockErr + }, + }, + } + + // Call the restartPods function + err := r.restartPods(ctx, githubApp) + + // Check if the error is as expected + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(fmt.Sprintf("failed to list pods with label foo=bar: %v", mockErr))) + }) + }) + })