1
0
Fork 0

Bump to go1.24

Co-authored-by: Romain <rtribotte@users.noreply.github.com>
This commit is contained in:
Kevin Pollet 2025-06-02 10:36:05 +02:00 committed by GitHub
parent 5f35c88805
commit cd16321dd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
88 changed files with 284 additions and 362 deletions

View file

@ -1,7 +1,6 @@
package failover
import (
"context"
"net/http"
"net/http/httptest"
"testing"
@ -51,7 +50,7 @@ func TestFailover(t *testing.T) {
assert.Equal(t, []int{200}, recorder.status)
assert.True(t, status)
failover.SetHandlerStatus(context.Background(), false)
failover.SetHandlerStatus(t.Context(), false)
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
failover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
@ -61,7 +60,7 @@ func TestFailover(t *testing.T) {
assert.Equal(t, []int{200}, recorder.status)
assert.True(t, status)
failover.SetFallbackHandlerStatus(context.Background(), false)
failover.SetFallbackHandlerStatus(t.Context(), false)
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
failover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
@ -92,7 +91,7 @@ func TestFailoverDownThenUp(t *testing.T) {
assert.Equal(t, 0, recorder.save["fallback"])
assert.Equal(t, []int{200}, recorder.status)
failover.SetHandlerStatus(context.Background(), false)
failover.SetHandlerStatus(t.Context(), false)
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
failover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
@ -101,7 +100,7 @@ func TestFailoverDownThenUp(t *testing.T) {
assert.Equal(t, 1, recorder.save["fallback"])
assert.Equal(t, []int{200}, recorder.status)
failover.SetHandlerStatus(context.Background(), true)
failover.SetHandlerStatus(t.Context(), true)
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
failover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
@ -129,7 +128,7 @@ func TestFailoverPropagate(t *testing.T) {
rw.WriteHeader(http.StatusOK)
}))
err := failover.RegisterStatusUpdater(func(up bool) {
topFailover.SetHandlerStatus(context.Background(), up)
topFailover.SetHandlerStatus(t.Context(), up)
})
require.NoError(t, err)
@ -141,7 +140,7 @@ func TestFailoverPropagate(t *testing.T) {
assert.Equal(t, 0, recorder.save["topFailover"])
assert.Equal(t, []int{200}, recorder.status)
failover.SetHandlerStatus(context.Background(), false)
failover.SetHandlerStatus(t.Context(), false)
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
topFailover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
@ -151,7 +150,7 @@ func TestFailoverPropagate(t *testing.T) {
assert.Equal(t, 0, recorder.save["topFailover"])
assert.Equal(t, []int{200}, recorder.status)
failover.SetFallbackHandlerStatus(context.Background(), false)
failover.SetFallbackHandlerStatus(t.Context(), false)
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
topFailover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))

View file

@ -2,7 +2,6 @@ package mirror
import (
"bytes"
"context"
"io"
"net/http"
"net/http/httptest"
@ -20,7 +19,7 @@ func TestMirroringOn100(t *testing.T) {
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
})
pool := safe.NewPool(context.Background())
pool := safe.NewPool(t.Context())
mirror := New(handler, pool, defaultMaxBodySize, nil)
err := mirror.AddMirror(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
atomic.AddInt32(&countMirror1, 1)
@ -49,7 +48,7 @@ func TestMirroringOn10(t *testing.T) {
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
})
pool := safe.NewPool(context.Background())
pool := safe.NewPool(t.Context())
mirror := New(handler, pool, defaultMaxBodySize, nil)
err := mirror.AddMirror(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
atomic.AddInt32(&countMirror1, 1)
@ -74,7 +73,7 @@ func TestMirroringOn10(t *testing.T) {
}
func TestInvalidPercent(t *testing.T) {
mirror := New(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), safe.NewPool(context.Background()), defaultMaxBodySize, nil)
mirror := New(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), safe.NewPool(t.Context()), defaultMaxBodySize, nil)
err := mirror.AddMirror(nil, -1)
assert.Error(t, err)
@ -92,7 +91,7 @@ func TestHijack(t *testing.T) {
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
})
pool := safe.NewPool(context.Background())
pool := safe.NewPool(t.Context())
mirror := New(handler, pool, defaultMaxBodySize, nil)
var mirrorRequest bool
@ -116,7 +115,7 @@ func TestFlush(t *testing.T) {
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
})
pool := safe.NewPool(context.Background())
pool := safe.NewPool(t.Context())
mirror := New(handler, pool, defaultMaxBodySize, nil)
var mirrorRequest bool
@ -144,7 +143,7 @@ func TestMirroringWithBody(t *testing.T) {
body = []byte(`body`)
)
pool := safe.NewPool(context.Background())
pool := safe.NewPool(t.Context())
handler := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
assert.NotNil(t, r.Body)

View file

@ -90,8 +90,8 @@ func TestBalancerNoServiceUp(t *testing.T) {
rw.WriteHeader(http.StatusInternalServerError)
}), pointer(1))
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "first", false)
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false)
balancer.SetStatus(context.WithValue(t.Context(), serviceName, "parent"), "first", false)
balancer.SetStatus(context.WithValue(t.Context(), serviceName, "parent"), "second", false)
recorder := httptest.NewRecorder()
balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
@ -110,7 +110,7 @@ func TestBalancerOneServerDown(t *testing.T) {
balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusInternalServerError)
}), pointer(1))
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false)
balancer.SetStatus(context.WithValue(t.Context(), serviceName, "parent"), "second", false)
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
for range 3 {
@ -132,7 +132,7 @@ func TestBalancerDownThenUp(t *testing.T) {
rw.Header().Set("server", "second")
rw.WriteHeader(http.StatusOK)
}), pointer(1))
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false)
balancer.SetStatus(context.WithValue(t.Context(), serviceName, "parent"), "second", false)
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
for range 3 {
@ -140,7 +140,7 @@ func TestBalancerDownThenUp(t *testing.T) {
}
assert.Equal(t, 3, recorder.save["first"])
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", true)
balancer.SetStatus(context.WithValue(t.Context(), serviceName, "parent"), "second", true)
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
for range 2 {
balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
@ -174,13 +174,13 @@ func TestBalancerPropagate(t *testing.T) {
topBalancer := New(nil, &dynamic.HealthCheck{})
topBalancer.AddService("balancer1", balancer1, pointer(1))
_ = balancer1.RegisterStatusUpdater(func(up bool) {
topBalancer.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "balancer1", up)
topBalancer.SetStatus(context.WithValue(t.Context(), 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, pointer(1))
_ = balancer2.RegisterStatusUpdater(func(up bool) {
topBalancer.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "balancer2", up)
topBalancer.SetStatus(context.WithValue(t.Context(), serviceName, "top"), "balancer2", up)
})
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
@ -195,7 +195,7 @@ func TestBalancerPropagate(t *testing.T) {
assert.Equal(t, wantStatus, recorder.status)
// fourth gets downed, but balancer2 still up since third is still up.
balancer2.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "fourth", false)
balancer2.SetStatus(context.WithValue(t.Context(), serviceName, "top"), "fourth", false)
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
for range 8 {
topBalancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
@ -209,7 +209,7 @@ func TestBalancerPropagate(t *testing.T) {
// third gets downed, and the propagation triggers balancer2 to be marked as
// down as well for topBalancer.
balancer2.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "third", false)
balancer2.SetStatus(context.WithValue(t.Context(), serviceName, "top"), "third", false)
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
for range 8 {
topBalancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))

View file

@ -1,7 +1,6 @@
package service
import (
"context"
"crypto/tls"
"crypto/x509"
"net"
@ -351,7 +350,7 @@ func TestKerberosRoundTripper(t *testing.T) {
}),
}
ctx := AddTransportOnContext(context.Background())
ctx := AddTransportOnContext(t.Context())
for _, expected := range test.expectedStatusCode {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://127.0.0.1", http.NoBody)
require.NoError(t, err)

View file

@ -69,7 +69,7 @@ func TestGetLoadBalancer(t *testing.T) {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
handler, err := sm.getLoadBalancer(context.Background(), test.serviceName, test.service, test.fwd)
handler, err := sm.getLoadBalancer(t.Context(), test.serviceName, test.service, test.fwd)
if test.expectError {
require.Error(t, err)
assert.Nil(t, handler)
@ -336,7 +336,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
handler, err := sm.getLoadBalancerServiceHandler(context.Background(), test.serviceName, test.service)
handler, err := sm.getLoadBalancerServiceHandler(t.Context(), test.serviceName, test.service)
assert.NoError(t, err)
assert.NotNil(t, handler)
@ -414,7 +414,7 @@ func Test1xxResponses(t *testing.T) {
},
},
}
handler, err := sm.getLoadBalancerServiceHandler(context.Background(), "foobar", config)
handler, err := sm.getLoadBalancerServiceHandler(t.Context(), "foobar", config)
assert.NoError(t, err)
frontend := httptest.NewServer(handler)
@ -458,7 +458,7 @@ func Test1xxResponses(t *testing.T) {
return nil
},
}
req, _ := http.NewRequestWithContext(httptrace.WithClientTrace(context.Background(), trace), http.MethodGet, frontend.URL, nil)
req, _ := http.NewRequestWithContext(httptrace.WithClientTrace(t.Context(), trace), http.MethodGet, frontend.URL, nil)
res, err := frontendClient.Do(req)
assert.NoError(t, err)
@ -506,15 +506,15 @@ func TestManager_ServiceBuilders(t *testing.T) {
return nil, nil
}))
h, err := manager.BuildHTTP(context.Background(), "test@internal")
h, err := manager.BuildHTTP(t.Context(), "test@internal")
require.NoError(t, err)
assert.Equal(t, internalHandler, h)
h, err = manager.BuildHTTP(context.Background(), "test@test")
h, err = manager.BuildHTTP(t.Context(), "test@test")
require.NoError(t, err)
assert.NotNil(t, h)
_, err = manager.BuildHTTP(context.Background(), "wrong@test")
_, err = manager.BuildHTTP(t.Context(), "wrong@test")
assert.Error(t, err)
}
@ -571,7 +571,7 @@ func TestManager_Build(t *testing.T) {
},
})
ctx := context.Background()
ctx := t.Context()
if len(test.providerName) > 0 {
ctx = provider.AddInContext(ctx, "foobar@"+test.providerName)
}
@ -598,6 +598,6 @@ func TestMultipleTypeOnBuildHTTP(t *testing.T) {
},
})
_, err := manager.BuildHTTP(context.Background(), "test@file")
_, err := manager.BuildHTTP(t.Context(), "test@file")
assert.Error(t, err, "cannot create service: multi-types service not supported, consider declaring two different pieces of service instead")
}

View file

@ -1,7 +1,6 @@
package tcp
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
@ -181,7 +180,7 @@ func TestManager_BuildTCP(t *testing.T) {
TCPServices: test.configs,
})
ctx := context.Background()
ctx := t.Context()
if len(test.providerName) > 0 {
ctx = provider.AddInContext(ctx, "foobar@"+test.providerName)
}

View file

@ -1,7 +1,6 @@
package udp
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
@ -181,7 +180,7 @@ func TestManager_BuildUDP(t *testing.T) {
UDPServices: test.configs,
})
ctx := context.Background()
ctx := t.Context()
if len(test.providerName) > 0 {
ctx = provider.AddInContext(ctx, "foobar@"+test.providerName)
}