daemon: use t.Context
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
8 files changed
+18
-23
No files matched your search
@@ -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", "")
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
+8
-9
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user