From 9bf553559cd45f9a506b35d8e28b88138d78527e Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 25 Apr 2018 18:53:49 -0300 Subject: [PATCH] Apply gometalinter suggestions --- internal/file/filesystem.go | 6 +----- .../ingress/annotations/annotations_test.go | 1 - internal/ingress/annotations/authreq/main.go | 10 +++++----- .../ingress/annotations/luarestywaf/main.go | 4 ++-- internal/ingress/controller/nginx.go | 4 +--- .../controller/template/template_test.go | 18 +++++++++--------- internal/ingress/controller/util_test.go | 6 ------ test/e2e/framework/util.go | 2 +- 8 files changed, 19 insertions(+), 32 deletions(-) diff --git a/internal/file/filesystem.go b/internal/file/filesystem.go index 4099b98b9..5d138205c 100644 --- a/internal/file/filesystem.go +++ b/internal/file/filesystem.go @@ -135,9 +135,5 @@ func restoreAsset(dir, name string, fs Filesystem) error { //Missing info.Mode() - err = fs.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil + return fs.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) } diff --git a/internal/ingress/annotations/annotations_test.go b/internal/ingress/annotations/annotations_test.go index 4657de41e..729499836 100644 --- a/internal/ingress/annotations/annotations_test.go +++ b/internal/ingress/annotations/annotations_test.go @@ -37,7 +37,6 @@ var ( annotationPassthrough = parser.GetAnnotationWithPrefix("ssl-passthrough") annotationAffinityType = parser.GetAnnotationWithPrefix("affinity") annotationCorsEnabled = parser.GetAnnotationWithPrefix("enable-cors") - annotationCorsAllowOrigin = parser.GetAnnotationWithPrefix("cors-allow-origin") annotationCorsAllowMethods = parser.GetAnnotationWithPrefix("cors-allow-methods") annotationCorsAllowHeaders = parser.GetAnnotationWithPrefix("cors-allow-headers") annotationCorsAllowCredentials = parser.GetAnnotationWithPrefix("cors-allow-credentials") diff --git a/internal/ingress/annotations/authreq/main.go b/internal/ingress/annotations/authreq/main.go index d7356c89b..3f3376226 100644 --- a/internal/ingress/annotations/authreq/main.go +++ b/internal/ingress/annotations/authreq/main.go @@ -121,17 +121,17 @@ func (a authReq) Parse(ing *extensions.Ingress) (interface{}, error) { return nil, ing_errors.NewLocationDenied("an empty string is not a valid URL") } - authUrl, err := url.Parse(urlString) + authURL, err := url.Parse(urlString) if err != nil { return nil, err } - if authUrl.Scheme == "" { + if authURL.Scheme == "" { return nil, ing_errors.NewLocationDenied("url scheme is empty") } - if authUrl.Host == "" { + if authURL.Host == "" { return nil, ing_errors.NewLocationDenied("url host is empty") } - if strings.Contains(authUrl.Host, "..") { + if strings.Contains(authURL.Host, "..") { return nil, ing_errors.NewLocationDenied("invalid url host") } @@ -162,7 +162,7 @@ func (a authReq) Parse(ing *extensions.Ingress) (interface{}, error) { return &Config{ URL: urlString, - Host: authUrl.Hostname(), + Host: authURL.Hostname(), SigninURL: signIn, Method: authMethod, ResponseHeaders: responseHeaders, diff --git a/internal/ingress/annotations/luarestywaf/main.go b/internal/ingress/annotations/luarestywaf/main.go index 5664ac711..ca7f4a8be 100644 --- a/internal/ingress/annotations/luarestywaf/main.go +++ b/internal/ingress/annotations/luarestywaf/main.go @@ -33,8 +33,8 @@ var luaRestyWAFModes = map[string]bool{"ACTIVE": true, "INACTIVE": true, "SIMULA type Config struct { Mode string `json:"mode"` Debug bool `json:"debug"` - IgnoredRuleSets []string `json: "ignored-rulesets"` - ExtraRulesetString string `json: "extra-ruleset-string"` + IgnoredRuleSets []string `json:"ignored-rulesets"` + ExtraRulesetString string `json:"extra-ruleset-string"` } // Equal tests for equality between two Config types diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 4ad1e0440..12056cad1 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -73,7 +73,6 @@ const ( var ( tmplPath = "/etc/nginx/template/nginx.tmpl" - geoipPath = "/etc/nginx/geoip" cfgPath = "/etc/nginx/nginx.conf" nginxBinary = "/usr/sbin/nginx" ) @@ -158,8 +157,7 @@ func NewNGINXController(config *Configuration, fs file.Filesystem) *NGINXControl glog.Warning("Update of ingress status is disabled (flag --update-status=false was specified)") } - var onTemplateChange func() - onTemplateChange = func() { + onTemplateChange := func() { template, err := ngx_template.NewTemplate(tmplPath, fs) if err != nil { // this error is different from the rest because it must be clear why nginx is not working diff --git a/internal/ingress/controller/template/template_test.go b/internal/ingress/controller/template/template_test.go index 504a5b48e..0c1521245 100644 --- a/internal/ingress/controller/template/template_test.go +++ b/internal/ingress/controller/template/template_test.go @@ -530,39 +530,39 @@ func TestBuildDenyVariable(t *testing.T) { func TestBuildClientBodyBufferSize(t *testing.T) { a := isValidClientBodyBufferSize("1000") - if a != true { + if !a { t.Errorf("Expected '%v' but returned '%v'", true, a) } b := isValidClientBodyBufferSize("1000k") - if b != true { + if !b { t.Errorf("Expected '%v' but returned '%v'", true, b) } c := isValidClientBodyBufferSize("1000m") - if c != true { + if !c { t.Errorf("Expected '%v' but returned '%v'", true, c) } d := isValidClientBodyBufferSize("1000km") - if d != false { + if d { t.Errorf("Expected '%v' but returned '%v'", false, d) } e := isValidClientBodyBufferSize("1000mk") - if e != false { + if e { t.Errorf("Expected '%v' but returned '%v'", false, e) } f := isValidClientBodyBufferSize("1000kk") - if f != false { + if f { t.Errorf("Expected '%v' but returned '%v'", false, f) } g := isValidClientBodyBufferSize("1000mm") - if g != false { + if g { t.Errorf("Expected '%v' but returned '%v'", false, g) } h := isValidClientBodyBufferSize(nil) - if h != false { + if h { t.Errorf("Expected '%v' but returned '%v'", false, h) } i := isValidClientBodyBufferSize("") - if i != false { + if i { t.Errorf("Expected '%v' but returned '%v'", false, i) } } diff --git a/internal/ingress/controller/util_test.go b/internal/ingress/controller/util_test.go index b0691bab6..de85e783a 100644 --- a/internal/ingress/controller/util_test.go +++ b/internal/ingress/controller/util_test.go @@ -20,12 +20,6 @@ import ( "testing" ) -type fakeError struct{} - -func (fe *fakeError) Error() string { - return "fakeError" -} - func TestSysctlFSFileMax(t *testing.T) { i := sysctlFSFileMax() if i < 1 { diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 28c1fbce9..cc32aafb8 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -130,7 +130,7 @@ func DeleteKubeNamespace(c kubernetes.Interface, namespace string) error { return c.CoreV1().Namespaces().Delete(namespace, metav1.NewDeleteOptions(0)) } -// ExpectNoError tests whether an error occured. +// ExpectNoError tests whether an error occurred. func ExpectNoError(err error, explain ...interface{}) { if err != nil { Logf("Unexpected error occurred: %v", err)