tests: fix possible null pointer dereference
In some cases AfterTestSuitCleanup can be called
while originalKV is still un-initialized. One example
is when the deploy test infra flag is on and the beforeSuite
fails to deploy it.
@@ -775,15 +775,16 @@ func AdjustKubeVirtResource() {
}
func RestoreKubeVirtResource() {
+ if originalKV != nil {
virtClient, err := kubecli.GetKubevirtClient()
PanicOnError(err)
-
data, err := json.Marshal(originalKV.Spec)
Expect(err).ToNot(HaveOccurred())
patchData := fmt.Sprintf(`[{ "op": "replace", "path": "/spec", "value": %s }]`, string(data))
_, err = virtClient.KubeVirt(originalKV.Namespace).Patch(originalKV.Name, types.JSONPatchType, []byte(patchData))
PanicOnError(err)
}
+}
func createStorageClass(name string) {
virtClient, err := kubecli.GetKubevirtClient()
