Update test to use testify framework (#12583)
* Update test to use testify framework * Add require.NotNil to avoid a nil err var * Add missing test var
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
b8dc5e3620
Коммит
40ff87637d
@@ -5,17 +5,17 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCommandWebhookPreSave(t *testing.T) {
|
func TestCommandWebhookPreSave(t *testing.T) {
|
||||||
h := CommandWebhook{}
|
h := CommandWebhook{}
|
||||||
h.PreSave()
|
h.PreSave()
|
||||||
if len(h.Id) != 26 {
|
|
||||||
t.Fatal("Id should be generated")
|
require.Len(t, h.Id, 26, "Id should be generated")
|
||||||
}
|
require.NotEqual(t, 0, h.CreateAt, "CreateAt should be set")
|
||||||
if h.CreateAt == 0 {
|
|
||||||
t.Fatal("CreateAt should be set")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandWebhookIsValid(t *testing.T) {
|
func TestCommandWebhookIsValid(t *testing.T) {
|
||||||
@@ -44,11 +44,14 @@ func TestCommandWebhookIsValid(t *testing.T) {
|
|||||||
tmp := h
|
tmp := h
|
||||||
test.Transform()
|
test.Transform()
|
||||||
err := h.IsValid()
|
err := h.IsValid()
|
||||||
if test.ExpectedError == "" && err != nil {
|
|
||||||
t.Fatal("hook should be valid")
|
if test.ExpectedError == "" {
|
||||||
} else if test.ExpectedError != "" && test.ExpectedError != err.Id {
|
assert.Error(t, err, "hook should be valid")
|
||||||
t.Fatal("expected " + test.ExpectedError + " error")
|
} else {
|
||||||
|
require.NotNil(t, err)
|
||||||
|
assert.Equal(t, test.ExpectedError, err.Id, "expected "+test.ExpectedError+" error")
|
||||||
}
|
}
|
||||||
|
|
||||||
h = tmp
|
h = tmp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user