Replace t.fatal() to testify require/assert calls (#12174)
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
a3c5cd5760
Коммит
3802c1e4d3
@@ -258,22 +258,17 @@ func TestUpdatePostEditAt(t *testing.T) {
|
|||||||
*post = *th.BasicPost
|
*post = *th.BasicPost
|
||||||
|
|
||||||
post.IsPinned = true
|
post.IsPinned = true
|
||||||
if saved, err := th.App.UpdatePost(post, true); err != nil {
|
saved, err := th.App.UpdatePost(post, true)
|
||||||
t.Fatal(err)
|
require.Nil(t, err)
|
||||||
} else if saved.EditAt != post.EditAt {
|
assert.Equal(t, saved.EditAt, post.EditAt, "shouldn't have updated post.EditAt when pinning post")
|
||||||
t.Fatal("shouldn't have updated post.EditAt when pinning post")
|
*post = *saved
|
||||||
|
|
||||||
*post = *saved
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Millisecond * 100)
|
||||||
|
|
||||||
post.Message = model.NewId()
|
post.Message = model.NewId()
|
||||||
if saved, err := th.App.UpdatePost(post, true); err != nil {
|
saved, err = th.App.UpdatePost(post, true)
|
||||||
t.Fatal(err)
|
require.Nil(t, err)
|
||||||
} else if saved.EditAt == post.EditAt {
|
assert.NotEqual(t, saved.EditAt, post.EditAt, "should have updated post.EditAt when updating post message")
|
||||||
t.Fatal("should have updated post.EditAt when updating post message")
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 200)
|
time.Sleep(time.Millisecond * 200)
|
||||||
}
|
}
|
||||||
@@ -290,25 +285,23 @@ func TestUpdatePostTimeLimit(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.PostEditTimeLimit = -1
|
*cfg.ServiceSettings.PostEditTimeLimit = -1
|
||||||
})
|
})
|
||||||
if _, err := th.App.UpdatePost(post, true); err != nil {
|
_, err := th.App.UpdatePost(post, true)
|
||||||
t.Fatal(err)
|
require.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.PostEditTimeLimit = 1000000000
|
*cfg.ServiceSettings.PostEditTimeLimit = 1000000000
|
||||||
})
|
})
|
||||||
post.Message = model.NewId()
|
post.Message = model.NewId()
|
||||||
if _, err := th.App.UpdatePost(post, true); err != nil {
|
|
||||||
t.Fatal("should allow you to edit the post")
|
_, err = th.App.UpdatePost(post, true)
|
||||||
}
|
require.Nil(t, err, "should allow you to edit the post")
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.PostEditTimeLimit = 1
|
*cfg.ServiceSettings.PostEditTimeLimit = 1
|
||||||
})
|
})
|
||||||
post.Message = model.NewId()
|
post.Message = model.NewId()
|
||||||
if _, err := th.App.UpdatePost(post, true); err == nil {
|
_, err = th.App.UpdatePost(post, true)
|
||||||
t.Fatal("should fail on update old post")
|
require.NotNil(t, err, "should fail on update old post")
|
||||||
}
|
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.PostEditTimeLimit = -1
|
*cfg.ServiceSettings.PostEditTimeLimit = -1
|
||||||
@@ -339,14 +332,11 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
|
|||||||
userNotInChannel := th.BasicUser
|
userNotInChannel := th.BasicUser
|
||||||
rootPost := th.BasicPost
|
rootPost := th.BasicPost
|
||||||
|
|
||||||
if _, err := th.App.AddUserToChannel(userInChannel, channel); err != nil {
|
_, err := th.App.AddUserToChannel(userInChannel, channel)
|
||||||
t.Fatal(err)
|
require.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
if err := th.App.RemoveUserFromChannel(userNotInChannel.Id, "", channel); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
err = th.App.RemoveUserFromChannel(userNotInChannel.Id, "", channel)
|
||||||
|
require.Nil(t, err)
|
||||||
replyPost := model.Post{
|
replyPost := model.Post{
|
||||||
Message: "asd",
|
Message: "asd",
|
||||||
ChannelId: channel.Id,
|
ChannelId: channel.Id,
|
||||||
@@ -357,9 +347,8 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
|
|||||||
CreateAt: 0,
|
CreateAt: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := th.App.CreatePostAsUser(&replyPost, ""); err != nil {
|
_, err = th.App.CreatePostAsUser(&replyPost, "")
|
||||||
t.Fatal(err)
|
require.Nil(t, err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostAttachPostToChildPost(t *testing.T) {
|
func TestPostAttachPostToChildPost(t *testing.T) {
|
||||||
@@ -381,9 +370,7 @@ func TestPostAttachPostToChildPost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res1, err := th.App.CreatePostAsUser(&replyPost1, "")
|
res1, err := th.App.CreatePostAsUser(&replyPost1, "")
|
||||||
if err != nil {
|
require.Nil(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
replyPost2 := model.Post{
|
replyPost2 := model.Post{
|
||||||
Message: "reply two",
|
Message: "reply two",
|
||||||
@@ -396,9 +383,7 @@ func TestPostAttachPostToChildPost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = th.App.CreatePostAsUser(&replyPost2, "")
|
_, err = th.App.CreatePostAsUser(&replyPost2, "")
|
||||||
if err.StatusCode != http.StatusBadRequest {
|
assert.Equalf(t, err.StatusCode, http.StatusBadRequest, "Expected BadRequest error, got %v", err)
|
||||||
t.Fatal(fmt.Sprintf("Expected BadRequest error, got %v", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
replyPost3 := model.Post{
|
replyPost3 := model.Post{
|
||||||
Message: "reply three",
|
Message: "reply three",
|
||||||
@@ -410,9 +395,8 @@ func TestPostAttachPostToChildPost(t *testing.T) {
|
|||||||
CreateAt: 0,
|
CreateAt: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := th.App.CreatePostAsUser(&replyPost3, ""); err != nil {
|
_, err = th.App.CreatePostAsUser(&replyPost3, "")
|
||||||
t.Fatal(err)
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostChannelMentions(t *testing.T) {
|
func TestPostChannelMentions(t *testing.T) {
|
||||||
@@ -428,9 +412,7 @@ func TestPostChannelMentions(t *testing.T) {
|
|||||||
Type: model.CHANNEL_OPEN,
|
Type: model.CHANNEL_OPEN,
|
||||||
TeamId: th.BasicTeam.Id,
|
TeamId: th.BasicTeam.Id,
|
||||||
}, false)
|
}, false)
|
||||||
if err != nil {
|
require.Nil(t, err)
|
||||||
t.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
defer th.App.PermanentDeleteChannel(channelToMention)
|
defer th.App.PermanentDeleteChannel(channelToMention)
|
||||||
|
|
||||||
_, err = th.App.AddUserToChannel(user, channel)
|
_, err = th.App.AddUserToChannel(user, channel)
|
||||||
@@ -617,14 +599,11 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
|
|||||||
data := []byte("abcd")
|
data := []byte("abcd")
|
||||||
|
|
||||||
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||||
if err != nil {
|
require.Nil(t, err)
|
||||||
t.Fatal(err)
|
defer func() {
|
||||||
} else {
|
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||||
defer func() {
|
th.App.RemoveFile(info1.Path)
|
||||||
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
}()
|
||||||
th.App.RemoveFile(info1.Path)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
post := &model.Post{
|
post := &model.Post{
|
||||||
Message: "asd",
|
Message: "asd",
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user