本文整理汇总了Golang中github.com/mattermost/platform/model.Channel.Id方法的典型用法代码示例。如果您正苦于以下问题:Golang Channel.Id方法的具体用法?Golang Channel.Id怎么用?Golang Channel.Id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mattermost/platform/model.Channel
的用法示例。
在下文中一共展示了Channel.Id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestChannelStoreUpdate
func TestChannelStoreUpdate(t *testing.T) {
Setup()
o1 := model.Channel{}
o1.TeamId = model.NewId()
o1.DisplayName = "Name"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
if err := (<-store.Channel().Save(&o1)).Err; err != nil {
t.Fatal(err)
}
time.Sleep(100 * time.Millisecond)
if err := (<-store.Channel().Update(&o1)).Err; err != nil {
t.Fatal(err)
}
o1.Id = "missing"
if err := (<-store.Channel().Update(&o1)).Err; err == nil {
t.Fatal("Update should have failed because of missing key")
}
o1.Id = model.NewId()
if err := (<-store.Channel().Update(&o1)).Err; err == nil {
t.Fatal("Update should have faile because id change")
}
}
示例2: TestChannelStoreSave
func TestChannelStoreSave(t *testing.T) {
Setup()
teamId := model.NewId()
o1 := model.Channel{}
o1.TeamId = teamId
o1.DisplayName = "Name"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
if err := (<-store.Channel().Save(&o1)).Err; err != nil {
t.Fatal("couldn't save item", err)
}
if err := (<-store.Channel().Save(&o1)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
o1.Id = ""
if err := (<-store.Channel().Save(&o1)).Err; err == nil {
t.Fatal("should be unique name")
}
o1.Id = ""
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_DIRECT
if err := (<-store.Channel().Save(&o1)).Err; err == nil {
t.Fatal("Should not be able to save direct channel")
}
}
示例3: TestChannelStoreSaveDirectChannel
func TestChannelStoreSaveDirectChannel(t *testing.T) {
Setup()
teamId := model.NewId()
o1 := model.Channel{}
o1.TeamId = teamId
o1.DisplayName = "Name"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_DIRECT
u1 := &model.User{}
u1.Email = model.NewId()
u1.Nickname = model.NewId()
Must(store.User().Save(u1))
Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u1.Id}))
u2 := &model.User{}
u2.Email = model.NewId()
u2.Nickname = model.NewId()
Must(store.User().Save(u2))
Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u2.Id}))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = u1.Id
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
m2 := model.ChannelMember{}
m2.ChannelId = o1.Id
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err != nil {
t.Fatal("couldn't save direct channel", err)
}
members := (<-store.Channel().GetMembers(o1.Id)).Data.([]model.ChannelMember)
if len(members) != 2 {
t.Fatal("should have saved 2 members")
}
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
o1.Id = ""
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err == nil {
t.Fatal("Should not be able to save non-direct channel")
}
}
示例4: TestChannelStoreSaveDirectChannel
func TestChannelStoreSaveDirectChannel(t *testing.T) {
Setup()
teamId := model.NewId()
o1 := model.Channel{}
o1.TeamId = teamId
o1.DisplayName = "Name"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_DIRECT
u1 := &model.User{}
u1.Email = model.NewId()
u1.Nickname = model.NewId()
Must(store.User().Save(u1))
Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u1.Id}))
u2 := &model.User{}
u2.Email = model.NewId()
u2.Nickname = model.NewId()
Must(store.User().Save(u2))
Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u2.Id}))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = u1.Id
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
m2 := model.ChannelMember{}
m2.ChannelId = o1.Id
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err != nil {
t.Fatal("couldn't save direct channel", err)
}
members := (<-store.Channel().GetMembers(o1.Id)).Data.([]model.ChannelMember)
if len(members) != 2 {
t.Fatal("should have saved 2 members")
}
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
// Attempt to save a direct channel that already exists
o1a := model.Channel{
TeamId: o1.TeamId,
DisplayName: o1.DisplayName,
Name: o1.Name,
Type: o1.Type,
}
if result := <-store.Channel().SaveDirectChannel(&o1a, &m1, &m2); result.Err == nil {
t.Fatal("should've failed to save a duplicate direct channel")
} else if result.Err.Id != CHANNEL_EXISTS_ERROR {
t.Fatal("should've returned CHANNEL_EXISTS_ERROR")
} else if returned := result.Data.(*model.Channel); returned.Id != o1.Id {
t.Fatal("should've returned original channel when saving a duplicate direct channel")
}
// Attempt to save a non-direct channel
o1.Id = ""
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err == nil {
t.Fatal("Should not be able to save non-direct channel")
}
}