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
This commit is contained in:
parent
fa9191b7b9
commit
2a02734f93
42 changed files with 218 additions and 348 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue