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

@ -18,7 +18,6 @@ package compose
import (
"bytes"
"context"
"fmt"
"io"
"os"
@ -244,16 +243,11 @@ services:
}
// Set up the context with necessary environment variables
ctx := context.Background()
_ = os.Setenv("TEST_VAR", "test-value")
_ = os.Setenv("API_KEY", "123456")
defer func() {
_ = os.Unsetenv("TEST_VAR")
_ = os.Unsetenv("API_KEY")
}()
t.Setenv("TEST_VAR", "test-value")
t.Setenv("API_KEY", "123456")
// Extract variables from the model
info, noVariables, err := extractInterpolationVariablesFromModel(ctx, cli, projectOptions, []string{})
info, noVariables, err := extractInterpolationVariablesFromModel(t.Context(), cli, projectOptions, []string{})
require.NoError(t, err)
require.False(t, noVariables)