aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/osutil/osutil.go2
-rw-r--r--internal/osutil/osutil_test.go12
2 files changed, 4 insertions, 10 deletions
diff --git a/internal/osutil/osutil.go b/internal/osutil/osutil.go
index 4f871587..b5c82455 100644
--- a/internal/osutil/osutil.go
+++ b/internal/osutil/osutil.go
@@ -34,7 +34,7 @@ func IsExist(path string) bool {
return err == nil || os.IsExist(err)
}
-// CurrentUsername returns the current system user
+// CurrentUsername returns the username of the current user.
func CurrentUsername() string {
username := os.Getenv("USER")
if len(username) > 0 {
diff --git a/internal/osutil/osutil_test.go b/internal/osutil/osutil_test.go
index 73a45836..65ead618 100644
--- a/internal/osutil/osutil_test.go
+++ b/internal/osutil/osutil_test.go
@@ -81,16 +81,10 @@ func TestIsExist(t *testing.T) {
}
func TestCurrentUsername(t *testing.T) {
- // Make sure it does not blow up
- CurrentUsername()
-}
-
-func TestCurrentUsernamePrefersEnvironmentVariable(t *testing.T) {
- // Some users/scripts expect that they can change the current username via environment variables
- if userBak, ok := os.LookupEnv("USER"); ok {
- defer os.Setenv("USER", userBak)
+ if oldUser, ok := os.LookupEnv("USER"); ok {
+ defer func() { _ = os.Setenv("USER", oldUser) }()
} else {
- defer os.Unsetenv("USER")
+ defer func() { _ = os.Unsetenv("USER") }()
}
if err := os.Setenv("USER", "__TESTING::USERNAME"); err != nil {