summaryrefslogtreecommitdiffstats
path: root/store/storetest/channel_member_history_store.go
diff options
context:
space:
mode:
authorJonathan <jonfritz@gmail.com>2017-12-05 16:32:23 -0500
committerGitHub <noreply@github.com>2017-12-05 16:32:23 -0500
commitc171872472672d129e1e4dbc99930d75a4cd59c7 (patch)
treedde4e50cf563b8356afdade6255b8f9e22b9de9a /store/storetest/channel_member_history_store.go
parente7725106ed5b435c625a63691d99acc197a2106a (diff)
downloadchat-c171872472672d129e1e4dbc99930d75a4cd59c7.tar.gz
chat-c171872472672d129e1e4dbc99930d75a4cd59c7.tar.bz2
chat-c171872472672d129e1e4dbc99930d75a4cd59c7.zip
PLT-8233: Purge ChannelMemberHistory Data when Data Retention Job runs (#7937)
* Changed the channel member history purge function to match pattern established by other data retention purge methods * Simplifying the channel member history store and associated tests * Regenerating mocks * Using a constant
Diffstat (limited to 'store/storetest/channel_member_history_store.go')
-rw-r--r--store/storetest/channel_member_history_store.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/store/storetest/channel_member_history_store.go b/store/storetest/channel_member_history_store.go
index c73a25f65..0be92c6e0 100644
--- a/store/storetest/channel_member_history_store.go
+++ b/store/storetest/channel_member_history_store.go
@@ -6,6 +6,8 @@ package storetest
import (
"testing"
+ "math"
+
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
"github.com/stretchr/testify/assert"
@@ -15,7 +17,7 @@ func TestChannelMemberHistoryStore(t *testing.T, ss store.Store) {
t.Run("Log Join Event", func(t *testing.T) { testLogJoinEvent(t, ss) })
t.Run("Log Leave Event", func(t *testing.T) { testLogLeaveEvent(t, ss) })
t.Run("Get Users In Channel At Time", func(t *testing.T) { testGetUsersInChannelAt(t, ss) })
- t.Run("Purge History", func(t *testing.T) { testPurgeHistoryBefore(t, ss) })
+ t.Run("Purge History", func(t *testing.T) { testPermanentDeleteBatch(t, ss) })
}
func testLogJoinEvent(t *testing.T, ss store.Store) {
@@ -135,7 +137,7 @@ func testGetUsersInChannelAt(t *testing.T, ss store.Store) {
assert.Len(t, channelMembers, 0)
}
-func testPurgeHistoryBefore(t *testing.T, ss store.Store) {
+func testPermanentDeleteBatch(t *testing.T, ss store.Store) {
// create a test channel
channel := model.Channel{
TeamId: model.NewId(),
@@ -171,8 +173,11 @@ func testPurgeHistoryBefore(t *testing.T, ss store.Store) {
channelMembers := store.Must(ss.ChannelMemberHistory().GetUsersInChannelDuring(joinTime+10, leaveTime-10, channel.Id)).([]*model.ChannelMemberHistory)
assert.Len(t, channelMembers, 2)
- // but if we purge the old data, only the user that didn't leave is left
- store.Must(ss.ChannelMemberHistory().PurgeHistoryBefore(leaveTime, channel.Id))
+ // the permanent delete should delete at least one record
+ rowsDeleted := store.Must(ss.ChannelMemberHistory().PermanentDeleteBatch(leaveTime, math.MaxInt64)).(int64)
+ assert.NotEqual(t, int64(0), rowsDeleted)
+
+ // after the delete, there should be one less member in the channel
channelMembers = store.Must(ss.ChannelMemberHistory().GetUsersInChannelDuring(joinTime+10, leaveTime-10, channel.Id)).([]*model.ChannelMemberHistory)
assert.Len(t, channelMembers, 1)
assert.Equal(t, user2.Id, channelMembers[0].UserId)