summaryrefslogtreecommitdiffstats
path: root/store/sqlstore/store_test.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-06 11:08:59 -0700
committerGitHub <noreply@github.com>2017-10-06 11:08:59 -0700
commit70e5f00241473c27a3008959ce08832c75e76ba8 (patch)
tree3afd074964c9220cc4a87210286a13dfd38c61d0 /store/sqlstore/store_test.go
parentd1958bdc49cd10277ca2e27bb2eea499c5994954 (diff)
downloadchat-70e5f00241473c27a3008959ce08832c75e76ba8.tar.gz
chat-70e5f00241473c27a3008959ce08832c75e76ba8.tar.bz2
chat-70e5f00241473c27a3008959ce08832c75e76ba8.zip
store/storetest package (#7588)
* prerequisites * storetest package
Diffstat (limited to 'store/sqlstore/store_test.go')
-rw-r--r--store/sqlstore/store_test.go134
1 files changed, 4 insertions, 130 deletions
diff --git a/store/sqlstore/store_test.go b/store/sqlstore/store_test.go
index 0f306a475..605c73b6a 100644
--- a/store/sqlstore/store_test.go
+++ b/store/sqlstore/store_test.go
@@ -4,13 +4,15 @@
package sqlstore
import (
+ "testing"
+
"github.com/mattermost/mattermost-server/store"
"github.com/mattermost/mattermost-server/utils"
)
var sqlStore store.Store
-func Setup() store.Store {
+func StoreTest(t *testing.T, f func(*testing.T, store.Store)) {
if sqlStore == nil {
utils.TranslationsPreInit()
utils.LoadConfig("config.json")
@@ -19,133 +21,5 @@ func Setup() store.Store {
sqlStore.MarkSystemRanUnitTests()
}
- return sqlStore
-}
-
-/*
-func TestSqlStore1(t *testing.T) {
- utils.TranslationsPreInit()
- utils.LoadConfig("config.json")
- utils.Cfg.SqlSettings.Trace = true
-
- store := NewSqlStore()
- ss.Close()
-
- utils.Cfg.SqlSettings.DataSourceReplicas = []string{utils.Cfg.SqlSettings.DataSource}
-
- store = NewSqlStore()
- ss.TotalMasterDbConnections()
- ss.TotalReadDbConnections()
- ss.Close()
-
- utils.LoadConfig("config.json")
-}
-
-func TestAlertDbCmds(t *testing.T) {
- ss := Setup()
-
- sqlStore := store.(SqlStore)
-
- if !sqlStore.DoesTableExist("Systems") {
- t.Fatal("Failed table exists")
- }
-
- if sqlStore.DoesColumnExist("Systems", "Test") {
- t.Fatal("Column should not exist")
- }
-
- if !sqlStore.CreateColumnIfNotExists("Systems", "Test", "VARCHAR(50)", "VARCHAR(50)", "") {
- t.Fatal("Failed to create column")
- }
-
- maxLen := sqlStore.GetMaxLengthOfColumnIfExists("Systems", "Test")
-
- if maxLen != "50" {
- t.Fatal("Failed to get max length found " + maxLen)
- }
-
- if !sqlStore.AlterColumnTypeIfExists("Systems", "Test", "VARCHAR(25)", "VARCHAR(25)") {
- t.Fatal("failed to alter column size")
- }
-
- maxLen2 := sqlStore.GetMaxLengthOfColumnIfExists("Systems", "Test")
-
- if maxLen2 != "25" {
- t.Fatal("Failed to get max length")
- }
-
- if !sqlStore.RenameColumnIfExists("Systems", "Test", "Test1", "VARCHAR(25)") {
- t.Fatal("Failed to rename column")
- }
-
- if sqlStore.DoesColumnExist("Systems", "Test") {
- t.Fatal("Column should not exist")
- }
-
- if !sqlStore.DoesColumnExist("Systems", "Test1") {
- t.Fatal("Column should exist")
- }
-
- sqlStore.CreateIndexIfNotExists("idx_systems_test1", "Systems", "Test1")
- sqlStore.RemoveIndexIfExists("idx_systems_test1", "Systems")
-
- sqlStore.CreateFullTextIndexIfNotExists("idx_systems_test1", "Systems", "Test1")
- sqlStore.RemoveIndexIfExists("idx_systems_test1", "Systems")
-
- if !sqlStore.RemoveColumnIfExists("Systems", "Test1") {
- t.Fatal("Failed to remove columns")
- }
-
- if sqlStore.DoesColumnExist("Systems", "Test1") {
- t.Fatal("Column should not exist")
- }
-}
-
-func TestCreateIndexIfNotExists(t *testing.T) {
- ss := Setup()
-
- sqlStore := store.(SqlStore)
-
- defer sqlStore.RemoveColumnIfExists("Systems", "Test")
- if !sqlStore.CreateColumnIfNotExists("Systems", "Test", "VARCHAR(50)", "VARCHAR(50)", "") {
- t.Fatal("Failed to create test column")
- }
-
- defer sqlStore.RemoveIndexIfExists("idx_systems_create_index_test", "Systems")
- if !sqlStore.CreateIndexIfNotExists("idx_systems_create_index_test", "Systems", "Test") {
- t.Fatal("Should've created test index")
- }
-
- if sqlStore.CreateIndexIfNotExists("idx_systems_create_index_test", "Systems", "Test") {
- t.Fatal("Shouldn't have created index that already exists")
- }
-}
-
-func TestRemoveIndexIfExists(t *testing.T) {
- ss := Setup()
-
- sqlStore := store.(SqlStore)
-
- defer sqlStore.RemoveColumnIfExists("Systems", "Test")
- if !sqlStore.CreateColumnIfNotExists("Systems", "Test", "VARCHAR(50)", "VARCHAR(50)", "") {
- t.Fatal("Failed to create test column")
- }
-
- if sqlStore.RemoveIndexIfExists("idx_systems_remove_index_test", "Systems") {
- t.Fatal("Should've failed to remove index that doesn't exist")
- }
-
- defer sqlStore.RemoveIndexIfExists("idx_systems_remove_index_test", "Systems")
- if !sqlStore.CreateIndexIfNotExists("idx_systems_remove_index_test", "Systems", "Test") {
- t.Fatal("Should've created test index")
- }
-
- if !sqlStore.RemoveIndexIfExists("idx_systems_remove_index_test", "Systems") {
- t.Fatal("Should've removed index that exists")
- }
-
- if sqlStore.RemoveIndexIfExists("idx_systems_remove_index_test", "Systems") {
- t.Fatal("Should've failed to remove index that was already removed")
- }
+ f(t, sqlStore)
}
-*/