Files
mostlymatter/server/channels/app/remote_cluster_test.go
Claudio Costa 611b2a8e79 [MM-62408] Server Code Coverage with Fully Parallel Tests (#30078)
* TestPool

* Store infra

* Store tests updates

* Bump maximum concurrent postgres connections

* More infra

* channels/jobs

* channels/app

* channels/api4

* Protect i18n from concurrent access

* Replace some use of os.Setenv

* Remove debug

* Lint fixes

* Fix more linting

* Fix test

* Remove use of Setenv in drafts tests

* Fix flaky TestWebHubCloseConnOnDBFail

* Fix merge

* [MM-62408] Add CI job to generate test coverage (#30284)

* Add CI job to generate test coverage

* Remove use of Setenv in drafts tests

* Fix flaky TestWebHubCloseConnOnDBFail

* Fix more Setenv usage

* Fix more potential flakyness

* Remove parallelism from flaky test

* Remove conflicting env var

* Fix

* Disable parallelism

* Test atomic covermode

* Disable parallelism

* Enable parallelism

* Add upload coverage step

* Fix codecov.yml

* Add codecov.yml

* Remove redundant workspace field

* Add Parallel() util methods and refactor

* Fix formatting

* More formatting fixes

* Fix reporting
2025-05-30 13:58:26 +02:00

110 строки
3.3 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/require"
"github.com/mattermost/mattermost/server/public/model"
)
func setupRemoteCluster(tb testing.TB) *TestHelper {
return SetupConfig(tb, func(cfg *model.Config) {
*cfg.ConnectedWorkspacesSettings.EnableRemoteClusterService = true
})
}
func TestAddRemoteCluster(t *testing.T) {
mainHelper.Parallel(t)
th := setupRemoteCluster(t).InitBasic()
defer th.TearDown()
t.Run("adding remote cluster with duplicate site url", func(t *testing.T) {
remoteCluster := &model.RemoteCluster{
Name: "test1",
SiteURL: "http://www1.example.com:8065",
Token: model.NewId(),
RemoteToken: model.NewId(),
Topics: "",
CreatorId: th.BasicUser.Id,
}
_, err := th.App.AddRemoteCluster(remoteCluster)
require.Nil(t, err, "Adding a remote cluster should not error")
remoteCluster.RemoteId = model.NewId()
_, err = th.App.AddRemoteCluster(remoteCluster)
require.Nil(t, err, "Adding a duplicate remote cluster should work fine")
})
}
func TestUpdateRemoteCluster(t *testing.T) {
mainHelper.Parallel(t)
th := setupRemoteCluster(t).InitBasic()
defer th.TearDown()
t.Run("update remote cluster with an already existing site url", func(t *testing.T) {
remoteCluster := &model.RemoteCluster{
Name: "test3",
SiteURL: "http://www3.example.com:8065",
Token: model.NewId(),
RemoteToken: model.NewId(),
Topics: "",
CreatorId: th.BasicUser.Id,
}
otherRemoteCluster := &model.RemoteCluster{
Name: "test4",
SiteURL: "http://www4.example.com:8066",
Token: model.NewId(),
RemoteToken: model.NewId(),
Topics: "",
CreatorId: th.BasicUser.Id,
}
_, err := th.App.AddRemoteCluster(remoteCluster)
require.Nil(t, err, "Adding a remote cluster should not error")
savedRemoteClustered, err := th.App.AddRemoteCluster(otherRemoteCluster)
require.Nil(t, err, "Adding a remote cluster should not error")
savedRemoteClustered.SiteURL = remoteCluster.SiteURL
_, err = th.App.UpdateRemoteCluster(savedRemoteClustered)
require.Nil(t, err, "Updating remote cluster with duplicate site url should work fine")
})
t.Run("update remote cluster with an already existing site url, is not allowed", func(t *testing.T) {
remoteCluster := &model.RemoteCluster{
Name: "test5",
SiteURL: "http://www5.example.com:8065",
Token: model.NewId(),
RemoteToken: model.NewId(),
Topics: "",
CreatorId: th.BasicUser.Id,
}
otherRemoteCluster := &model.RemoteCluster{
Name: "test6",
SiteURL: "http://www6.example.com:8065",
Token: model.NewId(),
RemoteToken: model.NewId(),
Topics: "",
CreatorId: th.BasicUser.Id,
}
existingRemoteCluster, err := th.App.AddRemoteCluster(remoteCluster)
require.Nil(t, err, "Adding a remote cluster should not error")
anotherExistingRemoteClustered, err := th.App.AddRemoteCluster(otherRemoteCluster)
require.Nil(t, err, "Adding a remote cluster should not error")
// Same site url
anotherExistingRemoteClustered.SiteURL = existingRemoteCluster.SiteURL
_, err = th.App.UpdateRemoteCluster(anotherExistingRemoteClustered)
require.Nil(t, err, "Updating remote cluster should work fine")
})
}