From aed9f8e7eefbae6a5b238e093a77331bfd9e1b78 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Sep 2026 14:01:58 +0200 Subject: [PATCH] daemon: use t.Context Signed-off-by: Sebastiaan van Stijn --- daemon/checkpoint_test.go | 3 +-- daemon/exec_linux_test.go | 5 ++--- daemon/images/store_test.go | 2 +- daemon/list_test.go | 17 ++++++++--------- daemon/migration_test.go | 2 +- daemon/mounts_test.go | 4 ++-- daemon/oci_linux_test.go | 5 ++--- daemon/reload_test.go | 3 +-- 8 files changed, 18 insertions(+), 23 deletions(-) diff --git a/daemon/checkpoint_test.go b/daemon/checkpoint_test.go index c98a1e7d4c..89f58a81c6 100644 --- a/daemon/checkpoint_test.go +++ b/daemon/checkpoint_test.go @@ -1,7 +1,6 @@ package daemon import ( - "context" "path/filepath" "runtime" "testing" @@ -77,7 +76,7 @@ func TestCheckpointOperationsValidateBeforeContainerLookup(t *testing.T) { { name: "restore", operation: func() error { - return daemon.ContainerStart(context.Background(), "missing", "../outside", "") + return daemon.ContainerStart(t.Context(), "missing", "../outside", "") }, }, } diff --git a/daemon/exec_linux_test.go b/daemon/exec_linux_test.go index 51ace6ca45..1e71d342d3 100644 --- a/daemon/exec_linux_test.go +++ b/daemon/exec_linux_test.go @@ -3,7 +3,6 @@ package daemon import ( - "context" "os" "path/filepath" "testing" @@ -32,7 +31,7 @@ func TestExecSetPlatformOptPreservesUmaskWhenResolvingUser(t *testing.T) { p := &specs.Process{User: specs.User{Umask: &umask}} cfg := &configStore{} - err := (&Daemon{}).execSetPlatformOpt(context.Background(), &cfg.Config, ec, p) + err := (&Daemon{}).execSetPlatformOpt(t.Context(), &cfg.Config, ec, p) assert.NilError(t, err) assert.Equal(t, p.User.UID, uint32(1234)) assert.Equal(t, p.User.GID, uint32(5678)) @@ -108,7 +107,7 @@ func TestExecSetPlatformOptAppArmor(t *testing.T) { ec := &container.ExecConfig{Container: c, Privileged: execPrivileged} p := &specs.Process{} - err := d.execSetPlatformOpt(context.Background(), &cfg.Config, ec, p) + err := d.execSetPlatformOpt(t.Context(), &cfg.Config, ec, p) assert.NilError(t, err) assert.Equal(t, p.ApparmorProfile, tc.expectedProfile) }) diff --git a/daemon/images/store_test.go b/daemon/images/store_test.go index 261a326eaf..be2cc59364 100644 --- a/daemon/images/store_test.go +++ b/daemon/images/store_test.go @@ -40,7 +40,7 @@ func setupTestStores(t *testing.T) (context.Context, content.Store, *imageStoreW assert.Check(t, db.Close()) assert.Check(t, os.RemoveAll(dir)) } - ctx := namespaces.WithNamespace(context.Background(), t.Name()) + ctx := namespaces.WithNamespace(t.Context(), t.Name()) images := &imageStoreWithLease{Store: imgStore, ns: t.Name(), leases: metadata.NewLeaseManager(mdb)} return ctx, cs, images, cleanup diff --git a/daemon/list_test.go b/daemon/list_test.go index 56732572d6..01b5033d45 100644 --- a/daemon/list_test.go +++ b/daemon/list_test.go @@ -1,7 +1,6 @@ package daemon import ( - "context" "fmt" "os" "path/filepath" @@ -110,7 +109,7 @@ func TestContainerList(t *testing.T) { } // list them and verify correctness - containerList, err := d.Containers(context.Background(), &backend.ContainerListOptions{All: true}) + containerList, err := d.Containers(t.Context(), &backend.ContainerListOptions{All: true}) assert.NilError(t, err) assert.Assert(t, is.Len(containerList, num)) @@ -129,7 +128,7 @@ func TestContainerList_InvalidFilter(t *testing.T) { containersReplica: db, } - _, err = d.Containers(context.Background(), &backend.ContainerListOptions{ + _, err = d.Containers(t.Context(), &backend.ContainerListOptions{ Filters: filters.NewArgs(filters.Arg("invalid", "foo")), }) assert.Assert(t, is.Error(err, "invalid filter 'invalid'")) @@ -150,7 +149,7 @@ func TestContainerList_NameFilter(t *testing.T) { // moby/moby #37453 - ^ regex not working due to prefix slash // not being stripped - containerList, err := d.Containers(context.Background(), &backend.ContainerListOptions{ + containerList, err := d.Containers(t.Context(), &backend.ContainerListOptions{ Filters: filters.NewArgs(filters.Arg("name", "^a")), }) assert.NilError(t, err) @@ -159,7 +158,7 @@ func TestContainerList_NameFilter(t *testing.T) { assert.Assert(t, containerListContainsName(containerList, two.Name)) // Same as above but with slash prefix should produce the same result - containerListWithPrefix, err := d.Containers(context.Background(), &backend.ContainerListOptions{ + containerListWithPrefix, err := d.Containers(t.Context(), &backend.ContainerListOptions{ Filters: filters.NewArgs(filters.Arg("name", "^/a")), }) assert.NilError(t, err) @@ -168,7 +167,7 @@ func TestContainerList_NameFilter(t *testing.T) { assert.Assert(t, containerListContainsName(containerListWithPrefix, two.Name)) // Same as above but make sure it works for exact names - containerList, err = d.Containers(context.Background(), &backend.ContainerListOptions{ + containerList, err = d.Containers(t.Context(), &backend.ContainerListOptions{ Filters: filters.NewArgs(filters.Arg("name", "b1")), }) assert.NilError(t, err) @@ -176,7 +175,7 @@ func TestContainerList_NameFilter(t *testing.T) { assert.Assert(t, containerListContainsName(containerList, three.Name)) // Same as above but with slash prefix should produce the same result - containerListWithPrefix, err = d.Containers(context.Background(), &backend.ContainerListOptions{ + containerListWithPrefix, err = d.Containers(t.Context(), &backend.ContainerListOptions{ Filters: filters.NewArgs(filters.Arg("name", "/b1")), }) assert.NilError(t, err) @@ -234,7 +233,7 @@ func TestContainerList_AnnotationFilter(t *testing.T) { for _, tc := range tests { t.Run(tc.doc, func(t *testing.T) { - containerList, err := d.Containers(context.Background(), &backend.ContainerListOptions{ + containerList, err := d.Containers(t.Context(), &backend.ContainerListOptions{ All: true, Filters: filters.NewArgs(tc.filters...), }) @@ -280,7 +279,7 @@ func TestContainerList_LimitFilter(t *testing.T) { for _, tc := range tests { t.Run(tc.doc, func(t *testing.T) { - containerList, err := d.Containers(context.Background(), &backend.ContainerListOptions{Limit: tc.limit}) + containerList, err := d.Containers(t.Context(), &backend.ContainerListOptions{Limit: tc.limit}) assert.NilError(t, err) expectedListLen := num if tc.limit > 0 { diff --git a/daemon/migration_test.go b/daemon/migration_test.go index a294764b33..8513550367 100644 --- a/daemon/migration_test.go +++ b/daemon/migration_test.go @@ -164,7 +164,7 @@ func TestContainerMigrateOS(t *testing.T) { } { ctr := tc.ctr t.Run(tc.name, func(t *testing.T) { - migrateContainerOS(context.Background(), mock, &ctr) + migrateContainerOS(t.Context(), mock, &ctr) assert.DeepEqual(t, tc.expected, ctr.ImagePlatform) }) diff --git a/daemon/mounts_test.go b/daemon/mounts_test.go index 47faeeff4d..e90e3e4f28 100644 --- a/daemon/mounts_test.go +++ b/daemon/mounts_test.go @@ -34,7 +34,7 @@ func TestPrepareMountPointsSerializesLiveRestoreWithCleanup(t *testing.T) { cleanupBeforeRestore := ctr.TryLock() var cleanupErr error if cleanupBeforeRestore { - cleanupErr = mountPoint.Cleanup(context.Background()) + cleanupErr = mountPoint.Cleanup(t.Context()) ctr.Unlock() } @@ -43,7 +43,7 @@ func TestPrepareMountPointsSerializesLiveRestoreWithCleanup(t *testing.T) { if !cleanupBeforeRestore { ctr.Lock() - cleanupErr = mountPoint.Cleanup(context.Background()) + cleanupErr = mountPoint.Cleanup(t.Context()) ctr.Unlock() } assert.NilError(t, cleanupErr) diff --git a/daemon/oci_linux_test.go b/daemon/oci_linux_test.go index 59d3975364..458946d5b3 100644 --- a/daemon/oci_linux_test.go +++ b/daemon/oci_linux_test.go @@ -1,7 +1,6 @@ package daemon import ( - "context" "maps" "os" "path/filepath" @@ -31,7 +30,7 @@ func setupFakeDaemon(t *testing.T, c *container.Container) *Daemon { err := os.MkdirAll(rootfs, 0o755) assert.NilError(t, err) - netController, err := libnetwork.New(context.Background(), nwconfig.OptionDataDir(t.TempDir())) + netController, err := libnetwork.New(t.Context(), nwconfig.OptionDataDir(t.TempDir())) assert.NilError(t, err) d := &Daemon{ @@ -380,7 +379,7 @@ func TestDefaultResources(t *testing.T) { } d := setupFakeDaemon(t, c) - s, err := d.createSpec(context.Background(), &configStore{}, c, nil) + s, err := d.createSpec(t.Context(), &configStore{}, c, nil) assert.NilError(t, err) checkResourcesAreUnset(t, s.Linux.Resources) } diff --git a/daemon/reload_test.go b/daemon/reload_test.go index 4a862e493a..defdbb768a 100644 --- a/daemon/reload_test.go +++ b/daemon/reload_test.go @@ -1,7 +1,6 @@ package daemon import ( - "context" "net/netip" "os" "testing" @@ -355,7 +354,7 @@ func TestDaemonReloadNetworkDiagnosticPort(t *testing.T) { if err != nil { t.Fatal(err) } - controller, err := libnetwork.New(context.Background(), netOptions...) + controller, err := libnetwork.New(t.Context(), netOptions...) if err != nil { t.Fatal(err) }