mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #81961 from pohly/ephemeral-unit-tests
storage: enhance test for ValidateCSIDriverUpdate
This commit is contained in:
commit
b1b1fc8034
@ -1800,7 +1800,7 @@ func TestCSIDriverValidation(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
// AttachRequired not set
|
||||
// PodInfoOnMount not set
|
||||
ObjectMeta: metav1.ObjectMeta{Name: driverName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachNotRequired,
|
||||
@ -1856,64 +1856,86 @@ func TestCSIDriverValidationUpdate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
errorCases := []storage.CSIDriver{
|
||||
// Each test case changes exactly one field. None of that is valid.
|
||||
errorCases := []struct {
|
||||
name string
|
||||
modify func(new *storage.CSIDriver)
|
||||
}{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: invalidName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachRequired,
|
||||
PodInfoOnMount: &podInfoOnMount,
|
||||
name: "invalid name",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Name = invalidName
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: longName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachNotRequired,
|
||||
PodInfoOnMount: ¬PodInfoOnMount,
|
||||
name: "long name",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Name = longName
|
||||
},
|
||||
},
|
||||
{
|
||||
// AttachRequired not set
|
||||
ObjectMeta: metav1.ObjectMeta{Name: driverName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: nil,
|
||||
PodInfoOnMount: &podInfoOnMount,
|
||||
name: "AttachRequired not set",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.AttachRequired = nil
|
||||
},
|
||||
},
|
||||
{
|
||||
// AttachRequired not set
|
||||
ObjectMeta: metav1.ObjectMeta{Name: driverName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachNotRequired,
|
||||
PodInfoOnMount: nil,
|
||||
name: "PodInfoOnMount not set",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.PodInfoOnMount = nil
|
||||
},
|
||||
},
|
||||
{
|
||||
// invalid mode
|
||||
ObjectMeta: metav1.ObjectMeta{Name: driverName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachNotRequired,
|
||||
PodInfoOnMount: ¬PodInfoOnMount,
|
||||
VolumeLifecycleModes: []storage.VolumeLifecycleMode{
|
||||
name: "AttachRequired changed",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.AttachRequired = &attachRequired
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "PodInfoOnMount changed",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.PodInfoOnMount = &podInfoOnMount
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid volume lifecycle mode",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.VolumeLifecycleModes = []storage.VolumeLifecycleMode{
|
||||
"no-such-mode",
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
// different modes
|
||||
ObjectMeta: metav1.ObjectMeta{Name: driverName},
|
||||
Spec: storage.CSIDriverSpec{
|
||||
AttachRequired: &attachNotRequired,
|
||||
PodInfoOnMount: ¬PodInfoOnMount,
|
||||
VolumeLifecycleModes: []storage.VolumeLifecycleMode{
|
||||
name: "volume lifecycle modes not set",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.VolumeLifecycleModes = nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "VolumeLifecyclePersistent removed",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.VolumeLifecycleModes = []storage.VolumeLifecycleMode{
|
||||
storage.VolumeLifecycleEphemeral,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "VolumeLifecycleEphemeral removed",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.VolumeLifecycleModes = []storage.VolumeLifecycleMode{
|
||||
storage.VolumeLifecyclePersistent,
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, csiDriver := range errorCases {
|
||||
if errs := ValidateCSIDriverUpdate(&csiDriver, &old); len(errs) == 0 {
|
||||
t.Errorf("Expected failure for test: %v", csiDriver)
|
||||
}
|
||||
for _, test := range errorCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
new := old.DeepCopy()
|
||||
test.modify(new)
|
||||
if errs := ValidateCSIDriverUpdate(new, &old); len(errs) == 0 {
|
||||
t.Errorf("Expected failure for test: %v", new)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user