@@ -969,3 +969,92 @@ func TestNodePublishVolumeIdempotentMount(t *testing.T) {
969969 err = os .RemoveAll (targetTest )
970970 assert .NoError (t , err )
971971}
972+
973+ func TestEnableGroupRWX (t * testing.T ) {
974+ tests := []struct {
975+ value string
976+ expectedValue string
977+ }{
978+ {
979+ value : "qwerty" ,
980+ expectedValue : "qwerty" ,
981+ },
982+ {
983+ value : "0111" ,
984+ expectedValue : "0171" ,
985+ },
986+ }
987+
988+ for _ , test := range tests {
989+ mode := enableGroupRWX (test .value )
990+ assert .Equal (t , test .expectedValue , mode )
991+ }
992+ }
993+
994+ func TestRaiseGroupRWXInMountFlags (t * testing.T ) {
995+ tests := []struct {
996+ mountFlags []string
997+ flag string
998+ expectedResult bool
999+ mountFlagsUpdated bool
1000+ expectedMountFlags []string
1001+ }{
1002+ {
1003+ mountFlags : []string {"" },
1004+ flag : "flag" ,
1005+ expectedResult : false ,
1006+ },
1007+ {
1008+ mountFlags : []string {"irrelevant" },
1009+ flag : "flag" ,
1010+ expectedResult : false ,
1011+ },
1012+ {
1013+ mountFlags : []string {"key=val" },
1014+ flag : "flag" ,
1015+ expectedResult : false ,
1016+ },
1017+ {
1018+ mountFlags : []string {"flag=key=val" },
1019+ flag : "flag" ,
1020+ expectedResult : false ,
1021+ },
1022+ {
1023+ // This is important: if we return false here, the caller will append another flag=...
1024+ mountFlags : []string {"flag=invalid" },
1025+ flag : "flag" ,
1026+ expectedResult : true ,
1027+ },
1028+ {
1029+ // Main case: raising group bits in the value
1030+ mountFlags : []string {"flag=0111" },
1031+ flag : "flag" ,
1032+ expectedResult : true ,
1033+ mountFlagsUpdated : true ,
1034+ expectedMountFlags : []string {"flag=0171" },
1035+ },
1036+ }
1037+
1038+ for _ , test := range tests {
1039+ savedMountFlags := make ([]string , len (test .mountFlags ))
1040+ copy (savedMountFlags , test .mountFlags )
1041+
1042+ result := raiseGroupRWXInMountFlags (test .mountFlags , test .flag )
1043+ if result != test .expectedResult {
1044+ t .Errorf ("raiseGroupRWXInMountFlags(%v, %s) returned %t (expected: %t)" ,
1045+ test .mountFlags , test .flag , result , test .expectedResult )
1046+ }
1047+
1048+ if test .mountFlagsUpdated {
1049+ if ! reflect .DeepEqual (test .expectedMountFlags , test .mountFlags ) {
1050+ t .Errorf ("raiseGroupRWXInMountFlags(%v, %s) did not update mountFlags (expected: %v)" ,
1051+ savedMountFlags , test .flag , test .expectedMountFlags )
1052+ }
1053+ } else {
1054+ if ! reflect .DeepEqual (savedMountFlags , test .mountFlags ) {
1055+ t .Errorf ("raiseGroupRWXInMountFlags(%v, %s) updated mountFlags: %v" ,
1056+ savedMountFlags , test .flag , test .mountFlags )
1057+ }
1058+ }
1059+ }
1060+ }
0 commit comments