summaryrefslogtreecommitdiffstats
path: root/app/apptestlib.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-16 08:09:43 -0700
committerJoram Wilander <jwawilander@gmail.com>2017-10-16 11:09:43 -0400
commit34285d8cca93fc0f473636e78680fade03f26bda (patch)
treeb8274ed8d17e5dc63ac36aadac7e7299635d2b43 /app/apptestlib.go
parentadb2b1d6eddabea803af8fa6cf53a75c98694427 (diff)
downloadchat-34285d8cca93fc0f473636e78680fade03f26bda.tar.gz
chat-34285d8cca93fc0f473636e78680fade03f26bda.tar.bz2
chat-34285d8cca93fc0f473636e78680fade03f26bda.zip
parallel tests (#7629)
Diffstat (limited to 'app/apptestlib.go')
-rw-r--r--app/apptestlib.go45
1 files changed, 43 insertions, 2 deletions
diff --git a/app/apptestlib.go b/app/apptestlib.go
index 09bf02d39..9c26e0bbb 100644
--- a/app/apptestlib.go
+++ b/app/apptestlib.go
@@ -7,6 +7,9 @@ import (
"time"
"github.com/mattermost/mattermost-server/model"
+ "github.com/mattermost/mattermost-server/store"
+ "github.com/mattermost/mattermost-server/store/sqlstore"
+ "github.com/mattermost/mattermost-server/store/storetest"
"github.com/mattermost/mattermost-server/utils"
l4g "github.com/alecthomas/log4go"
@@ -21,13 +24,47 @@ type TestHelper struct {
BasicPost *model.Post
}
+type persistentTestStore struct {
+ store.Store
+}
+
+func (*persistentTestStore) Close() {}
+
+var testStoreContainer *storetest.RunningContainer
+var testStore *persistentTestStore
+
+// UseTestStore sets the container and corresponding settings to use for tests. Once the tests are
+// complete (e.g. at the end of your TestMain implementation), you should call StopTestStore.
+func UseTestStore(container *storetest.RunningContainer, settings *model.SqlSettings) {
+ testStoreContainer = container
+ testStore = &persistentTestStore{store.NewLayeredStore(sqlstore.NewSqlSupplier(*settings, nil), nil, nil)}
+}
+
+func StopTestStore() {
+ if testStoreContainer != nil {
+ testStoreContainer.Stop()
+ testStoreContainer = nil
+ }
+}
+
func setupTestHelper(enterprise bool) *TestHelper {
- utils.TranslationsPreInit()
+ if utils.T == nil {
+ utils.TranslationsPreInit()
+ }
utils.LoadConfig("config.json")
utils.InitTranslations(utils.Cfg.LocalizationSettings)
+ var options []Option
+ if testStore != nil {
+ options = append(options, StoreOverride(testStore))
+ options = append(options, ConfigOverride(func(cfg *model.Config) {
+ cfg.ServiceSettings.ListenAddress = new(string)
+ *cfg.ServiceSettings.ListenAddress = ":0"
+ }))
+ }
+
th := &TestHelper{
- App: New(),
+ App: New(options...),
}
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
@@ -188,4 +225,8 @@ func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
func (me *TestHelper) TearDown() {
me.App.Shutdown()
+ if err := recover(); err != nil {
+ StopTestStore()
+ panic(err)
+ }
}