@@ -1826,3 +1826,94 @@ func TestCSIDriverValidation(t *testing.T) {
1826
1826
}
1827
1827
}
1828
1828
}
1829
+
1830
+ func TestCSIDriverValidationUpdate (t * testing.T ) {
1831
+ driverName := "test-driver"
1832
+ 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"
1833
+ invalidName := "-invalid-@#$%^&*()-"
1834
+ attachRequired := true
1835
+ attachNotRequired := false
1836
+ podInfoOnMount := true
1837
+ notPodInfoOnMount := false
1838
+ old := storage.CSIDriver {
1839
+ ObjectMeta : metav1.ObjectMeta {Name : driverName },
1840
+ Spec : storage.CSIDriverSpec {
1841
+ AttachRequired : & attachNotRequired ,
1842
+ PodInfoOnMount : & notPodInfoOnMount ,
1843
+ VolumeLifecycleModes : []storage.VolumeLifecycleMode {
1844
+ storage .VolumeLifecycleEphemeral ,
1845
+ storage .VolumeLifecyclePersistent ,
1846
+ },
1847
+ },
1848
+ }
1849
+
1850
+ // Currently there is only one success case: exactly the same
1851
+ // as the existing object.
1852
+ successCases := []storage.CSIDriver {old }
1853
+ for _ , csiDriver := range successCases {
1854
+ if errs := ValidateCSIDriverUpdate (& csiDriver , & old ); len (errs ) != 0 {
1855
+ t .Errorf ("expected success for %+v: %v" , csiDriver , errs )
1856
+ }
1857
+ }
1858
+
1859
+ errorCases := []storage.CSIDriver {
1860
+ {
1861
+ ObjectMeta : metav1.ObjectMeta {Name : invalidName },
1862
+ Spec : storage.CSIDriverSpec {
1863
+ AttachRequired : & attachRequired ,
1864
+ PodInfoOnMount : & podInfoOnMount ,
1865
+ },
1866
+ },
1867
+ {
1868
+ ObjectMeta : metav1.ObjectMeta {Name : longName },
1869
+ Spec : storage.CSIDriverSpec {
1870
+ AttachRequired : & attachNotRequired ,
1871
+ PodInfoOnMount : & notPodInfoOnMount ,
1872
+ },
1873
+ },
1874
+ {
1875
+ // AttachRequired not set
1876
+ ObjectMeta : metav1.ObjectMeta {Name : driverName },
1877
+ Spec : storage.CSIDriverSpec {
1878
+ AttachRequired : nil ,
1879
+ PodInfoOnMount : & podInfoOnMount ,
1880
+ },
1881
+ },
1882
+ {
1883
+ // AttachRequired not set
1884
+ ObjectMeta : metav1.ObjectMeta {Name : driverName },
1885
+ Spec : storage.CSIDriverSpec {
1886
+ AttachRequired : & attachNotRequired ,
1887
+ PodInfoOnMount : nil ,
1888
+ },
1889
+ },
1890
+ {
1891
+ // invalid mode
1892
+ ObjectMeta : metav1.ObjectMeta {Name : driverName },
1893
+ Spec : storage.CSIDriverSpec {
1894
+ AttachRequired : & attachNotRequired ,
1895
+ PodInfoOnMount : & notPodInfoOnMount ,
1896
+ VolumeLifecycleModes : []storage.VolumeLifecycleMode {
1897
+ "no-such-mode" ,
1898
+ },
1899
+ },
1900
+ },
1901
+ {
1902
+ // different modes
1903
+ ObjectMeta : metav1.ObjectMeta {Name : driverName },
1904
+ Spec : storage.CSIDriverSpec {
1905
+ AttachRequired : & attachNotRequired ,
1906
+ PodInfoOnMount : & notPodInfoOnMount ,
1907
+ VolumeLifecycleModes : []storage.VolumeLifecycleMode {
1908
+ storage .VolumeLifecycleEphemeral ,
1909
+ },
1910
+ },
1911
+ },
1912
+ }
1913
+
1914
+ for _ , csiDriver := range errorCases {
1915
+ if errs := ValidateCSIDriverUpdate (& csiDriver , & old ); len (errs ) == 0 {
1916
+ t .Errorf ("Expected failure for test: %v" , csiDriver )
1917
+ }
1918
+ }
1919
+ }
0 commit comments