diff --git a/cmd/plugin/request/request.go b/cmd/plugin/request/request.go index 7a893a65d..e1223a8a2 100644 --- a/cmd/plugin/request/request.go +++ b/cmd/plugin/request/request.go @@ -192,7 +192,7 @@ func tryAllNamespacesEndpointsCache(flags *genericclioptions.ConfigFlags) { } func tryFilteringEndpointsFromAllNamespacesCache(flags *genericclioptions.ConfigFlags, namespace string) *[]apiv1.Endpoints { - allEndpoints, _ := endpointsCache[""] + allEndpoints := endpointsCache[""] if allEndpoints != nil { endpoints := make([]apiv1.Endpoints, 0) for _, thisEndpoints := range *allEndpoints { diff --git a/internal/ingress/annotations/fastcgi/main_test.go b/internal/ingress/annotations/fastcgi/main_test.go index 3662bbbeb..6802a41c2 100644 --- a/internal/ingress/annotations/fastcgi/main_test.go +++ b/internal/ingress/annotations/fastcgi/main_test.go @@ -79,7 +79,7 @@ func TestParseEmptyFastCGIAnnotations(t *testing.T) { t.Errorf("Index should be an empty string") } - if 0 != len(config.Params) { + if len(config.Params) != 0 { t.Errorf("Params should be an empty slice") } } @@ -125,7 +125,7 @@ func TestParseEmptyFastCGIParamsConfigMapAnnotation(t *testing.T) { t.Errorf("Parse do not return a Config object") } - if 0 != len(config.Params) { + if len(config.Params) != 0 { t.Errorf("Params should be an empty slice") } } @@ -150,7 +150,7 @@ func TestParseFastCGIInvalidParamsConfigMapAnnotation(t *testing.T) { t.Errorf("Parse do not return a Config object") } - if 0 != len(config.Params) { + if len(config.Params) != 0 { t.Errorf("Params should be an empty slice") } } @@ -173,11 +173,11 @@ func TestParseFastCGIParamsConfigMapAnnotationWithoutNS(t *testing.T) { t.Errorf("Parse do not return a Config object") } - if 2 != len(config.Params) { + if len(config.Params) != 2 { t.Errorf("Params should have a length of 2") } - if "200" != config.Params["REDIRECT_STATUS"] || "$server_name" != config.Params["SERVER_NAME"] { + if config.Params["REDIRECT_STATUS"] != "200" || config.Params["SERVER_NAME"] != "$server_name" { t.Errorf("Params value is not the one expected") } } @@ -199,11 +199,11 @@ func TestParseFastCGIParamsConfigMapAnnotationWithNS(t *testing.T) { t.Errorf("Parse do not return a Config object") } - if 2 != len(config.Params) { + if len(config.Params) != 2 { t.Errorf("Params should have a length of 2") } - if "200" != config.Params["REDIRECT_STATUS"] || "$server_name" != config.Params["SERVER_NAME"] { + if config.Params["REDIRECT_STATUS"] != "200" || config.Params["SERVER_NAME"] != "$server_name" { t.Errorf("Params value is not the one expected") } } diff --git a/internal/ingress/controller/nginx_test.go b/internal/ingress/controller/nginx_test.go index 7590fceb3..710e071bd 100644 --- a/internal/ingress/controller/nginx_test.go +++ b/internal/ingress/controller/nginx_test.go @@ -295,13 +295,13 @@ func TestConfigureDynamically(t *testing.T) { if err != nil { t.Errorf("unexpected error posting dynamic configuration: %v", err) } - if count, _ := endpointStats["/configuration/backends"]; count != 0 { + if count := endpointStats["/configuration/backends"]; count != 0 { t.Errorf("Expected %v to receive %d requests but received %d.", "/configuration/backends", 0, count) } - if count, _ := endpointStats["/configuration/servers"]; count != 0 { + if count := endpointStats["/configuration/servers"]; count != 0 { t.Errorf("Expected %v to receive %d requests but received %d.", "/configuration/servers", 0, count) } - if count, _ := endpointStats["/configuration/general"]; count != 1 { + if count := endpointStats["/configuration/general"]; count != 1 { t.Errorf("Expected %v to receive %d requests but received %d.", "/configuration/general", 0, count) } diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 72d84cf27..25277537d 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -217,10 +217,8 @@ func quote(input interface{}) string { switch input := input.(type) { case string: inputStr = input - break case fmt.Stringer: inputStr = input.String() - break default: inputStr = fmt.Sprintf("%v", input) } diff --git a/internal/ingress/controller/template/template_test.go b/internal/ingress/controller/template/template_test.go index 08e07d681..00c909054 100644 --- a/internal/ingress/controller/template/template_test.go +++ b/internal/ingress/controller/template/template_test.go @@ -220,7 +220,11 @@ func TestBuildLuaSharedDictionaries(t *testing.T) { } // test invalid config configuration = buildLuaSharedDictionaries(invalidType, servers, false) - if expected != actual { + if configuration != "" { + t.Errorf("expected an empty string, but got %s", configuration) + } + + if actual != expected { t.Errorf("Expected '%v' but returned '%v' ", expected, actual) } } @@ -233,7 +237,7 @@ func TestLuaConfigurationRequestBodySize(t *testing.T) { } size := luaConfigurationRequestBodySize(cfg) - if "21" != size { + if size != "21" { t.Errorf("expected the size to be 20 but got: %v", size) } } diff --git a/internal/ingress/defaults/main.go b/internal/ingress/defaults/main.go index 1e43c67b1..f3034d202 100644 --- a/internal/ingress/defaults/main.go +++ b/internal/ingress/defaults/main.go @@ -29,7 +29,7 @@ type Backend struct { // http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors // http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page // By default this is disabled - CustomHTTPErrors []int `json:"custom-http-errors,-"` + CustomHTTPErrors []int `json:"custom-http-errors"` // http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size // Sets the maximum allowed size of the client request body @@ -102,7 +102,7 @@ type Backend struct { // SkipAccessLogURLs sets a list of URLs that should not appear in the NGINX access log // This is useful with urls like `/health` or `health-check` that make "complex" reading the logs // By default this list is empty - SkipAccessLogURLs []string `json:"skip-access-log-urls,-"` + SkipAccessLogURLs []string `json:"skip-access-log-urls"` // Enables or disables the redirect (301) to the HTTPS port SSLRedirect bool `json:"ssl-redirect"` @@ -134,7 +134,7 @@ type Backend struct { // WhitelistSourceRange allows limiting access to certain client addresses // http://nginx.org/en/docs/http/ngx_http_access_module.html - WhitelistSourceRange []string `json:"whitelist-source-range,-"` + WhitelistSourceRange []string `json:"whitelist-source-range"` // Limits the rate of response transmission to a client. // The rate is specified in bytes per second. The zero value disables rate limiting. diff --git a/test/e2e/annotations/auth.go b/test/e2e/annotations/auth.go index b0d483bf2..210707539 100644 --- a/test/e2e/annotations/auth.go +++ b/test/e2e/annotations/auth.go @@ -432,7 +432,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Auth", func() { err := f.DeleteDeployment("httpbin") Expect(err).NotTo(HaveOccurred()) - resp, _, errs = gorequest.New(). + _, _, errs = gorequest.New(). Get(f.GetURL(framework.HTTP)+fooPath). Retry(10, 1*time.Second, http.StatusNotFound). Set("Host", thisHost). diff --git a/test/e2e/defaultbackend/default_backend.go b/test/e2e/defaultbackend/default_backend.go index 04dec9f39..368dad90c 100644 --- a/test/e2e/defaultbackend/default_backend.go +++ b/test/e2e/defaultbackend/default_backend.go @@ -27,8 +27,6 @@ import ( "k8s.io/ingress-nginx/test/e2e/framework" ) -const defaultBackend = "default backend - 404" - var _ = framework.IngressNginxDescribe("Default backend", func() { f := framework.NewDefaultFramework("default-backend") diff --git a/test/e2e/framework/exec.go b/test/e2e/framework/exec.go index bd7ba108f..062d91ec0 100644 --- a/test/e2e/framework/exec.go +++ b/test/e2e/framework/exec.go @@ -93,7 +93,7 @@ func (f *Framework) NewIngressController(namespace string, namespaceOverlay stri cmd := exec.Command("./wait-for-nginx.sh", namespace, namespaceOverlay) out, err := cmd.CombinedOutput() if err != nil { - return fmt.Errorf("Unexpected error waiting for ingress controller deployment: %v.\nLogs:\n%v", err, string(out)) + return fmt.Errorf("unexpected error waiting for ingress controller deployment: %v.\nLogs:\n%v", err, string(out)) } return nil @@ -117,7 +117,7 @@ func (f *Framework) KubectlProxy(port int) (int, *exec.Cmd, error) { buf := make([]byte, 128) var n int if n, err = stdout.Read(buf); err != nil { - return -1, cmd, fmt.Errorf("Failed to read from kubectl proxy stdout: %v", err) + return -1, cmd, fmt.Errorf("failed to read from kubectl proxy stdout: %v", err) } output := string(buf[:n]) @@ -128,7 +128,7 @@ func (f *Framework) KubectlProxy(port int) (int, *exec.Cmd, error) { } } - return -1, cmd, fmt.Errorf("Failed to parse port from proxy stdout: %s", output) + return -1, cmd, fmt.Errorf("failed to parse port from proxy stdout: %s", output) } func startCmdAndStreamOutput(cmd *exec.Cmd) (stdout, stderr io.ReadCloser, err error) { diff --git a/test/e2e/framework/k8s.go b/test/e2e/framework/k8s.go index a072b05a9..5d9b8f7d9 100644 --- a/test/e2e/framework/k8s.go +++ b/test/e2e/framework/k8s.go @@ -211,7 +211,7 @@ func getIngressNGINXPod(ns string, kubeClientSet kubernetes.Interface) (*core.Po } if len(l.Items) == 0 { - return nil, fmt.Errorf("There is no ingress-nginx pods running in namespace %v", ns) + return nil, fmt.Errorf("there is no ingress-nginx pods running in namespace %v", ns) } var pod *core.Pod @@ -226,7 +226,7 @@ func getIngressNGINXPod(ns string, kubeClientSet kubernetes.Interface) (*core.Po } if pod == nil { - return nil, fmt.Errorf("There is no ingress-nginx pods running in namespace %v", ns) + return nil, fmt.Errorf("there is no ingress-nginx pods running in namespace %v", ns) } return pod, nil diff --git a/test/e2e/lua/dynamic_configuration.go b/test/e2e/lua/dynamic_configuration.go index 4b924a00a..9ce46aa88 100644 --- a/test/e2e/lua/dynamic_configuration.go +++ b/test/e2e/lua/dynamic_configuration.go @@ -277,12 +277,3 @@ func ensureHTTPSRequest(url string, host string, expectedDNSName string) { Expect(len(resp.TLS.PeerCertificates)).Should(BeNumerically("==", 1)) Expect(resp.TLS.PeerCertificates[0].DNSNames[0]).Should(Equal(expectedDNSName)) } - -func getCookie(name string, cookies []*http.Cookie) (*http.Cookie, error) { - for _, cookie := range cookies { - if cookie.Name == name { - return cookie, nil - } - } - return &http.Cookie{}, fmt.Errorf("Cookie does not exist") -} diff --git a/test/e2e/settings/configmap_change.go b/test/e2e/settings/configmap_change.go index bacb90c21..640e21a49 100644 --- a/test/e2e/settings/configmap_change.go +++ b/test/e2e/settings/configmap_change.go @@ -49,7 +49,7 @@ var _ = framework.IngressNginxDescribe("Configmap change", func() { f.UpdateNginxConfigMapData(wlKey, wlValue) - checksumRegex := regexp.MustCompile("Configuration checksum:\\s+(\\d+)") + checksumRegex := regexp.MustCompile(`Configuration checksum:\s+(\d+)`) checksum := "" f.WaitForNginxConfiguration( diff --git a/test/e2e/settings/global_external_auth.go b/test/e2e/settings/global_external_auth.go index e1dd3c832..938537191 100755 --- a/test/e2e/settings/global_external_auth.go +++ b/test/e2e/settings/global_external_auth.go @@ -181,7 +181,7 @@ var _ = framework.IngressNginxDescribe("Global External Auth", func() { err := f.DeleteDeployment("httpbin") Expect(err).NotTo(HaveOccurred()) - resp, _, errs = gorequest.New(). + _, _, errs = gorequest.New(). Get(f.GetURL(framework.HTTP)). Retry(10, 1*time.Second, http.StatusNotFound). Set("Host", host). diff --git a/test/e2e/settings/ingress_class.go b/test/e2e/settings/ingress_class.go index 73e26c930..eed41cff9 100644 --- a/test/e2e/settings/ingress_class.go +++ b/test/e2e/settings/ingress_class.go @@ -142,7 +142,7 @@ var _ = framework.IngressNginxDescribe("Ingress class", func() { Expect(resp.StatusCode).Should(Equal(http.StatusOK)) delete(ing.Annotations, "kubernetes.io/ingress.class") - ing = f.EnsureIngress(ing) + f.EnsureIngress(ing) f.WaitForNginxConfiguration(func(cfg string) bool { return !strings.Contains(cfg, "server_name foo") diff --git a/test/e2e/settings/tls.go b/test/e2e/settings/tls.go index cbf1f0c5f..bcedd7c54 100644 --- a/test/e2e/settings/tls.go +++ b/test/e2e/settings/tls.go @@ -182,7 +182,7 @@ var _ = framework.IngressNginxDescribe("Settings - TLS)", func() { framework.WaitForTLS(f.GetURL(framework.HTTPS), tlsConfig) resp, _, errs := gorequest.New(). - Get(fmt.Sprintf(f.GetURL(framework.HTTP))). + Get(f.GetURL(framework.HTTP)). Retry(10, 1*time.Second, http.StatusNotFound). RedirectPolicy(noRedirectPolicyFunc). Set("Host", host). @@ -206,7 +206,7 @@ var _ = framework.IngressNginxDescribe("Settings - TLS)", func() { framework.WaitForTLS(f.GetURL(framework.HTTPS), tlsConfig) resp, _, errs := gorequest.New(). - Get(fmt.Sprintf(f.GetURL(framework.HTTP))). + Get(f.GetURL(framework.HTTP)). Retry(10, 1*time.Second, http.StatusNotFound). RedirectPolicy(noRedirectPolicyFunc). Set("Host", host). diff --git a/test/e2e/status/update.go b/test/e2e/status/update.go index a8dcb073e..5814527f8 100644 --- a/test/e2e/status/update.go +++ b/test/e2e/status/update.go @@ -57,7 +57,7 @@ var _ = framework.IngressNginxDescribe("Status Update [Status]", func() { // flags --publish-service and --publish-status-address are mutually exclusive var index int for k, v := range args { - if strings.Index(v, "--publish-service") != -1 { + if strings.Contains(v, "--publish-service") { index = k break }