mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Remote Cluster Service - provides ability for multiple Mattermost cluster instances to create a trusted connection with each other and exchange messages - trusted connections are managed via slash commands (for now) - facilitates features requiring inter-cluster communication, such as Shared Channels Shared Channels Service - provides ability to shared channels between one or more Mattermost cluster instances (using trusted connection) - sharing/unsharing of channels is managed via slash commands (for now)
90 lines
2.8 KiB
Go
90 lines
2.8 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
|
)
|
|
|
|
func TestApp_CheckCanInviteToSharedChannel(t *testing.T) {
|
|
th := Setup(t).InitBasic()
|
|
|
|
channel1 := th.CreateChannel(th.BasicTeam)
|
|
channel2 := th.CreateChannel(th.BasicTeam)
|
|
channel3 := th.CreateChannel(th.BasicTeam)
|
|
|
|
data := []struct {
|
|
channelId string
|
|
home bool
|
|
name string
|
|
remoteId string
|
|
}{
|
|
{channelId: channel1.Id, home: true, name: "test_home", remoteId: ""},
|
|
{channelId: channel2.Id, home: false, name: "test_remote", remoteId: model.NewId()},
|
|
}
|
|
|
|
for _, d := range data {
|
|
sc := &model.SharedChannel{
|
|
ChannelId: d.channelId,
|
|
TeamId: th.BasicTeam.Id,
|
|
Home: d.home,
|
|
ShareName: d.name,
|
|
CreatorId: th.BasicUser.Id,
|
|
RemoteId: d.remoteId,
|
|
}
|
|
_, err := th.App.SaveSharedChannel(sc)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
t.Run("Test checkChannelNotShared: not yet shared channel", func(t *testing.T) {
|
|
err := th.App.checkChannelNotShared(channel3.Id)
|
|
assert.NoError(t, err, "unshared channel should not error")
|
|
})
|
|
|
|
t.Run("Test checkChannelNotShared: already shared channel", func(t *testing.T) {
|
|
err := th.App.checkChannelNotShared(channel1.Id)
|
|
assert.Error(t, err, "already shared channel should error")
|
|
})
|
|
|
|
t.Run("Test checkChannelNotShared: invalid channel", func(t *testing.T) {
|
|
err := th.App.checkChannelNotShared(model.NewId())
|
|
assert.Error(t, err, "invalid channel should error")
|
|
})
|
|
|
|
t.Run("Test checkChannelIsShared: not yet shared channel", func(t *testing.T) {
|
|
err := th.App.checkChannelIsShared(channel3.Id)
|
|
assert.Error(t, err, "unshared channel should error")
|
|
})
|
|
|
|
t.Run("Test checkChannelIsShared: already shared channel", func(t *testing.T) {
|
|
err := th.App.checkChannelIsShared(channel1.Id)
|
|
assert.NoError(t, err, "already channel should not error")
|
|
})
|
|
|
|
t.Run("Test checkChannelIsShared: invalid channel", func(t *testing.T) {
|
|
err := th.App.checkChannelIsShared(model.NewId())
|
|
assert.Error(t, err, "invalid channel should error")
|
|
})
|
|
|
|
t.Run("Test CheckCanInviteToSharedChannel: Home shared channel", func(t *testing.T) {
|
|
err := th.App.CheckCanInviteToSharedChannel(data[0].channelId)
|
|
assert.NoError(t, err, "home channel should allow invites")
|
|
})
|
|
|
|
t.Run("Test CheckCanInviteToSharedChannel: Remote shared channel", func(t *testing.T) {
|
|
err := th.App.CheckCanInviteToSharedChannel(data[1].channelId)
|
|
assert.Error(t, err, "home channel should not allow invites")
|
|
})
|
|
|
|
t.Run("Test CheckCanInviteToSharedChannel: Invalid shared channel", func(t *testing.T) {
|
|
err := th.App.CheckCanInviteToSharedChannel(model.NewId())
|
|
assert.Error(t, err, "invalid channel should not allow invites")
|
|
})
|
|
}
|