Fix golangci-lint errors (#10196)
* Fix golangci-lint errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix dupl errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix comments Signed-off-by: z1cheng <imchench@gmail.com> * Fix errcheck lint errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix assert in e2e test Signed-off-by: z1cheng <imchench@gmail.com> * Not interrupt the waitForPodsReady Signed-off-by: z1cheng <imchench@gmail.com> * Replace string with constant Signed-off-by: z1cheng <imchench@gmail.com> * Fix comments Signed-off-by: z1cheng <imchench@gmail.com> * Revert write file permision Signed-off-by: z1cheng <imchench@gmail.com> --------- Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
parent
46d87d3462
commit
b3060bfbd0
253 changed files with 2434 additions and 2113 deletions
|
|
@ -48,9 +48,9 @@ import (
|
|||
func init() {
|
||||
// the default value of nginx.TemplatePath assumes the template exists in
|
||||
// the root filesystem and not in the rootfs directory
|
||||
path, err := filepath.Abs(filepath.Join("../../../../rootfs/", nginx.TemplatePath))
|
||||
absPath, err := filepath.Abs(filepath.Join("..", "..", "..", "..", "rootfs", nginx.TemplatePath))
|
||||
if err == nil {
|
||||
nginx.TemplatePath = path
|
||||
nginx.TemplatePath = absPath
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ var (
|
|||
Target string
|
||||
Location string
|
||||
ProxyPass string
|
||||
AutoHttpProxyPass string
|
||||
AutoHTTPProxyPass string
|
||||
Sticky bool
|
||||
XForwardedPrefix string
|
||||
SecureBackend bool
|
||||
|
|
@ -200,6 +200,12 @@ proxy_pass $scheme://upstream_balancer;`,
|
|||
}
|
||||
)
|
||||
|
||||
const (
|
||||
defaultBackend = "upstream-name"
|
||||
defaultHost = "example.com"
|
||||
fooAuthHost = "foo.com/auth"
|
||||
)
|
||||
|
||||
func getTestDataDir() (string, error) {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
|
|
@ -326,9 +332,6 @@ func TestBuildLocation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBuildProxyPass(t *testing.T) {
|
||||
defaultBackend := "upstream-name"
|
||||
defaultHost := "example.com"
|
||||
|
||||
for k, tc := range tmplFuncTestcases {
|
||||
loc := &ingress.Location{
|
||||
Path: tc.Path,
|
||||
|
|
@ -339,7 +342,7 @@ func TestBuildProxyPass(t *testing.T) {
|
|||
}
|
||||
|
||||
if tc.SecureBackend {
|
||||
loc.BackendProtocol = "HTTPS"
|
||||
loc.BackendProtocol = httpsProtocol
|
||||
}
|
||||
|
||||
backend := &ingress.Backend{
|
||||
|
|
@ -367,9 +370,6 @@ func TestBuildProxyPass(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBuildProxyPassAutoHttp(t *testing.T) {
|
||||
defaultBackend := "upstream-name"
|
||||
defaultHost := "example.com"
|
||||
|
||||
for k, tc := range tmplFuncTestcases {
|
||||
loc := &ingress.Location{
|
||||
Path: tc.Path,
|
||||
|
|
@ -379,9 +379,9 @@ func TestBuildProxyPassAutoHttp(t *testing.T) {
|
|||
}
|
||||
|
||||
if tc.SecureBackend {
|
||||
loc.BackendProtocol = "HTTPS"
|
||||
loc.BackendProtocol = httpsProtocol
|
||||
} else {
|
||||
loc.BackendProtocol = "AUTO_HTTP"
|
||||
loc.BackendProtocol = autoHTTPProtocol
|
||||
}
|
||||
|
||||
backend := &ingress.Backend{
|
||||
|
|
@ -402,7 +402,7 @@ func TestBuildProxyPassAutoHttp(t *testing.T) {
|
|||
backends := []*ingress.Backend{backend}
|
||||
|
||||
pp := buildProxyPass(defaultHost, backends, loc)
|
||||
if !strings.EqualFold(tc.AutoHttpProxyPass, pp) {
|
||||
if !strings.EqualFold(tc.AutoHTTPProxyPass, pp) {
|
||||
t.Errorf("%s: expected \n'%v'\nbut returned \n'%v'", k, tc.ProxyPass, pp)
|
||||
}
|
||||
}
|
||||
|
|
@ -417,7 +417,7 @@ func TestBuildAuthLocation(t *testing.T) {
|
|||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
authURL := "foo.com/auth"
|
||||
authURL := fooAuthHost
|
||||
globalAuthURL := "foo.com/global-auth"
|
||||
|
||||
loc := &ingress.Location{
|
||||
|
|
@ -428,7 +428,7 @@ func TestBuildAuthLocation(t *testing.T) {
|
|||
EnableGlobalAuth: true,
|
||||
}
|
||||
|
||||
encodedAuthURL := strings.Replace(base64.URLEncoding.EncodeToString([]byte(loc.Path)), "=", "", -1)
|
||||
encodedAuthURL := strings.ReplaceAll(base64.URLEncoding.EncodeToString([]byte(loc.Path)), "=", "")
|
||||
externalAuthPath := fmt.Sprintf("/_external-auth-%v-default", encodedAuthURL)
|
||||
|
||||
testCases := []struct {
|
||||
|
|
@ -460,8 +460,7 @@ func TestBuildAuthLocation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestShouldApplyGlobalAuth(t *testing.T) {
|
||||
|
||||
authURL := "foo.com/auth"
|
||||
authURL := fooAuthHost
|
||||
globalAuthURL := "foo.com/global-auth"
|
||||
|
||||
loc := &ingress.Location{
|
||||
|
|
@ -579,12 +578,12 @@ func TestBuildAuthUpstreamName(t *testing.T) {
|
|||
|
||||
loc := &ingress.Location{
|
||||
ExternalAuth: authreq.Config{
|
||||
URL: "foo.com/auth",
|
||||
URL: fooAuthHost,
|
||||
},
|
||||
Path: "/cat",
|
||||
}
|
||||
|
||||
encodedAuthURL := strings.Replace(base64.URLEncoding.EncodeToString([]byte(loc.Path)), "=", "", -1)
|
||||
encodedAuthURL := strings.ReplaceAll(base64.URLEncoding.EncodeToString([]byte(loc.Path)), "=", "")
|
||||
externalAuthPath := fmt.Sprintf("external-auth-%v-default", encodedAuthURL)
|
||||
|
||||
testCases := []struct {
|
||||
|
|
@ -606,7 +605,7 @@ func TestBuildAuthUpstreamName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestShouldApplyAuthUpstream(t *testing.T) {
|
||||
authURL := "foo.com/auth"
|
||||
authURL := fooAuthHost
|
||||
|
||||
loc := &ingress.Location{
|
||||
ExternalAuth: authreq.Config{
|
||||
|
|
@ -702,7 +701,10 @@ func TestChangeHostPort(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTemplateWithData(t *testing.T) {
|
||||
pwd, _ := os.Getwd()
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
f, err := os.Open(path.Join(pwd, "../../../../test/data/config.json"))
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error reading json file: %v", err)
|
||||
|
|
@ -727,7 +729,7 @@ func TestTemplateWithData(t *testing.T) {
|
|||
|
||||
dat.Cfg.DefaultSSLCertificate = &ingress.SSLCert{}
|
||||
|
||||
rt, err := ngxTpl.Write(dat)
|
||||
rt, err := ngxTpl.Write(&dat)
|
||||
if err != nil {
|
||||
t.Errorf("invalid NGINX template: %v", err)
|
||||
}
|
||||
|
|
@ -746,7 +748,10 @@ func TestTemplateWithData(t *testing.T) {
|
|||
}
|
||||
|
||||
func BenchmarkTemplateWithData(b *testing.B) {
|
||||
pwd, _ := os.Getwd()
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
b.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
f, err := os.Open(path.Join(pwd, "../../../../test/data/config.json"))
|
||||
if err != nil {
|
||||
b.Errorf("unexpected error reading json file: %v", err)
|
||||
|
|
@ -767,7 +772,7 @@ func BenchmarkTemplateWithData(b *testing.B) {
|
|||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := ngxTpl.Write(dat); err != nil {
|
||||
if _, err := ngxTpl.Write(&dat); err != nil {
|
||||
b.Errorf("unexpected error writing template: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -1066,9 +1071,6 @@ func TestBuildUpstreamName(t *testing.T) {
|
|||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
defaultBackend := "upstream-name"
|
||||
defaultHost := "example.com"
|
||||
|
||||
for k, tc := range tmplFuncTestcases {
|
||||
loc := &ingress.Location{
|
||||
Path: tc.Path,
|
||||
|
|
@ -1079,7 +1081,7 @@ func TestBuildUpstreamName(t *testing.T) {
|
|||
}
|
||||
|
||||
if tc.SecureBackend {
|
||||
loc.BackendProtocol = "HTTPS"
|
||||
loc.BackendProtocol = httpsProtocol
|
||||
}
|
||||
|
||||
backend := &ingress.Backend{
|
||||
|
|
@ -1134,13 +1136,13 @@ func TestEscapeLiteralDollar(t *testing.T) {
|
|||
|
||||
func TestOpentracingPropagateContext(t *testing.T) {
|
||||
tests := map[*ingress.Location]string{
|
||||
{BackendProtocol: "HTTP"}: "opentracing_propagate_context;",
|
||||
{BackendProtocol: "HTTPS"}: "opentracing_propagate_context;",
|
||||
{BackendProtocol: "AUTO_HTTP"}: "opentracing_propagate_context;",
|
||||
{BackendProtocol: "GRPC"}: "opentracing_grpc_propagate_context;",
|
||||
{BackendProtocol: "GRPCS"}: "opentracing_grpc_propagate_context;",
|
||||
{BackendProtocol: "FCGI"}: "opentracing_propagate_context;",
|
||||
nil: "",
|
||||
{BackendProtocol: httpProtocol}: "opentracing_propagate_context;",
|
||||
{BackendProtocol: httpsProtocol}: "opentracing_propagate_context;",
|
||||
{BackendProtocol: autoHTTPProtocol}: "opentracing_propagate_context;",
|
||||
{BackendProtocol: grpcProtocol}: "opentracing_grpc_propagate_context;",
|
||||
{BackendProtocol: grpcsProtocol}: "opentracing_grpc_propagate_context;",
|
||||
{BackendProtocol: fcgiProtocol}: "opentracing_propagate_context;",
|
||||
nil: "",
|
||||
}
|
||||
|
||||
for loc, expectedDirective := range tests {
|
||||
|
|
@ -1153,13 +1155,13 @@ func TestOpentracingPropagateContext(t *testing.T) {
|
|||
|
||||
func TestOpentelemetryPropagateContext(t *testing.T) {
|
||||
tests := map[*ingress.Location]string{
|
||||
{BackendProtocol: "HTTP"}: "opentelemetry_propagate;",
|
||||
{BackendProtocol: "HTTPS"}: "opentelemetry_propagate;",
|
||||
{BackendProtocol: "AUTO_HTTP"}: "opentelemetry_propagate;",
|
||||
{BackendProtocol: "GRPC"}: "opentelemetry_propagate;",
|
||||
{BackendProtocol: "GRPCS"}: "opentelemetry_propagate;",
|
||||
{BackendProtocol: "FCGI"}: "opentelemetry_propagate;",
|
||||
nil: "",
|
||||
{BackendProtocol: httpProtocol}: "opentelemetry_propagate;",
|
||||
{BackendProtocol: httpsProtocol}: "opentelemetry_propagate;",
|
||||
{BackendProtocol: autoHTTPProtocol}: "opentelemetry_propagate;",
|
||||
{BackendProtocol: grpcProtocol}: "opentelemetry_propagate;",
|
||||
{BackendProtocol: grpcsProtocol}: "opentelemetry_propagate;",
|
||||
{BackendProtocol: fcgiProtocol}: "opentelemetry_propagate;",
|
||||
nil: "",
|
||||
}
|
||||
|
||||
for loc, expectedDirective := range tests {
|
||||
|
|
@ -1171,7 +1173,6 @@ func TestOpentelemetryPropagateContext(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetIngressInformation(t *testing.T) {
|
||||
|
||||
testcases := map[string]struct {
|
||||
Ingress interface{}
|
||||
Host string
|
||||
|
|
@ -1625,7 +1626,7 @@ func TestProxySetHeader(t *testing.T) {
|
|||
{
|
||||
name: "gRPC backend",
|
||||
loc: &ingress.Location{
|
||||
BackendProtocol: "GRPC",
|
||||
BackendProtocol: grpcProtocol,
|
||||
},
|
||||
expected: "grpc_set_header",
|
||||
},
|
||||
|
|
@ -1716,7 +1717,6 @@ func TestBuildOpenTracing(t *testing.T) {
|
|||
if expected != actual {
|
||||
t.Errorf("Expected '%v' but returned '%v'", expected, actual)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestBuildOpenTelemetry(t *testing.T) {
|
||||
|
|
@ -1777,6 +1777,7 @@ func TestEnforceRegexModifier(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
//nolint:dupl // Ignore dupl errors for similar test case
|
||||
func TestShouldLoadModSecurityModule(t *testing.T) {
|
||||
// ### Invalid argument type tests ###
|
||||
// The first tests should return false.
|
||||
|
|
@ -1877,6 +1878,7 @@ opentracing_trust_incoming_span off;`
|
|||
}
|
||||
}
|
||||
|
||||
//nolint:dupl // Ignore dupl errors for similar test case
|
||||
func TestShouldLoadOpentracingModule(t *testing.T) {
|
||||
// ### Invalid argument type tests ###
|
||||
// The first tests should return false.
|
||||
|
|
@ -1978,6 +1980,7 @@ opentelemetry_trust_incoming_spans off;`
|
|||
}
|
||||
}
|
||||
|
||||
//nolint:dupl // Ignore dupl errors for similar test case
|
||||
func TestShouldLoadOpentelemetryModule(t *testing.T) {
|
||||
// ### Invalid argument type tests ###
|
||||
// The first tests should return false.
|
||||
|
|
@ -2104,7 +2107,6 @@ func TestModSecurityForLocation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBuildServerName(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
title string
|
||||
hostname string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue