kubernetes-sigs / cluster-api-provider-kubevirt

Cluster API Provider for KubeVirt
Apache License 2.0
108 stars 61 forks source link

Unit-Test is broken #258

Closed nunnatsa closed 10 months ago

nunnatsa commented 10 months ago

What steps did you take and what happened

I ran the unit tests.

The [It] should succeed with the kubevirt cluster being deleted. test failed with the following log:

------------------------------
•! [PANICKED] [0.001 seconds]
Reconcile
.../cluster-api-provider-kubevirt/controllers/kubevirtcluster_controller_test.go:37
  reconcile cluster with finalizer and deletion time stamp
  .../cluster-api-provider-kubevirt/controllers/kubevirtcluster_controller_test.go:143
    [It] should succeed with the kubevirt cluster being deleted.
    .../cluster-api-provider-kubevirt/controllers/kubevirtcluster_controller_test.go:155

  Test Panicked
  In [It] at: /usr/local/go1.20.3/src/runtime/panic.go:260

  runtime error: invalid memory address or nil pointer dereference

  Full Stack Trace
    sigs.k8s.io/cluster-api-provider-kubevirt/controllers.(*KubevirtClusterReconciler).deleteExtraGVK(0x37b3ce0, 0xc0003f26c0, {{0x2614d0d, 0x0}, {0x2614d0e, 0x2}, {0x2622de1, 0xd}})
        .../cluster-api-provider-kubevirt/controllers/kubevirtcluster_controller.go:292 +0x323
    sigs.k8s.io/cluster-api-provider-kubevirt/controllers.(*KubevirtClusterReconciler).reconcileDelete(0x37b3ce0, 0xc0003f26c0, 0x7f94dc5b71a8?)
        .../cluster-api-provider-kubevirt/controllers/kubevirtcluster_controller.go:255 +0x5ec
    sigs.k8s.io/cluster-api-provider-kubevirt/controllers.(*KubevirtClusterReconciler).Reconcile(0x37b3ce0, {0x28db298?, 0xc000050168}, {{{0x0?, 0x37e4790?}, {0x2631233?, 0x37e4790?}}})
        .../cluster-api-provider-kubevirt/controllers/kubevirtcluster_controller.go:155 +0xaaa
    sigs.k8s.io/cluster-api-provider-kubevirt/controllers_test.glob..func1.5.3()
        .../cluster-api-provider-kubevirt/controllers/kubevirtcluster_controller_test.go:168 +0x1ea
------------------------------

What did you expect to happen

The test should pass

Anything else you would like to add

The reason for this failure is that the new KubevirtClusterReconciler.APIReader field is not mocked on unit tests, leaving its value as nil. When the test triggers call to APIReader.List(), the tst fails with panic.

Environment: Any

/kind bug [One or more /area label. See https://github.com/kubernetes-sigs/cluster-api-provider-kubevirt/labels?q=area for the list of labels]