CSI - API change for CSI volume source type

This commit tracks source code update to support the CSI volume source type additionn.
This commit is contained in:
Vladimir Vivien
2017-10-24 22:44:48 -04:00
parent 6a3d3a42db
commit af0c2bda94
8 changed files with 144 additions and 0 deletions

View File

@@ -1353,6 +1353,64 @@ func TestValidateGlusterfs(t *testing.T) {
}
}
func TestValidateCSIVolumeSource(t *testing.T) {
testCases := []struct {
name string
csi *api.CSIPersistentVolumeSource
errtype field.ErrorType
errfield string
}{
{
name: "all required fields ok",
csi: &api.CSIPersistentVolumeSource{Driver: "test-driver", VolumeHandle: "test-123", ReadOnly: true},
},
{
name: "with default values ok",
csi: &api.CSIPersistentVolumeSource{Driver: "test-driver", VolumeHandle: "test-123"},
},
{
name: "missing driver name",
csi: &api.CSIPersistentVolumeSource{VolumeHandle: "test-123"},
errtype: field.ErrorTypeRequired,
errfield: "driver",
},
{
name: "missing volume handle",
csi: &api.CSIPersistentVolumeSource{Driver: "my-driver"},
errtype: field.ErrorTypeRequired,
errfield: "volumeHandle",
},
}
err := utilfeature.DefaultFeatureGate.Set("CSIPersistentVolume=true")
if err != nil {
t.Errorf("Failed to enable feature gate for CSIPersistentVolumes: %v", err)
return
}
for i, tc := range testCases {
errs := validateCSIPersistentVolumeSource(tc.csi, field.NewPath("field"))
if len(errs) > 0 && tc.errtype == "" {
t.Errorf("[%d: %q] unexpected error(s): %v", i, tc.name, errs)
} else if len(errs) == 0 && tc.errtype != "" {
t.Errorf("[%d: %q] expected error type %v", i, tc.name, tc.errtype)
} else if len(errs) >= 1 {
if errs[0].Type != tc.errtype {
t.Errorf("[%d: %q] expected error type %v, got %v", i, tc.name, tc.errtype, errs[0].Type)
} else if !strings.HasSuffix(errs[0].Field, "."+tc.errfield) {
t.Errorf("[%d: %q] expected error on field %q, got %q", i, tc.name, tc.errfield, errs[0].Field)
}
}
}
err = utilfeature.DefaultFeatureGate.Set("CSIPersistentVolume=false")
if err != nil {
t.Errorf("Failed to disable feature gate for CSIPersistentVolumes: %v", err)
return
}
}
// helper
func newInt32(val int) *int32 {
p := new(int32)