mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Increase Channel Purpose length to 250. This commit increases the maxmimum length of the channel purpose field to 250, including the database migration necessary. It also adds a method to the Slack importer to check the lengths of channel properties before importing, and truncate them if necessary. Fixes #4168 * Fix database migration.
107 lines
1.9 KiB
Go
107 lines
1.9 KiB
Go
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestChannelJson(t *testing.T) {
|
|
o := Channel{Id: NewId(), Name: NewId()}
|
|
json := o.ToJson()
|
|
ro := ChannelFromJson(strings.NewReader(json))
|
|
|
|
if o.Id != ro.Id {
|
|
t.Fatal("Ids do not match")
|
|
}
|
|
}
|
|
|
|
func TestChannelIsValid(t *testing.T) {
|
|
o := Channel{}
|
|
|
|
if err := o.IsValid(); err == nil {
|
|
t.Fatal("should be invalid")
|
|
}
|
|
|
|
o.Id = NewId()
|
|
if err := o.IsValid(); err == nil {
|
|
t.Fatal("should be invalid")
|
|
}
|
|
|
|
o.CreateAt = GetMillis()
|
|
if err := o.IsValid(); err == nil {
|
|
t.Fatal("should be invalid")
|
|
}
|
|
|
|
o.UpdateAt = GetMillis()
|
|
if err := o.IsValid(); err == nil {
|
|
t.Fatal("should be invalid")
|
|
}
|
|
|
|
o.DisplayName = strings.Repeat("01234567890", 20)
|
|
if err := o.IsValid(); err == nil {
|
|
t.Fatal("should be invalid")
|
|
}
|
|
|
|
o.DisplayName = "1234"
|
|
o.Name = "ZZZZZZZ"
|
|
if err := o.IsValid(); err == nil {
|
|
t.Fatal("should be invalid")
|
|
}
|
|
|
|
o.Name = "zzzzz"
|
|
|
|
if err := o.IsValid(); err == nil {
|
|
t.Fatal("should be invalid")
|
|
}
|
|
|
|
o.Type = "U"
|
|
if err := o.IsValid(); err == nil {
|
|
t.Fatal("should be invalid")
|
|
}
|
|
|
|
o.Type = "P"
|
|
|
|
if err := o.IsValid(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
o.Header = strings.Repeat("01234567890", 100)
|
|
if err := o.IsValid(); err == nil {
|
|
t.Fatal("should be invalid")
|
|
}
|
|
|
|
o.Header = "1234"
|
|
if err := o.IsValid(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
o.Purpose = strings.Repeat("01234567890", 30)
|
|
if err := o.IsValid(); err == nil {
|
|
t.Fatal("should be invalid")
|
|
}
|
|
|
|
o.Purpose = "1234"
|
|
if err := o.IsValid(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
o.Purpose = strings.Repeat("0123456789", 25)
|
|
if err := o.IsValid(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestChannelPreSave(t *testing.T) {
|
|
o := Channel{Name: "test"}
|
|
o.PreSave()
|
|
o.Etag()
|
|
}
|
|
|
|
func TestChannelPreUpdate(t *testing.T) {
|
|
o := Channel{Name: "test"}
|
|
o.PreUpdate()
|
|
}
|