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>
Этот коммит содержится в:
Vladimir Lebedev
2020-01-13 23:07:42 +03:00
коммит произвёл Ali Farooq
родитель aa0d0f9943
Коммит ed555faa75

Просмотреть файл

@@ -9,6 +9,7 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestPostToJson(t *testing.T) { func TestPostToJson(t *testing.T) {
@@ -29,90 +30,72 @@ func TestPostIsValid(t *testing.T) {
o := Post{} o := Post{}
maxPostSize := 10000 maxPostSize := 10000
if err := o.IsValid(maxPostSize); err == nil { err := o.IsValid(maxPostSize)
t.Fatal("should be invalid") require.NotNil(t, err)
}
o.Id = NewId() o.Id = NewId()
if err := o.IsValid(maxPostSize); err == nil { err = o.IsValid(maxPostSize)
t.Fatal("should be invalid") require.NotNil(t, err)
}
o.CreateAt = GetMillis() o.CreateAt = GetMillis()
if err := o.IsValid(maxPostSize); err == nil { err = o.IsValid(maxPostSize)
t.Fatal("should be invalid") require.NotNil(t, err)
}
o.UpdateAt = GetMillis() o.UpdateAt = GetMillis()
if err := o.IsValid(maxPostSize); err == nil { err = o.IsValid(maxPostSize)
t.Fatal("should be invalid") require.NotNil(t, err)
}
o.UserId = NewId() o.UserId = NewId()
if err := o.IsValid(maxPostSize); err == nil { err = o.IsValid(maxPostSize)
t.Fatal("should be invalid") require.NotNil(t, err)
}
o.ChannelId = NewId() o.ChannelId = NewId()
o.RootId = "123" o.RootId = "123"
if err := o.IsValid(maxPostSize); err == nil { err = o.IsValid(maxPostSize)
t.Fatal("should be invalid") require.NotNil(t, err)
}
o.RootId = "" o.RootId = ""
o.ParentId = "123" o.ParentId = "123"
if err := o.IsValid(maxPostSize); err == nil { err = o.IsValid(maxPostSize)
t.Fatal("should be invalid") require.NotNil(t, err)
}
o.ParentId = NewId() o.ParentId = NewId()
o.RootId = "" o.RootId = ""
if err := o.IsValid(maxPostSize); err == nil { err = o.IsValid(maxPostSize)
t.Fatal("should be invalid") require.NotNil(t, err)
}
o.ParentId = "" o.ParentId = ""
o.Message = strings.Repeat("0", maxPostSize+1) o.Message = strings.Repeat("0", maxPostSize+1)
if err := o.IsValid(maxPostSize); err == nil { err = o.IsValid(maxPostSize)
t.Fatal("should be invalid") require.NotNil(t, err)
}
o.Message = strings.Repeat("0", maxPostSize) o.Message = strings.Repeat("0", maxPostSize)
if err := o.IsValid(maxPostSize); err != nil { err = o.IsValid(maxPostSize)
t.Fatal(err) require.Nil(t, err)
}
o.Message = "test" o.Message = "test"
if err := o.IsValid(maxPostSize); err != nil { err = o.IsValid(maxPostSize)
t.Fatal(err) require.Nil(t, err)
}
o.Type = "junk" o.Type = "junk"
if err := o.IsValid(maxPostSize); err == nil { err = o.IsValid(maxPostSize)
t.Fatal("should be invalid") require.NotNil(t, err)
}
o.Type = POST_CUSTOM_TYPE_PREFIX + "type" o.Type = POST_CUSTOM_TYPE_PREFIX + "type"
if err := o.IsValid(maxPostSize); err != nil { err = o.IsValid(maxPostSize)
t.Fatal(err) require.Nil(t, err)
}
} }
func TestPostPreSave(t *testing.T) { func TestPostPreSave(t *testing.T) {
o := Post{Message: "test"} o := Post{Message: "test"}
o.PreSave() o.PreSave()
if o.CreateAt == 0 { require.NotEqual(t, 0, o.CreateAt)
t.Fatal("should be set")
}
past := GetMillis() - 1 past := GetMillis() - 1
o = Post{Message: "test", CreateAt: past} o = Post{Message: "test", CreateAt: past}
o.PreSave() o.PreSave()
if o.CreateAt > past { require.LessOrEqual(t, o.CreateAt, past)
t.Fatal("should not be updated")
}
o.Etag() o.Etag()
} }
@@ -121,15 +104,12 @@ func TestPostIsSystemMessage(t *testing.T) {
post1 := Post{Message: "test_1"} post1 := Post{Message: "test_1"}
post1.PreSave() post1.PreSave()
if post1.IsSystemMessage() { require.False(t, post1.IsSystemMessage())
t.Fatalf("TestPostIsSystemMessage failed, expected post1.IsSystemMessage() to be false")
}
post2 := Post{Message: "test_2", Type: POST_JOIN_LEAVE} post2 := Post{Message: "test_2", Type: POST_JOIN_LEAVE}
post2.PreSave() 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) { func TestPostChannelMentions(t *testing.T) {
@@ -144,9 +124,7 @@ func TestPostSanitizeProps(t *testing.T) {
post1.SanitizeProps() post1.SanitizeProps()
if post1.Props[PROPS_ADD_CHANNEL_MEMBER] != nil { require.Nil(t, post1.Props[PROPS_ADD_CHANNEL_MEMBER])
t.Fatal("should be nil")
}
post2 := &Post{ post2 := &Post{
Message: "test", Message: "test",
@@ -157,9 +135,7 @@ func TestPostSanitizeProps(t *testing.T) {
post2.SanitizeProps() post2.SanitizeProps()
if post2.Props[PROPS_ADD_CHANNEL_MEMBER] != nil { require.Nil(t, post2.Props[PROPS_ADD_CHANNEL_MEMBER])
t.Fatal("should be nil")
}
post3 := &Post{ post3 := &Post{
Message: "test", Message: "test",
@@ -171,13 +147,9 @@ func TestPostSanitizeProps(t *testing.T) {
post3.SanitizeProps() post3.SanitizeProps()
if post3.Props[PROPS_ADD_CHANNEL_MEMBER] != nil { require.Nil(t, post3.Props[PROPS_ADD_CHANNEL_MEMBER])
t.Fatal("should be nil")
}
if post3.Props["attachments"] == nil { require.NotNil(t, post3.Props["attachments"])
t.Fatal("should not be nil")
}
} }
func TestPost_AttachmentsEqual(t *testing.T) { func TestPost_AttachmentsEqual(t *testing.T) {