summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-10-15 11:16:26 -0700
committer=Corey Hulen <corey@hulen.com>2015-10-15 11:16:26 -0700
commitde717aef56dfaa0b9b676ce82d4b9d7abdb12428 (patch)
treee35cbb702a1c6d508f3295865739186a1b3f44c9
parentadc20981e2c370f09467d4fa249065d23f533a0a (diff)
downloadchat-de717aef56dfaa0b9b676ce82d4b9d7abdb12428.tar.gz
chat-de717aef56dfaa0b9b676ce82d4b9d7abdb12428.tar.bz2
chat-de717aef56dfaa0b9b676ce82d4b9d7abdb12428.zip
Marking when user ran the unit tests
-rw-r--r--api/api_test.go2
-rw-r--r--mattermost.go14
-rw-r--r--model/system.go6
-rw-r--r--store/sql_store.go22
-rw-r--r--store/sql_store_test.go7
-rw-r--r--store/store.go1
-rw-r--r--utils/diagnostic.go1
-rw-r--r--web/web_test.go11
8 files changed, 49 insertions, 15 deletions
diff --git a/api/api_test.go b/api/api_test.go
index bea949ad2..2ef4e196d 100644
--- a/api/api_test.go
+++ b/api/api_test.go
@@ -19,6 +19,8 @@ func Setup() {
StartServer()
InitApi()
Client = model.NewClient("http://localhost" + utils.Cfg.ServiceSettings.ListenAddress)
+
+ Srv.Store.MarkSystemRanUnitTests()
}
}
diff --git a/mattermost.go b/mattermost.go
index d2a0567f4..48487ee73 100644
--- a/mattermost.go
+++ b/mattermost.go
@@ -84,16 +84,16 @@ func securityAndDiagnosticsJob() {
if *utils.Cfg.ServiceSettings.EnableSecurityFixAlert {
if result := <-api.Srv.Store.System().Get(); result.Err == nil {
props := result.Data.(model.StringMap)
- lastSecurityTime, _ := strconv.ParseInt(props["LastSecurityTime"], 10, 0)
+ lastSecurityTime, _ := strconv.ParseInt(props[model.SYSTEM_LAST_SECURITY_TIME], 10, 0)
currentTime := model.GetMillis()
if (currentTime - lastSecurityTime) > 1000*60*60*24*1 {
l4g.Debug("Checking for security update from Mattermost")
- id := props["DiagnosticId"]
+ id := props[model.SYSTEM_DIAGNOSTIC_ID]
if len(id) == 0 {
id = model.NewId()
- systemId := &model.System{Name: "DiagnosticId", Value: id}
+ systemId := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id}
<-api.Srv.Store.System().Save(systemId)
}
@@ -104,7 +104,13 @@ func securityAndDiagnosticsJob() {
v.Set(utils.PROP_DIAGNOSTIC_OS, runtime.GOOS)
v.Set(utils.PROP_DIAGNOSTIC_CATEGORY, utils.VAL_DIAGNOSTIC_CATEGORY_DEFAULT)
- systemSecurityLastTime := &model.System{Name: "LastSecurityTime", Value: strconv.FormatInt(currentTime, 10)}
+ if len(props[model.SYSTEM_RAN_UNIT_TESTS]) > 0 {
+ v.Set(utils.PROP_DIAGNOSTIC_UNIT_TESTS, "1")
+ } else {
+ v.Set(utils.PROP_DIAGNOSTIC_UNIT_TESTS, "0")
+ }
+
+ systemSecurityLastTime := &model.System{Name: model.SYSTEM_LAST_SECURITY_TIME, Value: strconv.FormatInt(currentTime, 10)}
if lastSecurityTime == 0 {
<-api.Srv.Store.System().Save(systemSecurityLastTime)
} else {
diff --git a/model/system.go b/model/system.go
index 033f660b3..70db529d5 100644
--- a/model/system.go
+++ b/model/system.go
@@ -8,6 +8,12 @@ import (
"io"
)
+const (
+ SYSTEM_DIAGNOSTIC_ID = "DiagnosticId"
+ SYSTEM_RAN_UNIT_TESTS = "RanUnitTests"
+ SYSTEM_LAST_SECURITY_TIME = "LastSecurityTime"
+)
+
type System struct {
Name string `json:"name"`
Value string `json:"value"`
diff --git a/store/sql_store.go b/store/sql_store.go
index 4b055e455..692ac2664 100644
--- a/store/sql_store.go
+++ b/store/sql_store.go
@@ -16,17 +16,18 @@ import (
"encoding/json"
"errors"
"fmt"
- "github.com/go-gorp/gorp"
- _ "github.com/go-sql-driver/mysql"
- _ "github.com/lib/pq"
- "github.com/mattermost/platform/model"
- "github.com/mattermost/platform/utils"
"io"
sqltrace "log"
"math/rand"
"os"
"strings"
"time"
+
+ "github.com/go-gorp/gorp"
+ _ "github.com/go-sql-driver/mysql"
+ _ "github.com/lib/pq"
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
)
type SqlStore struct {
@@ -179,6 +180,17 @@ func (ss SqlStore) GetCurrentSchemaVersion() string {
return version
}
+func (ss SqlStore) MarkSystemRanUnitTests() {
+ if result := <-ss.System().Get(); result.Err == nil {
+ props := result.Data.(model.StringMap)
+ unitTests := props[model.SYSTEM_RAN_UNIT_TESTS]
+ if len(unitTests) == 0 {
+ systemTests := &model.System{Name: model.SYSTEM_RAN_UNIT_TESTS, Value: "1"}
+ <-ss.System().Save(systemTests)
+ }
+ }
+}
+
func (ss SqlStore) DoesTableExist(tableName string) bool {
if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
count, err := ss.GetMaster().SelectInt(
diff --git a/store/sql_store_test.go b/store/sql_store_test.go
index a9e25cb33..1e04b676c 100644
--- a/store/sql_store_test.go
+++ b/store/sql_store_test.go
@@ -4,10 +4,11 @@
package store
import (
- "github.com/mattermost/platform/model"
- "github.com/mattermost/platform/utils"
"strings"
"testing"
+
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
)
var store Store
@@ -16,6 +17,8 @@ func Setup() {
if store == nil {
utils.LoadConfig("config.json")
store = NewSqlStore()
+
+ store.MarkSystemRanUnitTests()
}
}
diff --git a/store/store.go b/store/store.go
index 6e1614ccb..b436a5c40 100644
--- a/store/store.go
+++ b/store/store.go
@@ -38,6 +38,7 @@ type Store interface {
System() SystemStore
Webhook() WebhookStore
Preference() PreferenceStore
+ MarkSystemRanUnitTests()
Close()
}
diff --git a/utils/diagnostic.go b/utils/diagnostic.go
index 8572c2f51..fd24c2c25 100644
--- a/utils/diagnostic.go
+++ b/utils/diagnostic.go
@@ -19,6 +19,7 @@ const (
PROP_DIAGNOSTIC_OS = "os"
PROP_DIAGNOSTIC_USER_COUNT = "uc"
PROP_DIAGNOSTIC_ACTIVE_USER_COUNT = "auc"
+ PROP_DIAGNOSTIC_UNIT_TESTS = "ut"
)
func SendDiagnostic(values url.Values) {
diff --git a/web/web_test.go b/web/web_test.go
index ae29356c1..4e15037ad 100644
--- a/web/web_test.go
+++ b/web/web_test.go
@@ -4,15 +4,16 @@
package web
import (
- "github.com/mattermost/platform/api"
- "github.com/mattermost/platform/model"
- "github.com/mattermost/platform/store"
- "github.com/mattermost/platform/utils"
"net/http"
"net/url"
"strings"
"testing"
"time"
+
+ "github.com/mattermost/platform/api"
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/store"
+ "github.com/mattermost/platform/utils"
)
var ApiClient *model.Client
@@ -27,6 +28,8 @@ func Setup() {
InitWeb()
URL = "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress
ApiClient = model.NewClient(URL)
+
+ api.Srv.Store.MarkSystemRanUnitTests()
}
}