From 57fcbdfb73ec8b475d886640e29ee6949a33b912 Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Wed, 19 Feb 2020 21:43:14 -0300 Subject: [PATCH] Lint go code (#5132) --- test/e2e/annotations/serversnippet.go | 6 +-- test/e2e/framework/framework.go | 7 +++- test/e2e/framework/util.go | 9 ++--- test/e2e/lua/dynamic_certificates.go | 1 + test/e2e/settings/hash-size.go | 55 ++++++++++++++++----------- test/e2e/settings/keep-alive.go | 12 +++--- test/e2e/settings/reuse-port.go | 19 +++++---- 7 files changed, 60 insertions(+), 49 deletions(-) diff --git a/test/e2e/annotations/serversnippet.go b/test/e2e/annotations/serversnippet.go index d1a21048f..1e0455f59 100644 --- a/test/e2e/annotations/serversnippet.go +++ b/test/e2e/annotations/serversnippet.go @@ -19,7 +19,7 @@ package annotations import ( "strings" - . "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo" "k8s.io/ingress-nginx/test/e2e/framework" ) @@ -27,11 +27,11 @@ import ( var _ = framework.DescribeAnnotation("server-snippet", func() { f := framework.NewDefaultFramework("serversnippet") - BeforeEach(func() { + ginkgo.BeforeEach(func() { f.NewEchoDeployment() }) - It(`add valid directives to server via server snippet"`, func() { + ginkgo.It(`add valid directives to server via server snippet"`, func() { host := "serversnippet.foo.com" annotations := map[string]string{ "nginx.ingress.kubernetes.io/server-snippet": ` diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 04b358968..fecdee894 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -20,6 +20,7 @@ import ( "strings" "time" + "github.com/onsi/ginkgo" "github.com/pkg/errors" "github.com/stretchr/testify/assert" "gopkg.in/gavv/httpexpect.v2" @@ -34,8 +35,6 @@ import ( "k8s.io/client-go/kubernetes" restclient "k8s.io/client-go/rest" "k8s.io/klog" - - "github.com/onsi/ginkgo" ) // RequestScheme define a scheme used in a test request. @@ -301,6 +300,7 @@ func (f *Framework) SetNginxConfigMapData(cmData map[string]string) { time.Sleep(5 * time.Second) } +// CreateConfigMap creates a new configmap in the current namespace func (f *Framework) CreateConfigMap(name string, data map[string]string) { _, err := f.KubeClientSet.CoreV1().ConfigMaps(f.Namespace).Create(&v1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ @@ -349,10 +349,13 @@ func (f *Framework) DeleteNGINXPod(grace int64) { assert.Nil(ginkgo.GinkgoT(), err, "while waiting for ingress nginx pod to come up again") } +// HTTPTestClient returns a new httpexpect client for end-to-end HTTP testing. func (f *Framework) HTTPTestClient() *httpexpect.Expect { return f.newTestClient(nil) } +// HTTPTestClientWithTLSConfig returns a new httpexpect client for end-to-end +// HTTP testing with a custom TLS configuration. func (f *Framework) HTTPTestClientWithTLSConfig(config *tls.Config) *httpexpect.Expect { return f.newTestClient(config) } diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index fae9900aa..1fa55f601 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -21,8 +21,7 @@ import ( "os" "time" - . "github.com/onsi/ginkgo" - + "github.com/onsi/ginkgo" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -46,7 +45,7 @@ func nowStamp() string { } func log(level string, format string, args ...interface{}) { - fmt.Fprintf(GinkgoWriter, nowStamp()+": "+level+": "+format+"\n", args...) + fmt.Fprintf(ginkgo.GinkgoWriter, nowStamp()+": "+level+": "+format+"\n", args...) } // Logf logs to the INFO logs. @@ -58,14 +57,14 @@ func Logf(format string, args ...interface{}) { func Failf(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) log("INFO", msg) - Fail(nowStamp()+": "+msg, 1) + ginkgo.Fail(nowStamp()+": "+msg, 1) } // Skipf logs to the INFO logs and skips the test. func Skipf(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) log("INFO", msg) - Skip(nowStamp() + ": " + msg) + ginkgo.Skip(nowStamp() + ": " + msg) } // RestclientConfig deserializes the contents of a kubeconfig file into a Config object. diff --git a/test/e2e/lua/dynamic_certificates.go b/test/e2e/lua/dynamic_certificates.go index 00ad12cc5..06384d236 100644 --- a/test/e2e/lua/dynamic_certificates.go +++ b/test/e2e/lua/dynamic_certificates.go @@ -183,6 +183,7 @@ var _ = framework.IngressNginxDescribe("[Lua] dynamic certificates", func() { ginkgo.It("falls back to using default certificate when secret gets deleted without reloading", func() { ing, err := f.KubeClientSet.NetworkingV1beta1().Ingresses(f.Namespace).Get(host, metav1.GetOptions{}) + assert.Nil(ginkgo.GinkgoT(), err) ensureHTTPSRequest(f, fmt.Sprintf("%s?id=dummy_log_splitter_foo_bar", f.GetURL(framework.HTTPS)), host, host) diff --git a/test/e2e/settings/hash-size.go b/test/e2e/settings/hash-size.go index 3bae91728..42c9241bb 100644 --- a/test/e2e/settings/hash-size.go +++ b/test/e2e/settings/hash-size.go @@ -17,83 +17,94 @@ limitations under the License. package settings import ( - "fmt" "strings" - . "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo" "k8s.io/ingress-nginx/test/e2e/framework" ) -var _ = framework.DescribeSetting("Settings - hash size", func() { +var _ = framework.DescribeSetting("hash size", func() { f := framework.NewDefaultFramework("hash-size") host := "hash-size" - BeforeEach(func() { + ginkgo.BeforeEach(func() { f.NewEchoDeployment() ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil) f.EnsureIngress(ing) }) - Context("Check server names hash size", func() { - It("should set server_names_hash_bucket_size", func() { + + ginkgo.Context("Check server names hash size", func() { + + ginkgo.It("should set server_names_hash_bucket_size", func() { f.UpdateNginxConfigMapData("server-name-hash-bucket-size", "512") f.WaitForNginxConfiguration(func(server string) bool { - return strings.Contains(server, fmt.Sprintf(`server_names_hash_bucket_size 512;`)) + return strings.Contains(server, "server_names_hash_bucket_size 512;") }) }) - It("should set server_names_hash_max_size", func() { + ginkgo.It("should set server_names_hash_max_size", func() { f.UpdateNginxConfigMapData("server-name-hash-max-size", "4096") f.WaitForNginxConfiguration(func(server string) bool { - return strings.Contains(server, fmt.Sprintf(`server_names_hash_max_size 4096;`)) + return strings.Contains(server, "server_names_hash_max_size 4096;") }) }) + }) - Context("Check proxy header hash size", func() { - It("should set proxy-headers-hash-bucket-size", func() { + ginkgo.Context("Check proxy header hash size", func() { + + ginkgo.It("should set proxy-headers-hash-bucket-size", func() { f.UpdateNginxConfigMapData("proxy-headers-hash-bucket-size", "512") f.WaitForNginxConfiguration(func(server string) bool { - return strings.Contains(server, fmt.Sprintf(`proxy_headers_hash_bucket_size 512;`)) + return strings.Contains(server, "proxy_headers_hash_bucket_size 512;") }) }) - It("should set proxy-headers-hash-max-size", func() { + + ginkgo.It("should set proxy-headers-hash-max-size", func() { f.UpdateNginxConfigMapData("proxy-headers-hash-max-size", "4096") f.WaitForNginxConfiguration(func(server string) bool { - return strings.Contains(server, fmt.Sprintf(`proxy_headers_hash_max_size 4096;`)) + return strings.Contains(server, "proxy_headers_hash_max_size 4096;") }) }) + }) - Context("Check the variable hash size", func() { - It("should set variables-hash-bucket-size", func() { + + ginkgo.Context("Check the variable hash size", func() { + + ginkgo.It("should set variables-hash-bucket-size", func() { f.UpdateNginxConfigMapData("variables-hash-bucket-size", "512") f.WaitForNginxConfiguration(func(server string) bool { - return strings.Contains(server, fmt.Sprintf(`variables_hash_bucket_size 512;`)) + return strings.Contains(server, "variables_hash_bucket_size 512;") }) }) - It("should set variables-hash-max-size", func() { + + ginkgo.It("should set variables-hash-max-size", func() { f.UpdateNginxConfigMapData("variables-hash-max-size", "512") f.WaitForNginxConfiguration(func(server string) bool { - return strings.Contains(server, fmt.Sprintf(`variables_hash_max_size 512;`)) + return strings.Contains(server, "variables_hash_max_size 512;") }) }) + }) - Context("Check the map hash size", func() { - It("should set vmap-hash-bucket-size", func() { + ginkgo.Context("Check the map hash size", func() { + + ginkgo.It("should set vmap-hash-bucket-size", func() { f.UpdateNginxConfigMapData("map-hash-bucket-size", "512") f.WaitForNginxConfiguration(func(server string) bool { - return strings.Contains(server, fmt.Sprintf(`map_hash_bucket_size 512;`)) + return strings.Contains(server, "map_hash_bucket_size 512;") }) }) + }) }) diff --git a/test/e2e/settings/keep-alive.go b/test/e2e/settings/keep-alive.go index b08cfd60f..cdc29eec0 100644 --- a/test/e2e/settings/keep-alive.go +++ b/test/e2e/settings/keep-alive.go @@ -20,23 +20,22 @@ import ( "fmt" "strings" - . "github.com/onsi/ginkgo" - + "github.com/onsi/ginkgo" "k8s.io/ingress-nginx/test/e2e/framework" ) -var _ = framework.DescribeSetting("Settings - keep alive", func() { +var _ = framework.DescribeSetting("keep-alive keep-alive-requests", func() { f := framework.NewDefaultFramework("keep-alive") host := "keep-alive" - BeforeEach(func() { + ginkgo.BeforeEach(func() { f.NewEchoDeployment() ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil) f.EnsureIngress(ing) }) - It("should set keepalive_timeout", func() { + ginkgo.It("should set keepalive_timeout", func() { f.UpdateNginxConfigMapData("keep-alive", "140") f.WaitForNginxConfiguration(func(server string) bool { @@ -44,12 +43,11 @@ var _ = framework.DescribeSetting("Settings - keep alive", func() { }) }) - It("should set keepalive_requests", func() { + ginkgo.It("should set keepalive_requests", func() { f.UpdateNginxConfigMapData("keep-alive-requests", "200") f.WaitForNginxConfiguration(func(server string) bool { return strings.Contains(server, fmt.Sprintf(`keepalive_requests 200;`)) }) - }) }) diff --git a/test/e2e/settings/reuse-port.go b/test/e2e/settings/reuse-port.go index fd6b6dc17..b8b2c5611 100644 --- a/test/e2e/settings/reuse-port.go +++ b/test/e2e/settings/reuse-port.go @@ -17,44 +17,43 @@ limitations under the License. package settings import ( - "fmt" "strings" - . "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo" "k8s.io/ingress-nginx/test/e2e/framework" ) -var _ = framework.DescribeSetting("Settings - reuse port", func() { +var _ = framework.DescribeSetting("reuse-port", func() { f := framework.NewDefaultFramework("reuse-port") host := "reuse-port" - BeforeEach(func() { + ginkgo.BeforeEach(func() { f.NewEchoDeployment() ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil) f.EnsureIngress(ing) }) - It("reuse port should be enabled by default", func() { + ginkgo.It("reuse port should be enabled by default", func() { f.WaitForNginxConfiguration(func(server string) bool { - return strings.Contains(server, fmt.Sprintf(`reuseport`)) + return strings.Contains(server, "reuseport") }) }) - It("reuse port should be disabled", func() { + ginkgo.It("reuse port should be disabled", func() { f.UpdateNginxConfigMapData("reuse-port", "false") f.WaitForNginxConfiguration(func(server string) bool { - return !strings.Contains(server, fmt.Sprintf(`reuseport`)) + return !strings.Contains(server, "reuseport") }) }) - It("reuse port should be enabled", func() { + ginkgo.It("reuse port should be enabled", func() { f.UpdateNginxConfigMapData("reuse-port", "true") f.WaitForNginxConfiguration(func(server string) bool { - return strings.Contains(server, fmt.Sprintf(`reuseport`)) + return strings.Contains(server, "reuseport") }) }) })