diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/api.go | 2 | ||||
-rw-r--r-- | utils/authorization.go | 2 | ||||
-rw-r--r-- | utils/config.go | 20 | ||||
-rw-r--r-- | utils/config_test.go | 2 | ||||
-rw-r--r-- | utils/emoji.go | 62 | ||||
-rw-r--r-- | utils/html.go | 2 | ||||
-rw-r--r-- | utils/license.go | 2 | ||||
-rw-r--r-- | utils/license_test.go | 2 | ||||
-rw-r--r-- | utils/log.go | 2 | ||||
-rw-r--r-- | utils/mail.go | 2 | ||||
-rw-r--r-- | utils/mail_test.go | 2 | ||||
-rw-r--r-- | utils/password.go | 2 | ||||
-rw-r--r-- | utils/random.go | 2 | ||||
-rw-r--r-- | utils/textgeneration.go | 2 | ||||
-rw-r--r-- | utils/time_test.go | 2 | ||||
-rw-r--r-- | utils/urlencode.go | 2 | ||||
-rw-r--r-- | utils/urlencode_test.go | 2 | ||||
-rw-r--r-- | utils/utils.go | 2 | ||||
-rw-r--r-- | utils/utils_test.go | 2 |
19 files changed, 94 insertions, 22 deletions
diff --git a/utils/api.go b/utils/api.go index 388271bd2..228808f3c 100644 --- a/utils/api.go +++ b/utils/api.go @@ -1,4 +1,4 @@ -// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/authorization.go b/utils/authorization.go index 8078f4023..7dbb0c808 100644 --- a/utils/authorization.go +++ b/utils/authorization.go @@ -1,4 +1,4 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/config.go b/utils/config.go index 8c80d5349..802dfc2e9 100644 --- a/utils/config.go +++ b/utils/config.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils @@ -37,6 +37,7 @@ var CfgDiagnosticId = "" var CfgHash = "" var ClientCfgHash = "" var CfgFileName string = "" +var CfgDisableConfigWatch = false var ClientCfg map[string]string = map[string]string{} var originalDisableDebugLvl l4g.Level = l4g.DEBUG var siteURL = "" @@ -67,6 +68,8 @@ func FindDir(dir string) string { fileName, _ = filepath.Abs("./" + dir + "/") } else if _, err := os.Stat("../" + dir + "/"); err == nil { fileName, _ = filepath.Abs("../" + dir + "/") + } else if _, err := os.Stat("../../" + dir + "/"); err == nil { + fileName, _ = filepath.Abs("../../" + dir + "/") } return fileName + "/" @@ -177,6 +180,10 @@ func InitializeConfigWatch() { cfgMutex.Lock() defer cfgMutex.Unlock() + if CfgDisableConfigWatch { + return + } + if watcher == nil { var err error watcher, err = fsnotify.NewWatcher() @@ -214,11 +221,13 @@ func EnableConfigWatch() { cfgMutex.Lock() defer cfgMutex.Unlock() - configFile := filepath.Clean(CfgFileName) - configDir, _ := filepath.Split(configFile) - if watcher != nil { - watcher.Add(configDir) + configFile := filepath.Clean(CfgFileName) + configDir, _ := filepath.Split(configFile) + + if watcher != nil { + watcher.Add(configDir) + } } } @@ -258,6 +267,7 @@ func LoadConfig(fileName string) { viper.SetConfigType("json") viper.AddConfigPath("./config") viper.AddConfigPath("../config") + viper.AddConfigPath("../../config") viper.AddConfigPath(".") configReadErr := viper.ReadInConfig() diff --git a/utils/config_test.go b/utils/config_test.go index c15165fe5..755cd9acd 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/emoji.go b/utils/emoji.go new file mode 100644 index 000000000..ced3c4ddd --- /dev/null +++ b/utils/emoji.go @@ -0,0 +1,62 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package utils + +import ( + "bytes" + "image" + "image/color" + "image/gif" + "image/jpeg" + "image/png" + "testing" +) + +func CreateTestGif(t *testing.T, width int, height int) []byte { + var buffer bytes.Buffer + + if err := gif.Encode(&buffer, image.NewRGBA(image.Rect(0, 0, width, height)), nil); err != nil { + t.Fatalf("failed to create gif: %v", err.Error()) + } + + return buffer.Bytes() +} + +func CreateTestAnimatedGif(t *testing.T, width int, height int, frames int) []byte { + var buffer bytes.Buffer + + img := gif.GIF{ + Image: make([]*image.Paletted, frames, frames), + Delay: make([]int, frames, frames), + } + for i := 0; i < frames; i++ { + img.Image[i] = image.NewPaletted(image.Rect(0, 0, width, height), color.Palette{color.Black}) + img.Delay[i] = 0 + } + if err := gif.EncodeAll(&buffer, &img); err != nil { + t.Fatalf("failed to create animated gif: %v", err.Error()) + } + + return buffer.Bytes() +} + +func CreateTestJpeg(t *testing.T, width int, height int) []byte { + var buffer bytes.Buffer + + if err := jpeg.Encode(&buffer, image.NewRGBA(image.Rect(0, 0, width, height)), nil); err != nil { + t.Fatalf("failed to create jpeg: %v", err.Error()) + } + + return buffer.Bytes() +} + +func CreateTestPng(t *testing.T, width int, height int) []byte { + var buffer bytes.Buffer + + if err := png.Encode(&buffer, image.NewRGBA(image.Rect(0, 0, width, height))); err != nil { + t.Fatalf("failed to create png: %v", err.Error()) + } + + return buffer.Bytes() +} diff --git a/utils/html.go b/utils/html.go index 48033b43e..c902030d8 100644 --- a/utils/html.go +++ b/utils/html.go @@ -1,4 +1,4 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/license.go b/utils/license.go index f0763d741..d3e2c1362 100644 --- a/utils/license.go +++ b/utils/license.go @@ -1,4 +1,4 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/license_test.go b/utils/license_test.go index 7a30070b3..289262f4c 100644 --- a/utils/license_test.go +++ b/utils/license_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/log.go b/utils/log.go index 360c785d0..ab2750f36 100644 --- a/utils/log.go +++ b/utils/log.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/mail.go b/utils/mail.go index 959a60fb2..ea62fab12 100644 --- a/utils/mail.go +++ b/utils/mail.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/mail_test.go b/utils/mail_test.go index 523ca0ba5..774ecbf5b 100644 --- a/utils/mail_test.go +++ b/utils/mail_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/password.go b/utils/password.go index b129869d3..6aa785df8 100644 --- a/utils/password.go +++ b/utils/password.go @@ -1,4 +1,4 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/random.go b/utils/random.go index 99743e777..8f3008f9d 100644 --- a/utils/random.go +++ b/utils/random.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/textgeneration.go b/utils/textgeneration.go index 96c43f402..eeabe4705 100644 --- a/utils/textgeneration.go +++ b/utils/textgeneration.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/time_test.go b/utils/time_test.go index 7d65046bf..451ceb5aa 100644 --- a/utils/time_test.go +++ b/utils/time_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/urlencode.go b/utils/urlencode.go index dc8b9acfd..0110ab6e3 100644 --- a/utils/urlencode.go +++ b/utils/urlencode.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/urlencode_test.go b/utils/urlencode_test.go index 04d69fd98..2ba453c73 100644 --- a/utils/urlencode_test.go +++ b/utils/urlencode_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/utils.go b/utils/utils.go index 6d34387c4..f34c82f24 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,4 +1,4 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils diff --git a/utils/utils_test.go b/utils/utils_test.go index 88356dadb..b80247867 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package utils |