diff options
Diffstat (limited to 'internal/osutil/osutil_test.go')
-rw-r--r-- | internal/osutil/osutil_test.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/osutil/osutil_test.go b/internal/osutil/osutil_test.go index ca2c75bf..73a45836 100644 --- a/internal/osutil/osutil_test.go +++ b/internal/osutil/osutil_test.go @@ -5,6 +5,7 @@ package osutil import ( + "os" "testing" "github.com/stretchr/testify/assert" @@ -83,3 +84,17 @@ 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) + } else { + defer os.Unsetenv("USER") + } + + if err := os.Setenv("USER", "__TESTING::USERNAME"); err != nil { + t.Skip("Could not set the USER environment variable:", err) + } + assert.Equal(t, "__TESTING::USERNAME", CurrentUsername()) +} |