summaryrefslogtreecommitdiffstats
path: root/store/sql_store_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-01-27 09:30:33 -0500
committerChristopher Speller <crspeller@gmail.com>2017-01-27 09:30:33 -0500
commit8d2e8525a445a80085282142375b0cc68916d552 (patch)
treec2627b71c568346bbcca7be4a555744e3c2c757c /store/sql_store_test.go
parentcfbace70ca4222e7abba92c5e3af7440539452c7 (diff)
parent0d8bb03b5773923cf52f4d8cb2711131caae105c (diff)
downloadchat-8d2e8525a445a80085282142375b0cc68916d552.tar.gz
chat-8d2e8525a445a80085282142375b0cc68916d552.tar.bz2
chat-8d2e8525a445a80085282142375b0cc68916d552.zip
Merge branch 'release-3.6'
Diffstat (limited to 'store/sql_store_test.go')
-rw-r--r--store/sql_store_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/store/sql_store_test.go b/store/sql_store_test.go
index d65d591ad..3c6081e3c 100644
--- a/store/sql_store_test.go
+++ b/store/sql_store_test.go
@@ -118,3 +118,51 @@ func TestAlertDbCmds(t *testing.T) {
t.Fatal("Column should not exist")
}
}
+
+func TestCreateIndexIfNotExists(t *testing.T) {
+ 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) {
+ 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")
+ }
+}