File tree 2 files changed +4
-10
lines changed
2 files changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ func IsExist(path string) bool {
34
34
return err == nil || os .IsExist (err )
35
35
}
36
36
37
- // CurrentUsername returns the current system user
37
+ // CurrentUsername returns the username of the current user.
38
38
func CurrentUsername () string {
39
39
username := os .Getenv ("USER" )
40
40
if len (username ) > 0 {
Original file line number Diff line number Diff line change @@ -81,16 +81,10 @@ func TestIsExist(t *testing.T) {
81
81
}
82
82
83
83
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 ) }()
92
86
} else {
93
- defer os .Unsetenv ("USER" )
87
+ defer func () { _ = os .Unsetenv ("USER" ) }( )
94
88
}
95
89
96
90
if err := os .Setenv ("USER" , "__TESTING::USERNAME" ); err != nil {
You can’t perform that action at this time.
0 commit comments