* Add tear down to APIv4 tests

* Defer tear downs
Этот коммит содержится в:
Joram Wilander
2017-02-02 11:46:42 -05:00
коммит произвёл Harrison Healey
родитель 60be5c902f
Коммит 365514174e
13 изменённых файлов: 194 добавлений и 2 удалений

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

@@ -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