Fix panic in pkg/volume/csi tests

When run as non-root user, TestAttacherMountDevice fails, because of missing
nil check that induces a panic. Fixed by doing err nil check
before using the returned user value from user.Current()
This commit is contained in:
Pushkar Joglekar 2021-06-23 13:14:56 -07:00
parent 0ae157df39
commit 1e250610b2

View File

@ -1187,10 +1187,14 @@ func TestAttacherMountDevice(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
user, _ := user.Current() user, err := user.Current()
if err != nil {
t.Logf("Current user could not be determined, assuming non-root: %v", err)
} else {
if tc.populateDeviceMountPath && user.Uid == "0" { if tc.populateDeviceMountPath && user.Uid == "0" {
t.Skipf("Skipping intentional failure on existing data when running as root.") t.Skipf("Skipping intentional failure on existing data when running as root.")
} }
}
t.Run(tc.testName, func(t *testing.T) { t.Run(tc.testName, func(t *testing.T) {
t.Logf("Running test case: %s", tc.testName) t.Logf("Running test case: %s", tc.testName)