summaryrefslogtreecommitdiffstats
path: root/store/sql_store_test.go
diff options
context:
space:
mode:
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")
+ }
+}