mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
storage: add test for ValidateCSIDriverUpdate
Adding this test was forgotten when adding CSIDriver.
This commit is contained in:
parent
7bbc06fcd4
commit
1db1263476
@ -1826,3 +1826,94 @@ func TestCSIDriverValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCSIDriverValidationUpdate(t *testing.T) {
|
||||
driverName := "test-driver"
|
||||
longName := "my-a-b-c-d-c-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-ABCDEFGHIJKLMNOPQRSTUVWXYZ-driver"
|
||||
invalidName := "-invalid-@#$%^&*()-"
|
||||
attachRequired := true
|
||||
attachNotRequired := false
|
||||
podInfoOnMount := true
|
||||
notPodInfoOnMount := false
|
||||
old := storage.CSIDriver{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: driverName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachNotRequired,
|
||||
PodInfoOnMount: ¬PodInfoOnMount,
|
||||
VolumeLifecycleModes: []storage.VolumeLifecycleMode{
|
||||
storage.VolumeLifecycleEphemeral,
|
||||
storage.VolumeLifecyclePersistent,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Currently there is only one success case: exactly the same
|
||||
// as the existing object.
|
||||
successCases := []storage.CSIDriver{old}
|
||||
for _, csiDriver := range successCases {
|
||||
if errs := ValidateCSIDriverUpdate(&csiDriver, &old); len(errs) != 0 {
|
||||
t.Errorf("expected success for %+v: %v", csiDriver, errs)
|
||||
}
|
||||
}
|
||||
|
||||
errorCases := []storage.CSIDriver{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: invalidName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachRequired,
|
||||
PodInfoOnMount: &podInfoOnMount,
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: longName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachNotRequired,
|
||||
PodInfoOnMount: ¬PodInfoOnMount,
|
||||
},
|
||||
},
|
||||
{
|
||||
// AttachRequired not set
|
||||
ObjectMeta: metav1.ObjectMeta{Name: driverName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: nil,
|
||||
PodInfoOnMount: &podInfoOnMount,
|
||||
},
|
||||
},
|
||||
{
|
||||
// AttachRequired not set
|
||||
ObjectMeta: metav1.ObjectMeta{Name: driverName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachNotRequired,
|
||||
PodInfoOnMount: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
// invalid mode
|
||||
ObjectMeta: metav1.ObjectMeta{Name: driverName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachNotRequired,
|
||||
PodInfoOnMount: ¬PodInfoOnMount,
|
||||
VolumeLifecycleModes: []storage.VolumeLifecycleMode{
|
||||
"no-such-mode",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// different modes
|
||||
ObjectMeta: metav1.ObjectMeta{Name: driverName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachNotRequired,
|
||||
PodInfoOnMount: ¬PodInfoOnMount,
|
||||
VolumeLifecycleModes: []storage.VolumeLifecycleMode{
|
||||
storage.VolumeLifecycleEphemeral,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, csiDriver := range errorCases {
|
||||
if errs := ValidateCSIDriverUpdate(&csiDriver, &old); len(errs) == 0 {
|
||||
t.Errorf("Expected failure for test: %v", csiDriver)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user