summaryrefslogtreecommitdiffstats
path: root/store/storetest/channel_store.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-05-14 15:59:04 +0100
committerGitHub <noreply@github.com>2018-05-14 15:59:04 +0100
commit51bd710ecdca6628461c9fa2679737073e4d5059 (patch)
treeb2a4837ced3ed515ee505728917a6630b0553f76 /store/storetest/channel_store.go
parent91557bbd978500388a11b99401783164e143a966 (diff)
downloadchat-51bd710ecdca6628461c9fa2679737073e4d5059.tar.gz
chat-51bd710ecdca6628461c9fa2679737073e4d5059.tar.bz2
chat-51bd710ecdca6628461c9fa2679737073e4d5059.zip
MM-9728: Online migration for advanced permissions phase 2 (#8744)
* MM-9728: Online migration for advanced permissions phase 2 * Add unit tests for new store functions. * Move migration specific code to own file. * Add migration state function test. * Style fixes. * Add i18n strings. * Fix mocks. * Add TestMain to migrations package tests. * Fix typo. * Fix review comments. * Fix up the "Check if migration is done" check to actually work.
Diffstat (limited to 'store/storetest/channel_store.go')
-rw-r--r--store/storetest/channel_store.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go
index d90a0ae1e..d044f3907 100644
--- a/store/storetest/channel_store.go
+++ b/store/storetest/channel_store.go
@@ -5,6 +5,7 @@ package storetest
import (
"sort"
+ "strings"
"testing"
"time"
@@ -52,6 +53,7 @@ func TestChannelStore(t *testing.T, ss store.Store) {
t.Run("GetPinnedPosts", func(t *testing.T) { testChannelStoreGetPinnedPosts(t, ss) })
t.Run("MaxChannelsPerTeam", func(t *testing.T) { testChannelStoreMaxChannelsPerTeam(t, ss) })
t.Run("GetChannelsByScheme", func(t *testing.T) { testChannelStoreGetChannelsByScheme(t, ss) })
+ t.Run("MigrateChannelMembers", func(t *testing.T) { testChannelStoreMigrateChannelMembers(t, ss) })
}
@@ -2254,3 +2256,76 @@ func testChannelStoreGetChannelsByScheme(t *testing.T, ss store.Store) {
d3 := res3.Data.(model.ChannelList)
assert.Len(t, d3, 0)
}
+
+func testChannelStoreMigrateChannelMembers(t *testing.T, ss store.Store) {
+ s1 := model.NewId()
+ c1 := &model.Channel{
+ TeamId: model.NewId(),
+ DisplayName: "Name",
+ Name: model.NewId(),
+ Type: model.CHANNEL_OPEN,
+ SchemeId: &s1,
+ }
+ c1 = (<-ss.Channel().Save(c1, 100)).Data.(*model.Channel)
+
+ cm1 := &model.ChannelMember{
+ ChannelId: c1.Id,
+ UserId: model.NewId(),
+ ExplicitRoles: "channel_admin channel_user",
+ NotifyProps: model.GetDefaultChannelNotifyProps(),
+ }
+ cm2 := &model.ChannelMember{
+ ChannelId: c1.Id,
+ UserId: model.NewId(),
+ ExplicitRoles: "channel_user",
+ NotifyProps: model.GetDefaultChannelNotifyProps(),
+ }
+ cm3 := &model.ChannelMember{
+ ChannelId: c1.Id,
+ UserId: model.NewId(),
+ ExplicitRoles: "something_else",
+ NotifyProps: model.GetDefaultChannelNotifyProps(),
+ }
+
+ cm1 = (<-ss.Channel().SaveMember(cm1)).Data.(*model.ChannelMember)
+ cm2 = (<-ss.Channel().SaveMember(cm2)).Data.(*model.ChannelMember)
+ cm3 = (<-ss.Channel().SaveMember(cm3)).Data.(*model.ChannelMember)
+
+ lastDoneChannelId := strings.Repeat("0", 26)
+ lastDoneUserId := strings.Repeat("0", 26)
+
+ for {
+ res := <-ss.Channel().MigrateChannelMembers(lastDoneChannelId, lastDoneUserId)
+ if assert.Nil(t, res.Err) {
+ if res.Data == nil {
+ break
+ }
+ data := res.Data.(map[string]string)
+ lastDoneChannelId = data["ChannelId"]
+ lastDoneUserId = data["UserId"]
+ }
+ }
+
+ ss.Channel().ClearCaches()
+
+ res1 := <-ss.Channel().GetMember(cm1.ChannelId, cm1.UserId)
+ assert.Nil(t, res1.Err)
+ cm1b := res1.Data.(*model.ChannelMember)
+ assert.Equal(t, "", cm1b.ExplicitRoles)
+ assert.True(t, cm1b.SchemeUser)
+ assert.True(t, cm1b.SchemeAdmin)
+
+ res2 := <-ss.Channel().GetMember(cm2.ChannelId, cm2.UserId)
+ assert.Nil(t, res2.Err)
+ cm2b := res2.Data.(*model.ChannelMember)
+ assert.Equal(t, "", cm2b.ExplicitRoles)
+ assert.True(t, cm2b.SchemeUser)
+ assert.False(t, cm2b.SchemeAdmin)
+
+ res3 := <-ss.Channel().GetMember(cm3.ChannelId, cm3.UserId)
+ assert.Nil(t, res3.Err)
+ cm3b := res3.Data.(*model.ChannelMember)
+ assert.Equal(t, "something_else", cm3b.ExplicitRoles)
+ assert.False(t, cm3b.SchemeUser)
+ assert.False(t, cm3b.SchemeAdmin)
+}