test: replace context.Background()/context.TODO() with t.Context()

Replace manual context creation with t.Context() which is automatically
cancelled when the test completes.

Go 1.24 modernization pattern.

Assisted-By: cagent
Signed-off-by: David Gageot <david.gageot@docker.com>
This commit is contained in:
David Gageot
2026-01-20 10:30:31 +01:00
committed by Guillaume Lours
parent b92b87dd9c
commit 093205121c
19 changed files with 56 additions and 96 deletions

View File

@@ -17,7 +17,6 @@
package desktop
import (
"context"
"os"
"testing"
"time"
@@ -34,9 +33,6 @@ func TestClientPing(t *testing.T) {
t.Skip("Skipping - COMPOSE_TEST_DESKTOP_ENDPOINT not defined")
}
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
client := NewClient(desktopEndpoint)
t.Cleanup(func() {
_ = client.Close()
@@ -44,7 +40,7 @@ func TestClientPing(t *testing.T) {
now := time.Now()
ret, err := client.Ping(ctx)
ret, err := client.Ping(t.Context())
require.NoError(t, err)
serverTime := time.Unix(0, ret.ServerTime)