Skip to content

Commit

Permalink
test: adding check for client init
Browse files Browse the repository at this point in the history
  • Loading branch information
talasulin committed Oct 25, 2023
1 parent 67199af commit b39619c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions internal/controller/pvc_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -34,7 +33,7 @@ func getReconciler() *PVCReconciler {
PvcAnoCustomValue: "enabled",
}

return reconciler
return reconciler, nil
}

func getFakeClient(initObjs ...client.Object) (client.WithWatch, error) {
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit b39619c

Please sign in to comment.