Merge pull request #51045 from thaJeztah/t_context

use t.Context() instead of context.TODO() in various tests
This commit is contained in:
Paweł Gronowski
2025-09-26 09:09:01 +00:00
committed by GitHub
25 changed files with 87 additions and 94 deletions

View File

@@ -53,7 +53,7 @@ func TestEnv2Variables(t *testing.T) {
instructions.KeyValuePair{Key: "var2", Value: "val2"},
},
}
err := dispatch(context.TODO(), sb, envCommand)
err := dispatch(t.Context(), sb, envCommand)
assert.NilError(t, err)
expected := []string{
@@ -72,7 +72,7 @@ func TestEnvValueWithExistingRunConfigEnv(t *testing.T) {
instructions.KeyValuePair{Key: "var1", Value: "val1"},
},
}
err := dispatch(context.TODO(), sb, envCommand)
err := dispatch(t.Context(), sb, envCommand)
assert.NilError(t, err)
expected := []string{
"var1=val1",
@@ -86,7 +86,7 @@ func TestMaintainer(t *testing.T) {
b := newBuilderWithMockBackend(t)
sb := newDispatchRequest(b, '\\', nil, NewBuildArgs(make(map[string]*string)), newStagesBuildResults())
cmd := &instructions.MaintainerCommand{Maintainer: maintainerEntry}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Check(t, is.Equal(sb.state.maintainer, maintainerEntry))
}
@@ -102,7 +102,7 @@ func TestLabel(t *testing.T) {
instructions.KeyValuePair{Key: labelName, Value: labelValue},
},
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Assert(t, is.Contains(sb.state.runConfig.Labels, labelName))
@@ -115,7 +115,7 @@ func TestFromScratch(t *testing.T) {
cmd := &instructions.Stage{
BaseName: "scratch",
}
err := initializeStage(context.TODO(), sb, cmd)
err := initializeStage(t.Context(), sb, cmd)
if runtime.GOOS == "windows" {
assert.Check(t, is.Error(err, "Windows does not support FROM scratch"))
@@ -153,7 +153,7 @@ func TestFromWithArg(t *testing.T) {
sb := newDispatchRequest(b, '\\', nil, args, newStagesBuildResults())
assert.NilError(t, err)
err = initializeStage(context.TODO(), sb, cmd)
err = initializeStage(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Check(t, is.Equal(sb.state.imageID, expected))
@@ -174,7 +174,7 @@ func TestFromWithArgButBuildArgsNotGiven(t *testing.T) {
sb := newDispatchRequest(b, '\\', nil, args, newStagesBuildResults())
assert.NilError(t, err)
err = initializeStage(context.TODO(), sb, cmd)
err = initializeStage(t.Context(), sb, cmd)
assert.Error(t, err, "base name (${THETAG}) should not be blank")
}
@@ -194,7 +194,7 @@ func TestFromWithUndefinedArg(t *testing.T) {
cmd := &instructions.Stage{
BaseName: "alpine${THETAG}",
}
err := initializeStage(context.TODO(), sb, cmd)
err := initializeStage(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Check(t, is.Equal(sb.state.imageID, expected))
}
@@ -206,12 +206,12 @@ func TestFromMultiStageWithNamedStage(t *testing.T) {
previousResults := newStagesBuildResults()
firstSB := newDispatchRequest(b, '\\', nil, NewBuildArgs(make(map[string]*string)), previousResults)
secondSB := newDispatchRequest(b, '\\', nil, NewBuildArgs(make(map[string]*string)), previousResults)
err := initializeStage(context.TODO(), firstSB, firstFrom)
err := initializeStage(t.Context(), firstSB, firstFrom)
assert.NilError(t, err)
assert.Check(t, firstSB.state.hasFromImage())
previousResults.indexed["base"] = firstSB.state.runConfig
previousResults.flat = append(previousResults.flat, firstSB.state.runConfig)
err = initializeStage(context.TODO(), secondSB, secondFrom)
err = initializeStage(t.Context(), secondSB, secondFrom)
assert.NilError(t, err)
assert.Check(t, secondSB.state.hasFromImage())
}
@@ -222,7 +222,7 @@ func TestOnbuild(t *testing.T) {
cmd := &instructions.OnbuildCommand{
Expression: "ADD . /app/src",
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Check(t, is.Equal(sb.state.runConfig.OnBuild[0], "ADD . /app/src"))
}
@@ -239,7 +239,7 @@ func TestWorkdir(t *testing.T) {
Path: workingDir,
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Check(t, is.Equal(sb.state.runConfig.WorkingDir, workingDir))
}
@@ -249,7 +249,7 @@ func TestCmd(t *testing.T) {
sb := newDispatchRequest(b, '`', nil, NewBuildArgs(make(map[string]*string)), newStagesBuildResults())
sb.state.baseImage = &mockImage{}
err := dispatch(context.TODO(), sb, &instructions.CmdCommand{
err := dispatch(t.Context(), sb, &instructions.CmdCommand{
ShellDependantCmdLine: instructions.ShellDependantCmdLine{
CmdLine: []string{"./executable"},
PrependShell: true,
@@ -276,7 +276,7 @@ func TestHealthcheckNone(t *testing.T) {
Test: []string{"NONE"},
},
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Assert(t, sb.state.runConfig.Healthcheck != nil)
@@ -292,7 +292,7 @@ func TestHealthcheckCmd(t *testing.T) {
Test: expectedTest,
},
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Assert(t, sb.state.runConfig.Healthcheck != nil)
@@ -304,7 +304,7 @@ func TestEntrypoint(t *testing.T) {
sb := newDispatchRequest(b, '`', nil, NewBuildArgs(make(map[string]*string)), newStagesBuildResults())
sb.state.baseImage = &mockImage{}
err := dispatch(context.TODO(), sb, &instructions.EntrypointCommand{
err := dispatch(t.Context(), sb, &instructions.EntrypointCommand{
ShellDependantCmdLine: instructions.ShellDependantCmdLine{
CmdLine: []string{"/usr/sbin/nginx"},
PrependShell: true,
@@ -329,7 +329,7 @@ func TestExpose(t *testing.T) {
cmd := &instructions.ExposeCommand{
Ports: []string{exposedPort},
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Assert(t, sb.state.runConfig.ExposedPorts != nil)
@@ -345,7 +345,7 @@ func TestUser(t *testing.T) {
cmd := &instructions.UserCommand{
User: "test",
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Check(t, is.Equal(sb.state.runConfig.User, "test"))
}
@@ -359,7 +359,7 @@ func TestVolume(t *testing.T) {
cmd := &instructions.VolumeCommand{
Volumes: []string{exposedVolume},
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Assert(t, sb.state.runConfig.Volumes != nil)
assert.Check(t, is.Len(sb.state.runConfig.Volumes, 1))
@@ -379,7 +379,7 @@ func TestStopSignal(t *testing.T) {
cmd := &instructions.StopSignalCommand{
Signal: signal,
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
assert.Check(t, is.Equal(sb.state.runConfig.StopSignal, signal))
}
@@ -391,7 +391,7 @@ func TestArg(t *testing.T) {
argName := "foo"
argVal := "bar"
cmd := &instructions.ArgCommand{Args: []instructions.KeyValuePairOptional{{Key: argName, Value: &argVal}}}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.NilError(t, err)
expected := map[string]string{argName: argVal}
@@ -403,7 +403,7 @@ func TestShell(t *testing.T) {
sb := newDispatchRequest(b, '`', nil, NewBuildArgs(make(map[string]*string)), newStagesBuildResults())
shellCmd := []string{"powershell"}
err := dispatch(context.TODO(), sb, &instructions.ShellCommand{
err := dispatch(t.Context(), sb, &instructions.ShellCommand{
Shell: shellCmd,
})
assert.NilError(t, err)
@@ -459,7 +459,7 @@ func TestRunWithBuildArgs(t *testing.T) {
return imageCache
}
prober, err := newImageProber(context.TODO(), mockBackend, nil, false)
prober, err := newImageProber(t.Context(), mockBackend, nil, false)
assert.NilError(t, err, "Could not create image prober")
b.imageProber = prober
@@ -484,7 +484,7 @@ func TestRunWithBuildArgs(t *testing.T) {
return "", nil
}
from := &instructions.Stage{BaseName: "abcdef"}
err = initializeStage(context.TODO(), sb, from)
err = initializeStage(t.Context(), sb, from)
assert.NilError(t, err)
sb.state.buildArgs.AddArg("one", strPtr("two"))
@@ -504,7 +504,7 @@ func TestRunWithBuildArgs(t *testing.T) {
runinst.CmdLine = []string{"echo foo"}
runinst.PrependShell = true
assert.NilError(t, dispatch(context.TODO(), sb, runinst))
assert.NilError(t, dispatch(t.Context(), sb, runinst))
// Check that runConfig.Cmd has not been modified by run
assert.Check(t, is.DeepEqual(sb.state.runConfig.Cmd, origCmd))
@@ -528,10 +528,10 @@ func TestRunIgnoresHealthcheck(t *testing.T) {
mockBackend.makeImageCacheFunc = func(_ []string) builder.ImageCache {
return imageCache
}
imageProber, err := newImageProber(context.TODO(), mockBackend, nil, false)
imgProber, err := newImageProber(t.Context(), mockBackend, nil, false)
assert.NilError(t, err, "Could not create image prober")
b.imageProber = imageProber
b.imageProber = imgProber
mockBackend.getImageFunc = func(_ string) (builder.Image, builder.ROLayer, error) {
return &mockImage{
id: "abcdef",
@@ -545,7 +545,7 @@ func TestRunIgnoresHealthcheck(t *testing.T) {
return "", nil
}
from := &instructions.Stage{BaseName: "abcdef"}
err = initializeStage(context.TODO(), sb, from)
err = initializeStage(t.Context(), sb, from)
assert.NilError(t, err)
expectedTest := []string{"CMD-SHELL", "curl -f http://localhost/ || exit 1"}
@@ -562,7 +562,7 @@ func TestRunIgnoresHealthcheck(t *testing.T) {
assert.NilError(t, err)
cmd := healthint.(*instructions.HealthCheckCommand)
assert.NilError(t, dispatch(context.TODO(), sb, cmd))
assert.NilError(t, dispatch(t.Context(), sb, cmd))
assert.Assert(t, sb.state.runConfig.Healthcheck != nil)
mockBackend.containerCreateFunc = func(config backend.ContainerCreateConfig) (container.CreateResponse, error) {
@@ -577,7 +577,7 @@ func TestRunIgnoresHealthcheck(t *testing.T) {
run := runint.(*instructions.RunCommand)
run.PrependShell = true
assert.NilError(t, dispatch(context.TODO(), sb, run))
assert.NilError(t, dispatch(t.Context(), sb, run))
assert.Check(t, is.DeepEqual(sb.state.runConfig.Healthcheck.Test, expectedTest))
}
@@ -595,7 +595,7 @@ func TestDispatchUnsupportedOptions(t *testing.T) {
},
Chmod: "0655",
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.Error(t, err, "the --chmod option requires BuildKit. Refer to https://docs.docker.com/go/buildkit/ to learn how to build images with BuildKit enabled")
})
@@ -607,7 +607,7 @@ func TestDispatchUnsupportedOptions(t *testing.T) {
},
Chmod: "0655",
}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.Error(t, err, "the --chmod option requires BuildKit. Refer to https://docs.docker.com/go/buildkit/ to learn how to build images with BuildKit enabled")
})
@@ -621,7 +621,7 @@ func TestDispatchUnsupportedOptions(t *testing.T) {
// one or more of these flags will be supported in future
for _, f := range []string{"mount", "network", "security", "any-flag"} {
cmd.FlagsUsed = []string{f}
err := dispatch(context.TODO(), sb, cmd)
err := dispatch(t.Context(), sb, cmd)
assert.Error(t, err, fmt.Sprintf("the --%s option requires BuildKit. Refer to https://docs.docker.com/go/buildkit/ to learn how to build images with BuildKit enabled", f))
}
})

View File

@@ -1,7 +1,6 @@
package dockerfile
import (
"context"
"os"
"runtime"
"testing"
@@ -130,7 +129,7 @@ func TestDispatch(t *testing.T) {
b := newBuilderWithMockBackend(t)
sb := newDispatchRequest(b, '`', buildContext, NewBuildArgs(make(map[string]*string)), newStagesBuildResults())
err = dispatch(context.TODO(), sb, tc.cmd)
err = dispatch(t.Context(), sb, tc.cmd)
assert.Check(t, is.ErrorContains(err, tc.expectedError))
})
}

View File

@@ -1,7 +1,6 @@
package dockerfile
import (
"context"
"os"
"path/filepath"
"testing"
@@ -115,7 +114,7 @@ othergrp:x:6666:
},
} {
t.Run(testcase.name, func(t *testing.T) {
idPair, err := parseChownFlag(context.TODO(), testcase.builder, testcase.state, testcase.chownStr, contextDir, testcase.idMapping)
idPair, err := parseChownFlag(t.Context(), testcase.builder, testcase.state, testcase.chownStr, contextDir, testcase.idMapping)
assert.NilError(t, err, "Failed to parse chown flag: %q", testcase.chownStr)
assert.Check(t, is.DeepEqual(testcase.expected, idPair), "chown flag mapping failure")
})
@@ -156,7 +155,7 @@ othergrp:x:6666:
},
} {
t.Run(testcase.name, func(t *testing.T) {
_, err := parseChownFlag(context.TODO(), testcase.builder, testcase.state, testcase.chownStr, contextDir, testcase.idMapping)
_, err := parseChownFlag(t.Context(), testcase.builder, testcase.state, testcase.chownStr, contextDir, testcase.idMapping)
assert.Check(t, is.Error(err, testcase.descr), "Expected error string doesn't match")
})
}

View File

@@ -1,7 +1,6 @@
package dockerfile
import (
"context"
"fmt"
"os"
"runtime"
@@ -206,6 +205,6 @@ func TestExportImage(t *testing.T) {
imageSources: getMockImageSource(nil, nil, nil),
docker: getMockBuildBackend(),
}
err := b.exportImage(context.TODO(), ds, &MockRWLayer{}, parentImage, &container.Config{})
err := b.exportImage(t.Context(), ds, &MockRWLayer{}, parentImage, &container.Config{})
assert.NilError(t, err)
}

View File

@@ -1,7 +1,6 @@
package containerd
import (
"context"
"testing"
c8dimages "github.com/containerd/containerd/v2/core/images"
@@ -17,7 +16,7 @@ import (
)
func TestImageDelete(t *testing.T) {
ctx := namespaces.WithNamespace(context.TODO(), "testing")
ctx := namespaces.WithNamespace(t.Context(), "testing")
for _, tc := range []struct {
ref string

View File

@@ -1,7 +1,6 @@
package containerd
import (
"context"
"fmt"
"path/filepath"
"testing"
@@ -17,7 +16,7 @@ import (
)
func TestImageInspect(t *testing.T) {
ctx := namespaces.WithNamespace(context.TODO(), "testing")
ctx := namespaces.WithNamespace(t.Context(), "testing")
blobsDir := t.TempDir()

View File

@@ -89,7 +89,7 @@ func BenchmarkImageList(b *testing.B) {
for _, count := range []int{10, 100, 1000} {
csDir := b.TempDir()
ctx := namespaces.WithNamespace(context.TODO(), "testing-"+strconv.Itoa(count))
ctx := namespaces.WithNamespace(b.Context(), "testing-"+strconv.Itoa(count))
cs := &delayedStore{
store: &blobsDirContentStore{blobs: filepath.Join(csDir, "blobs/sha256")},
@@ -113,7 +113,7 @@ func BenchmarkImageList(b *testing.B) {
}
func TestImageListCheckTotalSize(t *testing.T) {
ctx := namespaces.WithNamespace(context.TODO(), "testing")
ctx := namespaces.WithNamespace(t.Context(), "testing")
blobsDir := t.TempDir()
cs := &blobsDirContentStore{blobs: filepath.Join(blobsDir, "blobs/sha256")}
@@ -209,7 +209,7 @@ func blobSize(t *testing.T, ctx context.Context, cs content.Store, dgst digest.D
}
func TestImageList(t *testing.T) {
ctx := namespaces.WithNamespace(context.TODO(), "testing")
ctx := namespaces.WithNamespace(t.Context(), "testing")
blobsDir := t.TempDir()

View File

@@ -30,7 +30,7 @@ func TestImageLoad(t *testing.T) {
linuxArmv5 := ocispec.Platform{OS: "linux", Architecture: "arm", Variant: "v5"}
linuxRiscv64 := ocispec.Platform{OS: "linux", Architecture: "riskv64"}
ctx := namespaces.WithNamespace(context.TODO(), "testing-"+t.Name())
ctx := namespaces.WithNamespace(t.Context(), "testing-"+t.Name())
store, err := local.NewLabeledStore(t.TempDir(), &labelstore.InMemory{})
assert.NilError(t, err)

View File

@@ -27,7 +27,7 @@ type pushTestCase struct {
}
func TestImagePushIndex(t *testing.T) {
ctx := namespaces.WithNamespace(context.TODO(), "testing-"+t.Name())
ctx := namespaces.WithNamespace(t.Context(), "testing-"+t.Name())
csDir := t.TempDir()
store := &blobsDirContentStore{blobs: filepath.Join(csDir, "blobs/sha256")}

View File

@@ -1,7 +1,6 @@
package containerd
import (
"context"
"io"
"path/filepath"
"testing"
@@ -16,7 +15,7 @@ import (
)
func TestImageMultiplatformSaveShallowWithNative(t *testing.T) {
ctx := namespaces.WithNamespace(context.TODO(), "testing-"+t.Name())
ctx := namespaces.WithNamespace(t.Context(), "testing-"+t.Name())
contentDir := t.TempDir()
store := &blobsDirContentStore{blobs: filepath.Join(contentDir, "blobs/sha256")}
@@ -72,7 +71,7 @@ func TestImageMultiplatformSaveShallowWithNative(t *testing.T) {
}
func TestImageMultiplatformSaveShallowWithoutNative(t *testing.T) {
ctx := namespaces.WithNamespace(context.TODO(), "testing-"+t.Name())
ctx := namespaces.WithNamespace(t.Context(), "testing-"+t.Name())
contentDir := t.TempDir()
store := &blobsDirContentStore{blobs: filepath.Join(contentDir, "blobs/sha256")}

View File

@@ -24,7 +24,7 @@ import (
)
func TestLookup(t *testing.T) {
ctx := namespaces.WithNamespace(context.TODO(), "testing")
ctx := namespaces.WithNamespace(t.Context(), "testing")
ctx = logtest.WithT(ctx, t)
mdb := newTestDB(ctx, t)
service := &ImageService{

View File

@@ -46,7 +46,7 @@ func testNetwork(networkType string, t *testing.T) {
epOptions := make(map[string]any)
te := &testEndpoint{}
err = d.CreateEndpoint(context.TODO(), "dummy", "ep1", te.Interface(), epOptions)
err = d.CreateEndpoint(t.Context(), "dummy", "ep1", te.Interface(), epOptions)
if err != nil {
t.Fatalf("Failed to create an endpoint : %s", err.Error())
}

View File

@@ -437,7 +437,7 @@ func TestNetworkEndpointsWalkers(t *testing.T) {
assert.Assert(t, epWanted != nil)
assert.Assert(t, is.Equal(epWanted, ep11))
ctx := context.TODO()
ctx := t.Context()
current := len(controller.Networks(ctx))
// Create network 2
@@ -1262,7 +1262,7 @@ func externalKeyTest(t *testing.T, reexec bool) {
assert.NilError(t, err, "Failed to create new osl sandbox")
defer func() {
if err := extOsBox.Destroy(); err != nil {
log.G(context.TODO()).Warnf("Failed to remove os sandbox: %v", err)
log.G(t.Context()).Warnf("Failed to remove os sandbox: %v", err)
}
}()

View File

@@ -1,7 +1,6 @@
package libnetwork
import (
"context"
"fmt"
"net"
"net/netip"
@@ -176,7 +175,7 @@ func TestAddEpToResolver(t *testing.T) {
}
// Add the endpoint and check expected results.
err := addEpToResolverImpl(context.TODO(),
err := addEpToResolverImpl(t.Context(),
"netname", "epname", tc.epToAdd, resolvers, tc.hnsEndpoints)
assert.Check(t, err)
for i, resolver := range resolvers {

View File

@@ -38,6 +38,7 @@ type TestingT interface {
assert.TestingT
poll.TestingT
Helper()
Context() context.Context
}
func launchNode(t TestingT, conf Config) *NetworkDB {
@@ -82,7 +83,7 @@ func createNetworkDBInstances(t TestingT, num int, namePrefix string, conf *Conf
func closeNetworkDBInstances(t TestingT, dbs []*NetworkDB) {
t.Helper()
log.G(context.TODO()).Print("Closing DB instances...")
log.G(t.Context()).Print("Closing DB instances...")
for _, db := range dbs {
db.Close()
}
@@ -923,7 +924,7 @@ func TestNetworkDBIslands(t *testing.T) {
// Now the 3 bootstrap nodes will cleanly leave, and will be properly removed from the other 2 nodes
for i := 0; i < 3; i++ {
log.G(context.TODO()).Infof("node %d leaving", i)
log.G(t.Context()).Infof("node %d leaving", i)
dbs[i].Close()
}
@@ -958,7 +959,7 @@ func TestNetworkDBIslands(t *testing.T) {
// Spawn again the first 3 nodes with different names but same IP:port
for i := 0; i < 3; i++ {
log.G(context.TODO()).Infof("node %d coming back", i)
log.G(t.Context()).Infof("node %d coming back", i)
conf := *dbs[i].config
conf.NodeID = stringid.TruncateID(stringid.GenerateRandomID())
dbs[i] = launchNode(t, conf)

View File

@@ -1,7 +1,6 @@
package kernel
import (
"context"
"testing"
"github.com/containerd/log"
@@ -18,7 +17,7 @@ func TestReadWriteKnobs(t *testing.T) {
// Check if the test is able to read the value
v, err := readSystemProperty(k)
if err != nil {
log.G(context.TODO()).WithError(err).Warnf("Path %v not readable", k)
log.G(t.Context()).WithError(err).Warnf("Path %v not readable", k)
// the path is not there, skip this key
continue
}

View File

@@ -1,7 +1,6 @@
package logger
import (
"context"
"encoding/binary"
"errors"
"io"
@@ -156,7 +155,7 @@ func TestAdapterReadLogs(t *testing.T) {
lr, ok := l.(LogReader)
assert.Check(t, ok, "Logger does not implement LogReader")
lw := lr.ReadLogs(context.TODO(), ReadConfig{})
lw := lr.ReadLogs(t.Context(), ReadConfig{})
for _, x := range testMsg {
select {
@@ -175,7 +174,7 @@ func TestAdapterReadLogs(t *testing.T) {
}
lw.ConsumerGone()
lw = lr.ReadLogs(context.TODO(), ReadConfig{Follow: true})
lw = lr.ReadLogs(t.Context(), ReadConfig{Follow: true})
for _, x := range testMsg {
select {
case msg := <-lw.Msg:

View File

@@ -142,7 +142,7 @@ func TestNewAWSLogsClientUserAgentHandler(t *testing.T) {
)
assert.NilError(t, err)
_, err = client.CreateLogGroup(context.TODO(), &cloudwatchlogs.CreateLogGroupInput{LogGroupName: aws.String("foo")})
_, err = client.CreateLogGroup(t.Context(), &cloudwatchlogs.CreateLogGroupInput{LogGroupName: aws.String("foo")})
assert.NilError(t, err)
}
@@ -185,7 +185,7 @@ func TestNewAWSLogsClientLogFormatHeaderHandler(t *testing.T) {
)
assert.NilError(t, err)
_, err = client.CreateLogGroup(context.TODO(), &cloudwatchlogs.CreateLogGroupInput{LogGroupName: aws.String("foo")})
_, err = client.CreateLogGroup(t.Context(), &cloudwatchlogs.CreateLogGroupInput{LogGroupName: aws.String("foo")})
assert.NilError(t, err)
})
}
@@ -216,7 +216,7 @@ func TestNewAWSLogsClientAWSLogsEndpoint(t *testing.T) {
)
assert.NilError(t, err)
_, err = client.CreateLogGroup(context.TODO(), &cloudwatchlogs.CreateLogGroupInput{LogGroupName: aws.String("foo")})
_, err = client.CreateLogGroup(t.Context(), &cloudwatchlogs.CreateLogGroupInput{LogGroupName: aws.String("foo")})
assert.NilError(t, err)
// make sure the endpoint was actually hit
@@ -1713,7 +1713,7 @@ func TestNewAWSLogsClientCredentialEndpointDetect(t *testing.T) {
client, err := newAWSLogsClient(info)
assert.Check(t, err)
_, err = client.CreateLogGroup(context.TODO(), &cloudwatchlogs.CreateLogGroupInput{LogGroupName: aws.String("foo")})
_, err = client.CreateLogGroup(t.Context(), &cloudwatchlogs.CreateLogGroupInput{LogGroupName: aws.String("foo")})
assert.NilError(t, err)
assert.Check(t, credsRetrieved)

View File

@@ -3,7 +3,6 @@ package jsonfilelog
import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"io"
@@ -64,7 +63,7 @@ func BenchmarkJSONFileLoggerReadLogs(b *testing.B) {
}
}()
lw := jsonlogger.(*JSONFileLogger).ReadLogs(context.TODO(), logger.ReadConfig{Follow: true})
lw := jsonlogger.(*JSONFileLogger).ReadLogs(b.Context(), logger.ReadConfig{Follow: true})
for {
select {
case _, ok := <-lw.Msg:

View File

@@ -99,7 +99,7 @@ func TestTailFiles(t *testing.T) {
started := make(chan struct{})
go func() {
close(started)
tailFiles(context.TODO(), files, watcher, dec, tailReader, config.Tail, fwd)
tailFiles(t.Context(), files, watcher, dec, tailReader, config.Tail, fwd)
}()
<-started
@@ -167,7 +167,7 @@ func TestTailFiles(t *testing.T) {
done := make(chan struct{})
go func() {
close(started)
tailFiles(context.TODO(), files, watcher, &testJSONStreamDecoder{}, tailReader, config.Tail, fwd)
tailFiles(t.Context(), files, watcher, &testJSONStreamDecoder{}, tailReader, config.Tail, fwd)
close(done)
}()
@@ -250,7 +250,7 @@ func TestCheckCapacityAndRotate(t *testing.T) {
t.Run("with log reader", func(t *testing.T) {
// Make sure rotate works with an active reader
lw := l.ReadLogs(context.TODO(), logger.ReadConfig{Follow: true, Tail: 1000})
lw := l.ReadLogs(t.Context(), logger.ReadConfig{Follow: true, Tail: 1000})
defer lw.ConsumerGone()
assert.NilError(t, l.WriteLogEntry(timestamp, []byte("hello world 0!\n")), ls)

View File

@@ -93,7 +93,7 @@ func TestTmpfsDevShmNoDupMount(t *testing.T) {
}
d := setupFakeDaemon(t, c)
_, err := d.createSpec(context.TODO(), &configStore{}, c, nil)
_, err := d.createSpec(t.Context(), &configStore{}, c, nil)
assert.Check(t, err)
}
@@ -111,7 +111,7 @@ func TestIpcPrivateVsReadonly(t *testing.T) {
}
d := setupFakeDaemon(t, c)
s, err := d.createSpec(context.TODO(), &configStore{}, c, nil)
s, err := d.createSpec(t.Context(), &configStore{}, c, nil)
assert.Check(t, err)
// Find the /dev/shm mount in ms, check it does not have ro
@@ -127,6 +127,7 @@ func TestIpcPrivateVsReadonly(t *testing.T) {
// Config.Domainname) are overridden by an explicit sysctl in the HostConfig.
func TestSysctlOverride(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
ctx := t.Context()
c := &container.Container{
Config: &containertypes.Config{
Hostname: "foobar",
@@ -140,7 +141,7 @@ func TestSysctlOverride(t *testing.T) {
d := setupFakeDaemon(t, c)
// Ensure that the implicit sysctl is set correctly.
s, err := d.createSpec(context.TODO(), &configStore{}, c, nil)
s, err := d.createSpec(ctx, &configStore{}, c, nil)
assert.NilError(t, err)
assert.Equal(t, s.Hostname, "foobar")
assert.Equal(t, s.Linux.Sysctl["kernel.domainname"], c.Config.Domainname)
@@ -156,14 +157,14 @@ func TestSysctlOverride(t *testing.T) {
assert.Assert(t, c.HostConfig.Sysctls["kernel.domainname"] != c.Config.Domainname)
c.HostConfig.Sysctls["net.ipv4.ip_unprivileged_port_start"] = "1024"
s, err = d.createSpec(context.TODO(), &configStore{}, c, nil)
s, err = d.createSpec(ctx, &configStore{}, c, nil)
assert.NilError(t, err)
assert.Equal(t, s.Hostname, "foobar")
assert.Equal(t, s.Linux.Sysctl["kernel.domainname"], c.HostConfig.Sysctls["kernel.domainname"])
assert.Equal(t, s.Linux.Sysctl["net.ipv4.ip_unprivileged_port_start"], c.HostConfig.Sysctls["net.ipv4.ip_unprivileged_port_start"])
// Ensure the ping_group_range is not set on a daemon with user-namespaces enabled
s, err = d.createSpec(context.TODO(), &configStore{Config: config.Config{RemappedRoot: "dummy:dummy"}}, c, nil)
s, err = d.createSpec(ctx, &configStore{Config: config.Config{RemappedRoot: "dummy:dummy"}}, c, nil)
assert.NilError(t, err)
_, ok := s.Linux.Sysctl["net.ipv4.ping_group_range"]
assert.Assert(t, !ok)
@@ -171,7 +172,7 @@ func TestSysctlOverride(t *testing.T) {
// Ensure the ping_group_range is set on a container in "host" userns mode
// on a daemon with user-namespaces enabled
c.HostConfig.UsernsMode = "host"
s, err = d.createSpec(context.TODO(), &configStore{Config: config.Config{RemappedRoot: "dummy:dummy"}}, c, nil)
s, err = d.createSpec(ctx, &configStore{Config: config.Config{RemappedRoot: "dummy:dummy"}}, c, nil)
assert.NilError(t, err)
assert.Equal(t, s.Linux.Sysctl["net.ipv4.ping_group_range"], "0 2147483647")
}
@@ -180,6 +181,7 @@ func TestSysctlOverride(t *testing.T) {
// with host networking
func TestSysctlOverrideHost(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
ctx := t.Context()
c := &container.Container{
Config: &containertypes.Config{},
HostConfig: &containertypes.HostConfig{
@@ -190,7 +192,7 @@ func TestSysctlOverrideHost(t *testing.T) {
d := setupFakeDaemon(t, c)
// Ensure that the implicit sysctl is not set
s, err := d.createSpec(context.TODO(), &configStore{}, c, nil)
s, err := d.createSpec(ctx, &configStore{}, c, nil)
assert.NilError(t, err)
assert.Equal(t, s.Linux.Sysctl["net.ipv4.ip_unprivileged_port_start"], "")
assert.Equal(t, s.Linux.Sysctl["net.ipv4.ping_group_range"], "")
@@ -198,7 +200,7 @@ func TestSysctlOverrideHost(t *testing.T) {
// Set an explicit sysctl.
c.HostConfig.Sysctls["net.ipv4.ip_unprivileged_port_start"] = "1024"
s, err = d.createSpec(context.TODO(), &configStore{}, c, nil)
s, err = d.createSpec(ctx, &configStore{}, c, nil)
assert.NilError(t, err)
assert.Equal(t, s.Linux.Sysctl["net.ipv4.ip_unprivileged_port_start"], c.HostConfig.Sysctls["net.ipv4.ip_unprivileged_port_start"])
}

View File

@@ -25,7 +25,7 @@ func muteLogs(t *testing.T) {
func newDaemonForReloadT(t *testing.T, cfg *config.Config) *Daemon {
t.Helper()
daemon := &Daemon{
imageService: images.NewImageService(context.TODO(), images.ImageServiceConfig{}),
imageService: images.NewImageService(t.Context(), images.ImageServiceConfig{}),
}
var err error
daemon.registryService, err = registry.NewService(registry.ServiceOptions{})
@@ -63,7 +63,7 @@ func TestDaemonReloadLabels(t *testing.T) {
func TestDaemonReloadMirrors(t *testing.T) {
daemon := &Daemon{
imageService: images.NewImageService(context.TODO(), images.ImageServiceConfig{}),
imageService: images.NewImageService(t.Context(), images.ImageServiceConfig{}),
}
muteLogs(t)
@@ -162,7 +162,7 @@ func TestDaemonReloadMirrors(t *testing.T) {
func TestDaemonReloadInsecureRegistries(t *testing.T) {
daemon := &Daemon{
imageService: images.NewImageService(context.TODO(), images.ImageServiceConfig{}),
imageService: images.NewImageService(t.Context(), images.ImageServiceConfig{}),
}
muteLogs(t)

View File

@@ -29,7 +29,7 @@ func TestExecResizeNoSuchExec(t *testing.T) {
Container: c,
}
d.registerExecCommand(c, ec)
err := d.ContainerExecResize(context.TODO(), "no-such-exec", height, width)
err := d.ContainerExecResize(t.Context(), "no-such-exec", height, width)
assert.ErrorContains(t, err, "No such exec instance")
}
@@ -70,7 +70,7 @@ func TestExecResize(t *testing.T) {
close(ec.Started)
d.containers.Add(n, c)
d.registerExecCommand(c, ec)
err := d.ContainerExecResize(context.TODO(), n, height, width)
err := d.ContainerExecResize(t.Context(), n, height, width)
assert.NilError(t, err)
assert.Equal(t, mp.Width, width)
assert.Equal(t, mp.Height, height)
@@ -103,6 +103,6 @@ func TestExecResizeTimeout(t *testing.T) {
}
d.containers.Add(n, c)
d.registerExecCommand(c, ec)
err := d.ContainerExecResize(context.TODO(), n, height, width)
err := d.ContainerExecResize(t.Context(), n, height, width)
assert.ErrorContains(t, err, "timeout waiting for exec session ready")
}

View File

@@ -11,26 +11,26 @@ import (
func TestDockerUserAgent(t *testing.T) {
t.Run("daemon user-agent", func(t *testing.T) {
ua := DockerUserAgent(context.TODO())
ua := DockerUserAgent(t.Context())
expected := getDaemonUserAgent()
assert.Check(t, is.Equal(ua, expected))
})
t.Run("daemon user-agent custom metadata", func(t *testing.T) {
ua := DockerUserAgent(context.TODO(), useragent.VersionInfo{Name: "hello", Version: "world"}, useragent.VersionInfo{Name: "foo", Version: "bar"})
ua := DockerUserAgent(t.Context(), useragent.VersionInfo{Name: "hello", Version: "world"}, useragent.VersionInfo{Name: "foo", Version: "bar"})
expected := getDaemonUserAgent() + ` hello/world foo/bar`
assert.Check(t, is.Equal(ua, expected))
})
t.Run("daemon user-agent with upstream", func(t *testing.T) {
ctx := context.WithValue(context.TODO(), UAStringKey{}, "Magic-Client/1.2.3 (linux)")
ctx := context.WithValue(t.Context(), UAStringKey{}, "Magic-Client/1.2.3 (linux)")
ua := DockerUserAgent(ctx)
expected := getDaemonUserAgent() + ` UpstreamClient(Magic-Client/1.2.3 \(linux\))`
assert.Check(t, is.Equal(ua, expected))
})
t.Run("daemon user-agent with upstream and custom metadata", func(t *testing.T) {
ctx := context.WithValue(context.TODO(), UAStringKey{}, "Magic-Client/1.2.3 (linux)")
ctx := context.WithValue(t.Context(), UAStringKey{}, "Magic-Client/1.2.3 (linux)")
ua := DockerUserAgent(ctx, useragent.VersionInfo{Name: "hello", Version: "world"}, useragent.VersionInfo{Name: "foo", Version: "bar"})
expected := getDaemonUserAgent() + ` hello/world foo/bar UpstreamClient(Magic-Client/1.2.3 \(linux\))`
assert.Check(t, is.Equal(ua, expected))

View File

@@ -957,7 +957,7 @@ func TestEmptyPortBindingsBC(t *testing.T) {
// Skip this subtest if the daemon doesn't support the client version.
// TODO(aker): drop this once the Engine supports API version >= 1.53
_, err := apiClient.ServerVersion(context.TODO())
_, err := apiClient.ServerVersion(ctx)
if err != nil && strings.Contains(err.Error(), fmt.Sprintf("client version %s is too new", version)) {
t.Skipf("requires API %s", version)
}