Skip to content

Commit debef3d

Browse files
unknwonmpsonntag
authored andcommitted
osutil: update docstring and tests (#6255)
1 parent 50572df commit debef3d

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

internal/osutil/osutil.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func IsExist(path string) bool {
3434
return err == nil || os.IsExist(err)
3535
}
3636

37-
// CurrentUsername returns the current system user
37+
// CurrentUsername returns the username of the current user.
3838
func CurrentUsername() string {
3939
username := os.Getenv("USER")
4040
if len(username) > 0 {

internal/osutil/osutil_test.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,10 @@ func TestIsExist(t *testing.T) {
8181
}
8282

8383
func TestCurrentUsername(t *testing.T) {
84-
// Make sure it does not blow up
85-
CurrentUsername()
86-
}
87-
88-
func TestCurrentUsernamePrefersEnvironmentVariable(t *testing.T) {
89-
// Some users/scripts expect that they can change the current username via environment variables
90-
if userBak, ok := os.LookupEnv("USER"); ok {
91-
defer os.Setenv("USER", userBak)
84+
if oldUser, ok := os.LookupEnv("USER"); ok {
85+
defer func() { _ = os.Setenv("USER", oldUser) }()
9286
} else {
93-
defer os.Unsetenv("USER")
87+
defer func() { _ = os.Unsetenv("USER") }()
9488
}
9589

9690
if err := os.Setenv("USER", "__TESTING::USERNAME"); err != nil {

0 commit comments

Comments
 (0)