@@ -1800,7 +1800,7 @@ func TestCSIDriverValidation(t *testing.T) {
1800
1800
},
1801
1801
},
1802
1802
{
1803
- // AttachRequired not set
1803
+ // PodInfoOnMount not set
1804
1804
ObjectMeta : metav1.ObjectMeta {Name : driverName },
1805
1805
Spec : storage.CSIDriverSpec {
1806
1806
AttachRequired : & attachNotRequired ,
@@ -1856,64 +1856,86 @@ func TestCSIDriverValidationUpdate(t *testing.T) {
1856
1856
}
1857
1857
}
1858
1858
1859
- errorCases := []storage.CSIDriver {
1859
+ // Each test case changes exactly one field. None of that is valid.
1860
+ errorCases := []struct {
1861
+ name string
1862
+ modify func (new * storage.CSIDriver )
1863
+ }{
1860
1864
{
1861
- ObjectMeta : metav1.ObjectMeta {Name : invalidName },
1862
- Spec : storage.CSIDriverSpec {
1863
- AttachRequired : & attachRequired ,
1864
- PodInfoOnMount : & podInfoOnMount ,
1865
+ name : "invalid name" ,
1866
+ modify : func (new * storage.CSIDriver ) {
1867
+ new .Name = invalidName
1865
1868
},
1866
1869
},
1867
1870
{
1868
- ObjectMeta : metav1.ObjectMeta {Name : longName },
1869
- Spec : storage.CSIDriverSpec {
1870
- AttachRequired : & attachNotRequired ,
1871
- PodInfoOnMount : & notPodInfoOnMount ,
1871
+ name : "long name" ,
1872
+ modify : func (new * storage.CSIDriver ) {
1873
+ new .Name = longName
1872
1874
},
1873
1875
},
1874
1876
{
1875
- // AttachRequired not set
1876
- ObjectMeta : metav1.ObjectMeta {Name : driverName },
1877
- Spec : storage.CSIDriverSpec {
1878
- AttachRequired : nil ,
1879
- PodInfoOnMount : & podInfoOnMount ,
1877
+ name : "AttachRequired not set" ,
1878
+ modify : func (new * storage.CSIDriver ) {
1879
+ new .Spec .AttachRequired = nil
1880
1880
},
1881
1881
},
1882
1882
{
1883
- // AttachRequired not set
1884
- ObjectMeta : metav1.ObjectMeta {Name : driverName },
1885
- Spec : storage.CSIDriverSpec {
1886
- AttachRequired : & attachNotRequired ,
1887
- PodInfoOnMount : nil ,
1883
+ name : "PodInfoOnMount not set" ,
1884
+ modify : func (new * storage.CSIDriver ) {
1885
+ new .Spec .PodInfoOnMount = nil
1888
1886
},
1889
1887
},
1890
1888
{
1891
- // invalid mode
1892
- ObjectMeta : metav1.ObjectMeta {Name : driverName },
1893
- Spec : storage.CSIDriverSpec {
1894
- AttachRequired : & attachNotRequired ,
1895
- PodInfoOnMount : & notPodInfoOnMount ,
1896
- VolumeLifecycleModes : []storage.VolumeLifecycleMode {
1889
+ name : "AttachRequired changed" ,
1890
+ modify : func (new * storage.CSIDriver ) {
1891
+ new .Spec .AttachRequired = & attachRequired
1892
+ },
1893
+ },
1894
+ {
1895
+ name : "PodInfoOnMount changed" ,
1896
+ modify : func (new * storage.CSIDriver ) {
1897
+ new .Spec .PodInfoOnMount = & podInfoOnMount
1898
+ },
1899
+ },
1900
+ {
1901
+ name : "invalid volume lifecycle mode" ,
1902
+ modify : func (new * storage.CSIDriver ) {
1903
+ new .Spec .VolumeLifecycleModes = []storage.VolumeLifecycleMode {
1897
1904
"no-such-mode" ,
1898
- },
1905
+ }
1899
1906
},
1900
1907
},
1901
1908
{
1902
- // different modes
1903
- ObjectMeta : metav1.ObjectMeta {Name : driverName },
1904
- Spec : storage.CSIDriverSpec {
1905
- AttachRequired : & attachNotRequired ,
1906
- PodInfoOnMount : & notPodInfoOnMount ,
1907
- VolumeLifecycleModes : []storage.VolumeLifecycleMode {
1909
+ name : "volume lifecycle modes not set" ,
1910
+ modify : func (new * storage.CSIDriver ) {
1911
+ new .Spec .VolumeLifecycleModes = nil
1912
+ },
1913
+ },
1914
+ {
1915
+ name : "VolumeLifecyclePersistent removed" ,
1916
+ modify : func (new * storage.CSIDriver ) {
1917
+ new .Spec .VolumeLifecycleModes = []storage.VolumeLifecycleMode {
1908
1918
storage .VolumeLifecycleEphemeral ,
1909
- },
1919
+ }
1920
+ },
1921
+ },
1922
+ {
1923
+ name : "VolumeLifecycleEphemeral removed" ,
1924
+ modify : func (new * storage.CSIDriver ) {
1925
+ new .Spec .VolumeLifecycleModes = []storage.VolumeLifecycleMode {
1926
+ storage .VolumeLifecyclePersistent ,
1927
+ }
1910
1928
},
1911
1929
},
1912
1930
}
1913
1931
1914
- for _ , csiDriver := range errorCases {
1915
- if errs := ValidateCSIDriverUpdate (& csiDriver , & old ); len (errs ) == 0 {
1916
- t .Errorf ("Expected failure for test: %v" , csiDriver )
1917
- }
1932
+ for _ , test := range errorCases {
1933
+ t .Run (test .name , func (t * testing.T ) {
1934
+ new := old .DeepCopy ()
1935
+ test .modify (new )
1936
+ if errs := ValidateCSIDriverUpdate (new , & old ); len (errs ) == 0 {
1937
+ t .Errorf ("Expected failure for test: %v" , new )
1938
+ }
1939
+ })
1918
1940
}
1919
1941
}
0 commit comments