aboutsummaryrefslogtreecommitdiffstats
path: root/modules/user
diff options
context:
space:
mode:
Diffstat (limited to 'modules/user')
-rw-r--r--modules/user/user_test.go22
1 files changed, 10 insertions, 12 deletions
diff --git a/modules/user/user_test.go b/modules/user/user_test.go
index 372a675d34..d6b3911ca6 100644
--- a/modules/user/user_test.go
+++ b/modules/user/user_test.go
@@ -8,6 +8,9 @@ import (
"runtime"
"strings"
"testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func getWhoamiOutput() (string, error) {
@@ -20,24 +23,19 @@ func getWhoamiOutput() (string, error) {
func TestCurrentUsername(t *testing.T) {
user := CurrentUsername()
- if len(user) == 0 {
- t.Errorf("expected non-empty user, got: %s", user)
- }
+ require.NotEmpty(t, user)
+
// Windows whoami is weird, so just skip remaining tests
if runtime.GOOS == "windows" {
t.Skip("skipped test because of weird whoami on Windows")
}
whoami, err := getWhoamiOutput()
- if err != nil {
- t.Errorf("failed to run whoami to test current user: %f", err)
- }
+ require.NoError(t, err)
+
user = CurrentUsername()
- if user != whoami {
- t.Errorf("expected %s as user, got: %s", whoami, user)
- }
+ assert.Equal(t, whoami, user)
+
t.Setenv("USER", "spoofed")
user = CurrentUsername()
- if user != whoami {
- t.Errorf("expected %s as user, got: %s", whoami, user)
- }
+ assert.Equal(t, whoami, user)
}