Fix panic when source PVC does not exist

checkAndUpdateSnapshotClass must always return a snapshot, even though it
fails somewhere in ctrl.SetDefaultSnapshotClass.

Add unit tests for that.
This commit is contained in:
Jan Safranek
2020-09-29 14:53:48 +02:00
parent e02d45a6a6
commit 73f72bd7b6
3 changed files with 39 additions and 2 deletions

View File

@@ -86,6 +86,19 @@ func TestUpdateSnapshotClass(t *testing.T) {
},
test: testUpdateSnapshotClass,
},
{
// PVC does not exist
name: "1-5 - snapshot update with default class name failed because PVC was not found",
initialContents: nocontents,
initialSnapshots: newSnapshotArray("snap1-5", "snapuid1-5", "claim1-5", "", "", "", &True, nil, nil, nil, false, true, nil),
expectedSnapshots: newSnapshotArray("snap1-5", "snapuid1-5", "claim1-5", "", "", "", &False, nil, nil, newVolumeError("Failed to set default snapshot class with error failed to retrieve PVC claim1-5 from the lister: \"persistentvolumeclaim \\\"claim1-5\\\" not found\""), false, true, nil),
initialClaims: nil,
initialVolumes: nil,
initialStorageClasses: []*storage.StorageClass{},
expectedEvents: []string{"Warning SetDefaultSnapshotClassFailed"},
errors: noerrors,
test: testUpdateSnapshotClass,
},
}
runUpdateSnapshotClassTests(t, tests, snapshotClasses)