From a2adf7b3f5ee106ea81a8996c10e026d87e07e34 Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Fri, 1 Nov 2019 23:08:01 +0100 Subject: [PATCH] Run unused against codebase (#12968) * Remove unused methods * Fix missed issues --- api4/job_test.go | 2 +- config/export_test.go | 5 ----- plugin/stringifier.go | 2 +- plugin/stringifier_test.go | 4 ++-- store/layered_store_hints.go | 9 --------- store/local_cache_supplier.go | 24 ------------------------ store/localcachelayer/layer_test.go | 13 ------------- web/handlers.go | 19 ------------------- 8 files changed, 4 insertions(+), 74 deletions(-) diff --git a/api4/job_test.go b/api4/job_test.go index e2426c5478..f24d4abde3 100644 --- a/api4/job_test.go +++ b/api4/job_test.go @@ -108,7 +108,7 @@ func TestGetJobs(t *testing.T) { received, resp = th.SystemAdminClient.GetJobs(1, 2) require.Nil(t, resp.Error) - require.Equal(t,jobs[1].Id, received[0].Id, "should've received oldest job last") + require.Equal(t, jobs[1].Id, received[0].Id, "should've received oldest job last") _, resp = th.Client.GetJobs(0, 60) CheckForbiddenStatus(t, resp) diff --git a/config/export_test.go b/config/export_test.go index b8ef523982..e818975c94 100644 --- a/config/export_test.go +++ b/config/export_test.go @@ -21,8 +21,3 @@ func UnmarshalConfig(r io.Reader, allowEnvironmentOverrides bool) (*model.Config func InitializeConfigurationsTable(db *sqlx.DB) error { return initializeConfigurationsTable(db) } - -// ResolveConfigFilePath exposes the internal resolveConfigFilePath to test only. -func ResolveConfigFilePath(path string) (string, error) { - return resolveConfigFilePath(path) -} diff --git a/plugin/stringifier.go b/plugin/stringifier.go index 1455fb4e63..4a438d1ce2 100644 --- a/plugin/stringifier.go +++ b/plugin/stringifier.go @@ -8,7 +8,7 @@ import ( ) func stringify(objects []interface{}) []string { - stringified := make([]string, len(objects), len(objects)) + stringified := make([]string, len(objects)) for i, object := range objects { stringified[i] = fmt.Sprintf("%+v", object) } diff --git a/plugin/stringifier_test.go b/plugin/stringifier_test.go index 58ae7e44d1..c9ac212939 100644 --- a/plugin/stringifier_test.go +++ b/plugin/stringifier_test.go @@ -15,7 +15,7 @@ func TestStringify(t *testing.T) { assert.Empty(t, strings) }) t.Run("EmptyShouldReturnEmpty", func(t *testing.T) { - strings := stringify(make([]interface{}, 0, 0)) + strings := stringify(make([]interface{}, 0)) assert.Empty(t, strings) }) t.Run("PrimitivesAndCompositesShouldReturnCorrectValues", func(t *testing.T) { @@ -83,7 +83,7 @@ func TestToObjects(t *testing.T) { assert.Nil(t, objects) }) t.Run("EmptyShouldReturnEmpty", func(t *testing.T) { - objects := toObjects(make([]string, 0, 0)) + objects := toObjects(make([]string, 0)) assert.Empty(t, objects) }) t.Run("ShouldReturnSliceOfObjects", func(t *testing.T) { diff --git a/store/layered_store_hints.go b/store/layered_store_hints.go index 066f0a2fab..6154af7c9f 100644 --- a/store/layered_store_hints.go +++ b/store/layered_store_hints.go @@ -9,12 +9,3 @@ const ( LSH_NO_CACHE LayeredStoreHint = iota LSH_MASTER_ONLY ) - -func hintsContains(hints []LayeredStoreHint, contains LayeredStoreHint) bool { - for _, hint := range hints { - if hint == contains { - return true - } - } - return false -} diff --git a/store/local_cache_supplier.go b/store/local_cache_supplier.go index 6dc971c226..76f084a115 100644 --- a/store/local_cache_supplier.go +++ b/store/local_cache_supplier.go @@ -49,30 +49,6 @@ func (s *LocalCacheSupplier) Next() LayeredStoreSupplier { return s.next } -func (s *LocalCacheSupplier) doStandardReadCache(ctx context.Context, cache ObjectCache, key string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { - if hintsContains(hints, LSH_NO_CACHE) { - if s.metrics != nil { - s.metrics.IncrementMemCacheMissCounter(cache.Name()) - } - return nil - } - - if cacheItem, ok := cache.Get(key); ok { - if s.metrics != nil { - s.metrics.IncrementMemCacheHitCounter(cache.Name()) - } - result := NewSupplierResult() - result.Data = cacheItem - return result - } - - if s.metrics != nil { - s.metrics.IncrementMemCacheMissCounter(cache.Name()) - } - - return nil -} - func (s *LocalCacheSupplier) doStandardAddToCache(ctx context.Context, cache ObjectCache, key string, result *LayeredStoreSupplierResult, hints ...LayeredStoreHint) { if result.Err == nil && result.Data != nil { cache.AddWithDefaultExpires(key, result.Data) diff --git a/store/localcachelayer/layer_test.go b/store/localcachelayer/layer_test.go index 71f3fefa82..d180ee9bdd 100644 --- a/store/localcachelayer/layer_test.go +++ b/store/localcachelayer/layer_test.go @@ -35,19 +35,6 @@ func StoreTest(t *testing.T, f func(*testing.T, store.Store)) { } } -func StoreTestWithSqlSupplier(t *testing.T, f func(*testing.T, store.Store, storetest.SqlSupplier)) { - defer func() { - if err := recover(); err != nil { - tearDownStores() - panic(err) - } - }() - for _, st := range storeTypes { - st := st - t.Run(st.Name, func(t *testing.T) { f(t, st.Store, st.SqlSupplier) }) - } -} - func initStores() { storeTypes = append(storeTypes, &storeType{ Name: "LocalCache+MySQL", diff --git a/web/handlers.go b/web/handlers.go index ea2885ba13..3bdaff286e 100644 --- a/web/handlers.go +++ b/web/handlers.go @@ -315,22 +315,3 @@ func (w *Web) ApiSessionRequired(h func(*Context, http.ResponseWriter, *http.Req } return handler } - -// apiHandlerTrustRequester provides a handler for API endpoints which do not require the user to be logged in and are -// allowed to be requested directly rather than via javascript/XMLHttpRequest, such as site branding images or the -// websocket. -func (w *Web) apiHandlerTrustRequester(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler { - handler := &Handler{ - GetGlobalAppOptions: w.GetGlobalAppOptions, - HandleFunc: h, - HandlerName: GetHandlerName(h), - RequireSession: false, - TrustRequester: true, - RequireMfa: false, - IsStatic: false, - } - if *w.ConfigService.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) - } - return handler -}