diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-02-02 11:46:42 -0500 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-02-02 11:46:42 -0500 |
commit | 365514174ef00dcf426b2b5704c3d7adebe926e1 (patch) | |
tree | 41f5544aed1b822ae4e476c9ede496ce740d5048 /store | |
parent | 60be5c902fe30c978d5b30f265509dc28c451407 (diff) | |
download | chat-365514174ef00dcf426b2b5704c3d7adebe926e1.tar.gz chat-365514174ef00dcf426b2b5704c3d7adebe926e1.tar.bz2 chat-365514174ef00dcf426b2b5704c3d7adebe926e1.zip |
Add tear down to APIv4 tests (#5250)
* Add tear down to APIv4 tests
* Defer tear downs
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_channel_store.go | 35 | ||||
-rw-r--r-- | store/sql_channel_store_test.go | 17 | ||||
-rw-r--r-- | store/sql_post_store.go | 17 | ||||
-rw-r--r-- | store/sql_post_store_test.go | 14 | ||||
-rw-r--r-- | store/sql_team_store.go | 21 | ||||
-rw-r--r-- | store/sql_team_store_test.go | 22 | ||||
-rw-r--r-- | store/store.go | 4 |
7 files changed, 130 insertions, 0 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index a8474be80..7c4e97bc0 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -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 diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go index 90a5f4479..51ca11e8e 100644 --- a/store/sql_channel_store_test.go +++ b/store/sql_channel_store_test.go @@ -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) { diff --git a/store/sql_post_store.go b/store/sql_post_store.go index a8fe52380..96cfc071e 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -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) diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go index 7416e0ab7..626894a2a 100644 --- a/store/sql_post_store_test.go +++ b/store/sql_post_store_test.go @@ -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) { diff --git a/store/sql_team_store.go b/store/sql_team_store.go index 9620feb11..f1b023854 100644 --- a/store/sql_team_store.go +++ b/store/sql_team_store.go @@ -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) diff --git a/store/sql_team_store_test.go b/store/sql_team_store_test.go index 0ea499d7e..62efa4d1a 100644 --- a/store/sql_team_store_test.go +++ b/store/sql_team_store_test.go @@ -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() diff --git a/store/store.go b/store/store.go index 980ff7b1f..c75ec4554 100644 --- a/store/store.go +++ b/store/store.go @@ -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 |