summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-30 11:58:00 -0500
committerGitHub <noreply@github.com>2017-10-30 11:58:00 -0500
commit3cbacb6858ea2dda67719de64854ed30dea3b626 (patch)
tree8d0177242e65c809250fa73bd93faae26bd1ca10
parentc5e8cb25caa39ed018ede5270e1566e8f7448396 (diff)
downloadchat-3cbacb6858ea2dda67719de64854ed30dea3b626.tar.gz
chat-3cbacb6858ea2dda67719de64854ed30dea3b626.tar.bz2
chat-3cbacb6858ea2dda67719de64854ed30dea3b626.zip
Remove unused variables / code (#7736)
* remove unused variables / code * fix bug in testPostStoreGetOldest
-rw-r--r--api/context.go1
-rw-r--r--api/emoji.go4
-rw-r--r--cmd/platform/cmdtestlib.go45
-rw-r--r--cmd/platform/output.go12
-rw-r--r--model/config.go4
-rw-r--r--plugin/rpcplugin/muxer.go1
-rw-r--r--store/layered_store_hints.go11
-rw-r--r--store/sqlstore/channel_store.go5
-rw-r--r--store/storetest/post_store.go2
-rw-r--r--utils/logger/logger.go11
-rw-r--r--utils/logger/logger_test.go281
11 files changed, 6 insertions, 371 deletions
diff --git a/api/context.go b/api/context.go
index 778df4625..fee78dbfd 100644
--- a/api/context.go
+++ b/api/context.go
@@ -32,7 +32,6 @@ type Context struct {
T goi18n.TranslateFunc
Locale string
TeamId string
- isSystemAdmin bool
}
func (api *API) ApiAppHandler(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
diff --git a/api/emoji.go b/api/emoji.go
index 8e89cf075..4edbbd082 100644
--- a/api/emoji.go
+++ b/api/emoji.go
@@ -192,10 +192,6 @@ func getEmojiImage(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write(image)
}
-func getEmojiImagePath(id string) string {
- return "emoji/" + id + "/image"
-}
-
func resizeEmoji(img image.Image, width int, height int) image.Image {
emojiWidth := float64(width)
emojiHeight := float64(height)
diff --git a/cmd/platform/cmdtestlib.go b/cmd/platform/cmdtestlib.go
deleted file mode 100644
index 16bfc2b21..000000000
--- a/cmd/platform/cmdtestlib.go
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-package main
-
-import (
- "bytes"
- "strings"
-
- "github.com/spf13/cobra"
- "github.com/spf13/pflag"
-)
-
-func runCommand(argString string) error {
- err, _ := runCommandWithOutput(argString)
-
- return err
-}
-
-func runCommandWithOutput(argString string) (error, string) {
- // Set arguments on the root command
- rootCmd.SetArgs(strings.Split(argString, " "))
- defer rootCmd.SetArgs([]string{})
-
- output := new(bytes.Buffer)
- rootCmd.SetOutput(output)
- defer rootCmd.SetOutput(nil)
-
- // Executing the root command will call the necessary subcommand
- cmd, err := rootCmd.ExecuteC()
-
- // And clear the arguments on the subcommand that was actually called since they'd otherwise
- // be used on the next call to this command
- clearArgs(cmd)
-
- return err, output.String()
-}
-
-func clearArgs(command *cobra.Command) {
- command.Flags().VisitAll(clearFlag)
-}
-
-func clearFlag(flag *pflag.Flag) {
- flag.Value.Set(flag.DefValue)
-}
diff --git a/cmd/platform/output.go b/cmd/platform/output.go
index e4666910e..edf6ccc71 100644
--- a/cmd/platform/output.go
+++ b/cmd/platform/output.go
@@ -11,22 +11,10 @@ func CommandPrintln(a ...interface{}) (int, error) {
return fmt.Println(a...)
}
-func CommandPrint(a ...interface{}) (int, error) {
- return fmt.Print(a...)
-}
-
func CommandPrintErrorln(a ...interface{}) (int, error) {
return fmt.Fprintln(os.Stderr, a...)
}
-func CommandPrintError(a ...interface{}) (int, error) {
- return fmt.Fprint(os.Stderr, a...)
-}
-
func CommandPrettyPrintln(a ...interface{}) (int, error) {
return fmt.Fprintln(os.Stderr, a...)
}
-
-func CommandPrettyPrint(a ...interface{}) (int, error) {
- return fmt.Fprint(os.Stderr, a...)
-}
diff --git a/model/config.go b/model/config.go
index 41a5db8cd..6cc7251b8 100644
--- a/model/config.go
+++ b/model/config.go
@@ -586,10 +586,6 @@ func (o *Config) GetSSOService(service string) *SSOSettings {
return nil
}
-func (o *Config) getClientRequirementsFromConfig() ClientRequirements {
- return o.ClientRequirements
-}
-
func ConfigFromJson(data io.Reader) *Config {
decoder := json.NewDecoder(data)
var o Config
diff --git a/plugin/rpcplugin/muxer.go b/plugin/rpcplugin/muxer.go
index 8a8ce8933..a7260c399 100644
--- a/plugin/rpcplugin/muxer.go
+++ b/plugin/rpcplugin/muxer.go
@@ -223,7 +223,6 @@ type muxerStream struct {
readWake *sync.Cond
isClosed bool
remoteClosed bool
- closeErr error
}
func (s *muxerStream) Read(p []byte) (int, error) {
diff --git a/store/layered_store_hints.go b/store/layered_store_hints.go
index 064f4f326..066f0a2fa 100644
--- a/store/layered_store_hints.go
+++ b/store/layered_store_hints.go
@@ -18,14 +18,3 @@ func hintsContains(hints []LayeredStoreHint, contains LayeredStoreHint) bool {
}
return false
}
-
-func hintsContainsAny(hints []LayeredStoreHint, contains ...LayeredStoreHint) bool {
- for _, hint := range hints {
- for _, hint2 := range contains {
- if hint == hint2 {
- return true
- }
- }
- }
- return false
-}
diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go
index 2a22632a9..cf712d974 100644
--- a/store/sqlstore/channel_store.go
+++ b/store/sqlstore/channel_store.go
@@ -420,11 +420,6 @@ func (s SqlChannelStore) PermanentDeleteMembersByChannel(channelId string) store
})
}
-type channelWithMember struct {
- model.Channel
- model.ChannelMember
-}
-
func (s SqlChannelStore) GetChannels(teamId string, userId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
data := &model.ChannelList{}
diff --git a/store/storetest/post_store.go b/store/storetest/post_store.go
index b288cde34..afa8ae293 100644
--- a/store/storetest/post_store.go
+++ b/store/storetest/post_store.go
@@ -41,6 +41,7 @@ func TestPostStore(t *testing.T, ss store.Store) {
t.Run("GetPostsByIds", func(t *testing.T) { testPostStoreGetPostsByIds(t, ss) })
t.Run("GetPostsBatchForIndexing", func(t *testing.T) { testPostStoreGetPostsBatchForIndexing(t, ss) })
t.Run("PermanentDeleteBatch", func(t *testing.T) { testPostStorePermanentDeleteBatch(t, ss) })
+ t.Run("GetOldest", func(t *testing.T) { testPostStoreGetOldest(t, ss) })
}
func testPostStoreSave(t *testing.T, ss store.Store) {
@@ -1700,7 +1701,6 @@ func testPostStoreGetOldest(t *testing.T, ss store.Store) {
o1 = (<-ss.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
- o2.Id = model.NewId()
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "b"
diff --git a/utils/logger/logger.go b/utils/logger/logger.go
index 410a5a5fc..da549dcc4 100644
--- a/utils/logger/logger.go
+++ b/utils/logger/logger.go
@@ -28,15 +28,14 @@ var infoLog = l4g.Info
var errorLog = l4g.Error
func init() {
+ // listens for configuration changes that we might need to respond to
+ utils.AddConfigListener(func(oldConfig *model.Config, newConfig *model.Config) {
+ infoLog("Configuration change detected, reloading log settings")
+ initL4g(newConfig.LogSettings)
+ })
initL4g(utils.Cfg.LogSettings)
}
-// listens for configuration changes that we might need to respond to
-var configListenerID = utils.AddConfigListener(func(oldConfig *model.Config, newConfig *model.Config) {
- infoLog("Configuration change detected, reloading log settings")
- initL4g(newConfig.LogSettings)
-})
-
// assumes that ../config.go::configureLog has already been called, and has in turn called l4g.close() to clean up
// any old filters that we might have previously created
func initL4g(logSettings model.LogSettings) {
diff --git a/utils/logger/logger_test.go b/utils/logger/logger_test.go
deleted file mode 100644
index 3aba48561..000000000
--- a/utils/logger/logger_test.go
+++ /dev/null
@@ -1,281 +0,0 @@
-// this is a new logger interface for mattermost
-
-package logger
-
-type LogMessage struct {
- Context map[string]string
- File string
- Message string
-}
-
-const validPath = `^utils/([a-z_]+/)*logger_test.go$`
-
-/*
-
-Broken because code somehow depends on path
-
-// ensures that the relative path of the file that called into the logger is returned
-func TestGetCallerFilename(t *testing.T) {
- filename, _ := getCallerFilename()
- fmt.Println("Thing: " + filename)
- matched, err := regexp.MatchString(validPath, filename)
- require.NoError(t, err)
- assert.True(t, matched)
-}
-
-// ensures that values can be recorded on a Context object, and that the data in question is serialized as a part of the log message
-func TestSerializeContext(t *testing.T) {
- ctx := context.Background()
-
- expectedUserId := "some-fake-user-id"
- ctx = WithUserId(ctx, expectedUserId)
-
- expectedRequestId := "some-fake-request-id"
- ctx = WithRequestId(ctx, expectedRequestId)
-
- serialized := serializeContext(ctx)
-
- assert.Equal(t, map[string]string{
- "user_id": expectedUserId,
- "request_id": expectedRequestId,
- }, serialized)
-}
-
-// ensures that an entire log message with an empty context can be properly serialized into a JSON object
-func TestSerializeLogMessageEmptyContext(t *testing.T) {
- emptyContext := context.Background()
-
- var logMessage = "This is a log message"
- var serialized = serializeLogMessage(emptyContext, logMessage)
-
- var deserialized LogMessage
- json.Unmarshal([]byte(serialized), &deserialized)
-
- assert.Empty(t, deserialized.Context)
- assert.Equal(t, logMessage, deserialized.Message)
- matched, err := regexp.MatchString(validPath, deserialized.File)
- require.NoError(t, err)
- assert.True(t, matched)
-}
-
-// ensures that an entire log message with a populated context can be properly serialized into a JSON object
-func TestSerializeLogMessagePopulatedContext(t *testing.T) {
- populatedContext := context.Background()
-
- populatedContext = WithRequestId(populatedContext, "foo")
- populatedContext = WithUserId(populatedContext, "bar")
-
- var logMessage = "This is a log message"
- var serialized = serializeLogMessage(populatedContext, logMessage)
-
- var deserialized LogMessage
- json.Unmarshal([]byte(serialized), &deserialized)
-
- assert.Equal(t, map[string]string{
- "request_id": "foo",
- "user_id": "bar",
- }, deserialized.Context)
- assert.Equal(t, logMessage, deserialized.Message)
- matched, err := regexp.MatchString(validPath, deserialized.File)
- require.NoError(t, err)
- assert.True(t, matched)
-}
-
-// ensures that a debugLog message is passed through to the underlying logger as expected
-func TestDebugc(t *testing.T) {
- // inject a "mocked" debugLog method that captures the first argument that is passed to it
- var capture string
- oldDebug := debugLog
- defer func() { debugLog = oldDebug }()
- type WrapperType func() string
- debugLog = func(format interface{}, args ...interface{}) {
- // the code that we're testing passes a closure to the debugLog method, so we have to execute it to get the actual message back
- if f, ok := format.(func() string); ok {
- capture = WrapperType(f)()
- } else {
- t.Error("First parameter passed to Debug is not a closure")
- }
- }
-
- // log something
- emptyContext := context.Background()
- var logMessage = "Some log message"
- Debugc(emptyContext, logMessage)
-
- // check to see that the message is logged to the underlying log system, in this case our mock method
- var deserialized LogMessage
- json.Unmarshal([]byte(capture), &deserialized)
-
- assert.Empty(t, deserialized.Context)
- assert.Equal(t, logMessage, deserialized.Message)
- matched, err := regexp.MatchString(validPath, deserialized.File)
- require.NoError(t, err)
- assert.True(t, matched)
-}
-
-// ensures that a debugLog message is passed through to the underlying logger as expected
-func TestDebugf(t *testing.T) {
- // inject a "mocked" debugLog method that captures the first argument that is passed to it
- var capture string
- oldDebug := debugLog
- defer func() { debugLog = oldDebug }()
- type WrapperType func() string
- debugLog = func(format interface{}, args ...interface{}) {
- // the code that we're testing passes a closure to the debugLog method, so we have to execute it to get the actual message back
- if f, ok := format.(func() string); ok {
- capture = WrapperType(f)()
- } else {
- t.Error("First parameter passed to Debug is not a closure")
- }
- }
-
- // log something
- formatString := "Some %v message"
- param := "log"
- Debugf(formatString, param)
-
- // check to see that the message is logged to the underlying log system, in this case our mock method
- var deserialized LogMessage
- json.Unmarshal([]byte(capture), &deserialized)
-
- assert.Empty(t, deserialized.Context)
- assert.Equal(t, fmt.Sprintf(formatString, param), deserialized.Message)
- matched, err := regexp.MatchString(validPath, deserialized.File)
- require.NoError(t, err)
- assert.True(t, matched)
-}
-
-// ensures that an infoLog message is passed through to the underlying logger as expected
-func TestInfoc(t *testing.T) {
- // inject a "mocked" infoLog method that captures the first argument that is passed to it
- var capture string
- oldInfo := infoLog
- defer func() { infoLog = oldInfo }()
- type WrapperType func() string
- infoLog = func(format interface{}, args ...interface{}) {
- // the code that we're testing passes a closure to the infoLog method, so we have to execute it to get the actual message back
- if f, ok := format.(func() string); ok {
- capture = WrapperType(f)()
- } else {
- t.Error("First parameter passed to Info is not a closure")
- }
- }
-
- // log something
- emptyContext := context.Background()
- var logMessage = "Some log message"
- Infoc(emptyContext, logMessage)
-
- // check to see that the message is logged to the underlying log system, in this case our mock method
- var deserialized LogMessage
- json.Unmarshal([]byte(capture), &deserialized)
-
- assert.Empty(t, deserialized.Context)
- assert.Equal(t, logMessage, deserialized.Message)
- matched, err := regexp.MatchString(validPath, deserialized.File)
- require.NoError(t, err)
- assert.True(t, matched)
-}
-
-// ensures that an infoLog message is passed through to the underlying logger as expected
-func TestInfof(t *testing.T) {
- // inject a "mocked" infoLog method that captures the first argument that is passed to it
- var capture string
- oldInfo := infoLog
- defer func() { infoLog = oldInfo }()
- type WrapperType func() string
- infoLog = func(format interface{}, args ...interface{}) {
- // the code that we're testing passes a closure to the infoLog method, so we have to execute it to get the actual message back
- if f, ok := format.(func() string); ok {
- capture = WrapperType(f)()
- } else {
- t.Error("First parameter passed to Info is not a closure")
- }
- }
-
- // log something
- format := "Some %v message"
- param := "log"
- Infof(format, param)
-
- // check to see that the message is logged to the underlying log system, in this case our mock method
- var deserialized LogMessage
- json.Unmarshal([]byte(capture), &deserialized)
-
- assert.Empty(t, deserialized.Context)
- assert.Equal(t, fmt.Sprintf(format, param), deserialized.Message)
- matched, err := regexp.MatchString(validPath, deserialized.File)
- require.NoError(t, err)
- assert.True(t, matched)
-}
-
-// ensures that an error message is passed through to the underlying logger as expected
-func TestErrorc(t *testing.T) {
- // inject a "mocked" err method that captures the first argument that is passed to it
- var capture string
- oldError := errorLog
- defer func() { errorLog = oldError }()
- type WrapperType func() string
- errorLog = func(format interface{}, args ...interface{}) error {
- // the code that we're testing passes a closure to the err method, so we have to execute it to get the actual message back
- if f, ok := format.(func() string); ok {
- capture = WrapperType(f)()
- } else {
- t.Error("First parameter passed to Error is not a closure")
- }
-
- // the code under test doesn't care about this return value
- return errors.New(capture)
- }
-
- // log something
- emptyContext := context.Background()
- var logMessage = "Some log message"
- Errorc(emptyContext, logMessage)
-
- // check to see that the message is logged to the underlying log system, in this case our mock method
- var deserialized LogMessage
- json.Unmarshal([]byte(capture), &deserialized)
-
- assert.Empty(t, deserialized.Context)
- assert.Equal(t, logMessage, deserialized.Message)
- matched, err := regexp.MatchString(validPath, deserialized.File)
- require.NoError(t, err)
- assert.True(t, matched)
-}
-
-// ensures that an error message is passed through to the underlying logger as expected
-func TestErrorf(t *testing.T) {
- // inject a "mocked" err method that captures the first argument that is passed to it
- var capture string
- oldError := errorLog
- defer func() { errorLog = oldError }()
- type WrapperType func() string
- errorLog = func(format interface{}, args ...interface{}) error {
- // the code that we're testing passes a closure to the err method, so we have to execute it to get the actual message back
- if f, ok := format.(func() string); ok {
- capture = WrapperType(f)()
- } else {
- t.Error("First parameter passed to Error is not a closure")
- }
-
- // the code under test doesn't care about this return value
- return errors.New(capture)
- }
-
- // log something
- format := "Some %v message"
- param := "log"
- Errorf(format, param)
-
- // check to see that the message is logged to the underlying log system, in this case our mock method
- var deserialized LogMessage
- json.Unmarshal([]byte(capture), &deserialized)
-
- assert.Empty(t, deserialized.Context)
- assert.Equal(t, fmt.Sprintf(format, param), deserialized.Message)
- matched, err := regexp.MatchString(validPath, deserialized.File)
- require.NoError(t, err)
- assert.True(t, matched)
-}
-*/