From f437fb4230f663893dbd12da2f82a1c9a8660262 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Tue, 12 Nov 2024 10:56:06 +0100 Subject: [PATCH] chore: update linter --- .github/workflows/validate.yaml | 2 +- .golangci.yml | 13 +- .semaphore/semaphore.yml | 2 +- cmd/traefik/traefik.go | 2 +- integration/http_test.go | 6 +- pkg/api/handler_http_test.go | 26 +- pkg/api/handler_test.go | 2 +- pkg/config/label/label_test.go | 22 +- pkg/config/static/entrypoints.go | 4 +- pkg/healthcheck/healthcheck_test.go | 2 +- pkg/middlewares/accesslog/logger_test.go | 5 +- pkg/middlewares/tracing/mock_tracing_test.go | 28 +- pkg/muxer/tcp/mux.go | 2 +- pkg/provider/aggregator/aggregator.go | 10 +- pkg/provider/consulcatalog/config_test.go | 97 +++-- pkg/provider/docker/config.go | 2 +- pkg/provider/docker/config_test.go | 90 +++-- pkg/provider/ecs/config_test.go | 89 +++-- .../kubernetes/crd/kubernetes_http.go | 2 +- .../kubernetes/crd/kubernetes_test.go | 257 +++++++------ .../kubernetes/gateway/kubernetes_test.go | 358 ++++++++---------- .../kubernetes/ingress/annotations_test.go | 4 +- .../kubernetes/ingress/kubernetes_test.go | 108 +++--- pkg/provider/kv/kv_test.go | 18 +- pkg/provider/marathon/config_test.go | 81 ++-- pkg/provider/nomad/config_test.go | 87 +++-- pkg/provider/rancher/config_test.go | 43 +-- pkg/provider/traefik/internal.go | 2 +- pkg/redactor/redactor_config_test.go | 32 +- pkg/server/configurationwatcher_test.go | 6 +- .../service/loadbalancer/wrr/wrr_test.go | 50 +-- pkg/server/service/proxy_test.go | 2 +- pkg/server/service/proxy_websocket_test.go | 30 +- pkg/server/service/roundtripper_test.go | 6 +- pkg/server/service/service_test.go | 4 +- pkg/tcp/proxy.go | 4 +- pkg/tls/certificate.go | 122 +++--- pkg/tls/certificate_store.go | 6 +- 38 files changed, 796 insertions(+), 830 deletions(-) diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index abcbc97d7..832b91528 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -7,7 +7,7 @@ on: env: GO_VERSION: '1.23' - GOLANGCI_LINT_VERSION: v1.61.0 + GOLANGCI_LINT_VERSION: v1.62.0 MISSPELL_VERSION: v0.6.0 jobs: diff --git a/.golangci.yml b/.golangci.yml index 41a87c9fd..2ea78a8ed 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -159,8 +159,6 @@ linters-settings: linters: enable-all: true disable: - - execinquery # deprecated - - gomnd # deprecated - sqlclosecheck # not relevant (SQL) - rowserrcheck # not relevant (SQL) - cyclop # duplicate of gocyclo @@ -273,3 +271,14 @@ issues: - path: pkg/provider/acme/local_store.go linters: - musttag + - path: pkg/tls/certificate.go + text: 'the methods of "Certificates" use pointer receiver and non-pointer receiver.' + linters: + - recvcheck + +output: + show-stats: true + sort-results: true + sort-order: + - linter + - file diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index 419ea70a0..fa09ce3c4 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -25,7 +25,7 @@ global_job_config: - export "PATH=${GOPATH}/bin:${PATH}" - mkdir -vp "${SEMAPHORE_GIT_DIR}" "${GOPATH}/bin" - export GOPROXY=https://proxy.golang.org,direct - - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.61.0 + - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.62.0 - curl -sSfL https://gist.githubusercontent.com/traefiker/6d7ac019c11d011e4f131bb2cca8900e/raw/goreleaser.sh | bash -s -- -b "${GOPATH}/bin" - checkout - cache restore traefik-$(checksum go.sum) diff --git a/cmd/traefik/traefik.go b/cmd/traefik/traefik.go index 140242d3d..d54b806f3 100644 --- a/cmd/traefik/traefik.go +++ b/cmd/traefik/traefik.go @@ -187,7 +187,7 @@ func setupServer(staticConfiguration *static.Configuration) (*server.Server, err return nil, err } - acmeProviders := initACMEProvider(staticConfiguration, &providerAggregator, tlsManager, httpChallengeProvider, tlsChallengeProvider) + acmeProviders := initACMEProvider(staticConfiguration, providerAggregator, tlsManager, httpChallengeProvider, tlsChallengeProvider) // Entrypoints diff --git a/integration/http_test.go b/integration/http_test.go index 7d19c41d5..800ec316d 100644 --- a/integration/http_test.go +++ b/integration/http_test.go @@ -41,7 +41,7 @@ func (s *HTTPSuite) TestSimpleConfiguration() { Services: map[string]*dynamic.Service{ "serviceHTTP": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: boolRef(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://bacon:80", @@ -81,6 +81,4 @@ func startTestServerWithResponse(response []byte) (ts *httptest.Server) { return ts } -func boolRef(b bool) *bool { - return &b -} +func pointer[T any](v T) *T { return &v } diff --git a/pkg/api/handler_http_test.go b/pkg/api/handler_http_test.go index 7ed879a97..7c1d7fb4c 100644 --- a/pkg/api/handler_http_test.go +++ b/pkg/api/handler_http_test.go @@ -19,7 +19,7 @@ import ( "github.com/traefik/traefik/v2/pkg/config/static" ) -func Bool(v bool) *bool { return &v } +func pointer[T any](v T) *T { return &v } func TestHandler_HTTP(t *testing.T) { type expected struct { @@ -337,7 +337,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.1", @@ -354,7 +354,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.2", @@ -423,7 +423,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.1", @@ -440,7 +440,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.2", @@ -457,7 +457,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.3", @@ -487,7 +487,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.1", @@ -505,7 +505,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.2", @@ -536,7 +536,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.1", @@ -554,7 +554,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.2", @@ -585,7 +585,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.1", @@ -614,7 +614,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.1", @@ -643,7 +643,7 @@ func TestHandler_HTTP(t *testing.T) { si := &runtime.ServiceInfo{ Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.1", diff --git a/pkg/api/handler_test.go b/pkg/api/handler_test.go index 9a2e3ae76..b2d5395ca 100644 --- a/pkg/api/handler_test.go +++ b/pkg/api/handler_test.go @@ -38,7 +38,7 @@ func TestHandler_RawData(t *testing.T) { "foo-service@myprovider": { Service: &dynamic.Service{ LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://127.0.0.1", diff --git a/pkg/config/label/label_test.go b/pkg/config/label/label_test.go index a11fb3976..b4c209e4c 100644 --- a/pkg/config/label/label_test.go +++ b/pkg/config/label/label_test.go @@ -13,6 +13,8 @@ import ( "github.com/traefik/traefik/v2/pkg/types" ) +func pointer[T any](v T) *T { return &v } + func TestDecodeConfiguration(t *testing.T) { labels := map[string]string{ "traefik.http.middlewares.Middleware0.addprefix.prefix": "foobar", @@ -265,7 +267,7 @@ func TestDecodeConfiguration(t *testing.T) { Port: "42", }, }, - TerminationDelay: func(i int) *int { return &i }(42), + TerminationDelay: pointer(42), ProxyProtocol: &dynamic.ProxyProtocol{Version: 42}, }, }, @@ -276,7 +278,7 @@ func TestDecodeConfiguration(t *testing.T) { Port: "42", }, }, - TerminationDelay: func(i int) *int { return &i }(42), + TerminationDelay: pointer(42), ProxyProtocol: &dynamic.ProxyProtocol{Version: 2}, }, }, @@ -665,9 +667,9 @@ func TestDecodeConfiguration(t *testing.T) { "name0": "foobar", "name1": "foobar", }, - FollowRedirects: func(v bool) *bool { return &v }(true), + FollowRedirects: pointer(true), }, - PassHostHeader: func(v bool) *bool { return &v }(true), + PassHostHeader: pointer(true), ResponseForwarding: &dynamic.ResponseForwarding{ FlushInterval: "foobar", }, @@ -693,9 +695,9 @@ func TestDecodeConfiguration(t *testing.T) { "name0": "foobar", "name1": "foobar", }, - FollowRedirects: func(v bool) *bool { return &v }(true), + FollowRedirects: pointer(true), }, - PassHostHeader: func(v bool) *bool { return &v }(true), + PassHostHeader: pointer(true), ResponseForwarding: &dynamic.ResponseForwarding{ FlushInterval: "foobar", }, @@ -773,7 +775,7 @@ func TestEncodeConfiguration(t *testing.T) { Port: "42", }, }, - TerminationDelay: func(i int) *int { return &i }(42), + TerminationDelay: pointer(42), }, }, "Service1": { @@ -783,7 +785,7 @@ func TestEncodeConfiguration(t *testing.T) { Port: "42", }, }, - TerminationDelay: func(i int) *int { return &i }(42), + TerminationDelay: pointer(42), }, }, }, @@ -1170,7 +1172,7 @@ func TestEncodeConfiguration(t *testing.T) { "name1": "foobar", }, }, - PassHostHeader: func(v bool) *bool { return &v }(true), + PassHostHeader: pointer(true), ResponseForwarding: &dynamic.ResponseForwarding{ FlushInterval: "foobar", }, @@ -1197,7 +1199,7 @@ func TestEncodeConfiguration(t *testing.T) { "name1": "foobar", }, }, - PassHostHeader: func(v bool) *bool { return &v }(true), + PassHostHeader: pointer(true), ResponseForwarding: &dynamic.ResponseForwarding{ FlushInterval: "foobar", }, diff --git a/pkg/config/static/entrypoints.go b/pkg/config/static/entrypoints.go index 27b9f7a0b..017480098 100644 --- a/pkg/config/static/entrypoints.go +++ b/pkg/config/static/entrypoints.go @@ -24,14 +24,14 @@ type EntryPoint struct { // GetAddress strips any potential protocol part of the address field of the // entry point, in order to return the actual address. -func (ep EntryPoint) GetAddress() string { +func (ep *EntryPoint) GetAddress() string { splitN := strings.SplitN(ep.Address, "/", 2) return splitN[0] } // GetProtocol returns the protocol part of the address field of the entry point. // If none is specified, it defaults to "tcp". -func (ep EntryPoint) GetProtocol() (string, error) { +func (ep *EntryPoint) GetProtocol() (string, error) { splitN := strings.SplitN(ep.Address, "/", 2) if len(splitN) < 2 { return "tcp", nil diff --git a/pkg/healthcheck/healthcheck_test.go b/pkg/healthcheck/healthcheck_test.go index 73254b27e..4fcebde3b 100644 --- a/pkg/healthcheck/healthcheck_test.go +++ b/pkg/healthcheck/healthcheck_test.go @@ -278,7 +278,7 @@ func TestNewRequest(t *testing.T) { if test.expected.err { require.Error(t, err) - assert.Nil(t, nil) + assert.Nil(t, req) } else { require.NoError(t, err, "failed to create new backend request") require.NotNil(t, req) diff --git a/pkg/middlewares/accesslog/logger_test.go b/pkg/middlewares/accesslog/logger_test.go index dc48c3593..097a36322 100644 --- a/pkg/middlewares/accesslog/logger_test.go +++ b/pkg/middlewares/accesslog/logger_test.go @@ -12,7 +12,6 @@ import ( "net/url" "os" "path/filepath" - "regexp" "strconv" "strings" "testing" @@ -809,10 +808,10 @@ func assertValidLogData(t *testing.T, expected string, logData []byte) { assert.Equal(t, resultExpected[OriginContentSize], result[OriginContentSize], formatErrMessage) assert.Equal(t, resultExpected[RequestRefererHeader], result[RequestRefererHeader], formatErrMessage) assert.Equal(t, resultExpected[RequestUserAgentHeader], result[RequestUserAgentHeader], formatErrMessage) - assert.Regexp(t, regexp.MustCompile(`\d*`), result[RequestCount], formatErrMessage) + assert.Regexp(t, `\d*`, result[RequestCount], formatErrMessage) assert.Equal(t, resultExpected[RouterName], result[RouterName], formatErrMessage) assert.Equal(t, resultExpected[ServiceURL], result[ServiceURL], formatErrMessage) - assert.Regexp(t, regexp.MustCompile(`\d*ms`), result[Duration], formatErrMessage) + assert.Regexp(t, `\d*ms`, result[Duration], formatErrMessage) } func captureStdout(t *testing.T) (out *os.File, restoreStdout func()) { diff --git a/pkg/middlewares/tracing/mock_tracing_test.go b/pkg/middlewares/tracing/mock_tracing_test.go index 33aac1ee6..2d3c46891 100644 --- a/pkg/middlewares/tracing/mock_tracing_test.go +++ b/pkg/middlewares/tracing/mock_tracing_test.go @@ -38,24 +38,24 @@ type MockSpan struct { Tags map[string]interface{} } -func (n MockSpan) Context() opentracing.SpanContext { return MockSpanContext{} } -func (n MockSpan) SetBaggageItem(key, val string) opentracing.Span { - return MockSpan{Tags: make(map[string]interface{})} +func (n *MockSpan) Context() opentracing.SpanContext { return MockSpanContext{} } +func (n *MockSpan) SetBaggageItem(key, val string) opentracing.Span { + return &MockSpan{Tags: make(map[string]interface{})} } -func (n MockSpan) BaggageItem(key string) string { return "" } -func (n MockSpan) SetTag(key string, value interface{}) opentracing.Span { +func (n *MockSpan) BaggageItem(key string) string { return "" } +func (n *MockSpan) SetTag(key string, value interface{}) opentracing.Span { n.Tags[key] = value return n } -func (n MockSpan) LogFields(fields ...log.Field) {} -func (n MockSpan) LogKV(keyVals ...interface{}) {} -func (n MockSpan) Finish() {} -func (n MockSpan) FinishWithOptions(opts opentracing.FinishOptions) {} -func (n MockSpan) SetOperationName(operationName string) opentracing.Span { return n } -func (n MockSpan) Tracer() opentracing.Tracer { return MockTracer{} } -func (n MockSpan) LogEvent(event string) {} -func (n MockSpan) LogEventWithPayload(event string, payload interface{}) {} -func (n MockSpan) Log(data opentracing.LogData) {} +func (n *MockSpan) LogFields(fields ...log.Field) {} +func (n *MockSpan) LogKV(keyVals ...interface{}) {} +func (n *MockSpan) Finish() {} +func (n *MockSpan) FinishWithOptions(opts opentracing.FinishOptions) {} +func (n *MockSpan) SetOperationName(operationName string) opentracing.Span { return n } +func (n *MockSpan) Tracer() opentracing.Tracer { return MockTracer{} } +func (n *MockSpan) LogEvent(event string) {} +func (n *MockSpan) LogEventWithPayload(event string, payload interface{}) {} +func (n *MockSpan) Log(data opentracing.LogData) {} func (n *MockSpan) Reset() { n.Tags = make(map[string]interface{}) } diff --git a/pkg/muxer/tcp/mux.go b/pkg/muxer/tcp/mux.go index e50b78899..5bf4fbc08 100644 --- a/pkg/muxer/tcp/mux.go +++ b/pkg/muxer/tcp/mux.go @@ -102,7 +102,7 @@ func NewMuxer() (*Muxer, error) { // Match returns the handler of the first route matching the connection metadata, // and whether the match is exactly from the rule HostSNI(*). -func (m Muxer) Match(meta ConnData) (tcp.Handler, bool) { +func (m *Muxer) Match(meta ConnData) (tcp.Handler, bool) { for _, route := range m.routes { if route.matchers.match(meta) { return route.handler, route.catchAll diff --git a/pkg/provider/aggregator/aggregator.go b/pkg/provider/aggregator/aggregator.go index 888d51fa0..fca5f73ec 100644 --- a/pkg/provider/aggregator/aggregator.go +++ b/pkg/provider/aggregator/aggregator.go @@ -67,8 +67,8 @@ type ProviderAggregator struct { } // NewProviderAggregator returns an aggregate of all the providers configured in the static configuration. -func NewProviderAggregator(conf static.Providers) ProviderAggregator { - p := ProviderAggregator{ +func NewProviderAggregator(conf static.Providers) *ProviderAggregator { + p := &ProviderAggregator{ providersThrottleDuration: time.Duration(conf.ProvidersThrottleDuration), } @@ -172,12 +172,12 @@ func (p *ProviderAggregator) AddProvider(provider provider.Provider) error { } // Init the provider. -func (p ProviderAggregator) Init() error { +func (p *ProviderAggregator) Init() error { return nil } // Provide calls the provide method of every providers. -func (p ProviderAggregator) Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error { +func (p *ProviderAggregator) Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error { if p.fileProvider != nil { p.launchProvider(configurationChan, pool, p.fileProvider) } @@ -197,7 +197,7 @@ func (p ProviderAggregator) Provide(configurationChan chan<- dynamic.Message, po return nil } -func (p ProviderAggregator) launchProvider(configurationChan chan<- dynamic.Message, pool *safe.Pool, prd provider.Provider) { +func (p *ProviderAggregator) launchProvider(configurationChan chan<- dynamic.Message, pool *safe.Pool, prd provider.Provider) { jsonConf, err := redactor.RemoveCredentials(prd) if err != nil { log.WithoutContext().Debugf("Cannot marshal the provider configuration %T: %v", prd, err) diff --git a/pkg/provider/consulcatalog/config_test.go b/pkg/provider/consulcatalog/config_test.go index 5bfba067e..22f830c48 100644 --- a/pkg/provider/consulcatalog/config_test.go +++ b/pkg/provider/consulcatalog/config_test.go @@ -13,8 +13,7 @@ import ( "github.com/traefik/traefik/v2/pkg/types" ) -func Int(v int) *int { return &v } -func Bool(v bool) *bool { return &v } +func pointer[T any](v T) *T { return &v } func TestDefaultRule(t *testing.T) { testCases := []struct { @@ -64,7 +63,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -118,7 +117,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -164,7 +163,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -210,7 +209,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -262,7 +261,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -350,7 +349,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -407,7 +406,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "https://127.0.0.1:443", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), ServersTransport: "tls-ns-dc1-dev-Test", }, }, @@ -497,7 +496,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "https://127.0.0.2:444", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), ServersTransport: "tls-ns-dc1-dev-Test", }, }, @@ -578,7 +577,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Test2": { @@ -588,7 +587,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -651,7 +650,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -711,7 +710,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -774,7 +773,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -826,7 +825,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -879,7 +878,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -924,7 +923,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -982,7 +981,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1030,7 +1029,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -1040,7 +1039,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1216,7 +1215,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1267,7 +1266,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1344,7 +1343,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1408,7 +1407,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1488,7 +1487,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.3:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1548,7 +1547,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1622,7 +1621,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.3:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1688,7 +1687,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1740,7 +1739,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1793,7 +1792,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "h2c://127.0.0.1:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1840,7 +1839,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -1850,7 +1849,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2074,7 +2073,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2137,7 +2136,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2188,7 +2187,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2241,7 +2240,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2337,7 +2336,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2393,7 +2392,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:8080", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2515,7 +2514,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.2:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2544,7 +2543,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2631,7 +2630,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2668,7 +2667,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2760,7 +2759,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(200), + TerminationDelay: pointer(200), }, }, }, @@ -2844,7 +2843,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "https://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), ServersTransport: "tls-ns-dc1-Test", }, }, @@ -2855,7 +2854,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "https://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), ServersTransport: "tls-ns-dc1-Test", }, }, @@ -2933,7 +2932,7 @@ func Test_buildConfiguration(t *testing.T) { Servers: []dynamic.TCPServer{ {Address: "127.0.0.1:80"}, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, "Test-17573747155436217342": { @@ -2941,7 +2940,7 @@ func Test_buildConfiguration(t *testing.T) { Servers: []dynamic.TCPServer{ {Address: "127.0.0.2:80"}, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -3136,7 +3135,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, diff --git a/pkg/provider/docker/config.go b/pkg/provider/docker/config.go index f47b0221f..6ce921e3e 100644 --- a/pkg/provider/docker/config.go +++ b/pkg/provider/docker/config.go @@ -307,7 +307,7 @@ func (p *Provider) getIPPort(ctx context.Context, container dockerData, serverPo return ip, port, nil } -func (p Provider) getIPAddress(ctx context.Context, container dockerData) string { +func (p *Provider) getIPAddress(ctx context.Context, container dockerData) string { logger := log.FromContext(ctx) netNotFound := false diff --git a/pkg/provider/docker/config_test.go b/pkg/provider/docker/config_test.go index ed371e7ad..03a5af050 100644 --- a/pkg/provider/docker/config_test.go +++ b/pkg/provider/docker/config_test.go @@ -71,7 +71,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -130,7 +130,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -191,7 +191,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -244,7 +244,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -297,7 +297,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -356,7 +356,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -579,7 +579,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -658,7 +658,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Test2": { @@ -668,7 +668,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -747,7 +747,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -807,7 +807,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -868,7 +868,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -921,7 +921,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -987,7 +987,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1043,7 +1043,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -1053,7 +1053,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1113,7 +1113,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1353,7 +1353,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1412,7 +1412,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1508,7 +1508,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1591,7 +1591,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1696,7 +1696,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.3:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1773,7 +1773,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1872,7 +1872,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.3:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1954,7 +1954,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2026,7 +2026,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Test2": { @@ -2036,7 +2036,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2096,7 +2096,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2157,7 +2157,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "h2c://127.0.0.1:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2212,7 +2212,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -2222,7 +2222,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2418,7 +2418,7 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{ "Test": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2487,7 +2487,7 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.TCPService{ "Test": { LoadBalancer: &dynamic.TCPServersLoadBalancer{ - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2676,7 +2676,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2747,7 +2747,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2806,7 +2806,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2867,7 +2867,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2979,7 +2979,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -3043,7 +3043,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:8080", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -3215,7 +3215,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3314,7 +3314,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:8080", }, }, - TerminationDelay: Int(200), + TerminationDelay: pointer(200), }, }, }, @@ -3391,7 +3391,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://192.168.0.1:8081", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3451,7 +3451,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:79", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3958,6 +3958,4 @@ func TestSwarmGetPort(t *testing.T) { } } -func Int(v int) *int { return &v } - -func Bool(v bool) *bool { return &v } +func pointer[T any](v T) *T { return &v } diff --git a/pkg/provider/ecs/config_test.go b/pkg/provider/ecs/config_test.go index 3d8f912b8..39764d679 100644 --- a/pkg/provider/ecs/config_test.go +++ b/pkg/provider/ecs/config_test.go @@ -12,8 +12,7 @@ import ( "github.com/traefik/traefik/v2/pkg/types" ) -func Int(v int) *int { return &v } -func Bool(v bool) *bool { return &v } +func pointer[T any](v T) *T { return &v } func TestDefaultRule(t *testing.T) { testCases := []struct { @@ -66,7 +65,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://10.0.0.1:1337", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -120,7 +119,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -176,7 +175,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -224,7 +223,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -272,7 +271,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -326,7 +325,7 @@ func TestDefaultRule(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -528,7 +527,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -597,7 +596,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Test2": { @@ -607,7 +606,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -676,7 +675,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -731,7 +730,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -787,7 +786,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -835,7 +834,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -896,7 +895,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -947,7 +946,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -957,7 +956,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1012,7 +1011,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1217,7 +1216,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1271,7 +1270,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1357,7 +1356,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1430,7 +1429,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1520,7 +1519,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.3:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1587,7 +1586,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1671,7 +1670,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.3:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1744,7 +1743,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1806,7 +1805,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Test2": { @@ -1816,7 +1815,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1871,7 +1870,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1927,7 +1926,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "h2c://127.0.0.1:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1983,7 +1982,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "h2c://127.0.0.1:8040", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2047,7 +2046,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:32124", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -2057,7 +2056,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:32123", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2107,7 +2106,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -2117,7 +2116,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2397,7 +2396,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2463,7 +2462,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2517,7 +2516,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2573,7 +2572,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2675,7 +2674,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2734,7 +2733,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:8080", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2891,7 +2890,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2980,7 +2979,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:8080", }, }, - TerminationDelay: Int(200), + TerminationDelay: pointer(200), }, }, }, @@ -3046,7 +3045,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, diff --git a/pkg/provider/kubernetes/crd/kubernetes_http.go b/pkg/provider/kubernetes/crd/kubernetes_http.go index 56637a22a..ad84a247b 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_http.go +++ b/pkg/provider/kubernetes/crd/kubernetes_http.go @@ -321,7 +321,7 @@ func (c configBuilder) buildServersLB(namespace string, svc traefikv1alpha1.Load return &dynamic.Service{LoadBalancer: lb}, nil } -func (c *configBuilder) makeServersTransportKey(parentNamespace string, serversTransportName string) (string, error) { +func (c configBuilder) makeServersTransportKey(parentNamespace string, serversTransportName string) (string, error) { if serversTransportName == "" { return "", nil } diff --git a/pkg/provider/kubernetes/crd/kubernetes_test.go b/pkg/provider/kubernetes/crd/kubernetes_test.go index 1d9869d61..ba9031b33 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_test.go +++ b/pkg/provider/kubernetes/crd/kubernetes_test.go @@ -27,8 +27,7 @@ import ( var _ provider.Provider = (*Provider)(nil) -func Int(v int) *int { return &v } -func Bool(v bool) *bool { return &v } +func pointer[T any](v T) *T { return &v } func TestLoadIngressRouteTCPs(t *testing.T) { testCases := []struct { @@ -376,11 +375,11 @@ func TestLoadIngressRouteTCPs(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-test.route-fdd3e9338e47a45efefc-whoamitcp-8000", - Weight: func(i int) *int { return &i }(2), + Weight: pointer(2), }, { Name: "default-test.route-fdd3e9338e47a45efefc-whoamitcp2-8080", - Weight: func(i int) *int { return &i }(3), + Weight: pointer(3), }, }, }, @@ -443,15 +442,15 @@ func TestLoadIngressRouteTCPs(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-test.route-fdd3e9338e47a45efefc-whoamitcp-8000", - Weight: func(i int) *int { return &i }(2), + Weight: pointer(2), }, { Name: "default-test.route-fdd3e9338e47a45efefc-whoamitcp2-8080", - Weight: func(i int) *int { return &i }(3), + Weight: pointer(3), }, { Name: "default-test.route-fdd3e9338e47a45efefc-whoamitcp3-8083", - Weight: func(i int) *int { return &i }(4), + Weight: pointer(4), }, }, }, @@ -1054,7 +1053,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) { Address: "10.10.0.2:8000", }, }, - TerminationDelay: Int(500), + TerminationDelay: pointer(500), }, }, }, @@ -1264,11 +1263,11 @@ func TestLoadIngressRouteTCPs(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-test.route-673acf455cb2dab0b43a-whoamitcp-ipv6-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-test.route-673acf455cb2dab0b43a-external.service.with.ipv6-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -1313,7 +1312,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) { URL: "http://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:8080", }, }, - PassHostHeader: func(i bool) *bool { return &i }(true), + PassHostHeader: pointer(true), }, }, "default-external-svc-with-ipv6-8080": { @@ -1323,7 +1322,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) { URL: "http://[2001:db8:85a3:8d3:1319:8a2e:370:7347]:8080", }, }, - PassHostHeader: func(i bool) *bool { return &i }(true), + PassHostHeader: pointer(true), }, }, "default-test-route-6b204d94623b3df4370c": { @@ -1331,11 +1330,11 @@ func TestLoadIngressRouteTCPs(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-ipv6-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-external-svc-with-ipv6-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -1537,7 +1536,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1605,7 +1604,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1656,7 +1655,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1713,7 +1712,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1761,7 +1760,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-test-route-77c62dfe9517144aeeaa": { @@ -1774,7 +1773,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1813,11 +1812,11 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-whoami2-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -1832,7 +1831,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-whoami2-8080": { @@ -1845,7 +1844,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1883,7 +1882,7 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami5-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -1898,7 +1897,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1929,7 +1928,7 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami5-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -1944,7 +1943,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1982,11 +1981,11 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-wrr1", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-wrr2", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -1996,11 +1995,11 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami4-80", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-whoami5-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2015,7 +2014,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-whoami5-8080": { @@ -2028,7 +2027,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-wrr2": { @@ -2036,11 +2035,11 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami6-80", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-whoami7-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2055,7 +2054,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.6:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-whoami7-8080": { @@ -2068,7 +2067,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.8:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2106,11 +2105,11 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-wrr2", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-whoami5-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2120,7 +2119,7 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami5-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2135,7 +2134,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2173,15 +2172,15 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-wrr2", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-whoami5-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-mirror1", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2191,7 +2190,7 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami5-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2214,7 +2213,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-whoami5-8080": { @@ -2227,7 +2226,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2266,23 +2265,23 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "baz-whoami6-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "foo-wrr1", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "foo-mirror2", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "foo-mirror3", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "foo-mirror4", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2297,7 +2296,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.6:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "foo-wrr1": { @@ -2305,19 +2304,19 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "foo-whoami4-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "baz-whoami6-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "foo-mirror1", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "bar-wrr2", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2332,7 +2331,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "foo-mirror1": { @@ -2355,7 +2354,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "bar-mirrored": { @@ -2393,7 +2392,7 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "foo-whoami5-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2457,7 +2456,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-whoami5-8080": { @@ -2470,7 +2469,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2516,7 +2515,7 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami4-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2526,7 +2525,7 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami5-8080", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -2541,7 +2540,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-whoami5-8080": { @@ -2554,7 +2553,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2592,11 +2591,11 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: Int(10), + Weight: pointer(10), }, { Name: "default-whoami2-8080", - Weight: Int(0), + Weight: pointer(0), }, }, }, @@ -2611,7 +2610,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-whoami2-8080": { @@ -2624,7 +2623,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2744,7 +2743,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2813,7 +2812,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2861,7 +2860,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2930,7 +2929,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3000,7 +2999,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3068,7 +3067,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3140,7 +3139,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3213,7 +3212,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3257,7 +3256,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3300,7 +3299,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "https://10.10.0.6:8443", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3343,7 +3342,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "https://10.10.0.8:8443", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3590,7 +3589,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3632,7 +3631,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(false), + PassHostHeader: pointer(false), ResponseForwarding: &dynamic.ResponseForwarding{FlushInterval: "10s"}, }, }, @@ -3687,7 +3686,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3744,7 +3743,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3790,7 +3789,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3831,7 +3830,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://external.domain:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3870,7 +3869,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://external.domain:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -3909,7 +3908,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "https://external.domain:443", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -4000,7 +3999,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "https://external.domain:443", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), ServersTransport: "default-test", }, }, @@ -4014,7 +4013,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "https://10.10.0.6:8443", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), ServersTransport: "default-default-test", }, }, @@ -4023,11 +4022,11 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-external-svc-with-https-443", - Weight: Int(1), + Weight: pointer(1), }, { Name: "default-whoamitls-443", - Weight: Int(1), + Weight: pointer(1), }, }, }, @@ -4086,7 +4085,7 @@ func TestLoadIngressRoutes(t *testing.T) { Services: map[string]*dynamic.Service{ "default-test-route-6b204d94623b3df4370c": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -4130,7 +4129,7 @@ func TestLoadIngressRoutes(t *testing.T) { URL: "http://10.10.0.4:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -4176,18 +4175,18 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-test-weighted", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-test-mirror", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, }, "default-test-errorpage-errorpage-service": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-test-weighted": { @@ -4195,7 +4194,7 @@ func TestLoadIngressRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-without-endpoints-subsets-80", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -4215,7 +4214,7 @@ func TestLoadIngressRoutes(t *testing.T) { }, "default-whoami-without-endpoints-subsets-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -4390,11 +4389,11 @@ func TestLoadIngressRouteUDPs(t *testing.T) { Services: []dynamic.UDPWRRService{ { Name: "default-test.route-0-whoamiudp-8000", - Weight: func(i int) *int { return &i }(2), + Weight: pointer(2), }, { Name: "default-test.route-0-whoamiudp2-8080", - Weight: func(i int) *int { return &i }(3), + Weight: pointer(3), }, }, }, @@ -4456,15 +4455,15 @@ func TestLoadIngressRouteUDPs(t *testing.T) { Services: []dynamic.UDPWRRService{ { Name: "default-test.route-0-whoamiudp-8000", - Weight: func(i int) *int { return &i }(2), + Weight: pointer(2), }, { Name: "default-test.route-0-whoamiudp2-8080", - Weight: func(i int) *int { return &i }(3), + Weight: pointer(3), }, { Name: "default-test.route-0-whoamiudp3-8083", - Weight: func(i int) *int { return &i }(4), + Weight: pointer(4), }, }, }, @@ -5096,7 +5095,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -5171,7 +5170,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-test-crossnamespace-route-9313b71dbe6a649d5049": { @@ -5184,7 +5183,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-test-errorpage-errorpage-service": { @@ -5197,7 +5196,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-test-crossnamespace-route-a1963878aac7331b7950": { @@ -5210,7 +5209,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -5254,23 +5253,23 @@ func TestCrossNamespace(t *testing.T) { Services: []dynamic.WRRService{ { Name: "cross-ns-whoami-svc-80", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-tr-svc-wrr1", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "cross-ns-tr-svc-wrr2", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "default-tr-svc-mirror1", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, { Name: "cross-ns-tr-svc-mirror2", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -5285,7 +5284,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), ServersTransport: "foo-test@kubernetescrd", }, }, @@ -5299,7 +5298,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "default-tr-svc-wrr1": { @@ -5307,7 +5306,7 @@ func TestCrossNamespace(t *testing.T) { Services: []dynamic.WRRService{ { Name: "cross-ns-whoami-svc-80", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -5317,7 +5316,7 @@ func TestCrossNamespace(t *testing.T) { Services: []dynamic.WRRService{ { Name: "cross-ns-whoami-svc-80", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -5354,7 +5353,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -5385,7 +5384,7 @@ func TestCrossNamespace(t *testing.T) { Services: []dynamic.WRRService{ { Name: "cross-ns-whoami-svc-80", - Weight: func(i int) *int { return &i }(1), + Weight: pointer(1), }, }, }, @@ -5400,7 +5399,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "cross-ns-tr-svc-mirror2": { @@ -5424,7 +5423,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -5468,7 +5467,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), ServersTransport: "cross-ns-st-cross-ns@kubernetescrd", }, }, @@ -5560,7 +5559,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -5619,7 +5618,7 @@ func TestCrossNamespace(t *testing.T) { URL: "http://10.10.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -6167,7 +6166,7 @@ func TestExternalNameService(t *testing.T) { URL: "http://external.domain:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -6454,7 +6453,7 @@ func TestNativeLB(t *testing.T) { URL: "http://10.10.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, diff --git a/pkg/provider/kubernetes/gateway/kubernetes_test.go b/pkg/provider/kubernetes/gateway/kubernetes_test.go index ea0e7c504..1d51d26af 100644 --- a/pkg/provider/kubernetes/gateway/kubernetes_test.go +++ b/pkg/provider/kubernetes/gateway/kubernetes_test.go @@ -16,6 +16,8 @@ import ( var _ provider.Provider = (*Provider)(nil) +func ptr[T any](v T) *T { return &v } + func TestLoadHTTPRoutes(t *testing.T) { testCases := []struct { desc string @@ -536,7 +538,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -622,11 +624,11 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "service@file", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -682,7 +684,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -746,7 +748,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -801,7 +803,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -856,7 +858,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -916,7 +918,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -926,7 +928,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami2-8080", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -994,11 +996,11 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, { Name: "default-whoami2-8080", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1077,7 +1079,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1087,7 +1089,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1162,7 +1164,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1172,7 +1174,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1241,7 +1243,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1251,7 +1253,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1306,7 +1308,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1366,7 +1368,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1376,7 +1378,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "bar-whoami-bar-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1444,7 +1446,7 @@ func TestLoadHTTPRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "bar-whoami-bar-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1690,7 +1692,7 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1751,7 +1753,7 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1761,7 +1763,7 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-10000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1829,11 +1831,11 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-tcp-app-my-tcp-gateway-tcp-1-e3b0c44298fc1c149afb-wrr-0", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, { Name: "default-tcp-app-my-tcp-gateway-tcp-1-e3b0c44298fc1c149afb-wrr-1", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1843,7 +1845,7 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1853,7 +1855,7 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-10000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1919,11 +1921,11 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "service@file", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -1977,7 +1979,7 @@ func TestLoadTCPRoutes(t *testing.T) { Weighted: &dynamic.TCPWeightedRoundRobin{ Services: []dynamic.TCPWRRService{{ Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }}, }, }, @@ -2039,7 +2041,7 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2098,7 +2100,7 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2108,7 +2110,7 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "bar-whoamitcp-bar-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2174,7 +2176,7 @@ func TestLoadTCPRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "bar-whoamitcp-bar-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2458,7 +2460,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2524,7 +2526,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2581,7 +2583,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2645,7 +2647,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2655,7 +2657,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-10000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2731,11 +2733,11 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "service@file", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2801,7 +2803,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2858,7 +2860,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2915,7 +2917,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -2972,7 +2974,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3029,7 +3031,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3094,7 +3096,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3104,7 +3106,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "bar-whoamitcp-bar-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3173,7 +3175,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "bar-whoamitcp-bar-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3230,11 +3232,11 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-tls-app-my-gateway-tcp-1-673acf455cb2dab0b43a-wrr-0", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, { Name: "default-tls-app-my-gateway-tcp-1-673acf455cb2dab0b43a-wrr-1", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3244,7 +3246,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3254,7 +3256,7 @@ func TestLoadTLSRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-10000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3459,7 +3461,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3469,7 +3471,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3479,7 +3481,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3519,7 +3521,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3529,7 +3531,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3633,7 +3635,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3643,7 +3645,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3653,7 +3655,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3693,7 +3695,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3703,7 +3705,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3791,7 +3793,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3801,7 +3803,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3811,7 +3813,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3845,7 +3847,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "bar-whoamitcp-bar-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3855,7 +3857,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "bar-whoamitcp-bar-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3894,7 +3896,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3904,7 +3906,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3940,7 +3942,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "bar-whoami-bar-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -3950,7 +3952,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "bar-whoami-bar-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -4026,7 +4028,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "bar-whoamitcp-bar-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -4036,7 +4038,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "bar-whoamitcp-bar-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -4046,7 +4048,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "bar-whoamitcp-bar-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -4087,7 +4089,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "bar-whoami-bar-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -4097,7 +4099,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "bar-whoami-bar-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -4152,7 +4154,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -4162,7 +4164,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "default-whoamitcp-9000", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -4202,7 +4204,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -4212,7 +4214,7 @@ func TestLoadMixedRoutes(t *testing.T) { Services: []dynamic.WRRService{ { Name: "default-whoami-80", - Weight: func(i int) *int { return &i }(1), + Weight: ptr(1), }, }, }, @@ -4437,7 +4439,7 @@ func Test_extractRule(t *testing.T) { Matches: []gatev1alpha2.HTTPRouteMatch{ { Path: &gatev1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), + Type: ptr[gatev1alpha2.PathMatchType](gatev1alpha2.PathMatchExact), Value: nil, }, }, @@ -4451,7 +4453,7 @@ func Test_extractRule(t *testing.T) { Matches: []gatev1alpha2.HTTPRouteMatch{ { Path: &gatev1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), + Type: ptr[gatev1alpha2.PathMatchType](gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, }, @@ -4465,13 +4467,13 @@ func Test_extractRule(t *testing.T) { Matches: []gatev1alpha2.HTTPRouteMatch{ { Path: &gatev1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), + Type: ptr[gatev1alpha2.PathMatchType](gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, }, { Path: &gatev1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr("unknown"), + Type: ptr[gatev1alpha2.PathMatchType]("unknown"), Value: pointer.String("/foo/"), }, }, @@ -4485,7 +4487,7 @@ func Test_extractRule(t *testing.T) { Matches: []gatev1alpha2.HTTPRouteMatch{ { Path: &gatev1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), + Type: ptr[gatev1alpha2.PathMatchType](gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, }, @@ -4500,14 +4502,14 @@ func Test_extractRule(t *testing.T) { Matches: []gatev1alpha2.HTTPRouteMatch{ { Path: &gatev1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), + Type: ptr[gatev1alpha2.PathMatchType](gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, }, { Headers: []gatev1alpha2.HTTPHeaderMatch{ { - Type: headerMatchTypePtr(gatev1alpha2.HeaderMatchExact), + Type: ptr[gatev1alpha2.HeaderMatchType](gatev1alpha2.HeaderMatchExact), Name: "my-header", Value: "foo", }, @@ -4523,12 +4525,12 @@ func Test_extractRule(t *testing.T) { Matches: []gatev1alpha2.HTTPRouteMatch{ { Path: &gatev1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), + Type: ptr[gatev1alpha2.PathMatchType](gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, Headers: []gatev1alpha2.HTTPHeaderMatch{ { - Type: headerMatchTypePtr(gatev1alpha2.HeaderMatchExact), + Type: ptr[gatev1alpha2.HeaderMatchType](gatev1alpha2.HeaderMatchExact), Name: "my-header", Value: "foo", }, @@ -4545,12 +4547,12 @@ func Test_extractRule(t *testing.T) { Matches: []gatev1alpha2.HTTPRouteMatch{ { Path: &gatev1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), + Type: ptr[gatev1alpha2.PathMatchType](gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, Headers: []gatev1alpha2.HTTPHeaderMatch{ { - Type: headerMatchTypePtr(gatev1alpha2.HeaderMatchExact), + Type: ptr[gatev1alpha2.HeaderMatchType](gatev1alpha2.HeaderMatchExact), Name: "my-header", Value: "foo", }, @@ -4567,14 +4569,14 @@ func Test_extractRule(t *testing.T) { Matches: []gatev1alpha2.HTTPRouteMatch{ { Path: &gatev1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), + Type: ptr[gatev1alpha2.PathMatchType](gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, }, { Headers: []gatev1alpha2.HTTPHeaderMatch{ { - Type: headerMatchTypePtr(gatev1alpha2.HeaderMatchExact), + Type: ptr[gatev1alpha2.HeaderMatchType](gatev1alpha2.HeaderMatchExact), Name: "my-header", Value: "foo", }, @@ -4707,11 +4709,11 @@ func Test_shouldAttach(t *testing.T) { routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: []gatev1alpha2.ParentRef{ { - SectionName: sectionNamePtr("bar"), + SectionName: ptr[gatev1alpha2.SectionName]("bar"), Name: "gateway", - Namespace: namespacePtr("default"), - Kind: kindPtr("Foo"), - Group: groupPtr(gatev1alpha2.GroupName), + Namespace: ptr[gatev1alpha2.Namespace]("default"), + Kind: ptr[gatev1alpha2.Kind]("Foo"), + Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), }, }, }, @@ -4732,11 +4734,11 @@ func Test_shouldAttach(t *testing.T) { routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: []gatev1alpha2.ParentRef{ { - SectionName: sectionNamePtr("bar"), + SectionName: ptr[gatev1alpha2.SectionName]("bar"), Name: "gateway", - Namespace: namespacePtr("default"), - Kind: kindPtr("Gateway"), - Group: groupPtr("foo.com"), + Namespace: ptr[gatev1alpha2.Namespace]("default"), + Kind: ptr[gatev1alpha2.Kind]("Gateway"), + Group: ptr[gatev1alpha2.Group]("foo.com"), }, }, }, @@ -4757,10 +4759,10 @@ func Test_shouldAttach(t *testing.T) { routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: []gatev1alpha2.ParentRef{ { - SectionName: sectionNamePtr("bar"), + SectionName: ptr[gatev1alpha2.SectionName]("bar"), Name: "gateway", - Namespace: namespacePtr("default"), - Group: groupPtr(gatev1alpha2.GroupName), + Namespace: ptr[gatev1alpha2.Namespace]("default"), + Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), }, }, }, @@ -4781,10 +4783,10 @@ func Test_shouldAttach(t *testing.T) { routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: []gatev1alpha2.ParentRef{ { - SectionName: sectionNamePtr("bar"), + SectionName: ptr[gatev1alpha2.SectionName]("bar"), Name: "gateway", - Namespace: namespacePtr("default"), - Kind: kindPtr("Gateway"), + Namespace: ptr[gatev1alpha2.Namespace]("default"), + Kind: ptr[gatev1alpha2.Kind]("Gateway"), }, }, }, @@ -4805,11 +4807,11 @@ func Test_shouldAttach(t *testing.T) { routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: []gatev1alpha2.ParentRef{ { - SectionName: sectionNamePtr("bar"), + SectionName: ptr[gatev1alpha2.SectionName]("bar"), Name: "gateway", - Namespace: namespacePtr("default"), - Group: groupPtr(gatev1alpha2.GroupName), - Kind: kindPtr("Gateway"), + Namespace: ptr[gatev1alpha2.Namespace]("default"), + Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), + Kind: ptr[gatev1alpha2.Kind]("Gateway"), }, }, }, @@ -4830,11 +4832,11 @@ func Test_shouldAttach(t *testing.T) { routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: []gatev1alpha2.ParentRef{ { - SectionName: sectionNamePtr("bar"), + SectionName: ptr[gatev1alpha2.SectionName]("bar"), Name: "gateway", - Namespace: namespacePtr("bar"), - Group: groupPtr(gatev1alpha2.GroupName), - Kind: kindPtr("Gateway"), + Namespace: ptr[gatev1alpha2.Namespace]("bar"), + Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), + Kind: ptr[gatev1alpha2.Kind]("Gateway"), }, }, }, @@ -4855,10 +4857,10 @@ func Test_shouldAttach(t *testing.T) { routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: []gatev1alpha2.ParentRef{ { - SectionName: sectionNamePtr("bar"), + SectionName: ptr[gatev1alpha2.SectionName]("bar"), Name: "gateway", - Group: groupPtr(gatev1alpha2.GroupName), - Kind: kindPtr("Gateway"), + Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), + Kind: ptr[gatev1alpha2.Kind]("Gateway"), }, }, }, @@ -4879,11 +4881,11 @@ func Test_shouldAttach(t *testing.T) { routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: []gatev1alpha2.ParentRef{ { - SectionName: sectionNamePtr("bar"), + SectionName: ptr[gatev1alpha2.SectionName]("bar"), Name: "gateway", - Namespace: namespacePtr("default"), - Kind: kindPtr("Gateway"), - Group: groupPtr(gatev1alpha2.GroupName), + Namespace: ptr[gatev1alpha2.Namespace]("default"), + Kind: ptr[gatev1alpha2.Kind]("Gateway"), + Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), }, }, }, @@ -4904,10 +4906,10 @@ func Test_shouldAttach(t *testing.T) { routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: []gatev1alpha2.ParentRef{ { - SectionName: sectionNamePtr("foo"), + SectionName: ptr[gatev1alpha2.SectionName]("foo"), Name: "gateway", - Kind: kindPtr("Gateway"), - Group: groupPtr(gatev1alpha2.GroupName), + Kind: ptr[gatev1alpha2.Kind]("Gateway"), + Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), }, }, }, @@ -4928,11 +4930,11 @@ func Test_shouldAttach(t *testing.T) { routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: []gatev1alpha2.ParentRef{ { - SectionName: sectionNamePtr("foo"), + SectionName: ptr[gatev1alpha2.SectionName]("foo"), Name: "gateway", - Namespace: namespacePtr("default"), - Kind: kindPtr("Gateway"), - Group: groupPtr(gatev1alpha2.GroupName), + Namespace: ptr[gatev1alpha2.Namespace]("default"), + Kind: ptr[gatev1alpha2.Kind]("Gateway"), + Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), }, }, }, @@ -4954,15 +4956,15 @@ func Test_shouldAttach(t *testing.T) { ParentRefs: []gatev1alpha2.ParentRef{ { Name: "gateway2", - Namespace: namespacePtr("default"), - Kind: kindPtr("Gateway"), - Group: groupPtr(gatev1alpha2.GroupName), + Namespace: ptr[gatev1alpha2.Namespace]("default"), + Kind: ptr[gatev1alpha2.Kind]("Gateway"), + Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), }, { Name: "gateway", - Namespace: namespacePtr("default"), - Kind: kindPtr("Gateway"), - Group: groupPtr(gatev1alpha2.GroupName), + Namespace: ptr[gatev1alpha2.Namespace]("default"), + Kind: ptr[gatev1alpha2.Kind]("Gateway"), + Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), }, }, }, @@ -4993,7 +4995,7 @@ func Test_matchingHostnames(t *testing.T) { { desc: "Only listener hostname", listener: gatev1alpha2.Listener{ - Hostname: hostnamePtr("foo.com"), + Hostname: ptr[gatev1alpha2.Hostname]("foo.com"), }, want: []gatev1alpha2.Hostname{"foo.com"}, }, @@ -5005,7 +5007,7 @@ func Test_matchingHostnames(t *testing.T) { { desc: "Matching hostname", listener: gatev1alpha2.Listener{ - Hostname: hostnamePtr("foo.com"), + Hostname: ptr[gatev1alpha2.Hostname]("foo.com"), }, hostnames: []gatev1alpha2.Hostname{"foo.com"}, want: []gatev1alpha2.Hostname{"foo.com"}, @@ -5013,7 +5015,7 @@ func Test_matchingHostnames(t *testing.T) { { desc: "Matching hostname with wildcard", listener: gatev1alpha2.Listener{ - Hostname: hostnamePtr("*.foo.com"), + Hostname: ptr[gatev1alpha2.Hostname]("*.foo.com"), }, hostnames: []gatev1alpha2.Hostname{"*.foo.com"}, want: []gatev1alpha2.Hostname{"*.foo.com"}, @@ -5021,7 +5023,7 @@ func Test_matchingHostnames(t *testing.T) { { desc: "Matching subdomain with listener wildcard", listener: gatev1alpha2.Listener{ - Hostname: hostnamePtr("*.foo.com"), + Hostname: ptr[gatev1alpha2.Hostname]("*.foo.com"), }, hostnames: []gatev1alpha2.Hostname{"bar.foo.com"}, want: []gatev1alpha2.Hostname{"bar.foo.com"}, @@ -5029,7 +5031,7 @@ func Test_matchingHostnames(t *testing.T) { { desc: "Matching subdomain with route hostname wildcard", listener: gatev1alpha2.Listener{ - Hostname: hostnamePtr("bar.foo.com"), + Hostname: ptr[gatev1alpha2.Hostname]("bar.foo.com"), }, hostnames: []gatev1alpha2.Hostname{"*.foo.com"}, want: []gatev1alpha2.Hostname{"bar.foo.com"}, @@ -5037,21 +5039,21 @@ func Test_matchingHostnames(t *testing.T) { { desc: "Non matching root domain with listener wildcard", listener: gatev1alpha2.Listener{ - Hostname: hostnamePtr("*.foo.com"), + Hostname: ptr[gatev1alpha2.Hostname]("*.foo.com"), }, hostnames: []gatev1alpha2.Hostname{"foo.com"}, }, { desc: "Non matching root domain with route hostname wildcard", listener: gatev1alpha2.Listener{ - Hostname: hostnamePtr("foo.com"), + Hostname: ptr[gatev1alpha2.Hostname]("foo.com"), }, hostnames: []gatev1alpha2.Hostname{"*.foo.com"}, }, { desc: "Multiple route hostnames with one matching route hostname", listener: gatev1alpha2.Listener{ - Hostname: hostnamePtr("*.foo.com"), + Hostname: ptr[gatev1alpha2.Hostname]("*.foo.com"), }, hostnames: []gatev1alpha2.Hostname{"bar.com", "test.foo.com", "test.buz.com"}, want: []gatev1alpha2.Hostname{"test.foo.com"}, @@ -5059,14 +5061,14 @@ func Test_matchingHostnames(t *testing.T) { { desc: "Multiple route hostnames with non matching route hostname", listener: gatev1alpha2.Listener{ - Hostname: hostnamePtr("*.fuz.com"), + Hostname: ptr[gatev1alpha2.Hostname]("*.fuz.com"), }, hostnames: []gatev1alpha2.Hostname{"bar.com", "test.foo.com", "test.buz.com"}, }, { desc: "Multiple route hostnames with multiple matching route hostnames", listener: gatev1alpha2.Listener{ - Hostname: hostnamePtr("*.foo.com"), + Hostname: ptr[gatev1alpha2.Hostname]("*.foo.com"), }, hostnames: []gatev1alpha2.Hostname{"toto.foo.com", "test.foo.com", "test.buz.com"}, want: []gatev1alpha2.Hostname{"toto.foo.com", "test.foo.com"}, @@ -5097,10 +5099,10 @@ func Test_getAllowedRoutes(t *testing.T) { { desc: "Empty AllowedRoutes", supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, }, wantKinds: []gatev1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, }, }, { @@ -5108,12 +5110,12 @@ func Test_getAllowedRoutes(t *testing.T) { listener: gatev1alpha2.Listener{ AllowedRoutes: &gatev1alpha2.AllowedRoutes{ Kinds: []gatev1alpha2.RouteGroupKind{{ - Kind: kindTLSRoute, Group: groupPtr("foo"), + Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group]("foo"), }}, }, }, supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, }, wantErr: true, }, @@ -5127,7 +5129,7 @@ func Test_getAllowedRoutes(t *testing.T) { }, }, supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, }, wantErr: true, }, @@ -5136,12 +5138,12 @@ func Test_getAllowedRoutes(t *testing.T) { listener: gatev1alpha2.Listener{ AllowedRoutes: &gatev1alpha2.AllowedRoutes{ Kinds: []gatev1alpha2.RouteGroupKind{{ - Kind: "foo", Group: groupPtr(gatev1alpha2.GroupName), + Kind: "foo", Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), }}, }, }, supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, }, wantErr: true, }, @@ -5150,15 +5152,15 @@ func Test_getAllowedRoutes(t *testing.T) { listener: gatev1alpha2.Listener{ AllowedRoutes: &gatev1alpha2.AllowedRoutes{ Kinds: []gatev1alpha2.RouteGroupKind{{ - Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName), + Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName), }}, }, }, supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, }, wantKinds: []gatev1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, }, }, { @@ -5166,20 +5168,20 @@ func Test_getAllowedRoutes(t *testing.T) { listener: gatev1alpha2.Listener{ AllowedRoutes: &gatev1alpha2.AllowedRoutes{ Kinds: []gatev1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, - {Kind: kindTCPRoute, Group: groupPtr(gatev1alpha2.GroupName)}, - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, - {Kind: kindTCPRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, + {Kind: kindTCPRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, + {Kind: kindTCPRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, }, }, }, supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, - {Kind: kindTCPRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, + {Kind: kindTCPRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, }, wantKinds: []gatev1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, - {Kind: kindTCPRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, + {Kind: kindTCPRoute, Group: ptr[gatev1alpha2.Group](gatev1alpha2.GroupName)}, }, }, } @@ -5215,7 +5217,7 @@ func Test_makeListenerKey(t *testing.T) { listener: gatev1alpha2.Listener{ Port: 443, Protocol: gatev1alpha2.HTTPSProtocolType, - Hostname: hostnamePtr("www.example.com"), + Hostname: ptr[gatev1alpha2.Hostname]("www.example.com"), }, expectedKey: "HTTPS|www.example.com|443", }, @@ -5237,27 +5239,3 @@ func Test_makeListenerKey(t *testing.T) { }) } } - -func hostnamePtr(hostname gatev1alpha2.Hostname) *gatev1alpha2.Hostname { - return &hostname -} - -func groupPtr(group gatev1alpha2.Group) *gatev1alpha2.Group { - return &group -} - -func sectionNamePtr(sectionName gatev1alpha2.SectionName) *gatev1alpha2.SectionName { - return §ionName -} - -func namespacePtr(namespace gatev1alpha2.Namespace) *gatev1alpha2.Namespace { - return &namespace -} - -func kindPtr(kind gatev1alpha2.Kind) *gatev1alpha2.Kind { - return &kind -} - -func pathMatchTypePtr(p gatev1alpha2.PathMatchType) *gatev1alpha2.PathMatchType { return &p } - -func headerMatchTypePtr(h gatev1alpha2.HeaderMatchType) *gatev1alpha2.HeaderMatchType { return &h } diff --git a/pkg/provider/kubernetes/ingress/annotations_test.go b/pkg/provider/kubernetes/ingress/annotations_test.go index 7dbf309f9..f44e70079 100644 --- a/pkg/provider/kubernetes/ingress/annotations_test.go +++ b/pkg/provider/kubernetes/ingress/annotations_test.go @@ -124,7 +124,7 @@ func Test_parseServiceConfig(t *testing.T) { }, ServersScheme: "protocol", ServersTransport: "foobar@file", - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), NativeLB: true, }, }, @@ -137,7 +137,7 @@ func Test_parseServiceConfig(t *testing.T) { expected: &ServiceConfig{ Service: &ServiceIng{ Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{}}, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, diff --git a/pkg/provider/kubernetes/ingress/kubernetes_test.go b/pkg/provider/kubernetes/ingress/kubernetes_test.go index abd08ab01..e999e14b7 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes_test.go +++ b/pkg/provider/kubernetes/ingress/kubernetes_test.go @@ -21,7 +21,7 @@ import ( var _ provider.Provider = (*Provider)(nil) -func Bool(v bool) *bool { return &v } +func pointer[T any](v T) *T { return &v } func TestLoadConfigurationFromIngresses(t *testing.T) { testCases := []struct { @@ -68,7 +68,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -115,7 +115,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Sticky: &dynamic.Sticky{ Cookie: &dynamic.Cookie{ Name: "foobar", @@ -157,7 +157,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -191,7 +191,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -225,7 +225,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -259,7 +259,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -289,7 +289,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -319,7 +319,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-example-com-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.11.0.1:80", @@ -350,7 +350,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -384,7 +384,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -418,7 +418,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -431,7 +431,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { }, "testing-service2-8082": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.2:8080", @@ -462,7 +462,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -496,7 +496,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "default-backend": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -526,7 +526,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8089", @@ -556,7 +556,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-tchouk": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8089", @@ -586,7 +586,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-tchouk": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8089", @@ -620,7 +620,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-tchouk": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8089", @@ -633,7 +633,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { }, "testing-service1-carotte": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8090", @@ -663,7 +663,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-tchouk": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8089", @@ -697,7 +697,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-tchouk": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8089", @@ -710,7 +710,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { }, "toto-service1-tchouk": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.11.0.1:8089", @@ -762,7 +762,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-8080": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.0.0.1:8080", @@ -790,7 +790,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-example-com-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.11.0.1:80", @@ -827,7 +827,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-443": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "https://10.10.0.1:8443", @@ -857,7 +857,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-8443": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "https://10.10.0.1:8443", @@ -888,7 +888,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-8443": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "https://10.10.0.1:8443", @@ -919,7 +919,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "default-backend": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.30.0.1:8080", @@ -949,7 +949,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1023,7 +1023,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1053,7 +1053,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1085,7 +1085,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1113,7 +1113,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1141,7 +1141,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1169,7 +1169,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1197,7 +1197,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1225,7 +1225,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1265,7 +1265,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1294,7 +1294,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1322,7 +1322,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1350,7 +1350,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1378,7 +1378,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1406,7 +1406,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1434,7 +1434,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1462,7 +1462,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1490,7 +1490,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1518,7 +1518,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-80": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1546,7 +1546,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-foobar": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:4711", @@ -1587,7 +1587,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { Services: map[string]*dynamic.Service{ "default-backend": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.10.0.1:8080", @@ -1676,7 +1676,7 @@ func TestLoadConfigurationFromIngressesWithExternalNameServices(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-8080": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://traefik.wtf:8080", @@ -1708,7 +1708,7 @@ func TestLoadConfigurationFromIngressesWithExternalNameServices(t *testing.T) { URL: "http://[2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b]:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1736,7 +1736,7 @@ func TestLoadConfigurationFromIngressesWithExternalNameServices(t *testing.T) { URL: "http://[2001:0db8:3c4d:0015:0000:0000:1a2f:2a3b]:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1809,7 +1809,7 @@ func TestLoadConfigurationFromIngressesWithNativeLB(t *testing.T) { Services: map[string]*dynamic.Service{ "testing-service1-8080": { LoadBalancer: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: "http://10.0.0.1:8080", diff --git a/pkg/provider/kv/kv_test.go b/pkg/provider/kv/kv_test.go index 535a48bab..18693d485 100644 --- a/pkg/provider/kv/kv_test.go +++ b/pkg/provider/kv/kv_test.go @@ -15,6 +15,8 @@ import ( "github.com/traefik/traefik/v2/pkg/types" ) +func pointer[T any](v T) *T { return &v } + func Test_buildConfiguration(t *testing.T) { provider := newProviderMock(mapToPairs(map[string]string{ "traefik/http/routers/Router0/entryPoints/0": "foobar", @@ -647,13 +649,13 @@ func Test_buildConfiguration(t *testing.T) { Interval: "foobar", Timeout: "foobar", Hostname: "foobar", - FollowRedirects: func(v bool) *bool { return &v }(true), + FollowRedirects: pointer(true), Headers: map[string]string{ "name0": "foobar", "name1": "foobar", }, }, - PassHostHeader: func(v bool) *bool { return &v }(true), + PassHostHeader: pointer(true), ResponseForwarding: &dynamic.ResponseForwarding{ FlushInterval: "foobar", }, @@ -662,7 +664,7 @@ func Test_buildConfiguration(t *testing.T) { "Service02": { Mirroring: &dynamic.Mirroring{ Service: "foobar", - MaxBodySize: func(v int64) *int64 { return &v }(42), + MaxBodySize: pointer[int64](42), Mirrors: []dynamic.MirrorService{ { Name: "foobar", @@ -680,11 +682,11 @@ func Test_buildConfiguration(t *testing.T) { Services: []dynamic.WRRService{ { Name: "foobar", - Weight: func(v int) *int { return &v }(42), + Weight: pointer(42), }, { Name: "foobar", - Weight: func(v int) *int { return &v }(42), + Weight: pointer(42), }, }, Sticky: &dynamic.Sticky{ @@ -768,7 +770,7 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.TCPService{ "TCPService01": { LoadBalancer: &dynamic.TCPServersLoadBalancer{ - TerminationDelay: func(v int) *int { return &v }(42), + TerminationDelay: pointer(42), Servers: []dynamic.TCPServer{ {Address: "foobar"}, {Address: "foobar"}, @@ -780,11 +782,11 @@ func Test_buildConfiguration(t *testing.T) { Services: []dynamic.TCPWRRService{ { Name: "foobar", - Weight: func(v int) *int { return &v }(42), + Weight: pointer(42), }, { Name: "foobar", - Weight: func(v int) *int { return &v }(43), + Weight: pointer(43), }, }, }, diff --git a/pkg/provider/marathon/config_test.go b/pkg/provider/marathon/config_test.go index 8400b877a..f8923833c 100644 --- a/pkg/provider/marathon/config_test.go +++ b/pkg/provider/marathon/config_test.go @@ -13,8 +13,7 @@ import ( "github.com/traefik/traefik/v2/pkg/types" ) -func Int(v int) *int { return &v } -func Bool(v bool) *bool { return &v } +func pointer[T any](v T) *T { return &v } func TestGetConfigurationAPIErrors(t *testing.T) { fakeClient := newFakeClient(true, marathon.Applications{}) @@ -73,7 +72,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }}, }, ServersTransports: map[string]*dynamic.ServersTransport{}, @@ -146,7 +145,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }}, }, ServersTransports: map[string]*dynamic.ServersTransport{}, @@ -202,7 +201,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }}, }, ServersTransports: map[string]*dynamic.ServersTransport{}, @@ -248,7 +247,7 @@ func TestBuildConfiguration(t *testing.T) { Address: "localhost:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -314,7 +313,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:8081", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }}, }, ServersTransports: map[string]*dynamic.ServersTransport{}, @@ -378,7 +377,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:8083", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }}, }, ServersTransports: map[string]*dynamic.ServersTransport{}, @@ -431,7 +430,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }}, "bar": {LoadBalancer: &dynamic.ServersLoadBalancer{ Servers: []dynamic.Server{ @@ -439,7 +438,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:8081", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }}, }, ServersTransports: map[string]*dynamic.ServersTransport{}, @@ -487,7 +486,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:81", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -533,7 +532,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }}, }, ServersTransports: map[string]*dynamic.ServersTransport{}, @@ -580,7 +579,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -620,7 +619,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -673,7 +672,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -716,7 +715,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -726,7 +725,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -837,7 +836,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "app2": { @@ -847,7 +846,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -905,7 +904,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "app2": { @@ -915,7 +914,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -962,7 +961,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "app2": { @@ -972,7 +971,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1026,7 +1025,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1073,7 +1072,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "app2": { @@ -1083,7 +1082,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1130,7 +1129,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1178,7 +1177,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "h2c://localhost:90", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1220,7 +1219,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -1230,7 +1229,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1459,7 +1458,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1507,7 +1506,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1554,7 +1553,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1593,7 +1592,7 @@ func TestBuildConfiguration(t *testing.T) { Address: "localhost:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -1679,7 +1678,7 @@ func TestBuildConfiguration(t *testing.T) { Address: "localhost:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -1728,7 +1727,7 @@ func TestBuildConfiguration(t *testing.T) { Address: "localhost:8080", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -1824,7 +1823,7 @@ func TestBuildConfiguration(t *testing.T) { Address: "localhost:8080", }, }, - TerminationDelay: Int(200), + TerminationDelay: pointer(200), }, }, }, @@ -1874,7 +1873,7 @@ func TestBuildConfiguration(t *testing.T) { Address: "localhost:8080", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -1900,7 +1899,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1964,7 +1963,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2012,7 +2011,7 @@ func TestBuildConfiguration(t *testing.T) { URL: "http://localhost:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }}, }, ServersTransports: map[string]*dynamic.ServersTransport{}, diff --git a/pkg/provider/nomad/config_test.go b/pkg/provider/nomad/config_test.go index 84a4791bc..b18335d3c 100644 --- a/pkg/provider/nomad/config_test.go +++ b/pkg/provider/nomad/config_test.go @@ -58,7 +58,7 @@ func Test_defaultRule(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -112,7 +112,7 @@ func Test_defaultRule(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -157,7 +157,7 @@ func Test_defaultRule(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -208,7 +208,7 @@ func Test_defaultRule(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -282,7 +282,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -345,7 +345,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://192.168.1.101:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Test2": { @@ -355,7 +355,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://192.168.1.102:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -418,7 +418,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -478,7 +478,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -541,7 +541,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -593,7 +593,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -646,7 +646,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -691,7 +691,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -749,7 +749,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -797,7 +797,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -807,7 +807,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -984,7 +984,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1035,7 +1035,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1113,7 +1113,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1178,7 +1178,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1237,7 +1237,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1301,7 +1301,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1353,7 +1353,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1406,7 +1406,7 @@ func Test_buildConfig(t *testing.T) { URL: "h2c://127.0.0.1:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1453,7 +1453,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Service2": { @@ -1463,7 +1463,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:8080", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1654,7 +1654,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1717,7 +1717,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1768,7 +1768,7 @@ func Test_buildConfig(t *testing.T) { Address: "127.0.0.1:9999", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -1821,7 +1821,7 @@ func Test_buildConfig(t *testing.T) { Address: "127.0.0.1:9999", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -1917,7 +1917,7 @@ func Test_buildConfig(t *testing.T) { Address: "127.0.0.1:9999", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -1973,7 +1973,7 @@ func Test_buildConfig(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2095,7 +2095,7 @@ func Test_buildConfig(t *testing.T) { Address: "127.0.0.2:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2124,7 +2124,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2211,7 +2211,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2248,7 +2248,7 @@ func Test_buildConfig(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2340,7 +2340,7 @@ func Test_buildConfig(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(200), + TerminationDelay: pointer(200), }, }, }, @@ -2423,7 +2423,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Test-1234154071633021619": { @@ -2433,7 +2433,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2497,7 +2497,7 @@ func Test_buildConfig(t *testing.T) { Servers: []dynamic.TCPServer{ {Address: "127.0.0.1:80"}, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, "Test-8769860286750522282": { @@ -2505,7 +2505,7 @@ func Test_buildConfig(t *testing.T) { Servers: []dynamic.TCPServer{ {Address: "127.0.0.2:80"}, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -2648,7 +2648,7 @@ func Test_buildConfig(t *testing.T) { URL: "http://127.0.0.1:9999", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -2786,5 +2786,4 @@ func extractNamespacesFromProvider(providers []*Provider) []string { return res } -func Int(v int) *int { return &v } -func Bool(v bool) *bool { return &v } +func pointer[T any](v T) *T { return &v } diff --git a/pkg/provider/rancher/config_test.go b/pkg/provider/rancher/config_test.go index 633e85415..80e9b2322 100644 --- a/pkg/provider/rancher/config_test.go +++ b/pkg/provider/rancher/config_test.go @@ -11,8 +11,7 @@ import ( "github.com/traefik/traefik/v2/pkg/types" ) -func Int(v int) *int { return &v } -func Bool(v bool) *bool { return &v } +func pointer[T any](v T) *T { return &v } func Test_buildConfiguration(t *testing.T) { testCases := []struct { @@ -60,7 +59,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -123,7 +122,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Test2": { @@ -133,7 +132,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -199,7 +198,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, "Test2": { @@ -209,7 +208,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://128.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -262,7 +261,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -377,7 +376,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -466,7 +465,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -529,7 +528,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -580,7 +579,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -641,7 +640,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -685,7 +684,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -781,7 +780,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:80", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -833,7 +832,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:8080", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -942,7 +941,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.2:8080", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -971,7 +970,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1046,7 +1045,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.2:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, @@ -1083,7 +1082,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:8080", }, }, - TerminationDelay: Int(100), + TerminationDelay: pointer(100), }, }, }, @@ -1175,7 +1174,7 @@ func Test_buildConfiguration(t *testing.T) { Address: "127.0.0.1:8080", }, }, - TerminationDelay: Int(200), + TerminationDelay: pointer(200), }, }, }, @@ -1238,7 +1237,7 @@ func Test_buildConfiguration(t *testing.T) { URL: "http://127.0.0.1:80", }, }, - PassHostHeader: Bool(true), + PassHostHeader: pointer(true), }, }, }, diff --git a/pkg/provider/traefik/internal.go b/pkg/provider/traefik/internal.go index da44f8ff2..de367bfae 100644 --- a/pkg/provider/traefik/internal.go +++ b/pkg/provider/traefik/internal.go @@ -31,7 +31,7 @@ func New(staticCfg static.Configuration) *Provider { } // ThrottleDuration returns the throttle duration. -func (i Provider) ThrottleDuration() time.Duration { +func (i *Provider) ThrottleDuration() time.Duration { return 0 } diff --git a/pkg/redactor/redactor_config_test.go b/pkg/redactor/redactor_config_test.go index 468db5d62..f96eb04fa 100644 --- a/pkg/redactor/redactor_config_test.go +++ b/pkg/redactor/redactor_config_test.go @@ -85,12 +85,12 @@ func init() { Interval: "foo", Timeout: "foo", Hostname: "foo", - FollowRedirects: boolPtr(true), + FollowRedirects: pointer(true), Headers: map[string]string{ "foo": "bar", }, }, - PassHostHeader: boolPtr(true), + PassHostHeader: pointer(true), ResponseForwarding: &dynamic.ResponseForwarding{ FlushInterval: "foo", }, @@ -107,7 +107,7 @@ func init() { Services: []dynamic.WRRService{ { Name: "foo", - Weight: intPtr(42), + Weight: pointer(42), }, }, Sticky: &dynamic.Sticky{ @@ -123,7 +123,7 @@ func init() { "baz": { Mirroring: &dynamic.Mirroring{ Service: "foo", - MaxBodySize: int64Ptr(42), + MaxBodySize: pointer[int64](42), Mirrors: []dynamic.MirrorService{ { Name: "foo", @@ -379,7 +379,7 @@ func init() { Services: map[string]*dynamic.TCPService{ "foo": { LoadBalancer: &dynamic.TCPServersLoadBalancer{ - TerminationDelay: intPtr(42), + TerminationDelay: pointer(42), ProxyProtocol: &dynamic.ProxyProtocol{ Version: 42, }, @@ -395,7 +395,7 @@ func init() { Services: []dynamic.TCPWRRService{ { Name: "foo", - Weight: intPtr(42), + Weight: pointer(42), }, }, }, @@ -424,7 +424,7 @@ func init() { Services: []dynamic.UDPWRRService{ { Name: "foo", - Weight: intPtr(42), + Weight: pointer(42), }, }, }, @@ -481,7 +481,7 @@ func TestAnonymize_dynamicConfiguration(t *testing.T) { } expected := strings.TrimSuffix(string(expectedConfiguration), "\n") - assert.Equal(t, expected, cleanJSON) + assert.JSONEq(t, expected, cleanJSON) } func TestSecure_dynamicConfiguration(t *testing.T) { @@ -498,7 +498,7 @@ func TestSecure_dynamicConfiguration(t *testing.T) { } expected := strings.TrimSuffix(string(expectedConfiguration), "\n") - assert.Equal(t, expected, cleanJSON) + assert.JSONEq(t, expected, cleanJSON) } func TestDo_staticConfiguration(t *testing.T) { @@ -990,17 +990,7 @@ func TestDo_staticConfiguration(t *testing.T) { } expected := strings.TrimSuffix(string(expectedConfiguration), "\n") - assert.Equal(t, expected, cleanJSON) + assert.JSONEq(t, expected, cleanJSON) } -func boolPtr(value bool) *bool { - return &value -} - -func intPtr(value int) *int { - return &value -} - -func int64Ptr(value int64) *int64 { - return &value -} +func pointer[T any](v T) *T { return &v } diff --git a/pkg/server/configurationwatcher_test.go b/pkg/server/configurationwatcher_test.go index f353c1f90..e7179734c 100644 --- a/pkg/server/configurationwatcher_test.go +++ b/pkg/server/configurationwatcher_test.go @@ -317,7 +317,7 @@ func TestListenProvidersThrottleProviderConfigReload(t *testing.T) { }) } - providerAggregator := aggregator.ProviderAggregator{} + providerAggregator := &aggregator.ProviderAggregator{} err := providerAggregator.AddProvider(pvd) assert.NoError(t, err) @@ -499,7 +499,7 @@ func TestListenProvidersIgnoreSameConfig(t *testing.T) { }, } - providerAggregator := aggregator.ProviderAggregator{} + providerAggregator := &aggregator.ProviderAggregator{} err := providerAggregator.AddProvider(pvd) assert.NoError(t, err) @@ -641,7 +641,7 @@ func TestListenProvidersIgnoreIntermediateConfigs(t *testing.T) { }, } - providerAggregator := aggregator.ProviderAggregator{} + providerAggregator := &aggregator.ProviderAggregator{} err := providerAggregator.AddProvider(pvd) assert.NoError(t, err) diff --git a/pkg/server/service/loadbalancer/wrr/wrr_test.go b/pkg/server/service/loadbalancer/wrr/wrr_test.go index 32068504e..8ef17faeb 100644 --- a/pkg/server/service/loadbalancer/wrr/wrr_test.go +++ b/pkg/server/service/loadbalancer/wrr/wrr_test.go @@ -10,7 +10,7 @@ import ( "github.com/traefik/traefik/v2/pkg/config/dynamic" ) -func Int(v int) *int { return &v } +func pointer[T any](v T) *T { return &v } type responseRecorder struct { *httptest.ResponseRecorder @@ -32,12 +32,12 @@ func TestBalancer(t *testing.T) { balancer.AddService("first", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "first") rw.WriteHeader(http.StatusOK) - }), Int(3)) + }), pointer(3)) balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "second") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} for range 4 { @@ -63,9 +63,9 @@ func TestBalancerOneServerZeroWeight(t *testing.T) { balancer.AddService("first", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "first") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) - balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), Int(0)) + balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), pointer(0)) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} for range 3 { @@ -84,11 +84,11 @@ func TestBalancerNoServiceUp(t *testing.T) { balancer.AddService("first", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.WriteHeader(http.StatusInternalServerError) - }), Int(1)) + }), pointer(1)) balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.WriteHeader(http.StatusInternalServerError) - }), Int(1)) + }), pointer(1)) balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "first", false) balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false) @@ -105,11 +105,11 @@ func TestBalancerOneServerDown(t *testing.T) { balancer.AddService("first", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "first") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.WriteHeader(http.StatusInternalServerError) - }), Int(1)) + }), pointer(1)) balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} @@ -126,12 +126,12 @@ func TestBalancerDownThenUp(t *testing.T) { balancer.AddService("first", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "first") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "second") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} @@ -155,30 +155,30 @@ func TestBalancerPropagate(t *testing.T) { balancer1.AddService("first", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "first") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) balancer1.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "second") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) balancer2 := New(nil, &dynamic.HealthCheck{}) balancer2.AddService("third", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "third") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) balancer2.AddService("fourth", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "fourth") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) topBalancer := New(nil, &dynamic.HealthCheck{}) - topBalancer.AddService("balancer1", balancer1, Int(1)) + topBalancer.AddService("balancer1", balancer1, pointer(1)) _ = balancer1.RegisterStatusUpdater(func(up bool) { topBalancer.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "balancer1", up) // TODO(mpl): if test gets flaky, add channel or something here to signal that // propagation is done, and wait on it before sending request. }) - topBalancer.AddService("balancer2", balancer2, Int(1)) + topBalancer.AddService("balancer2", balancer2, pointer(1)) _ = balancer2.RegisterStatusUpdater(func(up bool) { topBalancer.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "balancer2", up) }) @@ -225,8 +225,8 @@ func TestBalancerPropagate(t *testing.T) { func TestBalancerAllServersZeroWeight(t *testing.T) { balancer := New(nil, nil) - balancer.AddService("test", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), Int(0)) - balancer.AddService("test2", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), Int(0)) + balancer.AddService("test", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), pointer(0)) + balancer.AddService("test2", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), pointer(0)) recorder := httptest.NewRecorder() balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil)) @@ -242,12 +242,12 @@ func TestSticky(t *testing.T) { balancer.AddService("first", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "first") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "second") rw.WriteHeader(http.StatusOK) - }), Int(2)) + }), pointer(2)) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} @@ -275,12 +275,12 @@ func TestSticky_FallBack(t *testing.T) { balancer.AddService("first", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "first") rw.WriteHeader(http.StatusOK) - }), Int(1)) + }), pointer(1)) balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "second") rw.WriteHeader(http.StatusOK) - }), Int(2)) + }), pointer(2)) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} @@ -304,12 +304,12 @@ func TestBalancerBias(t *testing.T) { balancer.AddService("first", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "A") rw.WriteHeader(http.StatusOK) - }), Int(11)) + }), pointer(11)) balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("server", "B") rw.WriteHeader(http.StatusOK) - }), Int(3)) + }), pointer(3)) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} diff --git a/pkg/server/service/proxy_test.go b/pkg/server/service/proxy_test.go index 567ba6105..40ca69d67 100644 --- a/pkg/server/service/proxy_test.go +++ b/pkg/server/service/proxy_test.go @@ -28,7 +28,7 @@ func BenchmarkProxy(b *testing.B) { req := testhelpers.MustNewRequest(http.MethodGet, "http://foo.bar/", nil) pool := newBufferPool() - handler, _ := buildProxy(Bool(false), nil, &staticTransport{res}, pool) + handler, _ := buildProxy(pointer(false), nil, &staticTransport{res}, pool) b.ReportAllocs() for range b.N { diff --git a/pkg/server/service/proxy_websocket_test.go b/pkg/server/service/proxy_websocket_test.go index 108133c37..eb0210a6e 100644 --- a/pkg/server/service/proxy_websocket_test.go +++ b/pkg/server/service/proxy_websocket_test.go @@ -18,10 +18,10 @@ import ( "golang.org/x/net/websocket" ) -func Bool(v bool) *bool { return &v } +func pointer[T any](v T) *T { return &v } func TestWebSocketTCPClose(t *testing.T) { - f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) errChan := make(chan error, 1) @@ -61,7 +61,7 @@ func TestWebSocketTCPClose(t *testing.T) { } func TestWebSocketPingPong(t *testing.T) { - f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) @@ -127,7 +127,7 @@ func TestWebSocketPingPong(t *testing.T) { } func TestWebSocketEcho(t *testing.T) { - f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) mux := http.NewServeMux() @@ -193,7 +193,7 @@ func TestWebSocketPassHost(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - f, err := buildProxy(Bool(test.passHost), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(test.passHost), nil, http.DefaultTransport, nil) require.NoError(t, err) @@ -252,7 +252,7 @@ func TestWebSocketPassHost(t *testing.T) { } func TestWebSocketServerWithoutCheckOrigin(t *testing.T) { - f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) upgrader := gorillawebsocket.Upgrader{CheckOrigin: func(r *http.Request) bool { @@ -293,7 +293,7 @@ func TestWebSocketServerWithoutCheckOrigin(t *testing.T) { } func TestWebSocketRequestWithOrigin(t *testing.T) { - f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) upgrader := gorillawebsocket.Upgrader{} @@ -339,7 +339,7 @@ func TestWebSocketRequestWithOrigin(t *testing.T) { } func TestWebSocketRequestWithQueryParams(t *testing.T) { - f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) upgrader := gorillawebsocket.Upgrader{} @@ -379,7 +379,7 @@ func TestWebSocketRequestWithQueryParams(t *testing.T) { } func TestWebSocketRequestWithHeadersInResponseWriter(t *testing.T) { - f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) mux := http.NewServeMux() @@ -411,7 +411,7 @@ func TestWebSocketRequestWithHeadersInResponseWriter(t *testing.T) { } func TestWebSocketRequestWithEncodedChar(t *testing.T) { - f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) upgrader := gorillawebsocket.Upgrader{} @@ -451,7 +451,7 @@ func TestWebSocketRequestWithEncodedChar(t *testing.T) { } func TestWebSocketUpgradeFailed(t *testing.T) { - f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) mux := http.NewServeMux() @@ -501,7 +501,7 @@ func TestWebSocketUpgradeFailed(t *testing.T) { } func TestForwardsWebsocketTraffic(t *testing.T) { - f, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + f, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) mux := http.NewServeMux() @@ -557,7 +557,7 @@ func TestWebSocketTransferTLSConfig(t *testing.T) { srv := createTLSWebsocketServer() defer srv.Close() - forwarderWithoutTLSConfig, err := buildProxy(Bool(true), nil, http.DefaultTransport, nil) + forwarderWithoutTLSConfig, err := buildProxy(pointer(true), nil, http.DefaultTransport, nil) require.NoError(t, err) proxyWithoutTLSConfig := createProxyWithForwarder(t, forwarderWithoutTLSConfig, srv.URL) @@ -576,7 +576,7 @@ func TestWebSocketTransferTLSConfig(t *testing.T) { transport := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } - forwarderWithTLSConfig, err := buildProxy(Bool(true), nil, transport, nil) + forwarderWithTLSConfig, err := buildProxy(pointer(true), nil, transport, nil) require.NoError(t, err) proxyWithTLSConfig := createProxyWithForwarder(t, forwarderWithTLSConfig, srv.URL) @@ -597,7 +597,7 @@ func TestWebSocketTransferTLSConfig(t *testing.T) { defaultTransport := http.DefaultTransport.(*http.Transport).Clone() defaultTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} - forwarderWithTLSConfigFromDefaultTransport, err := buildProxy(Bool(true), nil, defaultTransport, nil) + forwarderWithTLSConfigFromDefaultTransport, err := buildProxy(pointer(true), nil, defaultTransport, nil) require.NoError(t, err) proxyWithTLSConfigFromDefaultTransport := createProxyWithForwarder(t, forwarderWithTLSConfigFromDefaultTransport, srv.URL) diff --git a/pkg/server/service/roundtripper_test.go b/pkg/server/service/roundtripper_test.go index 8171de56b..2c5a2584e 100644 --- a/pkg/server/service/roundtripper_test.go +++ b/pkg/server/service/roundtripper_test.go @@ -16,10 +16,6 @@ import ( traefiktls "github.com/traefik/traefik/v2/pkg/tls" ) -func Int32(i int32) *int32 { - return &i -} - // LocalhostCert is a PEM-encoded TLS cert // for host example.com, www.example.com // expiring at Jan 29 16:00:00 2084 GMT. @@ -117,7 +113,7 @@ func TestKeepConnectionWhenSameConfiguration(t *testing.T) { rw.WriteHeader(http.StatusOK) })) - connCount := Int32(0) + connCount := pointer[int32](0) srv.Config.ConnState = func(conn net.Conn, state http.ConnState) { if state == http.StateNew { atomic.AddInt32(connCount, 1) diff --git a/pkg/server/service/service_test.go b/pkg/server/service/service_test.go index b761b410e..8b6b305a9 100644 --- a/pkg/server/service/service_test.go +++ b/pkg/server/service/service_test.go @@ -238,7 +238,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) { serviceName: "test", service: &dynamic.ServersLoadBalancer{ Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{}}, - PassHostHeader: func(v bool) *bool { return &v }(true), + PassHostHeader: pointer(true), Servers: []dynamic.Server{ { URL: serverPassHost.URL, @@ -256,7 +256,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) { desc: "PassHost doesn't pass the host instead of the IP", serviceName: "test", service: &dynamic.ServersLoadBalancer{ - PassHostHeader: Bool(false), + PassHostHeader: pointer(false), Sticky: &dynamic.Sticky{Cookie: &dynamic.Cookie{}}, Servers: []dynamic.Server{ { diff --git a/pkg/tcp/proxy.go b/pkg/tcp/proxy.go index 9f91c49b3..3b84c1d91 100644 --- a/pkg/tcp/proxy.go +++ b/pkg/tcp/proxy.go @@ -89,7 +89,7 @@ func (p *Proxy) ServeTCP(conn WriteCloser) { <-errChan } -func (p Proxy) dialBackend() (*net.TCPConn, error) { +func (p *Proxy) dialBackend() (*net.TCPConn, error) { // Dial using directly the TCPAddr for IP based addresses. if p.tcpAddr != nil { return net.DialTCP("tcp", nil, p.tcpAddr) @@ -106,7 +106,7 @@ func (p Proxy) dialBackend() (*net.TCPConn, error) { return conn.(*net.TCPConn), nil } -func (p Proxy) connCopy(dst, src WriteCloser, errCh chan error) { +func (p *Proxy) connCopy(dst, src WriteCloser, errCh chan error) { _, err := io.Copy(dst, src) errCh <- err diff --git a/pkg/tls/certificate.go b/pkg/tls/certificate.go index fca4a2586..02dd376a4 100644 --- a/pkg/tls/certificate.go +++ b/pkg/tls/certificate.go @@ -45,13 +45,6 @@ var ( } ) -// Certificate holds a SSL cert/key pair -// Certs and Key could be either a file path, or the file content itself. -type Certificate struct { - CertFile FileOrContent `json:"certFile,omitempty" toml:"certFile,omitempty" yaml:"certFile,omitempty"` - KeyFile FileOrContent `json:"keyFile,omitempty" toml:"keyFile,omitempty" yaml:"keyFile,omitempty" loggable:"false"` -} - // Certificates defines traefik certificates type // Certs and Keys could be either a file path, or the file content itself. type Certificates []Certificate @@ -73,31 +66,47 @@ func (c Certificates) GetCertificates() []tls.Certificate { return certs } -// FileOrContent hold a file path or content. -type FileOrContent string - -func (f FileOrContent) String() string { - return string(f) -} - -// IsPath returns true if the FileOrContent is a file path, otherwise returns false. -func (f FileOrContent) IsPath() bool { - _, err := os.Stat(f.String()) - return err == nil -} - -func (f FileOrContent) Read() ([]byte, error) { - var content []byte - if f.IsPath() { - var err error - content, err = os.ReadFile(f.String()) - if err != nil { - return nil, err - } - } else { - content = []byte(f) +// String is the method to format the flag's value, part of the flag.Value interface. +// The String method's output will be used in diagnostics. +func (c *Certificates) String() string { + if len(*c) == 0 { + return "" } - return content, nil + var result []string + for _, certificate := range *c { + result = append(result, certificate.CertFile.String()+","+certificate.KeyFile.String()) + } + return strings.Join(result, ";") +} + +// Set is the method to set the flag value, part of the flag.Value interface. +// Set's argument is a string to be parsed to set the flag. +// It's a comma-separated list, so we split it. +func (c *Certificates) Set(value string) error { + certificates := strings.Split(value, ";") + for _, certificate := range certificates { + files := strings.Split(certificate, ",") + if len(files) != 2 { + return fmt.Errorf("bad certificates format: %s", value) + } + *c = append(*c, Certificate{ + CertFile: FileOrContent(files[0]), + KeyFile: FileOrContent(files[1]), + }) + } + return nil +} + +// Type is type of the struct. +func (c *Certificates) Type() string { + return "certificates" +} + +// Certificate holds a SSL cert/key pair +// Certs and Key could be either a file path, or the file content itself. +type Certificate struct { + CertFile FileOrContent `json:"certFile,omitempty" toml:"certFile,omitempty" yaml:"certFile,omitempty"` + KeyFile FileOrContent `json:"keyFile,omitempty" toml:"keyFile,omitempty" yaml:"keyFile,omitempty" loggable:"false"` } // AppendCertificate appends a Certificate to a certificates map keyed by store name. @@ -194,40 +203,31 @@ func (c *Certificate) GetTruncatedCertificateName() string { return certName } -// String is the method to format the flag's value, part of the flag.Value interface. -// The String method's output will be used in diagnostics. -func (c *Certificates) String() string { - if len(*c) == 0 { - return "" - } - var result []string - for _, certificate := range *c { - result = append(result, certificate.CertFile.String()+","+certificate.KeyFile.String()) - } - return strings.Join(result, ";") +// FileOrContent hold a file path or content. +type FileOrContent string + +func (f FileOrContent) String() string { + return string(f) } -// Set is the method to set the flag value, part of the flag.Value interface. -// Set's argument is a string to be parsed to set the flag. -// It's a comma-separated list, so we split it. -func (c *Certificates) Set(value string) error { - certificates := strings.Split(value, ";") - for _, certificate := range certificates { - files := strings.Split(certificate, ",") - if len(files) != 2 { - return fmt.Errorf("bad certificates format: %s", value) +// IsPath returns true if the FileOrContent is a file path, otherwise returns false. +func (f FileOrContent) IsPath() bool { + _, err := os.Stat(f.String()) + return err == nil +} + +func (f FileOrContent) Read() ([]byte, error) { + var content []byte + if f.IsPath() { + var err error + content, err = os.ReadFile(f.String()) + if err != nil { + return nil, err } - *c = append(*c, Certificate{ - CertFile: FileOrContent(files[0]), - KeyFile: FileOrContent(files[1]), - }) + } else { + content = []byte(f) } - return nil -} - -// Type is type of the struct. -func (c *Certificates) Type() string { - return "certificates" + return content, nil } // VerifyPeerCertificate verifies the chain certificates and their URI. diff --git a/pkg/tls/certificate_store.go b/pkg/tls/certificate_store.go index 1a954a0e0..8a7d0e4ac 100644 --- a/pkg/tls/certificate_store.go +++ b/pkg/tls/certificate_store.go @@ -31,7 +31,7 @@ func NewCertificateStore() *CertificateStore { } } -func (c CertificateStore) getDefaultCertificateDomains() []string { +func (c *CertificateStore) getDefaultCertificateDomains() []string { var allCerts []string if c.DefaultCertificate == nil { @@ -58,7 +58,7 @@ func (c CertificateStore) getDefaultCertificateDomains() []string { } // GetAllDomains return a slice with all the certificate domain. -func (c CertificateStore) GetAllDomains() []string { +func (c *CertificateStore) GetAllDomains() []string { allDomains := c.getDefaultCertificateDomains() // Get dynamic certificates @@ -157,7 +157,7 @@ func (c *CertificateStore) GetCertificate(domains []string) *tls.Certificate { } // ResetCache clears the cache in the store. -func (c CertificateStore) ResetCache() { +func (c *CertificateStore) ResetCache() { if c.CertCache != nil { c.CertCache.Flush() }