MM-19137 - Migrate tests from "model/post_test.go" to use test… (#13521)
* MM-19137 - Migrate tests from "model/post_test.go" to use testify * revert go.sum file Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
Ali Farooq
родитель
aa0d0f9943
Коммит
ed555faa75
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPostToJson(t *testing.T) {
|
||||
@@ -29,90 +30,72 @@ func TestPostIsValid(t *testing.T) {
|
||||
o := Post{}
|
||||
maxPostSize := 10000
|
||||
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
err := o.IsValid(maxPostSize)
|
||||
require.NotNil(t, err)
|
||||
|
||||
o.Id = NewId()
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.NotNil(t, err)
|
||||
|
||||
o.CreateAt = GetMillis()
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.NotNil(t, err)
|
||||
|
||||
o.UpdateAt = GetMillis()
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.NotNil(t, err)
|
||||
|
||||
o.UserId = NewId()
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.NotNil(t, err)
|
||||
|
||||
o.ChannelId = NewId()
|
||||
o.RootId = "123"
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.NotNil(t, err)
|
||||
|
||||
o.RootId = ""
|
||||
o.ParentId = "123"
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.NotNil(t, err)
|
||||
|
||||
o.ParentId = NewId()
|
||||
o.RootId = ""
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.NotNil(t, err)
|
||||
|
||||
o.ParentId = ""
|
||||
o.Message = strings.Repeat("0", maxPostSize+1)
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.NotNil(t, err)
|
||||
|
||||
o.Message = strings.Repeat("0", maxPostSize)
|
||||
if err := o.IsValid(maxPostSize); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.Nil(t, err)
|
||||
|
||||
o.Message = "test"
|
||||
if err := o.IsValid(maxPostSize); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.Nil(t, err)
|
||||
o.Type = "junk"
|
||||
if err := o.IsValid(maxPostSize); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.NotNil(t, err)
|
||||
|
||||
o.Type = POST_CUSTOM_TYPE_PREFIX + "type"
|
||||
if err := o.IsValid(maxPostSize); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = o.IsValid(maxPostSize)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestPostPreSave(t *testing.T) {
|
||||
o := Post{Message: "test"}
|
||||
o.PreSave()
|
||||
|
||||
if o.CreateAt == 0 {
|
||||
t.Fatal("should be set")
|
||||
}
|
||||
require.NotEqual(t, 0, o.CreateAt)
|
||||
|
||||
past := GetMillis() - 1
|
||||
o = Post{Message: "test", CreateAt: past}
|
||||
o.PreSave()
|
||||
|
||||
if o.CreateAt > past {
|
||||
t.Fatal("should not be updated")
|
||||
}
|
||||
require.LessOrEqual(t, o.CreateAt, past)
|
||||
|
||||
o.Etag()
|
||||
}
|
||||
@@ -121,15 +104,12 @@ func TestPostIsSystemMessage(t *testing.T) {
|
||||
post1 := Post{Message: "test_1"}
|
||||
post1.PreSave()
|
||||
|
||||
if post1.IsSystemMessage() {
|
||||
t.Fatalf("TestPostIsSystemMessage failed, expected post1.IsSystemMessage() to be false")
|
||||
}
|
||||
require.False(t, post1.IsSystemMessage())
|
||||
|
||||
post2 := Post{Message: "test_2", Type: POST_JOIN_LEAVE}
|
||||
post2.PreSave()
|
||||
if !post2.IsSystemMessage() {
|
||||
t.Fatalf("TestPostIsSystemMessage failed, expected post2.IsSystemMessage() to be true")
|
||||
}
|
||||
|
||||
require.True(t, post2.IsSystemMessage())
|
||||
}
|
||||
|
||||
func TestPostChannelMentions(t *testing.T) {
|
||||
@@ -144,9 +124,7 @@ func TestPostSanitizeProps(t *testing.T) {
|
||||
|
||||
post1.SanitizeProps()
|
||||
|
||||
if post1.Props[PROPS_ADD_CHANNEL_MEMBER] != nil {
|
||||
t.Fatal("should be nil")
|
||||
}
|
||||
require.Nil(t, post1.Props[PROPS_ADD_CHANNEL_MEMBER])
|
||||
|
||||
post2 := &Post{
|
||||
Message: "test",
|
||||
@@ -157,9 +135,7 @@ func TestPostSanitizeProps(t *testing.T) {
|
||||
|
||||
post2.SanitizeProps()
|
||||
|
||||
if post2.Props[PROPS_ADD_CHANNEL_MEMBER] != nil {
|
||||
t.Fatal("should be nil")
|
||||
}
|
||||
require.Nil(t, post2.Props[PROPS_ADD_CHANNEL_MEMBER])
|
||||
|
||||
post3 := &Post{
|
||||
Message: "test",
|
||||
@@ -171,13 +147,9 @@ func TestPostSanitizeProps(t *testing.T) {
|
||||
|
||||
post3.SanitizeProps()
|
||||
|
||||
if post3.Props[PROPS_ADD_CHANNEL_MEMBER] != nil {
|
||||
t.Fatal("should be nil")
|
||||
}
|
||||
require.Nil(t, post3.Props[PROPS_ADD_CHANNEL_MEMBER])
|
||||
|
||||
if post3.Props["attachments"] == nil {
|
||||
t.Fatal("should not be nil")
|
||||
}
|
||||
require.NotNil(t, post3.Props["attachments"])
|
||||
}
|
||||
|
||||
func TestPost_AttachmentsEqual(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user