diff --git a/daemon/volume/safepath/join_test.go b/daemon/volume/safepath/join_test.go index c1e5b93886..651fff884e 100644 --- a/daemon/volume/safepath/join_test.go +++ b/daemon/volume/safepath/join_test.go @@ -1,7 +1,6 @@ package safepath import ( - "context" "os" "path/filepath" "runtime" @@ -41,9 +40,9 @@ func TestJoinEscapingSymlink(t *testing.T) { err = os.Symlink(tc.target, filepath.Join(dir, "link")) assert.NilError(t, err, "failed to create symlink to %s", tc.target) - safe, err := Join(context.Background(), dir, "link") + safe, err := Join(t.Context(), dir, "link") if err == nil { - safe.Close(context.Background()) + safe.Close(t.Context()) } assert.ErrorType(t, err, &ErrEscapesBase{}) }) @@ -71,10 +70,10 @@ func TestJoinGoodSymlink(t *testing.T) { "subdir_link_relative", "foo_link_relative", } { t.Run(target, func(t *testing.T) { - safe, err := Join(context.Background(), dir, target) + safe, err := Join(t.Context(), dir, target) assert.NilError(t, err) - defer safe.Close(context.Background()) + defer safe.Close(t.Context()) if strings.HasPrefix(target, "subdir") { data, err := os.ReadFile(filepath.Join(safe.Path(), "hello.txt")) assert.NilError(t, err) @@ -98,10 +97,10 @@ func TestJoinWithSymlinkReplace(t *testing.T) { err = os.Symlink(target, link) assert.Check(t, err, "failed to create symlink to foo") - safe, err := Join(context.Background(), dir, "link") + safe, err := Join(t.Context(), dir, "link") assert.NilError(t, err) - defer safe.Close(context.Background()) + defer safe.Close(t.Context()) // Delete the link target. err = os.Remove(target) @@ -133,12 +132,12 @@ func TestJoinCloseInvalidates(t *testing.T) { err = os.WriteFile(foo, []byte("bar"), 0o744) assert.NilError(t, err, "failed to create test file") - safe, err := Join(context.Background(), dir, "foo") + safe, err := Join(t.Context(), dir, "foo") assert.NilError(t, err) assert.Check(t, safe.IsValid()) - assert.NilError(t, safe.Close(context.Background())) + assert.NilError(t, safe.Close(t.Context())) assert.Check(t, !safe.IsValid()) } diff --git a/daemon/volume/service/restore_test.go b/daemon/volume/service/restore_test.go index ec1246c1f3..10c95333d0 100644 --- a/daemon/volume/service/restore_test.go +++ b/daemon/volume/service/restore_test.go @@ -1,7 +1,6 @@ package service import ( - "context" "testing" "github.com/moby/moby/v2/daemon/volume" @@ -24,7 +23,7 @@ func TestRestore(t *testing.T) { assert.NilError(t, err) defer s.Shutdown() - ctx := context.Background() + ctx := t.Context() _, err = s.Create(ctx, "test1", driverName) assert.NilError(t, err) diff --git a/daemon/volume/service/service_linux_test.go b/daemon/volume/service/service_linux_test.go index d459684325..24276019ea 100644 --- a/daemon/volume/service/service_linux_test.go +++ b/daemon/volume/service/service_linux_test.go @@ -1,7 +1,6 @@ package service import ( - "context" "os" "path/filepath" "testing" @@ -30,7 +29,7 @@ func TestLocalVolumeSize(t *testing.T) { service, cleanup := newTestService(t, ds) defer cleanup() - ctx := context.Background() + ctx := t.Context() v1, err := service.Create(ctx, "test1", volume.DefaultDriverName, opts.WithCreateReference("foo")) assert.NilError(t, err) v2, err := service.Create(ctx, "test2", volume.DefaultDriverName) diff --git a/daemon/volume/service/service_test.go b/daemon/volume/service/service_test.go index 30a6d54e33..4e3227f21b 100644 --- a/daemon/volume/service/service_test.go +++ b/daemon/volume/service/service_test.go @@ -1,7 +1,6 @@ package service import ( - "context" "testing" cerrdefs "github.com/containerd/errdefs" @@ -22,7 +21,7 @@ func TestServiceCreate(t *testing.T) { assert.Assert(t, ds.Register(testutils.NewFakeDriver("d1"), "d1")) assert.Assert(t, ds.Register(testutils.NewFakeDriver("d2"), "d2")) - ctx := context.Background() + ctx := t.Context() service, cleanup := newTestService(t, ds) defer cleanup() @@ -57,7 +56,7 @@ func TestServiceList(t *testing.T) { service, cleanup := newTestService(t, ds) defer cleanup() - ctx := context.Background() + ctx := t.Context() _, err := service.Create(ctx, "v1", "d1") assert.NilError(t, err) @@ -110,7 +109,7 @@ func TestServiceRemove(t *testing.T) { service, cleanup := newTestService(t, ds) defer cleanup() - ctx := context.Background() + ctx := t.Context() _, err := service.Create(ctx, "test", "d1") assert.NilError(t, err) @@ -127,7 +126,7 @@ func TestServiceGet(t *testing.T) { service, cleanup := newTestService(t, ds) defer cleanup() - ctx := context.Background() + ctx := t.Context() v, err := service.Get(ctx, "notexist") assert.Assert(t, IsNotExist(err)) @@ -165,7 +164,7 @@ func TestServicePrune(t *testing.T) { service, cleanup := newTestService(t, ds) defer cleanup() - ctx := context.Background() + ctx := t.Context() _, err := service.Create(ctx, "test", volume.DefaultDriverName) assert.NilError(t, err) diff --git a/daemon/volume/service/store_test.go b/daemon/volume/service/store_test.go index a71ac4fc98..00fd7590e2 100644 --- a/daemon/volume/service/store_test.go +++ b/daemon/volume/service/store_test.go @@ -1,7 +1,6 @@ package service import ( - "context" "errors" "fmt" "net" @@ -23,7 +22,7 @@ func TestCreate(t *testing.T) { defer cleanup() s.drivers.Register(volumetestutils.NewFakeDriver("fake"), "fake") - ctx := context.Background() + ctx := t.Context() v, err := s.Create(ctx, "fake1", "fake") if err != nil { t.Fatal(err) @@ -55,7 +54,7 @@ func TestRemove(t *testing.T) { s.drivers.Register(volumetestutils.NewFakeDriver("fake"), "fake") s.drivers.Register(volumetestutils.NewFakeDriver("noop"), "noop") - ctx := context.Background() + ctx := t.Context() // doing string compare here since this error comes directly from the driver expected := "no such volume" @@ -92,7 +91,7 @@ func TestList(t *testing.T) { s, err := NewStore(tmpDir, drivers) assert.NilError(t, err) - ctx := context.Background() + ctx := t.Context() if _, err := s.Create(ctx, "test", "fake"); err != nil { t.Fatal(err) } @@ -134,7 +133,7 @@ func TestFindByDriver(t *testing.T) { assert.Assert(t, s.drivers.Register(volumetestutils.NewFakeDriver("fake"), "fake")) assert.Assert(t, s.drivers.Register(volumetestutils.NewFakeDriver("noop"), "noop")) - ctx := context.Background() + ctx := t.Context() _, err := s.Create(ctx, "fake1", "fake") assert.NilError(t, err) @@ -165,7 +164,7 @@ func TestFindByReferenced(t *testing.T) { s.drivers.Register(volumetestutils.NewFakeDriver("fake"), "fake") s.drivers.Register(volumetestutils.NewFakeDriver("noop"), "noop") - ctx := context.Background() + ctx := t.Context() if _, err := s.Create(ctx, "fake1", "fake", opts.WithCreateReference("volReference")); err != nil { t.Fatal(err) } @@ -190,7 +189,7 @@ func TestDerefMultipleOfSameRef(t *testing.T) { defer cleanup() s.drivers.Register(volumetestutils.NewFakeDriver("fake"), "fake") - ctx := context.Background() + ctx := t.Context() v, err := s.Create(ctx, "fake1", "fake", opts.WithCreateReference("volReference")) if err != nil { t.Fatal(err) @@ -219,7 +218,7 @@ func TestCreateKeepOptsLabelsWhenExistsRemotely(t *testing.T) { t.Fatal(err) } - ctx := context.Background() + ctx := t.Context() v, err := s.Create(ctx, "foo", "fake", opts.WithCreateLabels(map[string]string{"hello": "world"})) if err != nil { t.Fatal(err) @@ -263,7 +262,7 @@ func TestDefererencePluginOnCreateError(t *testing.T) { pg := volumetestutils.NewFakePluginGetter(p) s.drivers = volumedrivers.NewStore(pg) - ctx := context.Background() + ctx := t.Context() // create a good volume so we have a plugin reference _, err = s.Create(ctx, "fake1", d.Name()) if err != nil { @@ -290,7 +289,7 @@ func TestRefDerefRemove(t *testing.T) { defer cleanup() s.drivers.Register(volumetestutils.NewFakeDriver(driverName), driverName) - ctx := context.Background() + ctx := t.Context() v, err := s.Create(ctx, "test", driverName, opts.WithCreateReference("test-ref")) assert.NilError(t, err) @@ -311,7 +310,7 @@ func TestGet(t *testing.T) { defer cleanup() s.drivers.Register(volumetestutils.NewFakeDriver(driverName), driverName) - ctx := context.Background() + ctx := t.Context() _, err := s.Get(ctx, "not-exist") assert.ErrorContains(t, err, "") assert.Equal(t, errNoSuchVolume, err.(*OpErr).Err) @@ -338,7 +337,7 @@ func TestGetWithReference(t *testing.T) { defer cleanup() s.drivers.Register(volumetestutils.NewFakeDriver(driverName), driverName) - ctx := context.Background() + ctx := t.Context() _, err := s.Get(ctx, "not-exist", opts.WithGetDriver(driverName), opts.WithGetReference("test-ref")) assert.ErrorContains(t, err, "")