From e5546c7bf819d7370b9daf8f95e8244ac8d09b3c Mon Sep 17 00:00:00 2001 From: Ankit Kurmi Date: Wed, 14 Aug 2024 13:38:34 +0530 Subject: [PATCH] feat: added unit test for namespace reconciler (#2659) Signed-off-by: Ankit152 --- .../appsv1/namespace_controller_test.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/controllers/appsv1/namespace_controller_test.go b/controllers/appsv1/namespace_controller_test.go index 717289daa..1ac643f46 100644 --- a/controllers/appsv1/namespace_controller_test.go +++ b/controllers/appsv1/namespace_controller_test.go @@ -1,12 +1,16 @@ package appsv1_test import ( + "context" "testing" "github.com/stretchr/testify/require" + "k8s.io/apimachinery/pkg/types" k8sconfig "sigs.k8s.io/controller-runtime/pkg/client/config" "sigs.k8s.io/controller-runtime/pkg/manager" + k8sreconcile "sigs.k8s.io/controller-runtime/pkg/reconcile" + v1 "github.com/jaegertracing/jaeger-operator/apis/v1" "github.com/jaegertracing/jaeger-operator/controllers/appsv1" ) @@ -28,3 +32,24 @@ func TestNamespaceControllerRegisterWithManager(t *testing.T) { // verify require.NoError(t, err) } + +func TestNewNamespaceInstance(t *testing.T) { + // prepare + nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"} + reconciler := appsv1.NewNamespaceReconciler( + k8sClient, + k8sClient, + testScheme, + ) + + instance := v1.NewJaeger(nsn) + err := k8sClient.Create(context.Background(), instance) + require.NoError(t, err) + + req := k8sreconcile.Request{ + NamespacedName: nsn, + } + + _, err = reconciler.Reconcile(context.Background(), req) + require.NoError(t, err) +}