avoid t.Fatal() in tests (#9189)
I've been burned a few times by tests that simply fatal, requiring me to run another build to learn more about what the mismatch was. Avoid this. This is part of a long running goal of mine to make testing "better".
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
0bbabd137b
Коммит
d8c8a19d35
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestOAuthAppJson(t *testing.T) {
|
||||
@@ -52,52 +54,32 @@ func TestOAuthAppPreUpdate(t *testing.T) {
|
||||
func TestOAuthAppIsValid(t *testing.T) {
|
||||
app := OAuthApp{}
|
||||
|
||||
if err := app.IsValid(); err == nil {
|
||||
t.Fatal()
|
||||
}
|
||||
require.NotNil(t, app.IsValid())
|
||||
|
||||
app.Id = NewId()
|
||||
if err := app.IsValid(); err == nil {
|
||||
t.Fatal()
|
||||
}
|
||||
require.NotNil(t, app.IsValid())
|
||||
|
||||
app.CreateAt = 1
|
||||
if err := app.IsValid(); err == nil {
|
||||
t.Fatal()
|
||||
}
|
||||
require.NotNil(t, app.IsValid())
|
||||
|
||||
app.UpdateAt = 1
|
||||
if err := app.IsValid(); err == nil {
|
||||
t.Fatal()
|
||||
}
|
||||
require.NotNil(t, app.IsValid())
|
||||
|
||||
app.CreatorId = NewId()
|
||||
if err := app.IsValid(); err == nil {
|
||||
t.Fatal()
|
||||
}
|
||||
require.NotNil(t, app.IsValid())
|
||||
|
||||
app.ClientSecret = NewId()
|
||||
if err := app.IsValid(); err == nil {
|
||||
t.Fatal()
|
||||
}
|
||||
require.NotNil(t, app.IsValid())
|
||||
|
||||
app.Name = "TestOAuthApp"
|
||||
if err := app.IsValid(); err == nil {
|
||||
t.Fatal()
|
||||
}
|
||||
require.NotNil(t, app.IsValid())
|
||||
|
||||
app.CallbackUrls = []string{"https://nowhere.com"}
|
||||
if err := app.IsValid(); err == nil {
|
||||
t.Fatal()
|
||||
}
|
||||
require.NotNil(t, app.IsValid())
|
||||
|
||||
app.Homepage = "https://nowhere.com"
|
||||
if err := app.IsValid(); err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
require.Nil(t, app.IsValid())
|
||||
|
||||
app.IconURL = "https://nowhere.com/icon_image.png"
|
||||
if err := app.IsValid(); err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
require.Nil(t, app.IsValid())
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user