Skip to content

Commit

Permalink
Add unit-tests for NodeStageVolume() helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mpatlasov committed Oct 17, 2024
1 parent 31dedc6 commit 93acf41
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions pkg/smb/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,92 @@ func TestNodePublishVolumeIdempotentMount(t *testing.T) {
err = os.RemoveAll(targetTest)
assert.NoError(t, err)
}

func TestEnableGroupRWX(t *testing.T) {
tests := []struct {
value string
expectedValue string
}{
{
value: "qwerty",
expectedValue: "qwerty",
},
{
value: "0111",
expectedValue: "0171",
},
}

for _, test := range tests {
mode := enableGroupRWX(test.value)
assert.Equal(t, test.expectedValue, mode)
}
}

func TestRaiseGroupRWXInMountFlags(t *testing.T) {
tests := []struct {
mountFlags []string
flag string
expectedResult bool
mountFlagsUpdated bool
expectedMountFlags []string
}{
{
mountFlags: []string{""},
flag: "flag",
expectedResult: false,
},
{
mountFlags: []string{"irrelevant"},
flag: "flag",
expectedResult: false,
},
{
mountFlags: []string{"key=val"},
flag: "flag",
expectedResult: false,
},
{
mountFlags: []string{"flag=key=val"},
flag: "flag",
expectedResult: false,
},
{
// This is important: if we return false here, the caller will append another flag=...
mountFlags: []string{"flag=invalid"},
flag: "flag",
expectedResult: true,
},
{
// Main case: raising group bits in the value
mountFlags: []string{"flag=0111"},
flag: "flag",
expectedResult: true,
mountFlagsUpdated: true,
expectedMountFlags: []string{"flag=0171"},
},
}

for _, test := range tests {
savedMountFlags := make([]string, len(test.mountFlags))
copy(savedMountFlags, test.mountFlags)

result := raiseGroupRWXInMountFlags(test.mountFlags, test.flag)
if result != test.expectedResult {
t.Errorf("raiseGroupRWXInMountFlags(%v, %s) returned %t (expected: %t)",
test.mountFlags, test.flag, result, test.expectedResult)
}

if test.mountFlagsUpdated {
if !reflect.DeepEqual(test.expectedMountFlags, test.mountFlags) {
t.Errorf("raiseGroupRWXInMountFlags(%v, %s) did not update mountFlags (expected: %v)",
savedMountFlags, test.flag, test.expectedMountFlags)
}
} else {
if !reflect.DeepEqual(savedMountFlags, test.mountFlags) {
t.Errorf("raiseGroupRWXInMountFlags(%v, %s) updated mountFlags: %v",
savedMountFlags, test.flag, test.mountFlags)
}
}
}
}

0 comments on commit 93acf41

Please sign in to comment.