chore: update linter

This commit is contained in:
Ludovic Fernandez 2024-11-12 10:56:06 +01:00 committed by GitHub
parent 9c50129520
commit f437fb4230
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 796 additions and 830 deletions

View file

@ -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:

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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 }

View file

@ -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",

View file

@ -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",

View file

@ -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",
},

View file

@ -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

View file

@ -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)

View file

@ -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()) {

View file

@ -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{})
}

View file

@ -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

View file

@ -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)

View file

@ -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),
},
},
},

View file

@ -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

View file

@ -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 }

View file

@ -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),
},
},
},

View file

@ -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
}

View file

@ -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),
},
},
},

File diff suppressed because it is too large Load diff

View file

@ -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),
},
},
},

View file

@ -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",

View file

@ -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),
},
},
},

View file

@ -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{},

View file

@ -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 }

View file

@ -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),
},
},
},

View file

@ -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
}

View file

@ -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 }

View file

@ -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)

View file

@ -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{}}

View file

@ -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 {

View file

@ -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)

View file

@ -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)

View file

@ -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{
{

View file

@ -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

View file

@ -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.

View file

@ -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()
}