Add tear down to APIv4 tests (#5250)
* Add tear down to APIv4 tests * Defer tear downs
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
60be5c902f
Коммит
365514174e
@@ -60,6 +60,34 @@ func Setup() *TestHelper {
|
||||
return th
|
||||
}
|
||||
|
||||
func TearDown() {
|
||||
options := map[string]bool{}
|
||||
options[store.USER_SEARCH_OPTION_NAMES_ONLY_NO_FULL_NAME] = true
|
||||
if result := <-app.Srv.Store.User().Search("", "fakeuser", options); result.Err != nil {
|
||||
l4g.Error("Error tearing down test users")
|
||||
} else {
|
||||
users := result.Data.([]*model.User)
|
||||
|
||||
for _, u := range users {
|
||||
if err := app.PermanentDeleteUser(u); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.Team().SearchByName("faketeam"); result.Err != nil {
|
||||
l4g.Error("Error tearing down test teams")
|
||||
} else {
|
||||
teams := result.Data.([]*model.Team)
|
||||
|
||||
for _, t := range teams {
|
||||
if err := app.PermanentDeleteTeam(t); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (me *TestHelper) InitBasic() *TestHelper {
|
||||
me.TeamAdminUser = me.CreateUser()
|
||||
me.LoginTeamAdmin()
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
func TestCreateTeam(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
|
||||
team := &model.Team{Name: GenerateTestUsername(), DisplayName: "Some Team", Type: model.TEAM_OPEN}
|
||||
|
||||
@@ -13,7 +13,8 @@ import (
|
||||
)
|
||||
|
||||
func TestCreateUser(t *testing.T) {
|
||||
th := Setup()
|
||||
th := Setup().InitBasic()
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
|
||||
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.ROLE_SYSTEM_ADMIN.Id + " " + model.ROLE_SYSTEM_USER.Id}
|
||||
@@ -28,6 +29,7 @@ func TestCreateUser(t *testing.T) {
|
||||
}
|
||||
|
||||
if ruser.Roles != model.ROLE_SYSTEM_USER.Id {
|
||||
t.Log(ruser.Roles)
|
||||
t.Fatal("did not clear roles")
|
||||
}
|
||||
|
||||
@@ -67,6 +69,7 @@ func TestCreateUser(t *testing.T) {
|
||||
|
||||
func TestGetUser(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
|
||||
user := th.CreateUser()
|
||||
@@ -130,6 +133,7 @@ func TestGetUser(t *testing.T) {
|
||||
|
||||
func TestUpdateUser(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
|
||||
user := th.CreateUser()
|
||||
|
||||
@@ -866,3 +866,19 @@ func ViewChannel(view *model.ChannelView, teamId string, userId string, clearPus
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
||||
if result := <-Srv.Store.Post().PermanentDeleteByChannel(channel.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Channel().PermanentDeleteMembersByChannel(channel.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Channel().PermanentDelete(channel.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -539,8 +539,13 @@ func PermanentDeleteTeam(team *model.Team) *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Channel().PermanentDeleteByTeam(team.Id); result.Err != nil {
|
||||
if result := <-Srv.Store.Channel().GetTeamChannels(team.Id); result.Err != nil {
|
||||
return result.Err
|
||||
} else {
|
||||
channels := result.Data.(*model.ChannelList)
|
||||
for _, c := range *channels {
|
||||
PermanentDeleteChannel(c)
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Team().RemoveAllMembersByTeam(team.Id); result.Err != nil {
|
||||
|
||||
@@ -4559,6 +4559,10 @@
|
||||
"id": "store.sql_channel.permanent_delete_by_team.app_error",
|
||||
"translation": "We couldn't delete the channels"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel.permanent_delete.app_error",
|
||||
"translation": "We couldn't delete the channel"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel.permanent_delete_members_by_user.app_error",
|
||||
"translation": "We couldn't remove the channel member"
|
||||
@@ -4915,6 +4919,10 @@
|
||||
"id": "store.sql_post.permanent_delete.app_error",
|
||||
"translation": "We couldn't delete the post"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_post.permanent_delete_by_channel.app_error",
|
||||
"translation": "We couldn't delete the posts by channel"
|
||||
},
|
||||
{
|
||||
"id": "store.sql_post.permanent_delete_all_comments_by_user.app_error",
|
||||
"translation": "We couldn't delete the comments for user"
|
||||
|
||||
@@ -410,6 +410,41 @@ func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) PermanentDelete(channelId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Channels WHERE Id = :ChannelId", map[string]interface{}{"ChannelId": channelId}); err != nil {
|
||||
result.Err = model.NewLocAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.app_error", nil, "channel_id="+channelId+", "+err.Error())
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) PermanentDeleteMembersByChannel(channelId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
_, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId})
|
||||
if err != nil {
|
||||
result.Err = model.NewLocAppError("SqlChannelStore.RemoveAllMembersByChannel", "store.sql_channel.remove_member.app_error", nil, "channel_id="+channelId+", "+err.Error())
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
type channelWithMember struct {
|
||||
model.Channel
|
||||
model.ChannelMember
|
||||
|
||||
@@ -340,6 +340,14 @@ func TestChannelStoreDelete(t *testing.T) {
|
||||
if len(*list) != 1 {
|
||||
t.Fatal("invalid number of channels")
|
||||
}
|
||||
|
||||
<-store.Channel().PermanentDelete(o2.Id)
|
||||
|
||||
cresult = <-store.Channel().GetChannels(o1.TeamId, m1.UserId)
|
||||
t.Log(cresult.Err)
|
||||
if cresult.Err.Id != "store.sql_channel.get_channels.not_found.app_error" {
|
||||
t.Fatal("no channels should be found")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannelStoreGetByName(t *testing.T) {
|
||||
@@ -560,6 +568,15 @@ func TestChannelDeleteMemberStore(t *testing.T) {
|
||||
if count != 1 {
|
||||
t.Fatal("should have removed 1 member")
|
||||
}
|
||||
|
||||
if r1 := <-store.Channel().PermanentDeleteMembersByChannel(o1.ChannelId); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
}
|
||||
|
||||
count = (<-store.Channel().GetMemberCount(o1.ChannelId, false)).Data.(int64)
|
||||
if count != 0 {
|
||||
t.Fatal("should have removed all members")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannelStoreGetChannels(t *testing.T) {
|
||||
|
||||
@@ -409,6 +409,23 @@ func (s SqlPostStore) PermanentDeleteByUser(userId string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlPostStore) PermanentDeleteByChannel(channelId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Posts WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}); err != nil {
|
||||
result.Err = model.NewLocAppError("SqlPostStore.PermanentDeleteByChannel", "store.sql_post.permanent_delete_by_channel.app_error", nil, "channel_id="+channelId+", "+err.Error())
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFromCache bool) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
|
||||
@@ -352,6 +352,12 @@ func TestPostStorePermDelete1Level(t *testing.T) {
|
||||
o2.RootId = o1.Id
|
||||
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
|
||||
|
||||
o3 := &model.Post{}
|
||||
o3.ChannelId = model.NewId()
|
||||
o3.UserId = model.NewId()
|
||||
o3.Message = "a" + model.NewId() + "b"
|
||||
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
|
||||
|
||||
if r2 := <-store.Post().PermanentDeleteByUser(o2.UserId); r2.Err != nil {
|
||||
t.Fatal(r2.Err)
|
||||
}
|
||||
@@ -363,6 +369,14 @@ func TestPostStorePermDelete1Level(t *testing.T) {
|
||||
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil {
|
||||
t.Fatal("Deleted id should have failed")
|
||||
}
|
||||
|
||||
if r2 := <-store.Post().PermanentDeleteByChannel(o3.ChannelId); r2.Err != nil {
|
||||
t.Fatal(r2.Err)
|
||||
}
|
||||
|
||||
if r3 := (<-store.Post().Get(o3.Id)); r3.Err == nil {
|
||||
t.Fatal("Deleted id should have failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostStorePermDelete1Level2(t *testing.T) {
|
||||
|
||||
@@ -236,6 +236,27 @@ func (s SqlTeamStore) GetByName(name string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) SearchByName(name string) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
var teams []*model.Team
|
||||
|
||||
if _, err := s.GetReplica().Select(&teams, "SELECT * FROM Teams WHERE Name LIKE :Name", map[string]interface{}{"Name": name + "%"}); err != nil {
|
||||
result.Err = model.NewLocAppError("SqlTeamStore.SearchByName", "store.sql_team.get_by_name.app_error", nil, "name="+name+", "+err.Error())
|
||||
}
|
||||
|
||||
result.Data = teams
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) GetAll() StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
|
||||
@@ -132,6 +132,28 @@ func TestTeamStoreGetByName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTeamStoreSearchByName(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
o1 := model.Team{}
|
||||
o1.DisplayName = "DisplayName"
|
||||
o1.Name = "zzz" + 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().SearchByName("zzz"); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
if r1.Data.([]*model.Team)[0].ToJson() != o1.ToJson() {
|
||||
t.Fatal("invalid returned team")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTeamStoreGetByIniviteId(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ type TeamStore interface {
|
||||
UpdateDisplayName(name string, teamId string) StoreChannel
|
||||
Get(id string) StoreChannel
|
||||
GetByName(name string) StoreChannel
|
||||
SearchByName(name string) StoreChannel
|
||||
GetAll() StoreChannel
|
||||
GetAllTeamListing() StoreChannel
|
||||
GetTeamsByUserId(userId string) StoreChannel
|
||||
@@ -92,6 +93,7 @@ type ChannelStore interface {
|
||||
Delete(channelId string, time int64) StoreChannel
|
||||
SetDeleteAt(channelId string, deleteAt int64, updateAt int64) StoreChannel
|
||||
PermanentDeleteByTeam(teamId string) StoreChannel
|
||||
PermanentDelete(channelId string) StoreChannel
|
||||
GetByName(team_id string, name string, allowFromCache bool) StoreChannel
|
||||
GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) StoreChannel
|
||||
GetDeletedByName(team_id string, name string) StoreChannel
|
||||
@@ -114,6 +116,7 @@ type ChannelStore interface {
|
||||
GetMemberCount(channelId string, allowFromCache bool) StoreChannel
|
||||
RemoveMember(channelId string, userId string) StoreChannel
|
||||
PermanentDeleteMembersByUser(userId string) StoreChannel
|
||||
PermanentDeleteMembersByChannel(channelId string) StoreChannel
|
||||
UpdateLastViewedAt(channelIds []string, userId string) StoreChannel
|
||||
SetLastViewedAt(channelId string, userId string, newLastViewedAt int64) StoreChannel
|
||||
IncrementMentionCount(channelId string, userId string) StoreChannel
|
||||
@@ -132,6 +135,7 @@ type PostStore interface {
|
||||
GetSingle(id string) StoreChannel
|
||||
Delete(postId string, time int64) StoreChannel
|
||||
PermanentDeleteByUser(userId string) StoreChannel
|
||||
PermanentDeleteByChannel(channelId string) StoreChannel
|
||||
GetPosts(channelId string, offset int, limit int, allowFromCache bool) StoreChannel
|
||||
GetFlaggedPosts(userId string, offset int, limit int) StoreChannel
|
||||
GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel
|
||||
|
||||
Ссылка в новой задаче
Block a user