Lint go code (#5132)

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-02-19 21:43:14 -03:00 committed by GitHub
parent f6c0faa6eb
commit 57fcbdfb73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 49 deletions

View file

@ -19,7 +19,7 @@ package annotations
import ( import (
"strings" "strings"
. "github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework" "k8s.io/ingress-nginx/test/e2e/framework"
) )
@ -27,11 +27,11 @@ import (
var _ = framework.DescribeAnnotation("server-snippet", func() { var _ = framework.DescribeAnnotation("server-snippet", func() {
f := framework.NewDefaultFramework("serversnippet") f := framework.NewDefaultFramework("serversnippet")
BeforeEach(func() { ginkgo.BeforeEach(func() {
f.NewEchoDeployment() 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" host := "serversnippet.foo.com"
annotations := map[string]string{ annotations := map[string]string{
"nginx.ingress.kubernetes.io/server-snippet": ` "nginx.ingress.kubernetes.io/server-snippet": `

View file

@ -20,6 +20,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/onsi/ginkgo"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/gavv/httpexpect.v2" "gopkg.in/gavv/httpexpect.v2"
@ -34,8 +35,6 @@ import (
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/klog" "k8s.io/klog"
"github.com/onsi/ginkgo"
) )
// RequestScheme define a scheme used in a test request. // 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) time.Sleep(5 * time.Second)
} }
// CreateConfigMap creates a new configmap in the current namespace
func (f *Framework) CreateConfigMap(name string, data map[string]string) { func (f *Framework) CreateConfigMap(name string, data map[string]string) {
_, err := f.KubeClientSet.CoreV1().ConfigMaps(f.Namespace).Create(&v1.ConfigMap{ _, err := f.KubeClientSet.CoreV1().ConfigMaps(f.Namespace).Create(&v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{ 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") 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 { func (f *Framework) HTTPTestClient() *httpexpect.Expect {
return f.newTestClient(nil) 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 { func (f *Framework) HTTPTestClientWithTLSConfig(config *tls.Config) *httpexpect.Expect {
return f.newTestClient(config) return f.newTestClient(config)
} }

View file

@ -21,8 +21,7 @@ import (
"os" "os"
"time" "time"
. "github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -46,7 +45,7 @@ func nowStamp() string {
} }
func log(level string, format string, args ...interface{}) { 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. // Logf logs to the INFO logs.
@ -58,14 +57,14 @@ func Logf(format string, args ...interface{}) {
func Failf(format string, args ...interface{}) { func Failf(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...) msg := fmt.Sprintf(format, args...)
log("INFO", msg) log("INFO", msg)
Fail(nowStamp()+": "+msg, 1) ginkgo.Fail(nowStamp()+": "+msg, 1)
} }
// Skipf logs to the INFO logs and skips the test. // Skipf logs to the INFO logs and skips the test.
func Skipf(format string, args ...interface{}) { func Skipf(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...) msg := fmt.Sprintf(format, args...)
log("INFO", msg) log("INFO", msg)
Skip(nowStamp() + ": " + msg) ginkgo.Skip(nowStamp() + ": " + msg)
} }
// RestclientConfig deserializes the contents of a kubeconfig file into a Config object. // RestclientConfig deserializes the contents of a kubeconfig file into a Config object.

View file

@ -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() { 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{}) 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) ensureHTTPSRequest(f, fmt.Sprintf("%s?id=dummy_log_splitter_foo_bar", f.GetURL(framework.HTTPS)), host, host)

View file

@ -17,83 +17,94 @@ limitations under the License.
package settings package settings
import ( import (
"fmt"
"strings" "strings"
. "github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework" "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") f := framework.NewDefaultFramework("hash-size")
host := "hash-size" host := "hash-size"
BeforeEach(func() { ginkgo.BeforeEach(func() {
f.NewEchoDeployment() f.NewEchoDeployment()
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil)
f.EnsureIngress(ing) 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.UpdateNginxConfigMapData("server-name-hash-bucket-size", "512")
f.WaitForNginxConfiguration(func(server string) bool { 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.UpdateNginxConfigMapData("server-name-hash-max-size", "4096")
f.WaitForNginxConfiguration(func(server string) bool { 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() { ginkgo.Context("Check proxy header hash size", func() {
It("should set proxy-headers-hash-bucket-size", func() {
ginkgo.It("should set proxy-headers-hash-bucket-size", func() {
f.UpdateNginxConfigMapData("proxy-headers-hash-bucket-size", "512") f.UpdateNginxConfigMapData("proxy-headers-hash-bucket-size", "512")
f.WaitForNginxConfiguration(func(server string) bool { 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.UpdateNginxConfigMapData("proxy-headers-hash-max-size", "4096")
f.WaitForNginxConfiguration(func(server string) bool { 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.UpdateNginxConfigMapData("variables-hash-bucket-size", "512")
f.WaitForNginxConfiguration(func(server string) bool { 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.UpdateNginxConfigMapData("variables-hash-max-size", "512")
f.WaitForNginxConfiguration(func(server string) bool { 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() { ginkgo.Context("Check the map hash size", func() {
It("should set vmap-hash-bucket-size", func() {
ginkgo.It("should set vmap-hash-bucket-size", func() {
f.UpdateNginxConfigMapData("map-hash-bucket-size", "512") f.UpdateNginxConfigMapData("map-hash-bucket-size", "512")
f.WaitForNginxConfiguration(func(server string) bool { 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;")
}) })
}) })
}) })
}) })

View file

@ -20,23 +20,22 @@ import (
"fmt" "fmt"
"strings" "strings"
. "github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework" "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") f := framework.NewDefaultFramework("keep-alive")
host := "keep-alive" host := "keep-alive"
BeforeEach(func() { ginkgo.BeforeEach(func() {
f.NewEchoDeployment() f.NewEchoDeployment()
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil)
f.EnsureIngress(ing) f.EnsureIngress(ing)
}) })
It("should set keepalive_timeout", func() { ginkgo.It("should set keepalive_timeout", func() {
f.UpdateNginxConfigMapData("keep-alive", "140") f.UpdateNginxConfigMapData("keep-alive", "140")
f.WaitForNginxConfiguration(func(server string) bool { 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.UpdateNginxConfigMapData("keep-alive-requests", "200")
f.WaitForNginxConfiguration(func(server string) bool { f.WaitForNginxConfiguration(func(server string) bool {
return strings.Contains(server, fmt.Sprintf(`keepalive_requests 200;`)) return strings.Contains(server, fmt.Sprintf(`keepalive_requests 200;`))
}) })
}) })
}) })

View file

@ -17,44 +17,43 @@ limitations under the License.
package settings package settings
import ( import (
"fmt"
"strings" "strings"
. "github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework" "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") f := framework.NewDefaultFramework("reuse-port")
host := "reuse-port" host := "reuse-port"
BeforeEach(func() { ginkgo.BeforeEach(func() {
f.NewEchoDeployment() f.NewEchoDeployment()
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil)
f.EnsureIngress(ing) 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 { 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.UpdateNginxConfigMapData("reuse-port", "false")
f.WaitForNginxConfiguration(func(server string) bool { 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.UpdateNginxConfigMapData("reuse-port", "true")
f.WaitForNginxConfiguration(func(server string) bool { f.WaitForNginxConfiguration(func(server string) bool {
return strings.Contains(server, fmt.Sprintf(`reuseport`)) return strings.Contains(server, "reuseport")
}) })
}) })
}) })