Browse code

daemon/containerd: use t.Context() in tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/09/26 02:26:56
Showing 7 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 package containerd
2 2
 
3 3
 import (
4
-	"context"
5 4
 	"testing"
6 5
 
7 6
 	c8dimages "github.com/containerd/containerd/v2/core/images"
... ...
@@ -17,7 +16,7 @@ import (
17 17
 )
18 18
 
19 19
 func TestImageDelete(t *testing.T) {
20
-	ctx := namespaces.WithNamespace(context.TODO(), "testing")
20
+	ctx := namespaces.WithNamespace(t.Context(), "testing")
21 21
 
22 22
 	for _, tc := range []struct {
23 23
 		ref       string
... ...
@@ -1,7 +1,6 @@
1 1
 package containerd
2 2
 
3 3
 import (
4
-	"context"
5 4
 	"fmt"
6 5
 	"path/filepath"
7 6
 	"testing"
... ...
@@ -17,7 +16,7 @@ import (
17 17
 )
18 18
 
19 19
 func TestImageInspect(t *testing.T) {
20
-	ctx := namespaces.WithNamespace(context.TODO(), "testing")
20
+	ctx := namespaces.WithNamespace(t.Context(), "testing")
21 21
 
22 22
 	blobsDir := t.TempDir()
23 23
 
... ...
@@ -89,7 +89,7 @@ func BenchmarkImageList(b *testing.B) {
89 89
 	for _, count := range []int{10, 100, 1000} {
90 90
 		csDir := b.TempDir()
91 91
 
92
-		ctx := namespaces.WithNamespace(context.TODO(), "testing-"+strconv.Itoa(count))
92
+		ctx := namespaces.WithNamespace(b.Context(), "testing-"+strconv.Itoa(count))
93 93
 
94 94
 		cs := &delayedStore{
95 95
 			store:    &blobsDirContentStore{blobs: filepath.Join(csDir, "blobs/sha256")},
... ...
@@ -113,7 +113,7 @@ func BenchmarkImageList(b *testing.B) {
113 113
 }
114 114
 
115 115
 func TestImageListCheckTotalSize(t *testing.T) {
116
-	ctx := namespaces.WithNamespace(context.TODO(), "testing")
116
+	ctx := namespaces.WithNamespace(t.Context(), "testing")
117 117
 
118 118
 	blobsDir := t.TempDir()
119 119
 	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
209 209
 }
210 210
 
211 211
 func TestImageList(t *testing.T) {
212
-	ctx := namespaces.WithNamespace(context.TODO(), "testing")
212
+	ctx := namespaces.WithNamespace(t.Context(), "testing")
213 213
 
214 214
 	blobsDir := t.TempDir()
215 215
 
... ...
@@ -30,7 +30,7 @@ func TestImageLoad(t *testing.T) {
30 30
 	linuxArmv5 := ocispec.Platform{OS: "linux", Architecture: "arm", Variant: "v5"}
31 31
 	linuxRiscv64 := ocispec.Platform{OS: "linux", Architecture: "riskv64"}
32 32
 
33
-	ctx := namespaces.WithNamespace(context.TODO(), "testing-"+t.Name())
33
+	ctx := namespaces.WithNamespace(t.Context(), "testing-"+t.Name())
34 34
 
35 35
 	store, err := local.NewLabeledStore(t.TempDir(), &labelstore.InMemory{})
36 36
 	assert.NilError(t, err)
... ...
@@ -27,7 +27,7 @@ type pushTestCase struct {
27 27
 }
28 28
 
29 29
 func TestImagePushIndex(t *testing.T) {
30
-	ctx := namespaces.WithNamespace(context.TODO(), "testing-"+t.Name())
30
+	ctx := namespaces.WithNamespace(t.Context(), "testing-"+t.Name())
31 31
 
32 32
 	csDir := t.TempDir()
33 33
 	store := &blobsDirContentStore{blobs: filepath.Join(csDir, "blobs/sha256")}
... ...
@@ -1,7 +1,6 @@
1 1
 package containerd
2 2
 
3 3
 import (
4
-	"context"
5 4
 	"io"
6 5
 	"path/filepath"
7 6
 	"testing"
... ...
@@ -16,7 +15,7 @@ import (
16 16
 )
17 17
 
18 18
 func TestImageMultiplatformSaveShallowWithNative(t *testing.T) {
19
-	ctx := namespaces.WithNamespace(context.TODO(), "testing-"+t.Name())
19
+	ctx := namespaces.WithNamespace(t.Context(), "testing-"+t.Name())
20 20
 
21 21
 	contentDir := t.TempDir()
22 22
 	store := &blobsDirContentStore{blobs: filepath.Join(contentDir, "blobs/sha256")}
... ...
@@ -72,7 +71,7 @@ func TestImageMultiplatformSaveShallowWithNative(t *testing.T) {
72 72
 }
73 73
 
74 74
 func TestImageMultiplatformSaveShallowWithoutNative(t *testing.T) {
75
-	ctx := namespaces.WithNamespace(context.TODO(), "testing-"+t.Name())
75
+	ctx := namespaces.WithNamespace(t.Context(), "testing-"+t.Name())
76 76
 
77 77
 	contentDir := t.TempDir()
78 78
 	store := &blobsDirContentStore{blobs: filepath.Join(contentDir, "blobs/sha256")}
... ...
@@ -24,7 +24,7 @@ import (
24 24
 )
25 25
 
26 26
 func TestLookup(t *testing.T) {
27
-	ctx := namespaces.WithNamespace(context.TODO(), "testing")
27
+	ctx := namespaces.WithNamespace(t.Context(), "testing")
28 28
 	ctx = logtest.WithT(ctx, t)
29 29
 	mdb := newTestDB(ctx, t)
30 30
 	service := &ImageService{