From b39619ca1bc9721ff23c07a06b8913a855a7efe1 Mon Sep 17 00:00:00 2001 From: talasulin Date: Wed, 25 Oct 2023 13:23:16 +0300 Subject: [PATCH] test: adding check for client init --- internal/controller/pvc_controller_test.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/controller/pvc_controller_test.go b/internal/controller/pvc_controller_test.go index 56ee326..783773f 100644 --- a/internal/controller/pvc_controller_test.go +++ b/internal/controller/pvc_controller_test.go @@ -8,17 +8,16 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/klog/v2/klogr" - "os" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" "testing" ) -func getReconciler() *PVCReconciler { +func getReconciler() (*PVCReconciler, error) { fakeClient, err := getFakeClient() if err != nil { fmt.Println("unable to create fake client. exiting..") - os.Exit(1) + return nil, err } logr := klogr.New() @@ -34,7 +33,7 @@ func getReconciler() *PVCReconciler { PvcAnoCustomValue: "enabled", } - return reconciler + return reconciler, nil } func getFakeClient(initObjs ...client.Object) (client.WithWatch, error) { @@ -46,7 +45,10 @@ func getFakeClient(initObjs ...client.Object) (client.WithWatch, error) { } func TestFilterPVCListByPV(t *testing.T) { - reconciler := getReconciler() + reconciler, err := getReconciler() + if err != nil { + t.Error("Failed to initialize client.") + } // Create a sample PVC list pvcList := &v1.PersistentVolumeClaimList{ @@ -97,7 +99,10 @@ func TestFilterPVCListByPV(t *testing.T) { } func TestFilterPVListByNodeName(t *testing.T) { - reconciler := getReconciler() + reconciler, err := getReconciler() + if err != nil { + t.Error("Failed to initialize client.") + } // Create a sample PV list pvList := &v1.PersistentVolumeList{