diff options
author | TheFox0x7 <thefox0x7@gmail.com> | 2025-01-09 02:21:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-09 09:21:47 +0800 |
commit | 2a02734f93c0091275c77e370b7eed03b2c5f18e (patch) | |
tree | 2dcad43764cbfa254f7c6d355f5a14ffdcdb109a /modules/user | |
parent | fa9191b7b9373666f30a55bbc63b932833bceefe (diff) | |
download | gitea-2a02734f93c0091275c77e370b7eed03b2c5f18e.tar.gz gitea-2a02734f93c0091275c77e370b7eed03b2c5f18e.zip |
Refactor older tests to use testify (#33140)
Refactor checks to use assert/require
Use require.Eventually for waiting in elastic and meilisearch tests
Use require to exit early instead of assert
Diffstat (limited to 'modules/user')
-rw-r--r-- | modules/user/user_test.go | 22 |
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) } |