From 1e250610b20ec89afacc5e36351a18ad8cfee897 Mon Sep 17 00:00:00 2001 From: Pushkar Joglekar Date: Wed, 23 Jun 2021 13:14:56 -0700 Subject: [PATCH] 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() --- pkg/volume/csi/csi_attacher_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/volume/csi/csi_attacher_test.go b/pkg/volume/csi/csi_attacher_test.go index 2634a219b51..2ad77408da2 100644 --- a/pkg/volume/csi/csi_attacher_test.go +++ b/pkg/volume/csi/csi_attacher_test.go @@ -1187,9 +1187,13 @@ func TestAttacherMountDevice(t *testing.T) { } for _, tc := range testCases { - user, _ := user.Current() - if tc.populateDeviceMountPath && user.Uid == "0" { - t.Skipf("Skipping intentional failure on existing data when running as root.") + 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" { + t.Skipf("Skipping intentional failure on existing data when running as root.") + } } t.Run(tc.testName, func(t *testing.T) { t.Logf("Running test case: %s", tc.testName)