summaryrefslogtreecommitdiffstats
path: root/store/sql_store_test.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-06-14 23:53:32 -0800
committer=Corey Hulen <corey@hulen.com>2015-06-14 23:53:32 -0800
commit56e74239d6b34df8f30ef046f0b0ff4ff0866a71 (patch)
tree044da29848cf0f5c8607eac34de69065171669cf /store/sql_store_test.go
downloadchat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.tar.gz
chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.tar.bz2
chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.zip
first commit
Diffstat (limited to 'store/sql_store_test.go')
-rw-r--r--store/sql_store_test.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/store/sql_store_test.go b/store/sql_store_test.go
new file mode 100644
index 000000000..84dbf5705
--- /dev/null
+++ b/store/sql_store_test.go
@@ -0,0 +1,83 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package store
+
+import (
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
+ "strings"
+ "testing"
+)
+
+var store Store
+
+func Setup() {
+ if store == nil {
+ utils.LoadConfig("config.json")
+ store = NewSqlStore()
+ }
+}
+
+func TestSqlStore1(t *testing.T) {
+ utils.LoadConfig("config.json")
+ utils.Cfg.SqlSettings.Trace = true
+
+ store := NewSqlStore()
+ store.Close()
+
+ utils.LoadConfig("config.json")
+}
+
+func TestSqlStore2(t *testing.T) {
+ defer func() {
+ if r := recover(); r == nil {
+ t.Fatal("should have been fatal")
+ }
+ }()
+
+ utils.LoadConfig("config.json")
+ utils.Cfg.SqlSettings.DriverName = "missing"
+ store = NewSqlStore()
+
+ utils.LoadConfig("config.json")
+}
+
+func TestSqlStore3(t *testing.T) {
+ defer func() {
+ if r := recover(); r == nil {
+ t.Fatal("should have been fatal")
+ }
+ }()
+
+ utils.LoadConfig("config.json")
+ utils.Cfg.SqlSettings.DataSource = "missing"
+ store = NewSqlStore()
+
+ utils.LoadConfig("config.json")
+}
+
+func TestEncrypt(t *testing.T) {
+ m := make(map[string]string)
+
+ key := []byte("IPc17oYK9NAj6WfJeCqm5AxIBF6WBNuN") // AES-256
+
+ originalText1 := model.MapToJson(m)
+ cryptoText1, _ := encrypt(key, originalText1)
+ text1, _ := decrypt(key, cryptoText1)
+ rm1 := model.MapFromJson(strings.NewReader(text1))
+
+ if len(rm1) != 0 {
+ t.Fatal("error in encrypt")
+ }
+
+ m["key"] = "value"
+ originalText2 := model.MapToJson(m)
+ cryptoText2, _ := encrypt(key, originalText2)
+ text2, _ := decrypt(key, cryptoText2)
+ rm2 := model.MapFromJson(strings.NewReader(text2))
+
+ if rm2["key"] != "value" {
+ t.Fatal("error in encrypt")
+ }
+}