Add test for prebound case

This commit is contained in:
Hakan Memisoglu
2019-03-06 16:29:38 -08:00
parent c424e68cef
commit d6c5d512c6
3 changed files with 44 additions and 24 deletions

View File

@@ -28,8 +28,6 @@ import (
"testing"
"time"
"k8s.io/klog"
crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
clientset "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned"
"github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/fake"
@@ -54,6 +52,7 @@ import (
core "k8s.io/client-go/testing"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/klog"
)
// This is a unit test framework for snapshot controller.
@@ -768,15 +767,17 @@ func newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToS
},
},
VolumeSnapshotClassName: &className,
PersistentVolumeRef: &v1.ObjectReference{
Kind: "PersistentVolume",
APIVersion: "v1",
UID: types.UID(volumeUID),
Name: volumeName,
},
DeletionPolicy: deletionPolicy,
DeletionPolicy: deletionPolicy,
},
}
if volumeName != noVolume {
content.Spec.PersistentVolumeRef = &v1.ObjectReference{
Kind: "PersistentVolume",
APIVersion: "v1",
UID: types.UID(volumeUID),
Name: volumeName,
}
}
if boundToSnapshotName != "" {
content.Spec.VolumeSnapshotRef = &v1.ObjectReference{
Kind: "VolumeSnapshot",
@@ -817,10 +818,6 @@ func newSnapshot(name, className, boundToContent, snapshotUID, claimName string,
SelfLink: "/apis/snapshot.storage.k8s.io/v1alpha1/namespaces/" + testNamespace + "/volumesnapshots/" + name,
},
Spec: crdv1.VolumeSnapshotSpec{
Source: &v1.TypedLocalObjectReference{
Name: claimName,
Kind: "PersistentVolumeClaim",
},
VolumeSnapshotClassName: &className,
SnapshotContentName: boundToContent,
},
@@ -831,6 +828,12 @@ func newSnapshot(name, className, boundToContent, snapshotUID, claimName string,
RestoreSize: size,
},
}
if claimName != noClaim {
snapshot.Spec.Source = &v1.TypedLocalObjectReference{
Name: claimName,
Kind: "PersistentVolumeClaim",
}
}
return withSnapshotFinalizer(&snapshot)
}
@@ -969,6 +972,9 @@ var (
validSecretClass = "valid-secret-class"
sameDriver = "sameDriver"
diffDriver = "diffDriver"
noClaim = ""
noBoundUID = ""
noVolume = ""
)
// wrapTestWithInjectedOperation returns a testCall that: