mirror of https://github.com/gogs/gogs.git
osutil: update docstring and tests (#6255)
parent
252d0fd977
commit
c6143edb44
|
@ -34,7 +34,7 @@ func IsExist(path string) bool {
|
||||||
return err == nil || os.IsExist(err)
|
return err == nil || os.IsExist(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentUsername returns the current system user
|
// CurrentUsername returns the username of the current user.
|
||||||
func CurrentUsername() string {
|
func CurrentUsername() string {
|
||||||
username := os.Getenv("USER")
|
username := os.Getenv("USER")
|
||||||
if len(username) > 0 {
|
if len(username) > 0 {
|
||||||
|
|
|
@ -81,16 +81,10 @@ func TestIsExist(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCurrentUsername(t *testing.T) {
|
func TestCurrentUsername(t *testing.T) {
|
||||||
// Make sure it does not blow up
|
if oldUser, ok := os.LookupEnv("USER"); ok {
|
||||||
CurrentUsername()
|
defer func() { _ = os.Setenv("USER", oldUser) }()
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
} else {
|
} else {
|
||||||
defer os.Unsetenv("USER")
|
defer func() { _ = os.Unsetenv("USER") }()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Setenv("USER", "__TESTING::USERNAME"); err != nil {
|
if err := os.Setenv("USER", "__TESTING::USERNAME"); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue