本文整理汇总了Golang中github.com/mattermost/platform/model.NewId函数的典型用法代码示例。如果您正苦于以下问题:Golang NewId函数的具体用法?Golang NewId怎么用?Golang NewId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewId函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUserStoreUpdateAuthData
func TestUserStoreUpdateAuthData(t *testing.T) {
Setup()
teamId := model.NewId()
u1 := &model.User{}
u1.Email = model.NewId()
Must(store.User().Save(u1))
Must(store.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u1.Id}))
service := "someservice"
authData := model.NewId()
if err := (<-store.User().UpdateAuthData(u1.Id, service, &authData, "")).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.User().GetByEmail(u1.Email); r1.Err != nil {
t.Fatal(r1.Err)
} else {
user := r1.Data.(*model.User)
if user.AuthService != service {
t.Fatal("AuthService was not updated correctly")
}
if *user.AuthData != authData {
t.Fatal("AuthData was not updated correctly")
}
if user.Password != "" {
t.Fatal("Password was not cleared properly")
}
}
}
示例2: TestTeamStoreGetByName
func TestTeamStoreGetByName(t *testing.T) {
Setup()
o1 := model.Team{}
o1.DisplayName = "DisplayName"
o1.Name = "a" + model.NewId() + "b"
o1.Email = model.NewId() + "@nowhere.com"
o1.Type = model.TEAM_OPEN
if err := (<-store.Team().Save(&o1)).Err; err != nil {
t.Fatal(err)
}
if r1 := <-store.Team().GetByName(o1.Name); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Team).ToJson() != o1.ToJson() {
t.Fatal("invalid returned team")
}
}
if err := (<-store.Team().GetByName("")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}
示例3: TestAllTeamListing
func TestAllTeamListing(t *testing.T) {
Setup()
o1 := model.Team{}
o1.DisplayName = "DisplayName"
o1.Name = "a" + model.NewId() + "b"
o1.Email = model.NewId() + "@nowhere.com"
o1.Type = model.TEAM_OPEN
o1.AllowTeamListing = true
Must(store.Team().Save(&o1))
o2 := model.Team{}
o2.DisplayName = "DisplayName"
o2.Name = "a" + model.NewId() + "b"
o2.Email = model.NewId() + "@nowhere.com"
o2.Type = model.TEAM_OPEN
Must(store.Team().Save(&o2))
if r1 := <-store.Team().GetAllTeamListing(); r1.Err != nil {
t.Fatal(r1.Err)
} else {
teams := r1.Data.([]*model.Team)
if len(teams) == 0 {
t.Fatal("failed team listing")
}
}
}
示例4: TestGetAudits
func TestGetAudits(t *testing.T) {
Setup()
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "[email protected]", Type: model.TEAM_OPEN}
rteam, _ := Client.CreateTeam(&team)
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "[email protected]", Nickname: "Corey Hulen", Password: "pwd"}
ruser, _ := Client.CreateUser(&user, "")
store.Must(Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
time.Sleep(100 * time.Millisecond)
Client.LoginByEmail(team.Name, user.Email, user.Password)
time.Sleep(100 * time.Millisecond)
if result, err := Client.GetAudits(ruser.Data.(*model.User).Id, ""); err != nil {
t.Fatal(err)
} else {
if len(result.Data.(model.Audits)) != 2 {
t.Fatal(result.Data.(model.Audits))
}
if cache_result, err := Client.GetAudits(ruser.Data.(*model.User).Id, result.Etag); err != nil {
t.Fatal(err)
} else if cache_result.Data.(model.Audits) != nil {
t.Fatal("cache should be empty")
}
}
if _, err := Client.GetAudits("FORBIDDENERROR", ""); err == nil {
t.Fatal("audit log shouldn't exist")
}
}
示例5: TestPostStorePermDelete1Level
func TestPostStorePermDelete1Level(t *testing.T) {
Setup()
o1 := &model.Post{}
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
if r2 := <-store.Post().PermanentDeleteByUser(o2.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Post().Get(o1.Id)); r3.Err != nil {
t.Fatal("Deleted id shouldn't have failed")
}
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed")
}
}
示例6: TestFuzzyUserCreate
func TestFuzzyUserCreate(t *testing.T) {
Setup()
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "[email protected]", Type: model.TEAM_OPEN}
rteam, _ := Client.CreateTeam(&team)
for i := 0; i < len(utils.FUZZY_STRINGS_NAMES) || i < len(utils.FUZZY_STRINGS_EMAILS); i++ {
testName := "Name"
testEmail := "[email protected]"
if i < len(utils.FUZZY_STRINGS_NAMES) {
testName = utils.FUZZY_STRINGS_NAMES[i]
}
if i < len(utils.FUZZY_STRINGS_EMAILS) {
testEmail = utils.FUZZY_STRINGS_EMAILS[i]
}
user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + testEmail, Nickname: testName, Password: "hello"}
_, err := Client.CreateUser(&user, "")
if err != nil {
t.Fatal(err)
}
}
}
示例7: TestGetAllTeams
func TestGetAllTeams(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th.BasicClient.Logout()
Client := th.BasicClient
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "[email protected]", Type: model.TEAM_OPEN}
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
user := &model.User{Email: model.NewId() + "[email protected]", Nickname: "Corey Hulen", Password: "passwd1"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
LinkUserToTeam(user, team)
store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.Login(user.Email, "passwd1")
Client.SetTeamId(team.Id)
if r1, err := Client.GetAllTeams(); err != nil {
t.Fatal(err)
} else if teams := r1.Data.(map[string]*model.Team); len(teams) != 1 {
t.Fatal("non admin users only get the teams that they're a member of")
} else if receivedTeam, ok := teams[team.Id]; !ok || receivedTeam.Id != team.Id {
t.Fatal("should've received team that the user is a member of")
}
if r1, err := th.SystemAdminClient.GetAllTeams(); err != nil {
t.Fatal(err)
} else if teams := r1.Data.(map[string]*model.Team); len(teams) == 1 {
t.Fatal("admin users should receive all teams")
} else if receivedTeam, ok := teams[team.Id]; !ok || receivedTeam.Id != team.Id {
t.Fatal("admin should've received team that they aren't a member of")
}
}
示例8: TestDeletePosts
func TestDeletePosts(t *testing.T) {
Setup()
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "[email protected]", Type: model.TEAM_OPEN}
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
userAdmin := &model.User{TeamId: team.Id, Email: team.Email, Nickname: "Corey Hulen", Password: "pwd"}
userAdmin = Client.Must(Client.CreateUser(userAdmin, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(userAdmin.Id))
user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "[email protected]", Nickname: "Corey Hulen", Password: "pwd"}
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
Client.LoginByEmail(team.Name, user1.Email, "pwd")
channel1 := &model.Channel{DisplayName: "TestGetPosts", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
time.Sleep(10 * time.Millisecond)
post1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post)
time.Sleep(10 * time.Millisecond)
post1a1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post1.Id}
post1a1 = Client.Must(Client.CreatePost(post1a1)).Data.(*model.Post)
time.Sleep(10 * time.Millisecond)
post1a2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post1.Id, ParentId: post1a1.Id}
post1a2 = Client.Must(Client.CreatePost(post1a2)).Data.(*model.Post)
time.Sleep(10 * time.Millisecond)
post2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post)
time.Sleep(10 * time.Millisecond)
post3 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post)
time.Sleep(10 * time.Millisecond)
post3a1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post3.Id}
post3a1 = Client.Must(Client.CreatePost(post3a1)).Data.(*model.Post)
time.Sleep(10 * time.Millisecond)
Client.Must(Client.DeletePost(channel1.Id, post3.Id))
r2 := Client.Must(Client.GetPosts(channel1.Id, 0, 10, "")).Data.(*model.PostList)
if len(r2.Posts) != 4 {
t.Fatal("should have returned 4 items")
}
time.Sleep(10 * time.Millisecond)
post4 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post)
Client.LoginByEmail(team.Name, userAdmin.Email, "pwd")
Client.Must(Client.DeletePost(channel1.Id, post4.Id))
}
示例9: TestFuzzyPosts
func TestFuzzyPosts(t *testing.T) {
Setup()
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "[email protected]", Type: model.TEAM_OPEN}
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
user := &model.User{TeamId: team.Id, Email: model.NewId() + "[email protected]", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.LoginByEmail(team.Name, user.Email, "pwd")
channel1 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
filenames := []string{"junk"}
for i := 0; i < len(utils.FUZZY_STRINGS_POSTS); i++ {
post := &model.Post{ChannelId: channel1.Id, Message: utils.FUZZY_STRINGS_POSTS[i], Filenames: filenames}
_, err := Client.CreatePost(post)
if err != nil {
t.Fatal(err)
}
}
}
示例10: TestOAuthStoreGetAccessData
func TestOAuthStoreGetAccessData(t *testing.T) {
Setup()
a1 := model.AccessData{}
a1.ClientId = model.NewId()
a1.UserId = model.NewId()
a1.Token = model.NewId()
a1.RefreshToken = model.NewId()
a1.ExpiresAt = model.GetMillis()
Must(store.OAuth().SaveAccessData(&a1))
if result := <-store.OAuth().GetAccessData(a1.Token); result.Err != nil {
t.Fatal(result.Err)
} else {
ra1 := result.Data.(*model.AccessData)
if a1.Token != ra1.Token {
t.Fatal("tokens didn't match")
}
}
if err := (<-store.OAuth().GetPreviousAccessData(a1.UserId, a1.ClientId)).Err; err != nil {
t.Fatal(err)
}
if err := (<-store.OAuth().GetPreviousAccessData("user", "junk")).Err; err != nil {
t.Fatal(err)
}
}
示例11: TestSearchHashtagPosts
func TestSearchHashtagPosts(t *testing.T) {
Setup()
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "[email protected]", Type: model.TEAM_OPEN}
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "[email protected]", Nickname: "Corey Hulen", Password: "pwd"}
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
Client.LoginByEmail(team.Name, user1.Email, "pwd")
channel1 := &model.Channel{DisplayName: "TestGetPosts", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
post1 := &model.Post{ChannelId: channel1.Id, Message: "#sgtitlereview with space"}
post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post)
post2 := &model.Post{ChannelId: channel1.Id, Message: "#sgtitlereview\n with return"}
post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post)
post3 := &model.Post{ChannelId: channel1.Id, Message: "no hashtag"}
post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post)
r1 := Client.Must(Client.SearchPosts("#sgtitlereview")).Data.(*model.PostList)
if len(r1.Order) != 2 {
t.Fatal("wrong search")
}
}
示例12: TestOAuthStoreUpdateApp
func TestOAuthStoreUpdateApp(t *testing.T) {
Setup()
a1 := model.OAuthApp{}
a1.CreatorId = model.NewId()
a1.Name = "TestApp" + model.NewId()
a1.CallbackUrls = []string{"https://nowhere.com"}
a1.Homepage = "https://nowhere.com"
Must(store.OAuth().SaveApp(&a1))
a1.CreateAt = 1
a1.ClientSecret = "pwd"
a1.CreatorId = "12345678901234567890123456"
a1.Name = "NewName"
if result := <-store.OAuth().UpdateApp(&a1); result.Err != nil {
t.Fatal(result.Err)
} else {
ua1 := (result.Data.([2]*model.OAuthApp)[0])
if ua1.Name != "NewName" {
t.Fatal("name did not update")
}
if ua1.CreateAt == 1 {
t.Fatal("create at should not have updated")
}
if ua1.CreatorId == "12345678901234567890123456" {
t.Fatal("creator id should not have updated")
}
}
}
示例13: TestOAuthGetAuthorizedApps
func TestOAuthGetAuthorizedApps(t *testing.T) {
Setup()
a1 := model.OAuthApp{}
a1.CreatorId = model.NewId()
a1.Name = "TestApp" + model.NewId()
a1.CallbackUrls = []string{"https://nowhere.com"}
a1.Homepage = "https://nowhere.com"
Must(store.OAuth().SaveApp(&a1))
// allow the app
p := model.Preference{}
p.UserId = a1.CreatorId
p.Category = model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP
p.Name = a1.Id
p.Value = "true"
Must(store.Preference().Save(&model.Preferences{p}))
if result := <-store.OAuth().GetAuthorizedApps(a1.CreatorId); result.Err != nil {
t.Fatal(result.Err)
} else {
apps := result.Data.([]*model.OAuthApp)
if len(apps) == 0 {
t.Fatal("It should have return apps")
}
}
}
示例14: createRandomTeam
func (cfg *AutoTeamCreator) createRandomTeam() (*model.Team, bool) {
var teamEmail string
var teamDisplayName string
var teamName string
if cfg.Fuzzy {
teamEmail = "success+" + model.NewId() + "simulator.amazonses.com"
teamDisplayName = utils.FuzzName()
teamName = utils.FuzzName()
} else {
teamEmail = "success+" + model.NewId() + "simulator.amazonses.com"
teamDisplayName = utils.RandomName(cfg.NameLength, cfg.NameCharset)
teamName = utils.RandomName(cfg.NameLength, cfg.NameCharset) + model.NewId()
}
team := &model.Team{
DisplayName: teamDisplayName,
Name: teamName,
Email: teamEmail,
Type: model.TEAM_OPEN,
}
result, err := cfg.client.CreateTeam(team)
if err != nil {
return nil, false
}
createdTeam := result.Data.(*model.Team)
return createdTeam, true
}
示例15: TestUpdateTeamDisplayName
func TestUpdateTeamDisplayName(t *testing.T) {
Setup()
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "[email protected]", Type: model.TEAM_OPEN}
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
user := &model.User{TeamId: team.Id, Email: "[email protected]", Nickname: "Corey Hulen", Password: "pwd"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(user.Id))
user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "[email protected]", Nickname: "Corey Hulen", Password: "pwd"}
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
store.Must(Srv.Store.User().VerifyEmail(user2.Id))
Client.LoginByEmail(team.Name, user2.Email, "pwd")
vteam := &model.Team{DisplayName: team.DisplayName, Name: team.Name, Email: team.Email, Type: team.Type}
vteam.DisplayName = "NewName"
if _, err := Client.UpdateTeam(vteam); err == nil {
t.Fatal("Should have errored, not admin")
}
Client.LoginByEmail(team.Name, user.Email, "pwd")
vteam.DisplayName = ""
if _, err := Client.UpdateTeam(vteam); err == nil {
t.Fatal("Should have errored, empty name")
}
vteam.DisplayName = "NewName"
if _, err := Client.UpdateTeam(vteam); err != nil {
t.Fatal(err)
}
}